source: main/ngren.theme/branches/ulif-user-dropdown/ngren/theme/browser/featured.py @ 10235

Last change on this file since 10235 was 10190, checked in by uli, 11 years ago

Add original theme as delivered by Fafalter.

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 Banner which will be displayed in the Gallery Container
22    """
23    title = schema.TextLine( title=_(u"Title"), required=True )
24    headline = schema.TextLine( title=_(u"Headline Text"), required=True )
25    picture = NamedImage(title=_(u"Banner"), 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.