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.
258 lines
8.5 KiB
258 lines
8.5 KiB
from django import forms
|
|
from django.db.models import Q
|
|
from django.forms.models import inlineformset_factory
|
|
from mptt.forms import TreeNodeChoiceField
|
|
from pprint import pprint, pformat
|
|
import itertools
|
|
|
|
from .models import Project, ProjectFile, Portfolio, Answer, Realty, PortfolioPhoto, Stage, Specialization
|
|
from common.models import Location
|
|
from users.models import User
|
|
|
|
|
|
class ProjectFilterForm(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)
|
|
|
|
class Meta:
|
|
model = Project
|
|
|
|
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()
|
|
# self.fields['specialization'].queryset = Specialization.objects # Migrate with this enabled
|
|
|
|
|
|
class ProjectFilterRealtyForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Realty
|
|
|
|
fields = (
|
|
'building_classification',
|
|
'construction_type',
|
|
'location',
|
|
)
|
|
|
|
widgets = {
|
|
'building_classification': forms.Select(attrs={'class': 'selectpicker'}),
|
|
'construction_type': forms.Select(attrs={'class': 'selectpicker'}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.request = kwargs.pop('request')
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.fields['building_classification'].empty_label = ''
|
|
self.fields['building_classification'].required = False
|
|
|
|
self.fields['construction_type'].empty_label = ''
|
|
self.fields['construction_type'].required = False
|
|
|
|
self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants()
|
|
# self.fields['location'].queryset = Location.objects # Migrate with this enabled
|
|
|
|
|
|
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'].queryset = Specialization.objects # Migrate with this enabled
|
|
|
|
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()
|
|
# self.fields['location'].queryset = Location.objects # Migrate with this enabled
|
|
|
|
|
|
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):
|
|
class Meta:
|
|
model = Answer
|
|
|
|
# ('author', 'Relation? True', 'Null? None', 'Blank? None'),
|
|
# ('content_type', 'Relation? True', 'Null? False', 'Blank? False'),
|
|
# ('portfolios', 'Relation? True', 'Null? False', 'Blank? True'),
|
|
# ('project', 'Relation? True', 'Null? False', 'Blank? False'),
|
|
#
|
|
# ('candidates', 'Relation? True', 'Null? True', 'Blank? None'),
|
|
# ('files', 'Relation? True', 'Null? True', 'Blank? None'),
|
|
#
|
|
#
|
|
# ('budget', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('created', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('currency', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('object_id', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('term', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('term_type', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('text', 'Relation? False', 'Null? False', 'Blank? False'),
|
|
# ('secure_deal_only', 'Relation? False', 'Null? False', 'Blank? True'),
|
|
|
|
fields = (
|
|
'budget',
|
|
'currency',
|
|
'term',
|
|
'term_type',
|
|
'text',
|
|
'secure_deal_only',
|
|
|
|
'portfolios',
|
|
# 'files', # Doesn't work for some fucked up reason
|
|
)
|
|
|
|
widgets = {
|
|
'currency': 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)
|
|
|
|
|
|
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'))
|
|
|
|
|
|
# import code; code.interact(local=dict(globals(), **locals()))
|
|
|