40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
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,
|
|
'website': self.context.website,
|
|
'degrees': self.context.degrees,
|
|
'mandates': self.context.mandates,
|
|
}
|
|
if self.context.picture:
|
|
d['picture'] = self.context.absolute_url() + '/photo'
|
|
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)
|
|
|
|
class DeputyPhoto(BrowserView):
|
|
def __call__(self):
|
|
self.request.response.setHeader('Content-type',
|
|
self.context.picture.contentType)
|
|
return self.context.picture.data
|
|
|