Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Copyright (C) 2009, Mathieu PASQUET <mpa@makina-corpus.com>
- # All rights reserved.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are met:
- #
- # 1. Redistributions of source code must retain the above copyright notice,
- # this list of conditions and the following disclaimer.
- # 2. Redistributions in binary form must reproduce the above copyright
- # notice, this list of conditions and the following disclaimer in the
- # documentation and/or other materials provided with the distribution.
- # 3. Neither the name of the <ORGANIZATION> nor the names of its
- # contributors may be used to endorse or promote products derived from
- # this software without specific prior written permission.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- # POSSIBILITY OF SUCH DAMAGE.
- __docformat__ = 'restructuredtext en'
- import z3c.form
- from nmd.sugar.forms.vocabulary import (
- categ1s_voc, categ2s_voc, categ3s_voc, categ4s_voc, categ5s_voc,
- effectifs_voc, codes_naf_voc, statess_voc
- )
- from nmd.sugar.forms.base import (
- _, IStatusMessage, c,
- zope, grok,
- IBaseSchema, RegisterValidator, EmailValidator, DigitValidator,
- FormWrapper, BaseForm, Group
- )
- from nmd.sugar.forms import interfaces as i
- class IAccountSchema(IBaseSchema):
- name = zope.schema.TextLine(title=_(u"Name"),
- max_length=70,
- description=_(u'Name'),
- required=False)
- address = zope.schema.TextLine(title=_(u"Address"),
- max_length=70,
- description=_(u'Any address'),
- required=False)
- city = zope.schema.TextLine(title=_(u"city") ,
- max_length=70,
- description=_(u'Any city'),
- required=False)
- email = zope.schema.TextLine(title=_(u"Email"),
- max_length=70,
- description=_(u'Any Email'),
- required=False)
- postal_code= zope.schema.Int(title=_(u"Postal Code") ,
- description=_(u'Postal Code'),
- required=False)
- phone = zope.schema.TextLine(title=_(u'Phone'),
- max_length=30,
- description=_(u'Any Phone numbers without spaces and indicator ('
- 'At least 4 digits).'),
- required=False)
- effectif= zope.schema.Set(title=_(u"effectif"),
- description=_(u'effectif'),
- value_type=c(vocabulary=effectifs_voc),
- required=False)
- code_naf= zope.schema.Set(title=_(u"code_naf") ,
- description=_(u'code_naf'),
- value_type=c(vocabulary=codes_naf_voc),
- required=False)
- states = zope.schema.Set(title=_(u"states"),
- description=_(u'states'),
- value_type=c(vocabulary=statess_voc),
- required=False)
- categ1 = zope.schema.Set(title=_(u"categ1"),
- description=_(u'categ1'),
- value_type=c(vocabulary=categ1s_voc),
- required=False)
- categ2 = zope.schema.Set(title=_(u"categ2"),
- description=_(u'categ2'),
- value_type=c(vocabulary=categ2s_voc),
- required=False)
- categ3 = zope.schema.Set(title=_(u"categ3"),
- description=_(u'categ3'),
- value_type=c(vocabulary=categ3s_voc),
- required=False)
- categ4 = zope.schema.Set(title=_(u"categ4"),
- description=_(u'categ4'),
- value_type=c(vocabulary=categ4s_voc),
- required=False)
- categ5 = zope.schema.Set(title=_(u"categ5"),
- description=_(u'categ5'),
- value_type=c(vocabulary=categ5s_voc),
- required=False)
- class PersonalInfosGroup(Group):
- label = _(u'Personal informations')
- fields = z3c.form.field.Fields(IAccountSchema).select( 'name', 'address', 'city', 'email' , 'phone')
- class OtherCriteriaGroup(Group):
- label = _(u'Other Criterias')
- fields = z3c.form.field.Fields(IAccountSchema).select('effectif', 'code_naf', 'states')
- class CategoriesGroup(Group):
- label = _(u'Categories')
- fields = z3c.form.field.Fields(IAccountSchema).select('categ1', 'categ2', 'categ3', 'categ4', 'categ5')
- RegisterValidator(EmailValidator, field=IAccountSchema['email'])
- RegisterValidator(DigitValidator, field=IAccountSchema['phone'])
- class AccountForm(BaseForm):
- groups = (PersonalInfosGroup,OtherCriteriaGroup, CategoriesGroup)
- def __init__(self, *args, **kwargs):
- BaseForm.__init__(self, *args, **kwargs)
- # update vocs to sugar crm values
- monkfish = zope.component.queryAdapter(self.context, i.ISugarMonkFish)
- for field in ('effectif', 'code_naf', 'states',
- 'categ1', 'categ2', 'categ3', 'categ4', 'categ5'):
- voc = monkfish.get_vocabulary_values('Accounts', '%s' % field)
- IAccountSchema[field].value_type.vocabulary = voc
- def process_ok(self, action, *args, **kwargs):
- """"""
- # BaseForm.ok(self, action, *args, **kwargs)
- # squirrel = zope.component.queryAdapter(self.context, i.ISugarSquirrel)
- class nmdsearchaccount_view(FormWrapper):
- form = AccountForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement