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.
 
 
 
 
 
 

156 lines
4.1 KiB

from django import forms
from django.db.models import Q
from django.forms import ModelForm, HiddenInput, Form, Select
from django.forms.models import inlineformset_factory
from mptt.forms import TreeNodeChoiceField
from .models import Project, Portfolio, Answer, Realty, PortfolioPhoto, Stage, Specialization
from users.models import User
# RealtyFormSet = inlineformset_factory(Project, Realty)
class ProjectsForm(Form):
name = forms.CharField(max_length=255)
class CustomerProjectCreateForm(ModelForm):
specialization = TreeNodeChoiceField(queryset=Specialization.objects.exclude(id=1))
class Meta:
model = Project
fields = (
'budget',
'budget_by_agreement',
'cro',
'currency',
'deal_type',
'name',
'price_and_term_required',
'specialization',
'term_type',
'text',
'work_type',
)
widgets = {
'specialization': Select(attrs={'class':'selectpicker'}),
'currency': Select(attrs={'class':'selectpicker2 valul'}),
'term_type': Select(attrs={'class':'selectpicker'}),
}
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)
class RealtyForm(ModelForm):
class Meta:
model = Realty
fields = (
'building_classification',
'construction_type',
'name',
)
widgets = {
'construction_type': Select(attrs={'class':'selectpicker'}),
'building_classification': Select(attrs={'class':'selectpicker'}),
}
class Realty1Form(Form):
pass
class PortfolioForm(ModelForm):
class Meta:
model = Portfolio
fields = '__all__'
class ContractorProjectAnswerForm(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': Select(attrs={'class':'selectpicker'}),
'term_type': Select(attrs={'class':'selectpicker'}),
}
class StageForm(ModelForm):
class Meta:
model = Stage
fields = (
# 'cost',
# 'cost_type',
# 'name',
# 'result',
# 'term',
# 'term_type',
)
PortfolioPhotoFormSet = inlineformset_factory(Portfolio, PortfolioPhoto, fields=('img',))
class ProjectEditForm(forms.ModelForm):
pk = forms.ModelChoiceField(queryset=Project.objects.none())
class Meta:
model = Project
fields = '__all__'
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 ProjectTrashForm(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 ProjectRestoreForm(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 ProjectDeleteForm(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'))