from django import forms from django.forms import ModelForm from .models import User, ContractorFinancialInfo from common.models import Location from projects.models import BuildingClassfication, ConstructionType from specializations.models import Specialization class UserEditForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if kwargs.get('instance'): if kwargs.get('instance').is_contractor(): self.fields['contractor_specializations'].queryset = kwargs.get('instance').contractor_specializations.all() class Meta: model = User fields = ( 'first_name', 'last_name', 'patronym', 'location', 'date_of_birth', 'website', 'skype', 'avatar', 'contractor_specializations', 'cro', 'phone', 'gender', ) widgets = { 'date_of_birth': forms.SelectDateWidget(years=range(1940, 2015)), # 'contractor_specializations': forms.Select(), } class ContractorFilterForm(forms.ModelForm): # PROJECT_ORDER_CHOICES = ( # "Упорядочить по"... # ('name', 'названию'), # ('budget', 'цене'), # ('created', 'дате размещения'), # ('views', 'просмотрам'), # ) # # order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES) # last_order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES) # reverse_order = forms.BooleanField(required=False) # keywords = forms.CharField(required=False, max_length=255) specialization = forms.ModelChoiceField( queryset=Specialization.objects.root_nodes()[0].get_descendants(), required=False, ) location = forms.ModelChoiceField( queryset=Location.objects.root_nodes()[0].get_descendants(), required=False, ) building_classification = forms.ModelChoiceField( queryset=BuildingClassfication.objects, required=False, ) class Meta: model = User fields = ( # 'cro', # 'specialization', # 'work_type', ) # widgets = { # 'work_type': forms.Select(attrs={'class': 'selectpicker'}), # } def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super().__init__(*args, **kwargs) # self.fields['work_type'].choices = tuple(itertools.chain((('',''),), self.fields['work_type'].choices)) # self.fields['work_type'].required = False # self.fields['work_type'].initial = '' # # self.fields['specialization'].required = False # # self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants() class ContractorFinancicalInfoForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['residency'].choices = self.fields['residency'].choices[1:] self.fields['legal_status'].choices = self.fields['legal_status'].choices[1:] # self.fields['residency'].empty_label = None # self.fields['residency'].widget.choices = self.fields['residency'].choices class Meta: model = ContractorFinancialInfo fields = ( 'fio', 'date_of_birth', 'phone', 'residency', 'legal_status', 'passport_series', 'passport_number', 'subdivision_code', 'passport_issued_by', 'passport_issue_date', 'inn', 'yandex_money', 'credit_card_number', 'passport_scan', ) widgets = { 'residency': forms.RadioSelect(), 'legal_status': forms.RadioSelect(), }