# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField from Products.Archetypes.public import FileWidget from Products.Archetypes.public import OrderedBaseFolder, BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Products.CMFCore.permissions import View from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, TASK_TYPES, BLOG_TYPES from Common import CommonMix schema = BaseSchema class GroupData(OrderedBaseFolder, CommonMix): """ Group Data""" meta_type = "GroupData" archetype_name = "Group Data" global_allow = 0 exclude_from_nav = False filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/groups_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'visible':False, }, { 'id':'metadata', 'visible':False, }, ) def notifyGroupAreaCreated(self): for x in self.objectValues('Group'): x.manage_permission('View', ('Manager','Owner'), 0) registerType(GroupData, PROJECT_NAME) class Group(OrderedBaseFolder, CommonMix): """ Group """ meta_type = "Group" archetype_name = "Group" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() icon = 'group.gif' schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/group_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'visible':False, }, { 'id':'metadata', 'visible':'False', }, ) aliases = { '(Default)' : '', 'view' : 'group_view', 'edit' : 'base_edit', } def __init__(self, id): self.id = id self.largeIcon = "groups.gif" self.groupNotes = [] def manage_afterAdd(self,item,container): self.makeGroupContent() #self.manage_permission('View', ('Manager','Owner'), 0) #self.manage_permission('Access contents information', ('Manager',), 0) #import traceback #traceback.print_stack() def getLargeIcon(self): """ returns large icon name """ return self.largeIcon def getGroupObject(self): """return group obj""" gt = getToolByName(self, 'portal_groups') return gt.getGroupById(self.id) def getBlogpostsByMember(self, username): """return some blog posts""" pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':BLOG_TYPES, 'Creator':username},sort_on='modified', sort_order='descending', sort_limit=3) return [ x.getObject() for x in res ] def getNumberOfBlogpostsByMember(self, username): """return some blog posts""" pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':BLOG_TYPES, 'Creator':username}) return len(res) def getGroupTasks(self): """group tasks""" pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':TASK_TYPES, 'getTarget':self.id},sort_on='getDeadline', sort_order='descending') return [ x.getObject() for x in res ] def getRecentForumTopics(self): """recent forum topics""" if hasattr(self, 'forum'): return getattr(self,'forum').getRecentTopics() return False def getGroupNotes(self): """group notes""" if hasattr(self, 'notes'): print "Notes olemas" return getattr(self,'notes').getGroupNotes() return False def addGroupNote(self): """add group note""" note_id = self.REQUEST.get('note_id') note_title = self.REQUEST.get('note_title') note_note = self.REQUEST.get('note_note') self.notes.addGroupNote(note_id,note_title,note_note) def delGroupNote(self,note_id): """del group note""" note_id = self.REQUEST.get('note_id') self.notes.delGroupNote(note_id) def setReferencesKeywords(self): """ """ keywords = self.REQUEST.get('keywords') self.references.setKeywords(keywords) def setPhotosKeywords(self): """ """ keywords = self.REQUEST.get('ps_keyword', '') service = self.REQUEST.get('ps_service', '') username = self.REQUEST.get('ps_username', '') self.photos.setPhotoService(keywords, service, username) # def getReferencesTags(self): # """ """ # return self.tags def makeGroupContent(self): """ creates all content to group folder """ #XXX groups Notes Folder if not hasattr(self, 'notes'): from GroupNote import GroupNoteFolder notes = GroupNoteFolder('notes') self._setObject(notes.id, notes) ob=getattr(self,notes.id) ob.setTitle('Notes') ob.manage_permission('View', ('Manager','Owner'), 0) ob.reindexObject() #XXX groups Forum Folder if not hasattr(self, 'forum'): from GroupForum import GroupForumFolder forum = GroupForumFolder('forum') self._setObject(forum.id, forum) ob=getattr(self,forum.id) ob.setTitle('Forum') ob.manage_permission('View', ('Manager','Owner'), 0) ob.reindexObject() #XXX groups Photo Folder if not hasattr(self, 'photos'): from GroupPhoto import GroupPhotoFolder photos = GroupPhotoFolder('photos') self._setObject(photos.id, photos) ob=getattr(self,photos.id) ob.setTitle('Photos') ob.manage_permission('View', ('Manager','Owner'), 0) ob.reindexObject() #XXX groups Reference Folder if not hasattr(self, 'references'): from GroupReference import GroupReferenceFolder references = GroupReferenceFolder('references') self._setObject(references.id, references) ob=getattr(self,references.id) ob.setTitle('References') ob.manage_permission('View', ('Manager','Owner'), 0) ob.reindexObject() def RSS(self, REQUEST): """ RSS feed """ REQUEST.RESPONSE.setHeader("Content-type", "text/xml; charset=utf-8") rss = """\n """ rss += "\t\n" group = self.getGroupObject() if group.getProperty('title'): group_title = group.getProperty('title') else: group_title = group.getId() rss += "\t%s\n" % group_title rss += "\t%s\n" % self.absolute_url() rss += "\tEportfolio\n" rss += "\ten\n" path = '' for p in self.getPhysicalPath(): path += p + '/' pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':['GroupNote', 'ForumTopicFolder'], 'path':path}) + \ pc({'portal_type':TASK_TYPES, 'getTarget':self.id}) res = [ x.getObject() for x in res ] res = [[x.ModificationDate(), x] for x in res] res.sort() res.reverse() for x in res: x = x[1] rss += "\t\n" rss += "\t\t%s\n" % x.Title() if x.meta_type == 'GroupNote': rss += "\t\t%s\n" % self.absolute_url() else: rss += "\t\t%s\n" % x.absolute_url() rss += "\t\t%s\n" % x.ModificationDate() rss += "\t\t%s\n" % x.Creator() if x.meta_type == 'GroupNote': rss += "\t\t\n" % x.getGroupnote() elif x.meta_type == 'ForumTopicFolder': rss += "\t\t\n" % x.getBody() else: trs = getToolByName(self, 'translation_service') deadline = trs.utranslate('eportfolio', 'Deadline:', self, self) try: deadline = deadline.encode('utf-8') except UnicodeDecodeError: deadline = unicode(deadline, 'iso-8859-1').encode('utf-8') deadline += ' '+ self.structureTime(str(x.getDeadline())) rss += "\t\t\n" % deadline rss += "\t\n" rss += "\t\n" rss += "" return rss registerType(Group, PROJECT_NAME)