source: main/ngren.theme/trunk/ngren/theme/browser/featured.py @ 12777

Last change on this file since 12777 was 11763, checked in by Henrik Bettermann, 10 years ago

Avoid confusion of meaning of frontpage items.

File size: 2.0 KB
Line 
1from five import grok
2from zope import schema
3
4from plone.directives import form, dexterity
5
6from plone.app.textfield import RichText
7from plone.namedfile.field import NamedImage
8
9from ngren.theme import _
10
11from plone.dexterity.content import Item, Container
12
13from plone.app.layout.viewlets.common import ViewletBase
14from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
15from Products.CMFCore.utils import getToolByName
16from frontpagecontent import IFrontpageContent
17from zope.app.component.hooks import getSite
18
19
20class IFeatured(form.Schema):
21    """A Featured box which will be displayed in the Featured Gallery
22    """
23    title = schema.TextLine( title=_(u"Title"), required=True )
24    headline = schema.TextLine( title=_(u"Headline"), required=True )
25    picture = NamedImage(title=_(u"Featured Box Image"), description=_(u"Please upload an image"), required=False)
26    text = schema.TextLine( title=_(u"Text"), required=False)
27    link = schema.TextLine(title=_(u"Link"), required=False)
28
29class Featured( Item ):
30    grok.implements(IFeatured)
31
32    def __init__(self, *args):
33        super(Featured, self).__init__(*args)
34        self.exclude_from_nav = True       
35
36               
37               
38               
39class FeaturedViewlet(ViewletBase):
40        index = ViewPageTemplateFile('templates/featuredviewlet.pt')
41       
42        def update(self):
43                self.featured_items = []
44                portal = getSite()
45                catalog = getToolByName(portal, "portal_catalog")
46                path = "/".join(portal.getPhysicalPath())
47                frontpagecontents = catalog.searchResults(
48                        object_provides=IFrontpageContent.__identifier__,
49                        path={'query':path, 'depth':1},
50                        sort_on='getObjPositionInParent')
51
52                if len(frontpagecontents) > 0:
53                        path2 = "/".join(frontpagecontents[0].getObject().getPhysicalPath())
54                        featured = catalog.searchResults(
55                                object_provides=IFeatured.__identifier__,
56                                path={'query':path2, 'depth':1},
57                                sort_on='getObjPositionInParent',
58                                review_state='published')
59               
60                        self.featured_items = [i.getObject() for i in featured]
61                        if len(self.featured_items) > 2:
62                                self.featured_items = self.featured_items[:2]
Note: See TracBrowser for help on using the repository browser.