1 | from five import grok |
---|
2 | from zope import schema |
---|
3 | |
---|
4 | from plone.directives import form, dexterity |
---|
5 | |
---|
6 | from plone.app.textfield import RichText |
---|
7 | from plone.namedfile.field import NamedImage |
---|
8 | |
---|
9 | from ngren.theme import _ |
---|
10 | |
---|
11 | from plone.dexterity.content import Item, Container |
---|
12 | |
---|
13 | from plone.app.layout.viewlets.common import ViewletBase |
---|
14 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
15 | from Products.CMFCore.utils import getToolByName |
---|
16 | from frontpagecontent import IFrontpageContent |
---|
17 | from zope.app.component.hooks import getSite |
---|
18 | |
---|
19 | |
---|
20 | class 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 | |
---|
29 | class 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 | |
---|
39 | class 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] |
---|