# -*- coding: utf-8 from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField from Products.Archetypes.public import FileWidget from Products.Archetypes.public import BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from Common import CommonMix schema = BaseSchema import time import datetime class Dashboard(BaseContent, CommonMix): """ Dashboard """ meta_type = "Dashboard" archetype_name = "Dashboard" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/dashboard_view', 'permissions': ('View',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Access Denied',), }, ) aliases = { '(Default)' : '', 'view' : 'base_view', 'edit' : 'base_edit', } def __init__(self, id): self.id = id self.largeIcon = "groups.gif" def getLargeIcon(self): """ returns large icon name """ return self.largeIcon def getUserEntries(self): """ """ user = str(self.REQUEST.AUTHENTICATED_USER) pc = getToolByName(self, 'portal_catalog') from config import BLOG_TYPES res = pc({'portal_type':BLOG_TYPES, 'Creator':user}, sort_order='descending') entries = [] ent_dates=[] for x in res: x = x.getObject() comments = x.getReplyReplies(x) for com in comments: c = {} comment = com['object'] date = comment.Date() c['entry'] = x c['obj'] = comment c['date'] = comment.Date() entries.append(c) ent_date_int = int(time.mktime(time.strptime(date, '%Y-%m-%d %H:%M:%S'))) ent_dates.append(ent_date_int) ent_dates.sort() ent_dates.reverse() ent = [] for d in ent_dates: for e in entries: e_date = int(time.mktime(time.strptime(e['date'], '%Y-%m-%d %H:%M:%S'))) if d == e_date: ent.append(e) return ent def setGroupsBoxRange(self): """ """ today = datetime.date.today() date = time.strptime(str(today), "%Y-%m-%d") year = int(time.strftime("%Y", date)) month = time.strftime("%m", date) day = time.strftime("%d", date) interval = self.REQUEST.get('interval', '') if interval == 'day': self.range = 'day' today = int(time.mktime(date)) beg = today - 86400 if interval == 'week': self.range = 'week' today = int(time.mktime(date)) beg = today - 604800 if interval == 'month': self.range = 'month' print int(month) if int(month) == 1: month = 12 else: month = int(month) - 1 print month beg = str(year)+'-'+str(month)+'-'+str(day) beg = int(time.mktime(time.strptime(beg, '%Y-%m-%d'))) if interval == 'year': self.range = 'year' year = year - 1 beg = str(year)+'-'+str(month)+'-'+str(day) beg = int(time.mktime(time.strptime(beg, '%Y-%m-%d'))) self.newdate = beg return self.REQUEST.RESPONSE.redirect(self.absolute_url()) def getGroupsBoxRange(self): if not hasattr(self, 'range'): self.range = 'week' return self.range def getInterval(self): if not hasattr(self, 'newdate'): today = datetime.date.today() date = time.strptime(str(today), "%Y-%m-%d") todayInt = int(time.mktime(date)) beg = todayInt - 604800 self.newdate = beg return self.newdate def getGroupNotes(self, group): """ """ beg = self.getInterval() pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':'GroupNote'}, sort_order='descending') notes=[] for x in res: mod = x.ModificationDate path = x.getPath() path = path.split('/') mod = time.strptime(mod, '%Y-%m-%d %H:%M:%S') mod = time.strftime('%Y-%m-%d', mod) mod = int(time.mktime(time.strptime(mod, '%Y-%m-%d'))) if mod > beg and path[-3] == str(group): notes.append(x) return [x.getObject() for x in notes] def getGroupForumTopics(self, group): """ """ beg = self.getInterval() pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':'ForumTopicFolder'}, sort_order='descending') topics = [] for x in res: mod = x.ModificationDate path = x.getPath() path = path.split('/') mod = time.strptime(mod, '%Y-%m-%d %H:%M:%S') mod = time.strftime('%Y-%m-%d', mod) mod = int(time.mktime(time.strptime(mod, '%Y-%m-%d'))) if mod > beg and path[-3] == str(group): topics.append(x) return [x.getObject() for x in topics] def cutComment(self, comment): """ cut tail of comment """ if len(comment)==0: return "..." comments = comment.split(' ') com = '' if len(comments)>4: i = 0 while i < 4: com += str(comments[i]) + ' ' i += 1 return com + '...' return comment registerType(Dashboard, PROJECT_NAME)