# -*- coding: utf-8 -*- # # File: DemandTypeTerm.py # # Copyright (c) 2007 by CommunesPlone # Generator: ArchGenXML Version 1.5.3 dev/svn # http://plone.org/products/archgenxml # # GNU General Public License (GPL) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # __author__ = """Gauthier BASTIEN , Stephan GEULETTE """ __docformat__ = 'plaintext' from AccessControl import ClassSecurityInfo from Products.Archetypes.atapi import * from Products.TeleServices.config import * ##code-section module-header #fill in your manual code here from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget from Products.CMFCore.utils import getToolByName from Products.validation.interfaces.IValidator import IValidator from Products.validation import validation from Products.CMFPlone.i18nl10n import utranslate #from zope.i18nmessageid import MessageFactory class StructuredComBeginValidator: """ Validates the structuredComBegin field : integer and max length of x chars """ from Products.TeleServices.config import SCB_LENGTH __implements__ = (IValidator, ) def __init__(self, name): self.name = name def __call__(self, value, *args, **kwargs): # _ = MessageFactory("TeleServices") if value: if not value.isdigit(): # return _(u'help_structuredComBeginDigit', u'You must enter only digits.') # return utranslate(msgid='help_structuredComBeginDigit', domain='TeleServices', default='gits.', context=value) return 'You must enter only digits.' if len(value) > SCB_LENGTH: #return utranslate(msgid='help_structuredComBeginLength', domain='TeleServices', mapping={'len':SCB_LENGTH}, default="The length must be less than %d."%SCB_LENGTH, context=self) return "The length must be less or equal to %d."%SCB_LENGTH validation.register(StructuredComBeginValidator('isValidStructuredComBegin')) ##/code-section module-header schema = Schema(( FloatField( name='price', default="0", widget=DecimalWidget( label='Price', label_msgid='TeleServices_label_price', i18n_domain='TeleServices', ), validators=('isDecimal',) ), StringField( name='description', allowable_content_types=('text/plain', 'text/structured', 'text/html', 'application/msword',), widget=VisualWidget( label="Description", description="Description of the demand.", description_msgid="TeleServices_help_dtt_description", label_msgid='TeleServices_label_description', i18n_domain='TeleServices', ), default_output_type='text/html', accessor= 'Description' ), BooleanField( name='eidRequired', default= False, widget=BooleanField._properties['widget']( label='Eidrequired', label_msgid='TeleServices_label_eidRequired', i18n_domain='TeleServices', ) ), StringField( name='structuredComBegin', default="0", mutator="setStructuredComBegin", widget=StringWidget( description="Encode beginning numbers of structured communication (only digits).", label='Structuredcombegin', label_msgid='TeleServices_label_structuredComBegin', description_msgid='TeleServices_help_structuredComBegin', i18n_domain='TeleServices', ), validators=('isValidStructuredComBegin',) ), LinesField( name='optionalFields', widget=MultiSelectionWidget( label='Optionalfields', label_msgid='TeleServices_label_optionalFields', i18n_domain='TeleServices', ), enforceVocabulary=True, vocabulary='listOptionalFields' ), ReferenceField( name='motivationTerms', index="KeywordIndex", widget=ReferenceBrowserWidget( force_close_on_insert=0, startup_directory= 'portal_teleservices/populationteleservice_config/motivationterms', allow_browse= 1, label='Motivationterms', label_msgid='TeleServices_label_motivationTerms', i18n_domain='TeleServices', ), allowed_types=('MotivationTerm',), multiValued=1, relationship='motivationTerms' ), ReferenceField( name='destinationTerms', index="KeywordIndex", widget=ReferenceBrowserWidget( force_close_on_insert=0, startup_directory= 'portal_teleservices/populationteleservice_config/destinationterms', allow_browse=1, label='Destinationterms', label_msgid='TeleServices_label_destinationTerms', i18n_domain='TeleServices', ), allowed_types=('DestinationTerm',), multiValued=1, relationship='destinationTerms' ), ), ) ##code-section after-local-schema #fill in your manual code here ##/code-section after-local-schema DemandTypeTerm_schema = BaseSchema.copy() + \ schema.copy() ##code-section after-schema #fill in your manual code here ##/code-section after-schema class DemandTypeTerm(BaseContent): """ """ security = ClassSecurityInfo() __implements__ = (getattr(BaseContent,'__implements__',()),) # This name appears in the 'add' box archetype_name = 'DemandTypeTerm' meta_type = 'DemandTypeTerm' portal_type = 'DemandTypeTerm' allowed_content_types = [] filter_content_types = 0 global_allow = 1 #content_icon = 'DemandTypeTerm.gif' immediate_view = 'base_view' default_view = 'base_view' suppl_views = () typeDescription = "DemandTypeTerm" typeDescMsgId = 'description_edit_demandtypeterm' _at_rename_after_creation = True schema = DemandTypeTerm_schema ##code-section class-header #fill in your manual code here ##/code-section class-header # Methods security.declarePublic('setStructuredComBegin') def setStructuredComBegin(self, key): """ while setting the structuredcombegin value, we update the structured_com_counters dictionary of TSTool """ tstool = getToolByName(self, 'portal_teleservices') counters = tstool.getCounters() key = str(key) if key == '': key = '0' if not counters.has_key(key): counters[key] = 0 self.getField('structuredComBegin').set(self, key) security.declarePublic('listOptionalFields') def listOptionalFields(self): """ return a DisplayList of fields wich are marked as optional (CP added attribute on the Fields of TeleService) """ lst = [] folder_id = self.aq_parent.aq_parent.getId() if not SCHEMAS.has_key(folder_id): return DisplayList(lst) current_schema = SCHEMAS[folder_id] for field in current_schema.fields(): try: if field.optional == True: lst.append((field.getName(), utranslate(msgid="TeleServices_label_" + field.getName(), domain='TeleServices', default=field.getName(), context=self))) except AttributeError: #most of time, the field has not the 'optional' attribute pass return DisplayList(lst) registerType(DemandTypeTerm, PROJECTNAME) # end of class DemandTypeTerm ##code-section module-footer #fill in your manual code here ##/code-section module-footer