示例#1
0
class Index(dexterity.DisplayForm):
    grok.context(IActivity)
    grok.require('zope2.View')
    grok.template('activity_view')
    grok.name('view')

    def update(self):
        self.rels = IActivityRelation(self.context)

    def related_news(self):
        return self.rels.related_news()[:3]
    
    def related_events(self):
        items = self.rels.related_events()
        current = datetime.datetime.now().strftime("%Y-%m-%d %H:%m")
        brains = []
        objects = []
        if items:
            for item in items:
                if item.start_date and item.end_date:
                    if item.start_date.strftime("%Y-%m-%d %H:%m") >= current  or current <= item.end_date.strftime("%Y-%m-%d %H:%m"):
                        brains.append({'start':item.start_date.strftime("%Y-%m-%d %H:%m"), 'obj':item})
        if brains:
            brains.sort(key=lambda val: val['start'])
            objects = [x['obj'] for x in brains]
        
        return objects[:3]

    def related_documents(self):
        return self.rels.related_documents()[:3]
示例#2
0
    def query(self):
        rels = IActivityRelation(aq_parent(self).obj)

        limit = int(self.request.get('limit', 20))

        def _should_include(obj):
            category = self.request.get('category', '')
            if not category:
                return True
            for subject in o.Subject():
                if subject.lower().strip() == category.lower().strip():
                    return True
            return False

        return [IJsonProvider(o).to_dict() for o in (
            rels.related_news()[:limit]) if _should_include(o)]
示例#3
0
    def query(self):
        rels = IActivityRelation(aq_parent(self).obj)

        limit = int(self.request.get('limit', 20))

        def _should_include(obj):
            category = self.request.get('category', '')
            if not category:
                return True
            for subject in o.Subject():
                if subject.lower().strip() == category.lower().strip():
                    return True
            return False

        return [
            IJsonProvider(o).to_dict() for o in (rels.related_news()[:limit])
            if _should_include(o)
        ]
示例#4
0
 def update(self):
     rels = IActivityRelation(self.context)
     self.items = rels.related_news()
示例#5
0
 def update(self):
     self.rels = IActivityRelation(self.context)