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

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

Initial import of the package

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