# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField, ReferenceField, ComputedField, TextField, FileField from Products.Archetypes.public import LinesWidget, TextAreaWidget, StringWidget, SelectionWidget, MultiSelectionWidget, ReferenceWidget, ComputedWidget, RichWidget, FileWidget from Widgets import StructuredTaskWidget, DictField, LinksWidget from Widgets import TagsWidget, TagsField, TrackbackWidget, TrackbacksMadeToWidget, TrackbackLinkWidget, HelpWidget from Products.Archetypes.public import BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Common import CommonMix as Common from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from ReflectionTask import ReflectionTask from StructuredTask import StructuredTask, StructuredWidgetFunctions from BaseTask import linksWidgetFunctions import time schema_base = BaseSchema + Schema(( FileField('attachedFile', accessor="getAttachedFile", widget=FileWidget( label="Attach File", label_msgid='label_attach_file', description="", description_msgid='', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio"), ), ReferenceField('ref_task', accessor='getRefToTask', mutator='setRefToTask', relationship = 'answer_to', widget = ReferenceWidget( visible = {'view':'invisible', 'edit':'invisible'}, ) ), LinesField('categories', accessor='getCategories', searchable=1, index='KeywordIndex:schema', vocabulary='getCategoryVocab', enforceVocabulary=True, default='Task', widget=MultiSelectionWidget( label = 'Category', label_msgid='label_blog_categories', description = 'Select proper categories', description_msgid='desc_blog_categories', i18n_domain="eportfolio", visible = {'view':'invisible', 'edit':'invisible'}, ), ), ComputedField('trackbacklink', accessor='getTrackbacklink', index='FieldIndex:schema', widget=TrackbackLinkWidget( label='Trackback link', label_msgid='label_trackbacklink', description='Link for trackback. Copy it for trackbacking this post', description_msgid='desc_trackbacklink', i18n_domain="eportfolio" ), ), StringField('trackbackurl', accessor='getTrackbackurl', mutator='sendTrackback', widget=HelpWidget( label='Trackback url', label_msgid='label_trackbackurl', description='Copy trackback urls here, separated by ;', description_msgid='desc_trackbackurl', visible={'view':'invisible','edit':'visible'}, help_keyword='trackback', i18n_domain="eportfolio" ), ), ComputedField('rdffield', accessor='generateRDF', widget = ComputedWidget( label = 'hideme', use_label = False, visible = {'edit':'invisible', 'view': 'visible'}, ), ), DictField('trackbacks', accessor='getTrackbacks', mutator='setTrackback', widget=TrackbackWidget( label='Trackbacks were made from', label_msgid='label_trackbacks', description='Trackback', description_msgid='desc_trackbacks', visible={'view':'visible','edit':'invisible'}, i18n_domain="eportfolio" ), ), DictField('trackbacksmade', accessor='getTrackbacksmade', mutator='setTrackbacksmade', widget=TrackbacksMadeToWidget( label='Trackbacks were made to', label_msgid='label_trackbacksmade', use_label = True, description='Trackback', description_msgid='desc_trackbacksmade', visible={'view':'visible','edit':'invisible'}, i18n_domain="eportfolio" ), ), )) schema_reft = schema_base + Schema(( ComputedField('TaskText', accessor='getTaskText', mutator='setTaskText', mode = 'rw', widget = ComputedWidget( label="", visible = {'view':'invisible', 'edit':'visible'} ), ), TextField('answer', accessor='getAnswer', required=True, searchable=True, primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Answer", description="", label_msgid='label_answer', description_msgid='description_answer', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio", rows = 25 ), ), )) schema_reft.moveField('attachedFile', pos='bottom') schema_reft.moveField('trackbacksmade', pos='bottom') schema_reft.moveField('trackbacks', pos='bottom') schema_reft.moveField('trackbackurl', pos='bottom') schema_strut = schema_base + Schema(( DictField('datafields', accessor='getDatafields', mutator='setDatafields', widget=StructuredTaskWidget( label='Fields', label_msgid='label_fields', description='Data fields', description_msgid='description_fields', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio" ), ), )) schema_strut.moveField('attachedFile', pos='bottom') schema_strut.moveField('trackbacksmade', pos='bottom') schema_strut.moveField('trackbacks', pos='bottom') schema_strut.moveField('trackbackurl', pos='bottom') class BaseAnswer(BaseContent, Common, linksWidgetFunctions): """ Application product """ meta_type = "BaseAnswer" archetype_name = "BaseAnswer" global_allow = 0 allow_discussion = 1 #commenting is turned on security = ClassSecurityInfo() security.declareObjectPublic() def getTitleText(self): """ returns title """ return self.title def allowRestricted(self): return True def allowAccepted(self): return True def getTrackbacklink(self): """this is trackbacklink""" return self.aq_parent.absolute_url()+"/redirector/trackback/"+str(self.UID()) def _addTrackback(self, url, title='', excerpt='', blog_name=''): """add trackback to entry""" val = {'url':url,'title':title, 'excerpt':excerpt, 'blog_name':blog_name} f = self.getField('trackbacks').setValue(self, str(time.time()), val) def generateRDF(self): """ generate RDF """ return """ """ % (self.absolute_url(), self.Title(), self.getTrackbacklink()) registerType(BaseAnswer, PROJECT_NAME) class StructuredAnswer(BaseAnswer, StructuredWidgetFunctions): """ Application product """ meta_type = "StructuredAnswer" archetype_name = "StructuredAnswer" global_allow = 0 security = ClassSecurityInfo() security.declareObjectPublic() schema = schema_strut actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'visible':False, }, { 'id':'competencies', 'name':'Associate with competency', 'action':'string:${object_url}/add_reference_to_competency?uid=${object/UID}', 'permissions': ('Modify portal content',), }, ) def __init__(self, id): self.id = id self.appData = {} def getFields(self): """ get Fields """ taskObj = self.getRefToTask() if hasattr(taskObj,'getFields'): return taskObj.getFields() return False def setDatafields(self,val): """ saves data from fields """ self.appData = {} for field in self.getFields(): value = self.REQUEST.get(field['id']) #data = {'id': field['id'], 'value': value} self.appData[field['id']]=value self._p_changed = 1 def getValue(self, fid): """return data""" if self.appData.has_key(fid): return self.appData[fid] return "" def hasAnswerContent(self): """has it""" for field in self.getFields(): if self.getValue(field['id'])!="": return True return False #return True registerType(StructuredAnswer, PROJECT_NAME) class ReflectionAnswer(BaseAnswer): """ Application product """ meta_type = "ReflectionAnswer" archetype_name = "ReflectionAnswer" global_allow = 0 security = ClassSecurityInfo() security.declareObjectPublic() schema = schema_reft actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'visible':False, }, { 'id':'competencies', 'name':'Associate with competency', 'action':'string:${object_url}/add_reference_to_competency?uid=${object/UID}', 'permissions': ('Modify portal content',), }, ) def __init__(self, id): self.id = id def getTaskText(self): """return task text""" taskObj = self.getRefToTask() return taskObj.getBody() def hasAnswerContent(self): """has it""" answerContent = self.getAnswer() if answerContent: return True return False registerType(ReflectionAnswer, PROJECT_NAME)