|
|
|
@ -6,6 +6,7 @@ from pprint import pprint, pformat |
|
|
|
import itertools |
|
|
|
import itertools |
|
|
|
|
|
|
|
|
|
|
|
from .models import Project, ProjectFile, Portfolio, Answer, AnswerMessage, Realty, PortfolioPhoto, Stage |
|
|
|
from .models import Project, ProjectFile, Portfolio, Answer, AnswerMessage, Realty, PortfolioPhoto, Stage |
|
|
|
|
|
|
|
from archilance import util |
|
|
|
from common.models import Location |
|
|
|
from common.models import Location |
|
|
|
from specializations.models import Specialization |
|
|
|
from specializations.models import Specialization |
|
|
|
from users.models import User, Team |
|
|
|
from users.models import User, Team |
|
|
|
@ -117,6 +118,11 @@ class CustomerProjectEditForm(forms.ModelForm): |
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
self.fields['realty'].empty_label = 'Создать новый' |
|
|
|
self.fields['realty'].empty_label = 'Создать новый' |
|
|
|
|
|
|
|
self.fields['realty'].queryset = self.request.user.realties.all() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.fields['budget'].required = False |
|
|
|
|
|
|
|
self.fields['currency'].required = False |
|
|
|
|
|
|
|
self.fields['term_type'].required = False |
|
|
|
|
|
|
|
|
|
|
|
self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants() |
|
|
|
self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants() |
|
|
|
# self.fields['specialization'].queryset = Specialization.objects # Migrate with this enabled |
|
|
|
# self.fields['specialization'].queryset = Specialization.objects # Migrate with this enabled |
|
|
|
@ -124,6 +130,16 @@ class CustomerProjectEditForm(forms.ModelForm): |
|
|
|
if self.instance.pk: |
|
|
|
if self.instance.pk: |
|
|
|
self.fields['files'].queryset = self.instance.files |
|
|
|
self.fields['files'].queryset = self.instance.files |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean(self): |
|
|
|
|
|
|
|
cleaned_data = super().clean() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not cleaned_data.get('budget_by_agreement'): |
|
|
|
|
|
|
|
if not cleaned_data.get('budget'): raise forms.ValidationError({'budget': 'Это поле обязательно'}) |
|
|
|
|
|
|
|
if not cleaned_data.get('currency'): raise forms.ValidationError({'currency': 'Это поле обязательно'}) |
|
|
|
|
|
|
|
if not cleaned_data.get('term_type'): raise forms.ValidationError({'term_type': 'Это поле обязательно'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cleaned_data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RealtyForm(forms.ModelForm): |
|
|
|
class RealtyForm(forms.ModelForm): |
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
@ -145,9 +161,25 @@ class RealtyForm(forms.ModelForm): |
|
|
|
self.request = kwargs.pop('request') |
|
|
|
self.request = kwargs.pop('request') |
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.fields['name'].required = False |
|
|
|
|
|
|
|
|
|
|
|
self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants() |
|
|
|
self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants() |
|
|
|
# self.fields['location'].queryset = Location.objects # Migrate with this enabled |
|
|
|
# self.fields['location'].queryset = Location.objects # Migrate with this enabled |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean_name(self): |
|
|
|
|
|
|
|
name = self.cleaned_data.get('name') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not name: |
|
|
|
|
|
|
|
if self.data.get('extra_fields'): |
|
|
|
|
|
|
|
raise forms.ValidationError('Это поле обязательно') |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
if not self.instance.pk: |
|
|
|
|
|
|
|
name = self.instance.name |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
name = 'Новый объект %s' % util.random_ident(length=20) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PortfolioForm(forms.ModelForm): |
|
|
|
class PortfolioForm(forms.ModelForm): |
|
|
|
duplicate = forms.BooleanField(required=False,label='Some label here') |
|
|
|
duplicate = forms.BooleanField(required=False,label='Some label here') |
|
|
|
|