diff --git a/api/urls.py b/api/urls.py index 5dba548..46d44c2 100755 --- a/api/urls.py +++ b/api/urls.py @@ -1,13 +1,20 @@ from rest_framework import routers -from .views import ProjectViewSet, SpecializationViewSet, UserViewSet, LocationViewSet +from .views import ( + LocationViewSet, + ProjectViewSet, + RealtyViewSet, + SpecializationViewSet, + UserViewSet, +) router = routers.DefaultRouter() +router.register(r'locations', LocationViewSet) router.register(r'projects', ProjectViewSet) +router.register(r'realties', RealtyViewSet) router.register(r'specializations', SpecializationViewSet) router.register(r'users', UserViewSet) -router.register(r'location', LocationViewSet) urlpatterns = router.urls diff --git a/api/views.py b/api/views.py index cd815e7..7cc6a88 100755 --- a/api/views.py +++ b/api/views.py @@ -1,8 +1,8 @@ from rest_framework.viewsets import ModelViewSet -from projects.models import Project -from projects.serializers import ProjectSerializer -from projects.filters import ProjectFilterSet +from projects.models import Project, Realty +from projects.serializers import ProjectSerializer, RealtySerializer +from projects.filters import ProjectFilterSet, RealtyFilterSet from specializations.models import Specialization from specializations.serializers import SpecializationSerializer @@ -16,12 +16,19 @@ from common.models import Location from common.serializers import LocationSerializer from common.filters import LocationFilterSet + class ProjectViewSet(ModelViewSet): queryset = Project.objects.all() serializer_class = ProjectSerializer filter_class = ProjectFilterSet +class RealtyViewSet(ModelViewSet): + queryset = Realty.objects.all() + serializer_class = RealtySerializer + filter_class = RealtyFilterSet + + class SpecializationViewSet(ModelViewSet): queryset = Specialization.objects.all() serializer_class = SpecializationSerializer diff --git a/common/filters.py b/common/filters.py index ec7adf7..fbfd842 100644 --- a/common/filters.py +++ b/common/filters.py @@ -3,8 +3,8 @@ from .models import Location class LocationFilterSet(FilterSet): - id = AllLookupsFilter() children = RelatedFilter('common.filters.LocationFilterSet') + id = AllLookupsFilter() level = AllLookupsFilter() lft = AllLookupsFilter() name = AllLookupsFilter() diff --git a/common/models.py b/common/models.py index e3770ed..e69440f 100644 --- a/common/models.py +++ b/common/models.py @@ -1,6 +1,7 @@ from django.db import models from mptt.models import TreeForeignKey, MPTTModel + class Location(MPTTModel): TYPES = ( ('_root', 'Корень'), diff --git a/common/serializers.py b/common/serializers.py index 0f2e68f..cc37b8c 100644 --- a/common/serializers.py +++ b/common/serializers.py @@ -3,7 +3,27 @@ from rest_framework.serializers import ModelSerializer from .models import Location +class NestedLocationSerializer(ModelSerializer): + class Meta: + model = Location + + fields = ( + 'id', + 'name', + 'children', + 'parent', + 'type', + 'lft', + 'rght', + 'level', + 'tree_id', + ) + + class LocationSerializer(ModelSerializer): + children = NestedLocationSerializer(many=True) + parent = NestedLocationSerializer() + class Meta: model = Location 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/filters.py b/projects/filters.py index 3225ede..3fc0181 100755 --- a/projects/filters.py +++ b/projects/filters.py @@ -1,12 +1,55 @@ from rest_framework_filters import FilterSet, RelatedFilter, AllLookupsFilter -from .models import Project + +from .models import Project, Realty, BuildingClassfication, ConstructionType + + +class BuildingClassficationFilterSet(FilterSet): + id = AllLookupsFilter() + name = AllLookupsFilter() + + class Meta: + model = BuildingClassfication + + +class ConstructionTypeFilterSet(FilterSet): + id = AllLookupsFilter() + name = AllLookupsFilter() + + class Meta: + model = ConstructionType + class ProjectFilterSet(FilterSet): + budget = AllLookupsFilter() + budget_by_agreement = AllLookupsFilter() + created = AllLookupsFilter() + cro = AllLookupsFilter() + currency = AllLookupsFilter() + deal_type = AllLookupsFilter() name = AllLookupsFilter() - price = AllLookupsFilter() + price_and_term_required = AllLookupsFilter() + state = AllLookupsFilter() + term = AllLookupsFilter() + term_type = AllLookupsFilter() text = AllLookupsFilter() - # user = RelatedFilter('users.filters.UserFilterSet') - # specialization = RelatedFilter('specializations.filters.SpecializationFilterSet') + work_type = AllLookupsFilter() + + customer = RelatedFilter('users.filters.UserFilterSet') + realty = RelatedFilter('projects.filters.RealtyFilterSet') + specialization = RelatedFilter('specializations.filters.SpecializationFilterSet') class Meta: model = Project + + +class RealtyFilterSet(FilterSet): + id = AllLookupsFilter() + name = AllLookupsFilter() + + building_classification = RelatedFilter('projects.filters.BuildingClassficationFilterSet') + construction_type = RelatedFilter('projects.filters.ConstructionTypeFilterSet') + location = RelatedFilter('common.filters.LocationFilterSet') + user = RelatedFilter('users.filters.UserFilterSet') + + class Meta: + model = Realty 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/migrations/0034_auto_20160622_1200.py b/projects/migrations/0034_auto_20160622_1200.py new file mode 100644 index 0000000..7a373bb --- /dev/null +++ b/projects/migrations/0034_auto_20160622_1200.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-22 09:00 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0033_auto_20160621_1057'), + ] + + operations = [ + migrations.AlterField( + model_name='project', + name='work_type', + field=models.IntegerField(choices=[('1', 'Проектирование'), ('2', 'Техническое сопровождение')], default=1, max_length=20), + ), + ] diff --git a/projects/models.py b/projects/models.py index 81f6e51..3c8b436 100644 --- a/projects/models.py +++ b/projects/models.py @@ -58,8 +58,8 @@ class Realty(models.Model): class Project(models.Model): WORK_TYPES = ( - ('1', 'Проектирование'), - ('2', 'Техническое сопровождение') + (1, 'Проектирование'), + (2, 'Техническое сопровождение') ) DEAL_TYPES = ( @@ -80,14 +80,14 @@ 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) term_type = models.CharField(max_length=20, choices=TERMS, default='hour') text = models.TextField(blank=True) - work_type = models.CharField(default='1', max_length=20, choices=WORK_TYPES) + work_type = models.IntegerField(default=1, choices=WORK_TYPES) state = models.CharField(default='active', max_length=20, choices=STATES) def __str__(self): @@ -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/serializers.py b/projects/serializers.py index 8ed0111..3c40c7c 100755 --- a/projects/serializers.py +++ b/projects/serializers.py @@ -1,21 +1,74 @@ from rest_framework.serializers import ModelSerializer -from .models import Project +from .models import Project, Realty, BuildingClassfication, ConstructionType +from common.serializers import LocationSerializer from specializations.serializers import SpecializationSerializer from users.serializers import UserSerializer + +class BuildingClassficationSerializer(ModelSerializer): + class Meta: + model = BuildingClassfication + + fields = ( + 'id', + 'name', + ) + + +class ConstructionTypeSerializer(ModelSerializer): + class Meta: + model = ConstructionType + + fields = ( + 'id', + 'name', + ) + + +class RealtySerializer(ModelSerializer): + building_classification = BuildingClassficationSerializer() + construction_type = ConstructionTypeSerializer() + location = LocationSerializer() + user = UserSerializer() + + class Meta: + model = Realty + + fields = ( + 'building_classification', + 'construction_type', + 'id', + 'location', + 'name', + 'user', + ) + + class ProjectSerializer(ModelSerializer): + customer = UserSerializer() specialization = SpecializationSerializer() - user = UserSerializer() + realty = RealtySerializer() class Meta: model = Project fields = ( + 'budget', + 'budget_by_agreement', + 'created', + 'cro', + 'currency', + 'customer', + 'deal_type', 'id', 'name', - 'price', + 'price_and_term_required', + 'realty', 'specialization', + 'state', + 'term', + 'term_type', 'text', - 'user', + 'work_type', ) diff --git a/projects/templates/customer_project_create.html b/projects/templates/customer_project_create.html index 172b172..21fbfe0 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 @@
Новый заказ