from zope.interface import implements from zope.component import getMultiAdapter from AccessControl import ClassSecurityInfo try: from Products.LinguaPlone.public import * except ImportError: # No multilingual support from Products.Archetypes.public import * from Products.Memories.config import * from Products.ATContentTypes.atct import * from Products.ATContentTypes.content.schemata import finalizeATCTSchema from Products.ATContentTypes.configuration import zconf from Products.CMFPlone import PloneMessageFactory as _ from zope.component import getUtility from zope.component import getMultiAdapter from plone.portlets.interfaces import IPortletAssignmentMapping, ILocalPortletAssignmentManager from plone.portlets.interfaces import IPortletManager from Products.Memories.portlets import memories, contacts, memfolder from plone.app.portlets import portlets from plone.portlets.constants import CONTEXT_CATEGORY as CONTEXT_PORTLETS from Products.CMFCore.utils import getToolByName MemoriesFolderSchema = ATFolderSchema.copy() + Schema(( ReferenceField( 'memberContacts', required = False, searchable = False, relationship = 'is contact of', accessot = 'getMemberContacts', mutator = 'setMemberContacts', multiValued = True, widget = ReferenceWidget( visible = {'view':'invisible', 'edit':'invisible'}, ), ), )) finalizeATCTSchema(MemoriesFolderSchema) class MemoriesFolder(ATFolder): """Memories Folder content type. """ schema = MemoriesFolderSchema meta_type = portal_type = archetype_name = 'MemoriesFolder' meta_type = 'MemoriesFolder' portal_type = 'MemoriesFolder' archetype_name = 'MemoriesFolder' #default_view = 'maps_map' #immediate_view = 'maps_map' #suppl_views = () security = ClassSecurityInfo() def manage_afterAdd(self, item, container): wftool = getToolByName(self, 'portal_workflow') BaseFolder.manage_afterAdd(self, item, container) leftColumn = getUtility(IPortletManager, name=u'plone.leftcolumn', context=self) portletAssignments = getMultiAdapter((self, leftColumn,), ILocalPortletAssignmentManager) portletAssignments.setBlacklistStatus(CONTEXT_PORTLETS, True) left = getMultiAdapter((self, leftColumn), IPortletAssignmentMapping, context=self) if u'portlets.memoriesmemories' not in left: left[u'portlets.memoriesmemories'] = memories.Assignment() if u'portlets.memoriesmemfolder' not in left: left[u'portlets.memoriesmemfolder'] = memfolder.Assignment() if u'portlets.memoriescontacts' not in left: left[u'portlets.memoriescontacts'] = contacts.Assignment() # Changing permissions so that Owner would be able to delete unwanted comments self.manage_permission('Manage portal', roles=['Owner',], acquire=1) def inMemoriesFolder(self): return True def getOwnerId(self): return self.Creator() def amIOwner(self): """ check owner """ roles = self.portal_membership.getAuthenticatedMember().getRolesInContext(self) return 'Owner' in roles def checkMemberInContacts(self, contact): field = self.getField('memberContacts') contacts = field.getRaw(self) if contact in contacts: checked = True else: checked = False return checked def getPossibleContacts(self): """ Will get possible contacts """ pc = getToolByName(self, 'portal_catalog') members = pc({'portal_type':'MemoriesFolder','sort_on':'created','sort_order':'descending'}) return [m for m in members if m.Creator != self.Creator()] security.declarePublic("getMemberContacts") def getMemberContacts(self): """ Will get members contacts """ pc = getToolByName(self, 'portal_catalog') field = self.getField('memberContacts') contacts = field.getRaw(self) result = pc({'UID':contacts,'sort_on':'created','sort_order':'descending'}) return result security.declareProtected(MODIFY_CONTENT,'setMemberContacts') def setMemberContacts(self, REQUEST): """ Will set members contacts """ contacts = REQUEST.get('contact_uid') result = [] field = self.getField('memberContacts') if contacts: for contact in contacts: result.append(contact) field.set(self, result) return REQUEST.RESPONSE.redirect(self.absolute_url()) def getMemberFolderUrl(self): return self.absolute_url() def getAllMemories(self): """ Will return all memories """ # XXX Use 'path' for local searches. You can get path with: getPhysicalPath catalog = getToolByName(self, 'portal_catalog') memories = catalog({'portal_type':'GeoLocation','Creator':self.Creator()}) return memories def getAllMyAnnouncements(self): """ Returns all announcements by member """ catalog = getToolByName(self, 'portal_catalog') announcements = catalog({'portal_type':'Announcement','Creator':self.Creator(),'sort_on':'created','sort_order':'descending'}) return announcements def getPrivateMemories(self): """ Will return all private memories """ catalog = getToolByName(self, 'portal_catalog') memories = catalog({'portal_type':'GeoLocation','Creator':self.Creator(),'review_state':'private'}) return memories def getPublicMemories(self): """ Will return all public memories """ catalog = getToolByName(self, 'portal_catalog') memories = catalog({'portal_type':'GeoLocation','Creator':self.Creator(),'review_state':'published'}) return memories registerType(MemoriesFolder, PROJECTNAME)