source: publico/Ombudsman/trunk/content/OmbudsmanClaim.py @ 6698

Última Alteração nesse arquivo desde 6698 foi 6698, incluída por jeanferri, 9 anos atrás

Removidos campos de sexo e idade no formulário de socilitação da ouvidoria

File size: 16.1 KB
Linha 
1# -*- coding: utf-8 -*-
2#
3# File: OmbudsmanClaim.py
4#
5# Copyright (c) 2012 by Interlegis
6# Generator: ArchGenXML
7#            http://plone.org/products/archgenxml
8#
9# GNU General Public License (GPL)
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24# 02110-1301, USA.
25#
26
27__author__ = """Rafahela Garcia Bazzanella <rafahela@gmail.com>, Jean Rodrigo Ferri
28<jeanferri@gmail.com>"""
29__docformat__ = 'plaintext'
30
31from AccessControl import ClassSecurityInfo
32from Products.Archetypes.atapi import *
33from Products.Ombudsman.interfaces.IClaim import IClaim
34from Products.Ombudsman.config import *
35
36# additional imports from tagged value 'import'
37from Products.Poi.content.PoiIssue import PoiIssue
38from Products.Poi.content.PoiTracker import PoiTracker
39
40##code-section module-header #fill in your manual code here
41import transaction
42from Products.CMFCore.utils import getToolByName
43from Acquisition import aq_parent, aq_inner
44from Products.generator import i18n
45##/code-section module-header
46
47copied_fields = {}
48copied_fields['title'] = PoiIssue.schema['title'].copy()
49copied_fields['contactEmail'] = PoiIssue.schema['contactEmail'].copy()
50copied_fields['issueType'] = PoiIssue.schema['issueType'].copy()
51copied_fields['details'] = PoiIssue.schema['details'].copy()
52copied_fields['responsibleManager'] = PoiIssue.schema['responsibleManager'].copy()
53copied_fields['area'] = PoiIssue.schema['area'].copy()
54schema = Schema((
55
56    copied_fields['title'],
57
58    StringField(
59        name='name',
60        widget=StringWidget(
61            description="Add your full name or the name of institution that is claiming.",
62            label="Name",
63            label_msgid='Ombudsman_label_name',
64            description_msgid='Ombudsman_help_name',
65            i18n_domain='Ombudsman',
66        ),
67        required=1,
68    ),
69
70    copied_fields['contactEmail'],
71
72    StringField(
73        name='address',
74        index="FieldIndex:schema",
75        widget=StringWidget(
76            size="40",
77            description="Add your address.",
78            label='Address',
79            label_msgid='Ombudsman_label_address',
80            description_msgid='Ombudsman_help_address',
81            i18n_domain='Ombudsman',
82        ),
83        required=1,
84        searchable=1,
85        default_method="getAddresses"
86    ),
87
88    StringField(
89        name='city',
90        index="FieldIndex:schema",
91        widget=StringWidget(
92            description="Add your city.",
93            label='City',
94            label_msgid='Ombudsman_label_city',
95            description_msgid='Ombudsman_help_city',
96            i18n_domain='Ombudsman',
97        ),
98        required=1,
99        searchable=1,
100        default_method="getCities"
101    ),
102
103    StringField(
104        name='region',
105        index="FieldIndex:schema",
106        widget=SelectionWidget(
107            description="Select your state/region.",
108            format="select",
109            label='Region',
110            label_msgid='Ombudsman_label_region',
111            description_msgid='Ombudsman_help_region',
112            i18n_domain='Ombudsman',
113        ),
114        enforceVocabulary=1,
115        vocabulary='getRegions',
116        searchable=1,
117        default_method="getDefaultRegion",
118        required=1
119    ),
120
121    StringField(
122        name='zip',
123        index="FieldIndex:schema",
124        widget=StringWidget(
125            size="10",
126            description="Add your zip code.",
127            label='Zip',
128            label_msgid='Ombudsman_label_zip',
129            description_msgid='Ombudsman_help_zip',
130            i18n_domain='Ombudsman',
131        ),
132        required=1,
133        searchable=1,
134        default_method="getZips"
135    ),
136
137    copied_fields['issueType'],
138    copied_fields['area'],
139    copied_fields['details'],
140    copied_fields['responsibleManager'],
141),
142)
143
144##code-section after-local-schema #fill in your manual code here
145
146copied_fields['contactEmail'].widget.i18n_domain="Ombudsman"
147copied_fields['issueType'].widget.i18n_domain="Ombudsman"
148copied_fields['responsibleManager'].widget.i18n_domain="Ombudsman"
149copied_fields['area'].widget.i18n_domain="Ombudsman"
150copied_fields['title'].required = 0
151copied_fields['title'].widget.visible = {'view':'invisible','edit':'invisible'}
152
153##/code-section after-local-schema
154
155OmbudsmanClaim_schema = BaseFolderSchema.copy() + \
156    schema.copy()
157
158##code-section after-schema #fill in your manual code here
159##/code-section after-schema
160
161class OmbudsmanClaim(BaseFolder):
162    """Class that defines claims of people.
163    """
164    security = ClassSecurityInfo()
165    __implements__ = (getattr(BaseFolder,'__implements__',()),) + (IClaim,)
166
167    # This name appears in the 'add' box
168    archetype_name = 'Claim'
169
170    meta_type = 'OmbudsmanClaim'
171    portal_type = 'OmbudsmanClaim'
172    allowed_content_types = ['OmbudsmanResponse']
173    filter_content_types = 1
174    global_allow = 0
175    content_icon = 'ombudsman_claim_icon.png'
176    immediate_view = 'base_view'
177    default_view = 'ombudsman_claim_view'
178    suppl_views = ()
179    typeDescription = "Class that defines claims of people"
180    typeDescMsgId = 'description_edit_ombudsmanclaim'
181    allow_discussion = 0
182
183
184    actions =  (
185
186
187       {'action': "string:${object_url}/ombudsman_claim_view",
188        'category': "object",
189        'id': 'view',
190        'name': 'View',
191        'permissions': ("View",),
192        'condition': 'python:1'
193       },
194
195
196    )
197
198    _at_rename_after_creation = True
199
200    schema = OmbudsmanClaim_schema
201
202    ##code-section class-header #fill in your manual code here
203    ##/code-section class-header
204
205    # Methods
206
207    # Methods from Interface IClaim
208
209    security.declarePublic('getAddresses')
210    def getAddresses(self):
211        """Return member address.
212        """
213        portal_membership = getToolByName(self, 'portal_membership')
214        member = portal_membership.getAuthenticatedMember()
215        address = member.getProperty('address', '')
216        return address
217
218    security.declarePublic('getSexs')
219    def getSexs(self):
220        """Return sex list.
221        """
222
223        portal_ombudsman = getToolByName(self, 'portal_ombudsman')
224        result = []
225        vocabulary = portal_ombudsman.getVocab_sex()
226
227        for item in vocabulary:
228            parts = item.split(';')
229            result.append([parts[0], parts[1]])
230        return DisplayList(tuple(result))
231
232    security.declarePublic('getZips')
233    def getZips(self):
234        """Return member zip code.
235        """
236        portal_membership = getToolByName(self, 'portal_membership')
237        member = portal_membership.getAuthenticatedMember()
238        zip_code = member.getProperty('zip', '')
239        return zip_code
240
241    security.declarePublic('getCities')
242    def getCities(self):
243        """Return cities list.
244        """
245        portal_membership = getToolByName(self, 'portal_membership')
246        member = portal_membership.getAuthenticatedMember()
247        city = member.getProperty('city', '')
248        return city
249
250    security.declarePublic('getRegions')
251    def getRegions(self):
252        """Return states/regions list.
253        """
254        portal_ombudsman = getToolByName(self, 'portal_ombudsman')
255        result = []
256        vocabulary = portal_ombudsman.getVocab_region()
257
258        for item in vocabulary:
259            parts = item.split(';')
260            result.append([parts[0], parts[1]])
261        return DisplayList(tuple(result))
262
263    security.declarePublic('getAges')
264    def getAges(self):
265        """Return ages list.
266        """
267
268        portal_ombudsman = getToolByName(self, 'portal_ombudsman')
269        result = []
270        vocabulary = portal_ombudsman.getVocab_age()
271
272        for item in vocabulary:
273            parts = item.split(';')
274            result.append([parts[0], parts[1]])
275        return DisplayList(tuple(result))
276
277    # Manually created methods
278
279    def Title(self):
280        """Replace the object title by the id.
281        """
282        return self.getId()
283
284    def sendRevisionMail(self):
285        """When this issue is created, send a notification email to all
286        managers/reviewers.
287        """
288        ombudsman = self.aq_parent
289        email = ombudsman.queryDataGrid('availableAreas', 'lookup', [self.getArea(), 'email'])
290
291        portal_url = getToolByName(self, 'portal_url')
292        portal_membership = getToolByName(self, 'portal_membership')
293        portal = portal_url.getPortalObject()
294        fromName = portal.getProperty('email_from_name', None)
295        title = portal.getProperty('title', None)
296
297
298        claimCreator = self.Creator()
299        claimCreatorInfo = portal_membership.getMemberInfo(claimCreator);
300        claimAuthor = claimCreator
301
302        if claimCreatorInfo:
303            claimAuthor = claimCreatorInfo['fullname'] or claimCreator
304
305        mailText = self.ombudsman_email_claim_reviewer(self,
306                                            ombudsman = ombudsman,
307                                            claim = self,
308                                            fromName = fromName,
309                                            claimAuthor = claimAuthor)
310        subject = "%s" % (title,)
311        #subject = "[%s] New claim: #%s" % (ombudsman.getExternalTitle(), self.Title(),)
312        #subject = i18n.translate(domain='Ombudsman',
313        #                         msgid='Ombudsman_subject_new_claim_reviewer',
314        #                         context=self,
315        #                         default="You have a new revision")
316
317        ombudsman.sendNotificationEmail(email, subject, mailText)
318
319    def getDefaultContactEmail(self):
320        """Get the default email address, that of the creating user
321        """
322        portal_membership = getToolByName(self, 'portal_membership')
323        member = portal_membership.getAuthenticatedMember()
324        email = member.getProperty('email', '')
325        return email
326
327    security.declarePublic('getDefaultAge')
328    def getDefaultAge(self):
329        """Return member age.
330        """
331        portal_membership = getToolByName(self, 'portal_membership')
332        member = portal_membership.getAuthenticatedMember()
333        return member.getProperty('age', '')
334
335    def sendResolvedMail(self):
336        """When this claim is resolved, send a notification email to user
337        that made the claim.
338        """
339        portal_membership = getToolByName(self, 'portal_membership')
340        portal_url = getToolByName(self, 'portal_url')
341        portal = portal_url.getPortalObject()
342        ombudsman = self.aq_parent
343        claim = self
344
345        claimEmail = self.getContactEmail()
346        if not claimEmail:
347            return
348
349        member = portal_membership.getAuthenticatedMember()
350        title = portal.getProperty('title', None)
351
352        memberInfo = portal_membership.getMemberInfo(member.getUserName());
353        stateChanger = member.getUserName()
354        if memberInfo:
355            stateChanger = memberInfo['fullname'] or stateChanger
356
357        fromName = portal.getProperty('email_from_name', None)
358        mailText = self.ombudsman_email_claim_resolved(claim,
359                                               ombudsman = ombudsman,
360                                               claim = claim,
361                                               fromName = fromName,
362                                               stateChanger = stateChanger)
363        subject = "%s" % (title,)
364        #subject = "[%s] Your claim is resolved - %s" % (ombudsman.getExternalTitle(), claim.Title(),)
365        #subject = i18n.translate(domain='Ombudsman',
366        #                         msgid='Ombudsman_subject_resolved_email',
367        #                         context=self,
368        #                         default="Your claim was resolved")
369
370        ombudsman.sendNotificationEmail([claimEmail], subject, mailText)
371
372    def getIssueTypesVocab(self):
373        """Get the issue types available as a DisplayList.
374        """
375        field = self.aq_parent.getField('availableIssueTypes')
376        return field.getAsDisplayList(self.aq_parent)
377
378    def getManagersVocab(self):
379        """Get the managers available as a DisplayList. The first item is 'None',
380        with a key of '(UNASSIGNED)'.
381        """
382        items = self.aq_parent.getManagers()
383        vocab = DisplayList()
384        vocab.add('(UNASSIGNED)', 'None', 'poi_voacb_none')
385        for item in items:
386            vocab.add(item, item)
387        return vocab
388
389    security.declarePublic('getDefaultRegion')
390    def getDefaultRegion(self):
391        """Return member state/region.
392        """
393
394        portal_membership = getToolByName(self, 'portal_membership')
395        member = portal_membership.getAuthenticatedMember()
396        return member.getProperty('region', '')
397
398    def getAreasVocab(self):
399        """Get the available areas as a DispayList.
400        """
401        field = self.aq_parent.getField('availableAreas')
402        return field.getAsDisplayList(self.aq_parent)
403
404    security.declarePublic('getDefaultSex')
405    def getDefaultSex(self):
406        """Return member sex.
407        """
408
409        portal_membership = getToolByName(self, 'portal_membership')
410        member = portal_membership.getAuthenticatedMember()
411        return member.getProperty('sex', '')
412
413    def getAvailableIssueTransitions(self):
414        """Get the available transitions for the issue.
415        """
416        wftool = getToolByName(self, 'portal_workflow')
417        transitions = DisplayList()
418        #transitions.add('', 'No change')
419        for tdef in wftool.getTransitionsFor(self):
420            transitions.add(tdef['id'], tdef['title_or_id'])
421        return transitions
422
423    def sendNotificationMail(self):
424        """When this claim is created, send a notification email to user
425        that made the claim.
426        """
427        ombudsman = self.aq_parent
428        claim = self
429
430        claimEmail = self.getContactEmail()
431        if not claimEmail:
432            return
433
434        portal_membership = getToolByName(self, 'portal_membership')
435        member = portal_membership.getAuthenticatedMember()
436
437        memberInfo = portal_membership.getMemberInfo(member.getUserName());
438        stateChanger = member.getUserName()
439        if memberInfo:
440            stateChanger = memberInfo['fullname'] or stateChanger
441
442        portal_url = getToolByName(self, 'portal_url')
443        portal = portal_url.getPortalObject()
444        fromName = portal.getProperty('email_from_name', None)
445        title = portal.getProperty('title', None)
446
447        mailText = self.ombudsman_email_claim_user(claim,
448                                            ombudsman = ombudsman,
449                                            claim = claim,
450                                            fromName = fromName,
451                                            stateChanger = stateChanger)
452        subject = "%s" % (title,)
453        #subject = "[%s] Your claim was sent - %s" % (ombudsman.getExternalTitle(), claim.Title(),)
454        #subject = i18n.translate(domain='Ombudsman',
455        #                         msgid='Ombudsman_subject_new_claim',
456        #                         context=self,
457        #                         default="Your claim was sent")
458
459        ombudsman.sendNotificationEmail([claimEmail], subject, mailText)
460
461    def _renameAfterCreation(self, check_auto_id=False):
462        parent = self.aq_inner.aq_parent
463        newId = parent.getNextProtocolBuffer()
464        # Can't rename without a subtransaction commit when using
465        # portal_factory!
466        transaction.savepoint(optimistic=True)
467        self.setId(newId)
468
469
470def modify_fti(fti):
471    # Hide unnecessary tabs (usability enhancement)
472    for a in fti['actions']:
473        if a['id'] in ['metadata', 'sharing']:
474            a['visible'] = 0
475    return fti
476
477registerType(OmbudsmanClaim, PROJECTNAME)
478# end of class OmbudsmanClaim
479
480##code-section module-footer #fill in your manual code here
481##/code-section module-footer
482
483
484
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.