add json view for deputies
This commit is contained in:
parent
86a7904499
commit
c1feae1cdd
|
@ -34,6 +34,18 @@ class Address(Field):
|
||||||
fax = None
|
fax = None
|
||||||
email = None
|
email = None
|
||||||
|
|
||||||
|
def as_dict(self):
|
||||||
|
return {
|
||||||
|
'title': self.title,
|
||||||
|
'street': self.street,
|
||||||
|
'zipcode': self.zipcode,
|
||||||
|
'city': self.city,
|
||||||
|
'phone1': self.phone1,
|
||||||
|
'phone2': self.phone2,
|
||||||
|
'fax': self.fax,
|
||||||
|
'email': self.email,
|
||||||
|
}
|
||||||
|
|
||||||
class IAddressWidget(IWidget):
|
class IAddressWidget(IWidget):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,14 @@
|
||||||
<!-- Grok the package to initialise schema interfaces and content classes -->
|
<!-- Grok the package to initialise schema interfaces and content classes -->
|
||||||
<grok:grok package="." />
|
<grok:grok package="." />
|
||||||
|
|
||||||
|
<browser:page
|
||||||
|
for="themis.datatypes.deputy.IDeputy"
|
||||||
|
name="json"
|
||||||
|
class=".views.DeputyJson"
|
||||||
|
permission="zope2.View"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
<!-- Register an extension profile to make the product installable -->
|
<!-- Register an extension profile to make the product installable -->
|
||||||
<genericsetup:registerProfile
|
<genericsetup:registerProfile
|
||||||
name="default"
|
name="default"
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from Products.Five import BrowserView
|
||||||
|
|
||||||
|
class DeputyJson(BrowserView):
|
||||||
|
def __call__(self):
|
||||||
|
d = {
|
||||||
|
'firstname': self.context.firstname,
|
||||||
|
'lastname': self.context.lastname,
|
||||||
|
'active': self.context.active,
|
||||||
|
'sex': self.context.sex,
|
||||||
|
'polgroup': self.context.polgroup.to_object.title,
|
||||||
|
'district': self.context.district,
|
||||||
|
'birthplace': self.context.birthplace,
|
||||||
|
'bio': self.context.bio,
|
||||||
|
'picture': None, #XXX: link to picture
|
||||||
|
'website': self.context.website,
|
||||||
|
'degrees': self.context.degrees,
|
||||||
|
'mandates': self.context.mandates,
|
||||||
|
}
|
||||||
|
if self.context.birthdate:
|
||||||
|
d['birthdate'] = self.context.birthdate.strftime('%Y-%m-%d')
|
||||||
|
if self.context.private_address:
|
||||||
|
d['private_address'] = self.context.private_address.as_dict(),
|
||||||
|
if self.context.work_address:
|
||||||
|
d['work_address'] = self.context.work_address.as_dict(),
|
||||||
|
if self.context.work_address_2:
|
||||||
|
d['work_address_2'] = self.context.work_address_2.as_dict()
|
||||||
|
|
||||||
|
self.request.response.setHeader('Content-type', 'application/json')
|
||||||
|
return json.dumps(d)
|
Reference in New Issue