[3129] | 1 | """Definition of the Bounty Program Submission content type |
---|
| 2 | """ |
---|
| 3 | |
---|
| 4 | from zope.interface import implements |
---|
| 5 | |
---|
| 6 | from Products.Archetypes import atapi |
---|
| 7 | from Products.ATContentTypes.content import base |
---|
| 8 | from Products.ATContentTypes.content import schemata |
---|
| 9 | from Products.ATContentTypes.configuration import zconf |
---|
| 10 | from Products.validation import V_REQUIRED |
---|
| 11 | |
---|
| 12 | # -*- Message Factory Imported Here -*- |
---|
| 13 | from ploneorg.kudobounty import kudobountyMessageFactory as _ |
---|
| 14 | |
---|
| 15 | from ploneorg.kudobounty.interfaces import IBountyProgramSubmission |
---|
| 16 | from ploneorg.kudobounty.config import PROJECTNAME |
---|
| 17 | |
---|
[3201] | 18 | def calcTitle(first, last, organization): |
---|
| 19 | """ |
---|
| 20 | Calculate title with space ceparated first and last name |
---|
| 21 | and add organization name by comma, if it exist. |
---|
| 22 | """ |
---|
| 23 | fst, lst, org = map(str.strip,[first, last, organization]) |
---|
| 24 | fst_lst = ' '.join(filter(None, [fst, lst])) |
---|
| 25 | comma = org and (fst or lst) and ', ' or '' |
---|
| 26 | return fst_lst + comma + org |
---|
| 27 | |
---|
[3129] | 28 | BountyProgramSubmissionSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema(( |
---|
| 29 | |
---|
| 30 | # -*- Your Archetypes field definitions here ... -*- |
---|
| 31 | atapi.ComputedField( |
---|
| 32 | name='title', |
---|
| 33 | required=1, |
---|
| 34 | searchable=1, |
---|
| 35 | default='', |
---|
| 36 | accessor='Title', |
---|
| 37 | storage=atapi.AnnotationStorage(), |
---|
| 38 | widget=atapi.ComputedWidget( |
---|
| 39 | label=_(u'Name'), |
---|
| 40 | ), |
---|
[3201] | 41 | expression="context.getCalcTitle()" |
---|
[3129] | 42 | ), |
---|
| 43 | |
---|
| 44 | atapi.ImageField( |
---|
| 45 | 'image', |
---|
| 46 | languageIndependent=True, |
---|
| 47 | storage=atapi.AnnotationStorage(), |
---|
| 48 | swallowResizeExceptions = zconf.swallowImageResizeExceptions.enable, |
---|
| 49 | pil_quality = zconf.pil_config.quality, |
---|
| 50 | pil_resize_algo = zconf.pil_config.resize_algo, |
---|
| 51 | max_size = zconf.ATImage.max_image_dimension, |
---|
| 52 | sizes= {'bounty': (150,100),}, |
---|
| 53 | widget=atapi.ImageWidget( |
---|
| 54 | label=_(u"Image"), |
---|
| 55 | description=_(u"Image or Logo"), |
---|
| 56 | ), |
---|
| 57 | required=True, |
---|
| 58 | validators = (('isNonEmptyFile', V_REQUIRED), |
---|
| 59 | ('checkImageMaxSize', V_REQUIRED)), |
---|
| 60 | ), |
---|
| 61 | |
---|
| 62 | atapi.StringField( |
---|
[3194] | 63 | 'remoteUrl', # for use getRemoteUrl metadata from catalog |
---|
[3129] | 64 | storage=atapi.AnnotationStorage(), |
---|
| 65 | widget=atapi.StringWidget( |
---|
| 66 | label=_(u"URL"), |
---|
[3202] | 67 | maxlength = '511', # Got from ATLinkSchema |
---|
[3129] | 68 | ), |
---|
| 69 | required=True, |
---|
| 70 | validators=('isURL'), |
---|
| 71 | default = "http://", |
---|
| 72 | ), |
---|
| 73 | |
---|
| 74 | atapi.StringField( |
---|
| 75 | 'description', |
---|
| 76 | accessor='Description', |
---|
| 77 | storage=atapi.AnnotationStorage(), |
---|
| 78 | widget=atapi.StringWidget( |
---|
| 79 | label=_(u"alt text"), |
---|
| 80 | ), |
---|
| 81 | ), |
---|
| 82 | |
---|
| 83 | atapi.StringField( |
---|
| 84 | 'firstName', |
---|
| 85 | storage=atapi.AnnotationStorage(), |
---|
| 86 | widget=atapi.StringWidget( |
---|
| 87 | label=_(u"First name"), |
---|
| 88 | ), |
---|
| 89 | ), |
---|
| 90 | |
---|
| 91 | atapi.StringField( |
---|
| 92 | 'lastName', |
---|
| 93 | storage=atapi.AnnotationStorage(), |
---|
| 94 | widget=atapi.StringWidget( |
---|
| 95 | label=_(u"Last name"), |
---|
| 96 | ), |
---|
| 97 | ), |
---|
| 98 | |
---|
| 99 | atapi.StringField( |
---|
| 100 | 'organization', |
---|
| 101 | storage=atapi.AnnotationStorage(), |
---|
| 102 | widget=atapi.StringWidget( |
---|
| 103 | label=_(u"Organization name"), |
---|
| 104 | ), |
---|
| 105 | ), |
---|
| 106 | |
---|
| 107 | atapi.StringField( |
---|
| 108 | 'email', |
---|
| 109 | storage=atapi.AnnotationStorage(), |
---|
| 110 | widget=atapi.StringWidget( |
---|
| 111 | label=_(u"Email address"), |
---|
| 112 | ), |
---|
| 113 | validators=('isEmail'), |
---|
| 114 | ), |
---|
| 115 | |
---|
| 116 | atapi.TextField( |
---|
| 117 | 'mission', |
---|
| 118 | storage=atapi.AnnotationStorage(), |
---|
| 119 | default_content_type = 'text/plain', |
---|
| 120 | allowable_content_types = ('text/plain',), |
---|
| 121 | widget=atapi.TextAreaWidget( |
---|
| 122 | label=_(u"Bounty mission"), |
---|
| 123 | description=_(u"Bounty mission trac ticket #"), |
---|
| 124 | ), |
---|
| 125 | required=True, |
---|
| 126 | ), |
---|
| 127 | |
---|
| 128 | )) |
---|
| 129 | |
---|
| 130 | # Set storage on fields copied from ATContentTypeSchema, making sure |
---|
| 131 | # they work well with the python bridge properties. |
---|
| 132 | |
---|
| 133 | BountyProgramSubmissionSchema = schemata.finalizeATCTSchema( |
---|
| 134 | BountyProgramSubmissionSchema, moveDiscussion=False) |
---|
| 135 | BountyProgramSubmissionSchema.moveField('description', after='remoteUrl') |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | class BountyProgramSubmission(base.ATCTContent): |
---|
| 139 | """Information for Bounty Program Submission""" |
---|
| 140 | implements(IBountyProgramSubmission) |
---|
| 141 | |
---|
| 142 | meta_type = "BountyProgramSubmission" |
---|
| 143 | schema = BountyProgramSubmissionSchema |
---|
| 144 | |
---|
| 145 | title = atapi.ATFieldProperty('title') |
---|
| 146 | description = atapi.ATFieldProperty('description') |
---|
| 147 | |
---|
| 148 | # -*- Your ATSchema to Python Property Bridges Here ... -*- |
---|
| 149 | image = atapi.ATFieldProperty('image') |
---|
| 150 | remoteUrl = atapi.ATFieldProperty('remoteUrl') |
---|
| 151 | firstName = atapi.ATFieldProperty('firstName') |
---|
| 152 | lastName = atapi.ATFieldProperty('lastName') |
---|
| 153 | organization = atapi.ATFieldProperty('organization') |
---|
| 154 | email = atapi.ATFieldProperty('email') |
---|
| 155 | mission = atapi.ATFieldProperty('mission') |
---|
| 156 | |
---|
| 157 | def __bobo_traverse__(self, REQUEST, name): |
---|
| 158 | """Transparent access to image scales |
---|
| 159 | """ |
---|
| 160 | if name.startswith('image'): |
---|
| 161 | field = self.getField('image') |
---|
| 162 | image = None |
---|
| 163 | if name == 'image': |
---|
| 164 | image = field.getScale(self) |
---|
| 165 | else: |
---|
| 166 | scalename = name[len('image_'):] |
---|
| 167 | if scalename in field.getAvailableSizes(self): |
---|
| 168 | image = field.getScale(self, scale=scalename) |
---|
| 169 | if image is not None and not isinstance(image, basestring): |
---|
| 170 | # image might be None or '' for empty images |
---|
| 171 | return image |
---|
| 172 | |
---|
| 173 | return base.ATCTContent.__bobo_traverse__(self, REQUEST, name) |
---|
[3201] | 174 | |
---|
| 175 | def getCalcTitle(self): |
---|
| 176 | return calcTitle(self.getFirstName(), self.getLastName(), |
---|
| 177 | self.getOrganization()) |
---|
| 178 | |
---|
[3129] | 179 | |
---|
| 180 | atapi.registerType(BountyProgramSubmission, PROJECTNAME) |
---|