Advertisement
Guest User

Untitled

a guest
May 6th, 2017
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Copyright (C) 2009, Mathieu PASQUET <mpa@makina-corpus.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of source code must retain the above copyright notice,
  10. # this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. # 3. Neither the name of the <ORGANIZATION> nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. # POSSIBILITY OF SUCH DAMAGE.
  29.  
  30. __docformat__ = 'restructuredtext en'
  31. import z3c.form
  32. from nmd.sugar.forms.vocabulary import (
  33. categ1s_voc, categ2s_voc, categ3s_voc, categ4s_voc, categ5s_voc,
  34. effectifs_voc, codes_naf_voc, statess_voc
  35. )
  36. from nmd.sugar.forms.base import (
  37. _, IStatusMessage, c,
  38. zope, grok,
  39. IBaseSchema, RegisterValidator, EmailValidator, DigitValidator,
  40. FormWrapper, BaseForm, Group
  41. )
  42. from nmd.sugar.forms import interfaces as i
  43.  
  44. class IAccountSchema(IBaseSchema):
  45. name = zope.schema.TextLine(title=_(u"Name"),
  46. max_length=70,
  47. description=_(u'Name'),
  48. required=False)
  49. address = zope.schema.TextLine(title=_(u"Address"),
  50. max_length=70,
  51. description=_(u'Any address'),
  52. required=False)
  53. city = zope.schema.TextLine(title=_(u"city") ,
  54. max_length=70,
  55. description=_(u'Any city'),
  56. required=False)
  57. email = zope.schema.TextLine(title=_(u"Email"),
  58. max_length=70,
  59. description=_(u'Any Email'),
  60. required=False)
  61. postal_code= zope.schema.Int(title=_(u"Postal Code") ,
  62. description=_(u'Postal Code'),
  63. required=False)
  64. phone = zope.schema.TextLine(title=_(u'Phone'),
  65. max_length=30,
  66. description=_(u'Any Phone numbers without spaces and indicator ('
  67. 'At least 4 digits).'),
  68. required=False)
  69. effectif= zope.schema.Set(title=_(u"effectif"),
  70. description=_(u'effectif'),
  71. value_type=c(vocabulary=effectifs_voc),
  72. required=False)
  73. code_naf= zope.schema.Set(title=_(u"code_naf") ,
  74. description=_(u'code_naf'),
  75. value_type=c(vocabulary=codes_naf_voc),
  76. required=False)
  77. states = zope.schema.Set(title=_(u"states"),
  78. description=_(u'states'),
  79.  
  80. value_type=c(vocabulary=statess_voc),
  81. required=False)
  82. categ1 = zope.schema.Set(title=_(u"categ1"),
  83. description=_(u'categ1'),
  84.  
  85. value_type=c(vocabulary=categ1s_voc),
  86. required=False)
  87. categ2 = zope.schema.Set(title=_(u"categ2"),
  88. description=_(u'categ2'),
  89.  
  90. value_type=c(vocabulary=categ2s_voc),
  91. required=False)
  92. categ3 = zope.schema.Set(title=_(u"categ3"),
  93. description=_(u'categ3'),
  94. value_type=c(vocabulary=categ3s_voc),
  95. required=False)
  96. categ4 = zope.schema.Set(title=_(u"categ4"),
  97. description=_(u'categ4'),
  98. value_type=c(vocabulary=categ4s_voc),
  99. required=False)
  100. categ5 = zope.schema.Set(title=_(u"categ5"),
  101. description=_(u'categ5'),
  102. value_type=c(vocabulary=categ5s_voc),
  103. required=False)
  104.  
  105. class PersonalInfosGroup(Group):
  106. label = _(u'Personal informations')
  107. fields = z3c.form.field.Fields(IAccountSchema).select( 'name', 'address', 'city', 'email' , 'phone')
  108. class OtherCriteriaGroup(Group):
  109. label = _(u'Other Criterias')
  110. fields = z3c.form.field.Fields(IAccountSchema).select('effectif', 'code_naf', 'states')
  111. class CategoriesGroup(Group):
  112. label = _(u'Categories')
  113. fields = z3c.form.field.Fields(IAccountSchema).select('categ1', 'categ2', 'categ3', 'categ4', 'categ5')
  114.  
  115. RegisterValidator(EmailValidator, field=IAccountSchema['email'])
  116. RegisterValidator(DigitValidator, field=IAccountSchema['phone'])
  117.  
  118. class AccountForm(BaseForm):
  119. groups = (PersonalInfosGroup,OtherCriteriaGroup, CategoriesGroup)
  120.  
  121. def __init__(self, *args, **kwargs):
  122. BaseForm.__init__(self, *args, **kwargs)
  123. # update vocs to sugar crm values
  124. monkfish = zope.component.queryAdapter(self.context, i.ISugarMonkFish)
  125. for field in ('effectif', 'code_naf', 'states',
  126. 'categ1', 'categ2', 'categ3', 'categ4', 'categ5'):
  127. voc = monkfish.get_vocabulary_values('Accounts', '%s' % field)
  128. IAccountSchema[field].value_type.vocabulary = voc
  129.  
  130. def process_ok(self, action, *args, **kwargs):
  131. """"""
  132. # BaseForm.ok(self, action, *args, **kwargs)
  133. # squirrel = zope.component.queryAdapter(self.context, i.ISugarSquirrel)
  134.  
  135. class nmdsearchaccount_view(FormWrapper):
  136. form = AccountForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement