# -*- coding: utf-8 # Copyright 2005 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField, TextField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget, MultiSelectionWidget from Products.Archetypes.public import BaseFolder, BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from BaseFunctions import BaseFunctions from Permissions import * from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema + Schema(( )) class LinkCollector(BaseFolder, BaseFunctions): """ LinkCollector """ meta_type = "LinkCollector" archetype_name = "LinkCollector" global_allow = 1 allowed_content_types = ('LinkItem',) security = ClassSecurityInfo() content_icon='gradebook_icon.gif' schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/linkcollector_view', 'permissions': ('View',), }, ) def manage_afterAdd(self,item,container): """sets permissions""" self.manage_permission('Add portal content', ('Manager','Teacher','Member') ,1) def deleteObject(self, REQUEST): """ delete object """ id = REQUEST.get("id") self._delObject(id) return REQUEST.RESPONSE.redirect(self.absolute_url()+'/linkcollector_view') registerType(LinkCollector, PROJECT_NAME) class LinkItem(BaseContent, BaseFunctions): """ LinkItem """ meta_type = "LinkItem" archetype_name = "LinkItem" global_allow = 1 allowed_content_types = () security = ClassSecurityInfo() content_icon='gradebook_icon.gif' schema = schema + Schema(( LinesField('Groups', required=1, searchable=1, accessor="getGroups", isMetadata=1, vocabulary='getClasses', widget=MultiSelectionWidget( format="checkbox", label="Groups", label_msgid='label_groups', description="Groups who see this link.", description_msgid='desc_link_groups', i18n_domain="krihvel"), ), StringField('link', accessor='Link', isMetadata=0, widget = StringWidget( label="Link", description="", label_msgid='label_link', description_msgid='desc_link', visible={'view':'visible','edit':'visible'}, i18n_domain="krihvel") ), TextField('comment', accessor='getComment', isMetadata=0, widget = TextAreaWidget( label="Comment", description="", label_msgid='label_comment', description_msgid='desc_comment', visible={'view':'visible','edit':'visible'}, i18n_domain="krihvel") ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/link_redirect', 'permissions': ('View',), }, ) def getLink(self): """ returns real link """ link=self.Link() print link[:7] if link[:7]!='http://': link = 'http://'+link return link def redirectPage(self, REQUEST): """sets permissions""" obj = self.aq_parent return REQUEST.RESPONSE.redirect(obj.absolute_url()+'/linkcollector_view') registerType(LinkItem, PROJECT_NAME)