json export of commissions

This commit is contained in:
Frédéric Péters 2011-10-31 14:05:27 +01:00
parent 5fdf268fc4
commit bbd17ecaa2
2 changed files with 21 additions and 0 deletions

View File

@ -26,6 +26,13 @@
permission="zope2.View"
/>
<browser:page
for="themis.datatypes.commission.ICommission"
name="json"
class=".views.CommissionJson"
permission="zope2.View"
/>
<!-- Register an extension profile to make the product installable -->
<genericsetup:registerProfile
name="default"

View File

@ -40,3 +40,17 @@ class DeputyPhoto(BrowserView):
self.context.picture.contentType)
return self.context.picture.data
class CommissionJson(BrowserView):
def __call__(self):
import themis.importexport.utils
d = {}
for k in ('title', 'active', 'president', 'vicepresidents', 'members',
'substitutes', 'competences', 'ministries'):
if not hasattr(self.context, k):
continue
v = getattr(self.context, k)
d[k] = themis.importexport.utils.convert(v)
self.request.response.setHeader('Content-type', 'application/json')
return json.dumps(d)