You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

170 lines
5.0 KiB

from django import forms
from django.db.models import Q
from django.forms.models import inlineformset_factory
from mptt.forms import TreeNodeChoiceField
from .models import Project, ProjectFile, Portfolio, Answer, Realty, PortfolioPhoto, Stage, Specialization
from common.models import Location
from users.models import User
# RealtyFormSet = inlineformset_factory(Project, Realty)
class ProjectsForm(forms.Form):
name = forms.CharField(max_length=255)
class CustomerProjectEditForm(forms.ModelForm):
files = forms.ModelMultipleChoiceField(
queryset=ProjectFile.objects.none(),
widget=forms.CheckboxSelectMultiple,
required=False,
)
class Meta:
model = Project
fields = (
'budget',
'budget_by_agreement',
'cro',
'currency',
'deal_type',
'files',
'name',
'price_and_term_required',
'realty',
'specialization',
'term_type',
'text',
'work_type',
)
widgets = {
'currency': forms.Select(attrs={'class': 'selectpicker2 valul'}),
'realty': forms.Select(attrs={'class': 'selectpicker'}),
'term_type': forms.Select(attrs={'class': 'selectpicker'}),
}
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)
self.fields['realty'].empty_label = 'Создать новый'
self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants()
self.fields['specialization'].widget.attrs = {'class': '-spec-select', 'style': 'width: 100%'}
if self.instance.pk:
self.fields['files'].queryset = self.instance.files
class RealtyForm(forms.ModelForm):
class Meta:
model = Realty
fields = (
'building_classification',
'construction_type',
'location',
'name',
)
widgets = {
'construction_type': forms.Select(attrs={'class':'selectpicker'}),
'building_classification': forms.Select(attrs={'class':'selectpicker'}),
}
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)
self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants()
class Realty1Form(forms.Form):
pass
class PortfolioForm(forms.ModelForm):
class Meta:
model = Portfolio
fields = '__all__'
widgets = {
'construction_type': forms.Select(attrs={'class':'selectpicker'}),
'building_classification': forms.Select(attrs={'class':'selectpicker'}),
'currency': forms.Select(attrs={'class':'selectpicker'}),
'term_type': forms.Select(attrs={'class':'selectpicker'}),
}
class ContractorProjectAnswerForm(forms.ModelForm):
# def __init__(self, *args, **kwargs):
# # import code; code.interact(local=dict(globals(), **locals()))
# self.project_id = kwargs.pop('project_id')
# super().__init__(*args, **kwargs)
# self.fields["project"].initial = self.project_id
class Meta:
model = Answer
fields = (
'budget',
'currency',
'term',
'term_type',
'text',
)
widgets = {
'currency': forms.Select(attrs={'class':'selectpicker'}),
'term_type': forms.Select(attrs={'class':'selectpicker'}),
}
class StageForm(forms.ModelForm):
class Meta:
model = Stage
fields = (
# 'cost',
# 'cost_type',
# 'name',
# 'result',
# 'term',
# 'term_type',
)
PortfolioPhotoFormSet = inlineformset_factory(Portfolio, PortfolioPhoto, fields=('img',))
class CustomerProjectTrashForm(forms.Form):
pk = forms.ModelChoiceField(queryset=Project.objects.none())
def __init__(self, *args, **kwargs):
self.req = kwargs.pop('req')
super().__init__(*args, **kwargs)
self.fields['pk'].queryset = self.req.user.projects.filter(state='active')
class CustomerProjectRestoreForm(forms.Form):
pk = forms.ModelChoiceField(queryset=Project.objects.none())
def __init__(self, *args, **kwargs):
self.req = kwargs.pop('req')
super().__init__(*args, **kwargs)
self.fields['pk'].queryset = self.req.user.projects.filter(state='trashed')
class CustomerProjectDeleteForm(forms.Form):
pk = forms.ModelChoiceField(queryset=Project.objects.none())
def __init__(self, *args, **kwargs):
self.req = kwargs.pop('req')
super().__init__(*args, **kwargs)
self.fields['pk'].queryset = self.req.user.projects.filter(Q(state='active') | Q(state='trashed'))