from Products.Archetypes.public import * from Products.Archetypes.Marshall import RFC822Marshaller, PrimaryFieldMarshaller from AccessControl import ClassSecurityInfo, Unauthorized from Products.CMFCore import CMFCorePermissions from DateTime import DateTime from DocumentTemplate.DT_Util import html_quote schema = ExtensibleMetadata.schema + Schema( ( StringField( 'guest_name', ), TextField( 'comment', required=1, primary=1, default_output_type='text/html', default_content_type='text/plain', allowable_content_types=('text/plain',), widget=TextAreaWidget( rows=10, cols=40, ), ), ), marshall=RFC822Marshaller() ) class ATGBEntry(BaseContent): """.""" global_allow = 0 schema = schema security = ClassSecurityInfo() def crop_text(self, text, length, ellipsis=None): """Crop text on a word boundary.""" props = self.portal_properties.site_properties ellipsis = getattr(props, 'ellipsis', '...') if len(text)>length: text = text[:length] l = text.rfind(' ') if l > length/2: text = text[:l+1] text += ellipsis return text security.declareProtected(CMFCorePermissions.View, 'Title') def Title(self, **kwargs): """Provide a calculated title.""" guest_name = self.getGuest_name() comment = self.crop_text(self.getComment(mimetype='text/plain'), 50) if not guest_name and not comment: return "ATGBEntry" return "%s - %s" % (guest_name, comment) def getComment(self, **kwargs): orig = self.Schema()['comment'].getRaw(self, **kwargs) return html_quote(orig.strip()).replace('\n', '
') registerType(ATGBEntry) def modify_fti(fti): for a in fti['actions']: if a['id'] in ('metadata','references'): a['visible'] = 0 return fti