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

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

Updated title - to add organization name with comma; update comments

  • Property svn:eol-style set to native
File size: 5.4 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
18BountyProgramSubmissionSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
19
20    # -*- Your Archetypes field definitions here ... -*-
21    atapi.ComputedField(
22        name='title',
23        required=1,
24        searchable=1,
25        default='',
26        accessor='Title',
27        storage=atapi.AnnotationStorage(),
28        widget=atapi.ComputedWidget(
29            label=_(u'Name'),
30        ),
31        expression="' '.join(filter(None, [context.getFirstName(),context.getLastName()])) + " \
32                   "context.getFirstName() or context.getLastName() and ', ' or '' + "\
33                   "context.getOrganization()"
34    ),
35
36    atapi.ImageField(
37        'image',
38        languageIndependent=True,
39        storage=atapi.AnnotationStorage(),
40        swallowResizeExceptions = zconf.swallowImageResizeExceptions.enable,
41        pil_quality = zconf.pil_config.quality,
42        pil_resize_algo = zconf.pil_config.resize_algo,
43        max_size = zconf.ATImage.max_image_dimension,
44        sizes= {'bounty': (150,100),},
45        widget=atapi.ImageWidget(
46            label=_(u"Image"),
47            description=_(u"Image or Logo"),
48        ),
49        required=True,
50        validators = (('isNonEmptyFile', V_REQUIRED),
51                      ('checkImageMaxSize', V_REQUIRED)),
52    ),
53
54    atapi.StringField(
55        'remoteUrl', # for use getRemoteUrl metadata from catalog
56        storage=atapi.AnnotationStorage(),
57        widget=atapi.StringWidget(
58            label=_(u"URL"),
59            maxlength = '511',
60        ),
61        required=True,
62        validators=('isURL'),
63        default = "http://",
64    ),
65
66    atapi.StringField(
67        'description',
68        accessor='Description',
69        storage=atapi.AnnotationStorage(),
70        widget=atapi.StringWidget(
71            label=_(u"alt text"),
72        ),
73    ),
74
75    atapi.StringField(
76        'firstName',
77        storage=atapi.AnnotationStorage(),
78        widget=atapi.StringWidget(
79            label=_(u"First name"),
80            description=_(u"Field description"),
81        ),
82    ),
83
84    atapi.StringField(
85        'lastName',
86        storage=atapi.AnnotationStorage(),
87        widget=atapi.StringWidget(
88            label=_(u"Last name"),
89            description=_(u"Field description"),
90        ),
91    ),
92
93    atapi.StringField(
94        'organization',
95        storage=atapi.AnnotationStorage(),
96        widget=atapi.StringWidget(
97            label=_(u"Organization name"),
98            description=_(u"Field description"),
99        ),
100    ),
101
102    atapi.StringField(
103        'email',
104        storage=atapi.AnnotationStorage(),
105        widget=atapi.StringWidget(
106            label=_(u"Email address"),
107        ),
108        validators=('isEmail'),
109    ),
110
111    atapi.TextField(
112        'mission',
113        storage=atapi.AnnotationStorage(),
114        default_content_type = 'text/plain',
115        allowable_content_types = ('text/plain',),
116        widget=atapi.TextAreaWidget(
117            label=_(u"Bounty mission"),
118            description=_(u"Bounty mission trac ticket #"),
119        ),
120        required=True,
121    ),
122
123))
124
125# Set storage on fields copied from ATContentTypeSchema, making sure
126# they work well with the python bridge properties.
127
128BountyProgramSubmissionSchema = schemata.finalizeATCTSchema(
129    BountyProgramSubmissionSchema, moveDiscussion=False)
130BountyProgramSubmissionSchema.moveField('description', after='remoteUrl')
131
132
133class BountyProgramSubmission(base.ATCTContent):
134    """Information for Bounty Program Submission"""
135    implements(IBountyProgramSubmission)
136
137    meta_type = "BountyProgramSubmission"
138    schema = BountyProgramSubmissionSchema
139
140    title = atapi.ATFieldProperty('title')
141    description = atapi.ATFieldProperty('description')
142
143    # -*- Your ATSchema to Python Property Bridges Here ... -*-
144    image = atapi.ATFieldProperty('image')
145    remoteUrl = atapi.ATFieldProperty('remoteUrl')
146    firstName = atapi.ATFieldProperty('firstName')
147    lastName = atapi.ATFieldProperty('lastName')
148    organization = atapi.ATFieldProperty('organization')
149    email = atapi.ATFieldProperty('email')
150    mission = atapi.ATFieldProperty('mission')
151
152    def __bobo_traverse__(self, REQUEST, name):
153        """Transparent access to image scales
154        """
155        if name.startswith('image'):
156            field = self.getField('image')
157            image = None
158            if name == 'image':
159                image = field.getScale(self)
160            else:
161                scalename = name[len('image_'):]
162                if scalename in field.getAvailableSizes(self):
163                    image = field.getScale(self, scale=scalename)
164            if image is not None and not isinstance(image, basestring):
165                # image might be None or '' for empty images
166                return image
167
168        return base.ATCTContent.__bobo_traverse__(self, REQUEST, name)
169   
170atapi.registerType(BountyProgramSubmission, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.