diff --git a/common/templatetags/common_tags.py b/common/templatetags/common_tags.py index 925aafe..b79f329 100644 --- a/common/templatetags/common_tags.py +++ b/common/templatetags/common_tags.py @@ -15,3 +15,10 @@ def inspect2(context, obj): return { 'obj': pformat(dir(obj)), } + +@register.simple_tag +def interact(**kwargs): + import code; code.interact(local=dict(kwargs, **dict(globals(), **locals()))) + + +# import code; code.interact(local=dict(globals(), **locals())) diff --git a/projects/forms.py b/projects/forms.py index e807541..a750a35 100644 --- a/projects/forms.py +++ b/projects/forms.py @@ -1,6 +1,5 @@ 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 @@ -11,13 +10,13 @@ from users.models import User # RealtyFormSet = inlineformset_factory(Project, Realty) -class ProjectsForm(Form): +class ProjectsForm(forms.Form): name = forms.CharField(max_length=255) -class CustomerProjectCreateForm(ModelForm): +class CustomerProjectCreateForm(forms.ModelForm): specialization = TreeNodeChoiceField(queryset=Specialization.objects.exclude(id=1)) - + class Meta: model = Project @@ -29,49 +28,59 @@ class CustomerProjectCreateForm(ModelForm): 'deal_type', 'name', 'price_and_term_required', + 'realty', 'specialization', 'term_type', 'text', 'work_type', ) - + widgets = { - 'specialization': Select(attrs={'class':'selectpicker'}), - 'currency': Select(attrs={'class':'selectpicker2 valul'}), - 'term_type': Select(attrs={'class':'selectpicker'}), + 'currency': forms.Select(attrs={'class':'selectpicker2 valul'}), + 'realty': forms.Select(attrs={'class':'selectpicker'}), + 'specialization': 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 = 'Создать новый' -class RealtyForm(ModelForm): +class RealtyForm(forms.ModelForm): class Meta: model = Realty fields = ( 'building_classification', 'construction_type', + 'location', 'name', ) - + widgets = { - 'construction_type': Select(attrs={'class':'selectpicker'}), - 'building_classification': Select(attrs={'class':'selectpicker'}), + '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) + -class Realty1Form(Form): +class Realty1Form(forms.Form): pass -class PortfolioForm(ModelForm): +class PortfolioForm(forms.ModelForm): class Meta: model = Portfolio fields = '__all__' -class ContractorProjectAnswerForm(ModelForm): +class ContractorProjectAnswerForm(forms.ModelForm): # def __init__(self, *args, **kwargs): # # import code; code.interact(local=dict(globals(), **locals())) # self.project_id = kwargs.pop('project_id') @@ -90,12 +99,12 @@ class ContractorProjectAnswerForm(ModelForm): ) widgets = { - 'currency': Select(attrs={'class':'selectpicker'}), - 'term_type': Select(attrs={'class':'selectpicker'}), + 'currency': forms.Select(attrs={'class':'selectpicker'}), + 'term_type': forms.Select(attrs={'class':'selectpicker'}), } -class StageForm(ModelForm): +class StageForm(forms.ModelForm): class Meta: model = Stage @@ -112,7 +121,7 @@ class StageForm(ModelForm): PortfolioPhotoFormSet = inlineformset_factory(Portfolio, PortfolioPhoto, fields=('img',)) -class ProjectEditForm(forms.ModelForm): +class CustomerProjectEditForm(forms.ModelForm): pk = forms.ModelChoiceField(queryset=Project.objects.none()) class Meta: @@ -126,7 +135,7 @@ class ProjectEditForm(forms.ModelForm): self.fields['pk'].queryset = self.req.user.projects.filter(state='active') -class ProjectTrashForm(Form): +class CustomerProjectTrashForm(forms.Form): pk = forms.ModelChoiceField(queryset=Project.objects.none()) def __init__(self, *args, **kwargs): @@ -136,7 +145,7 @@ class ProjectTrashForm(Form): self.fields['pk'].queryset = self.req.user.projects.filter(state='active') -class ProjectRestoreForm(Form): +class CustomerProjectRestoreForm(forms.Form): pk = forms.ModelChoiceField(queryset=Project.objects.none()) def __init__(self, *args, **kwargs): @@ -146,7 +155,7 @@ class ProjectRestoreForm(Form): self.fields['pk'].queryset = self.req.user.projects.filter(state='trashed') -class ProjectDeleteForm(Form): +class CustomerProjectDeleteForm(forms.Form): pk = forms.ModelChoiceField(queryset=Project.objects.none()) def __init__(self, *args, **kwargs): diff --git a/projects/migrations/0033_auto_20160621_1057.py b/projects/migrations/0033_auto_20160621_1057.py new file mode 100644 index 0000000..f78937f --- /dev/null +++ b/projects/migrations/0033_auto_20160621_1057.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-21 07:57 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0032_auto_20160615_1610'), + ] + + operations = [ + migrations.AlterField( + model_name='project', + name='realty', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='projects', to='projects.Realty'), + ), + ] diff --git a/projects/models.py b/projects/models.py index d0be358..302f4de 100644 --- a/projects/models.py +++ b/projects/models.py @@ -80,8 +80,8 @@ class Project(models.Model): currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES) customer = models.ForeignKey(User, related_name='projects') name = models.CharField(max_length=255) - price_and_term_required = models.BooleanField(default=False, blank=True) - realty = models.ForeignKey(Realty, null=True, related_name='projects') + price_and_term_required = models.BooleanField(default=False) + realty = models.ForeignKey(Realty, blank=True, null=True, related_name='projects') deal_type = models.CharField(max_length=20, default='secure_deal', choices=DEAL_TYPES) specialization = models.ForeignKey(Specialization, related_name='projects') term = models.IntegerField(default=0) @@ -96,11 +96,9 @@ class Project(models.Model): class Meta: verbose_name = 'Проект' verbose_name_plural = 'Проекты' - + def secure_deal(self): - if self.deal_type == 'secure_deal': - return True - return False + return self.deal_type == 'secure_deal' class ProjectFile(models.Model): diff --git a/projects/templates/customer_project_create.html b/projects/templates/customer_project_create.html index 172b172..76fcaa6 100644 --- a/projects/templates/customer_project_create.html +++ b/projects/templates/customer_project_create.html @@ -1,5 +1,7 @@ {% extends 'partials/base.html' %} +{% load common_tags %} + {% block content %} {% include 'partials/header.html' %} @@ -8,189 +10,250 @@
Новый заказ