123 lines
4.1 KiB
Python
123 lines
4.1 KiB
Python
import datetime
|
|
|
|
from five import grok
|
|
from zope import schema
|
|
from zope.schema import Field
|
|
from zope.schema.interfaces import IField, IFromUnicode
|
|
from zope.interface import implements, implementer
|
|
from zope.component import adapts, adapter, provideAdapter
|
|
from z3c.relationfield.interfaces import IHasRelations
|
|
|
|
from z3c.relationfield.schema import RelationChoice
|
|
from plone.formwidget.contenttree import ObjPathSourceBinder
|
|
from plone.dexterity.content import Item
|
|
from plone.app.textfield import RichText
|
|
from plone.namedfile.field import NamedImage
|
|
|
|
from plone.app.content.interfaces import INameFromTitle
|
|
from plone.directives import form, dexterity
|
|
|
|
from z3c.form.browser.text import TextWidget
|
|
from z3c.form.interfaces import IFormLayer, IFieldWidget
|
|
from z3c.form.widget import FieldWidget
|
|
|
|
|
|
from themis.datatypes.interfaces import MessageFactory as _
|
|
|
|
from themis.datatypes.polgroup import IPolGroup
|
|
|
|
class IAddress(IField):
|
|
title = schema.TextLine(title=_(u'Title'), required=False)
|
|
street = schema.TextLine(title=_(u'Street'), required=False)
|
|
zipcode = schema.TextLine(title=_(u'Zip'), required=False)
|
|
city = schema.TextLine(title=_(u'City'), required=False)
|
|
phone1 = schema.TextLine(title=_(u'Phone'), required=False)
|
|
phone2 = schema.TextLine(title=_(u'Phone 2'), required=False)
|
|
fax = schema.TextLine(title=_(u'Fax'), required=False)
|
|
email = schema.TextLine(title=_(u'Email'), required=False)
|
|
|
|
class Address(Field):
|
|
implements(IAddress, IFromUnicode)
|
|
|
|
def fromUnicode(self, str):
|
|
return None
|
|
|
|
def __str__(self):
|
|
return u'/'.join([x for x in (self.title, self.street, self.zipcode, self.city) if x])
|
|
|
|
@adapter(IAddress, IFormLayer)
|
|
@implementer(IFieldWidget)
|
|
def AddressFieldWidget(field, request):
|
|
"""IFieldWidget factory for Address."""
|
|
return FieldWidget(field, TextWidget(request))
|
|
|
|
|
|
class IDeputy(form.Schema):
|
|
firstname = schema.TextLine(title=_(u'First Name'))
|
|
lastname = schema.TextLine(title=_(u'Last Name'))
|
|
active = schema.Bool(title=_(u'Active'), default=True)
|
|
sex = schema.Choice(title=_(u'Sex'), values=('M', 'F'), required=False)
|
|
birthdate = schema.Date(title=_(u'Birthdate'), required=False)
|
|
polgroup = RelationChoice(
|
|
title=_(u"Political Group"),
|
|
source=ObjPathSourceBinder(object_provides=IPolGroup.__identifier__),
|
|
required=False)
|
|
district = schema.TextLine(title=_(u'District'), required=False)
|
|
|
|
birthplace = schema.TextLine(title=_(u'Birthplace'), required=False)
|
|
bio = schema.Text(title=_(u'Bio'), required=False)
|
|
picture = NamedImage(title=_(u'Picture'), required=False)
|
|
website = schema.TextLine(title=_(u'Website'), required=False)
|
|
degrees = schema.Text(title=_(u'Degrees'), required=False)
|
|
mandates = schema.Text(title=_(u'Other Mandates'), required=False)
|
|
|
|
private_address = Address(title=_(u'Private Address'), required=False)
|
|
work_address = Address(title=_(u'Work Address'), required=False)
|
|
work_address_2 = Address(title=_(u'Work Address (2)'), required=False)
|
|
|
|
|
|
class INameFromPersonNames(INameFromTitle):
|
|
def title():
|
|
'''Return a processed title'''
|
|
|
|
class NameFromPersonNames(object):
|
|
implements(INameFromPersonNames)
|
|
|
|
def __init__(self, context):
|
|
self.context = context
|
|
|
|
@property
|
|
def title(self):
|
|
return self.context.firstname + ' ' + self.context.lastname
|
|
|
|
class Deputy(Item):
|
|
implements(IDeputy, IHasRelations)
|
|
|
|
@property
|
|
def title(self):
|
|
return self.firstname + ' ' + self.lastname
|
|
|
|
def setTitle(self, value):
|
|
pass
|
|
|
|
@property
|
|
def agerange(self):
|
|
today = datetime.datetime.today()
|
|
age = (today.year - self.birthdate.year)
|
|
if today.month < self.birthdate.month or \
|
|
(today.month == self.birthdate.month and
|
|
today.day < self.birthdate.day):
|
|
age -= 1
|
|
if age < 30:
|
|
return '-30'
|
|
elif age < 40:
|
|
return '30-40'
|
|
elif age < 50:
|
|
return '40-50'
|
|
elif age < 60:
|
|
return '50-60'
|
|
elif age < 70:
|
|
return '60-70'
|
|
else:
|
|
return '+70'
|