Guest User

Untitled

a guest
Jul 22nd, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. I got a problem with multiple inheritance here
  2.  
  3. # User Address Form which inherits AddressForm and LanguageForm
  4. class UsersAddForm(AddressForm, LanguageForm): # Inherit AddressForm
  5. """ Form used to add users """
  6.  
  7. def __init__(self, data=None,initial=None, organization=None,language =None, error_class=None,edit=False ) :
  8. """ Constructor for Class AddForm """
  9. # Override Constructor for Address Form
  10. AddressForm.__init__(self, data=data, organization=organization,language=language,initial=initial,error_class=error_class)
  11.  
  12. # Override Constructor for Language Form
  13. LanguageForm.__init__(self, data=data, organization=organization, language=language, initial=initial,error_class=error_class)
  14.  
  15. self.organization = organization
  16. self.language = language
  17. self.data = data if data else {}
  18. self.edit = edit if edit else False
  19.  
  20. # set civility
  21. self.fields['civility'].choices = CIVILITY[self.language.code]
  22.  
  23. # set contact by
  24. self.fields['contact_by'].choices = CONTACT_BY[self.language.code]
  25.  
  26. # set active domain
  27. self.fields['active_domain'].choices = ACTIVE_DOMAIN[self.language.code]
  28.  
  29. # make username readonly in edit mode
  30. if self.edit :
  31. self.fields['username'].widget.attrs['readonly'] = True
  32.  
  33.  
  34. username = forms.CharField(label="Username:", max_length=50, required = True,
  35. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  36. first_name = forms.CharField(label="First Name:", max_length=50, required=False,
  37. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  38. last_name = forms.CharField(label="Last Name:", max_length=50,required=False,
  39. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  40. password = forms.CharField(label="Password:", max_length=50, required = False,
  41. widget=forms.PasswordInput(attrs={'class':'myacc_input'}))
  42. confirm_password = forms.CharField(label="Confirm Password:", max_length=50, required = False,
  43. widget=forms.PasswordInput(attrs={'class':'myacc_input'}))
  44. email = forms.EmailField(label="Email:", max_length=30, required = True,
  45. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  46. postal_code = forms.CharField(label="Postal Code:", max_length=100, required = False,
  47. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  48. phone = forms.CharField(label="Phone:", max_length=20, required = False,
  49. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  50. mobile = forms.CharField(label="Mobile:", max_length=20, required = False,
  51. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  52. fax = forms.CharField(label="Fax:", max_length=20, required = False,
  53. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  54. age = forms.CharField(label="Age:", max_length=2, required = False,
  55. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  56. url = forms.CharField(label="Url:", max_length=100, required = False,
  57. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  58. contact_by = forms.ChoiceField(label="Contact By:",required = False,
  59. widget=forms.Select(attrs={'class':'myacc_dropdown'}))
  60. civility = forms.ChoiceField(label="Civility:",required = False,
  61. widget=forms.Select(attrs={'class':'site_bui_drop'}))
  62. active_domain = forms.ChoiceField(label="Domaines d'activité:",required = False,
  63. widget=forms.Select(attrs={'class':'myacc_dropdown'}))
  64.  
  65. # Here is the address form
  66. class AddressForm(forms.Form):
  67. """ Generic Address form """
  68.  
  69. def __init__(self, data=None,initial=None, organization=None, language=None, error_class=None,prefix=None ) :
  70. """ Constructor for Address form """
  71.  
  72. # override constructor
  73. forms.Form.__init__(self, data=data,initial=initial,error_class=error_class,prefix=prefix)
  74.  
  75. self.organization = organization
  76. self.language = language
  77.  
  78. # Create object of Class Country
  79. country = Country(language=self.language)
  80. country_list = country.all()
  81.  
  82. # get values
  83. country_list = list (fetch_model_values_list(country_list,COUNTRY_DROPDOWN))
  84. # Add "Select" option to list
  85. country_list.insert(0, ('','Sélectionner') )
  86. # Assign the country to choices list
  87. self.fields['country'].choices = country_list
  88.  
  89. address_one = forms.CharField(label="Adresse:", max_length=100, required = False,
  90. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  91. address_two = forms.CharField(label="Adresse:", max_length=100, required = False,
  92. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  93. address_three = forms.CharField(label="Adresse 3:", max_length=100, required = False,
  94. widget=forms.TextInput(attrs={'class':'myacc_input'}))
  95. state = forms.CharField(label="Canton:", max_length=100, required = False,
  96. widget=forms.TextInput(attrs={'class':'myacc_input'})) # State
  97. city = forms.CharField(label="Ville:", max_length=100, required = False,
  98. widget=forms.TextInput(attrs={'class':'myacc_input'})) # City
  99. country = forms.ChoiceField(label="Pays:", required = False, initial=DEFAULT_COUNTRY,
  100. widget=forms.Select(attrs={'class':'myacc_dropdown'})) # Country
  101.  
  102. # Here is the LanguageForm
  103. class LanguageForm(forms.Form):
  104. """ Generic Language form """
  105.  
  106. def __init__(self, data=None,initial=None, organization=None, language=None, error_class=None,prefix=None ) :
  107. """ Constructor for Language form """
  108. # override constructor
  109. forms.Form.__init__(self, data=data,initial=initial,error_class=error_class,prefix=prefix)
  110.  
  111. self.organization = organization
  112. self.language = language
  113. self.language_code = self.language.code if self.language else DEFAULT_LANGUAGE
  114.  
  115. # get languages
  116. language = Language()
  117. status,language_list = language.all()
  118. language_list = fetch_model_values_list(language_list,LANGUAGE_DROPDOWN)
  119.  
  120. # set language in choices field
  121. self.fields['language'].choices = language_list
  122.  
  123. # set initial value
  124. default_language = {'language':self.language_code}
  125. if self.initial :
  126. self.initial.update(default_language)
  127. else :
  128. self.initial = default_language
  129.  
  130. language = forms.ChoiceField(label="Select Language", required = False,
  131. widget=forms.Select(attrs={'class':'site_bui_drop'}))
  132.  
  133. # PROBLEM - When I render this in the countries drop down I can not see any value, i.e the country drop down is empty. Any one can help me with ?
  134. Thanks
Add Comment
Please, Sign In to add comment