source: products/ploneorg.kudobounty/trunk/ploneorg/kudobounty/content/bountyprogramsubmission.py

Last change on this file was 3202, checked in by mylan, 13 years ago

Remove not descriptable fields descrtions, add comment to remoutUrl field

  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1"""Definition of the Bounty Program Submission content type
2"""
3
4from zope.interface import implements
5
6from Products.Archetypes import atapi
7from Products.ATContentTypes.content import base
8from Products.ATContentTypes.content import schemata
9from Products.ATContentTypes.configuration import zconf
10from Products.validation import V_REQUIRED
11
12# -*- Message Factory Imported Here -*-
13from ploneorg.kudobounty import kudobountyMessageFactory as _
14
15from ploneorg.kudobounty.interfaces import IBountyProgramSubmission
16from ploneorg.kudobounty.config import PROJECTNAME
17
18def 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
28BountyProgramSubmissionSchema = 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        ),
41        expression="context.getCalcTitle()"
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(
63        'remoteUrl', # for use getRemoteUrl metadata from catalog
64        storage=atapi.AnnotationStorage(),
65        widget=atapi.StringWidget(
66            label=_(u"URL"),
67            maxlength = '511', # Got from ATLinkSchema
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
133BountyProgramSubmissionSchema = schemata.finalizeATCTSchema(
134    BountyProgramSubmissionSchema, moveDiscussion=False)
135BountyProgramSubmissionSchema.moveField('description', after='remoteUrl')
136
137
138class 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)
174
175    def getCalcTitle(self):
176        return calcTitle(self.getFirstName(), self.getLastName(),
177                         self.getOrganization())
178
179   
180atapi.registerType(BountyProgramSubmission, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.