Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I got a problem with multiple inheritance here
- # User Address Form which inherits AddressForm and LanguageForm
- class UsersAddForm(AddressForm, LanguageForm): # Inherit AddressForm
- """ Form used to add users """
- def __init__(self, data=None,initial=None, organization=None,language =None, error_class=None,edit=False ) :
- """ Constructor for Class AddForm """
- # Override Constructor for Address Form
- AddressForm.__init__(self, data=data, organization=organization,language=language,initial=initial,error_class=error_class)
- # Override Constructor for Language Form
- LanguageForm.__init__(self, data=data, organization=organization, language=language, initial=initial,error_class=error_class)
- self.organization = organization
- self.language = language
- self.data = data if data else {}
- self.edit = edit if edit else False
- # set civility
- self.fields['civility'].choices = CIVILITY[self.language.code]
- # set contact by
- self.fields['contact_by'].choices = CONTACT_BY[self.language.code]
- # set active domain
- self.fields['active_domain'].choices = ACTIVE_DOMAIN[self.language.code]
- # make username readonly in edit mode
- if self.edit :
- self.fields['username'].widget.attrs['readonly'] = True
- username = forms.CharField(label="Username:", max_length=50, required = True,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- first_name = forms.CharField(label="First Name:", max_length=50, required=False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- last_name = forms.CharField(label="Last Name:", max_length=50,required=False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- password = forms.CharField(label="Password:", max_length=50, required = False,
- widget=forms.PasswordInput(attrs={'class':'myacc_input'}))
- confirm_password = forms.CharField(label="Confirm Password:", max_length=50, required = False,
- widget=forms.PasswordInput(attrs={'class':'myacc_input'}))
- email = forms.EmailField(label="Email:", max_length=30, required = True,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- postal_code = forms.CharField(label="Postal Code:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- phone = forms.CharField(label="Phone:", max_length=20, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- mobile = forms.CharField(label="Mobile:", max_length=20, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- fax = forms.CharField(label="Fax:", max_length=20, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- age = forms.CharField(label="Age:", max_length=2, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- url = forms.CharField(label="Url:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- contact_by = forms.ChoiceField(label="Contact By:",required = False,
- widget=forms.Select(attrs={'class':'myacc_dropdown'}))
- civility = forms.ChoiceField(label="Civility:",required = False,
- widget=forms.Select(attrs={'class':'site_bui_drop'}))
- active_domain = forms.ChoiceField(label="Domaines d'activité:",required = False,
- widget=forms.Select(attrs={'class':'myacc_dropdown'}))
- # Here is the address form
- class AddressForm(forms.Form):
- """ Generic Address form """
- def __init__(self, data=None,initial=None, organization=None, language=None, error_class=None,prefix=None ) :
- """ Constructor for Address form """
- # override constructor
- forms.Form.__init__(self, data=data,initial=initial,error_class=error_class,prefix=prefix)
- self.organization = organization
- self.language = language
- # Create object of Class Country
- country = Country(language=self.language)
- country_list = country.all()
- # get values
- country_list = list (fetch_model_values_list(country_list,COUNTRY_DROPDOWN))
- # Add "Select" option to list
- country_list.insert(0, ('','Sélectionner') )
- # Assign the country to choices list
- self.fields['country'].choices = country_list
- address_one = forms.CharField(label="Adresse:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- address_two = forms.CharField(label="Adresse:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- address_three = forms.CharField(label="Adresse 3:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'}))
- state = forms.CharField(label="Canton:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'})) # State
- city = forms.CharField(label="Ville:", max_length=100, required = False,
- widget=forms.TextInput(attrs={'class':'myacc_input'})) # City
- country = forms.ChoiceField(label="Pays:", required = False, initial=DEFAULT_COUNTRY,
- widget=forms.Select(attrs={'class':'myacc_dropdown'})) # Country
- # Here is the LanguageForm
- class LanguageForm(forms.Form):
- """ Generic Language form """
- def __init__(self, data=None,initial=None, organization=None, language=None, error_class=None,prefix=None ) :
- """ Constructor for Language form """
- # override constructor
- forms.Form.__init__(self, data=data,initial=initial,error_class=error_class,prefix=prefix)
- self.organization = organization
- self.language = language
- self.language_code = self.language.code if self.language else DEFAULT_LANGUAGE
- # get languages
- language = Language()
- status,language_list = language.all()
- language_list = fetch_model_values_list(language_list,LANGUAGE_DROPDOWN)
- # set language in choices field
- self.fields['language'].choices = language_list
- # set initial value
- default_language = {'language':self.language_code}
- if self.initial :
- self.initial.update(default_language)
- else :
- self.initial = default_language
- language = forms.ChoiceField(label="Select Language", required = False,
- widget=forms.Select(attrs={'class':'site_bui_drop'}))
- # 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 ?
- Thanks
Add Comment
Please, Sign In to add comment