diff --git a/.gitignore b/.gitignore index 5c00400..cf2bf01 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *.pyc .idea/ env/ +.ar/ +ar/ + diff --git a/archilance/settings/dev.py b/archilance/settings/dev.py index 012ec93..8fc56c2 100644 --- a/archilance/settings/dev.py +++ b/archilance/settings/dev.py @@ -1,5 +1,5 @@ from .base import * -# INSTALLED_APPS += ['debug_toolbar'] +INSTALLED_APPS += ['debug_toolbar'] AUTH_PASSWORD_VALIDATORS = [] diff --git a/archilance/urls.py b/archilance/urls.py index addbc88..d6f7aa8 100644 --- a/archilance/urls.py +++ b/archilance/urls.py @@ -11,7 +11,7 @@ urlpatterns = [ url(r'^$', HomeTemplateView.as_view()), url(r'^test/$', TemplateView.as_view(template_name='test.html'), name='test'), url(r'^projects/', include('projects.urls')), - url(r'^specialization/', include('specializations.urls')), + url(r'^specializations/', include('specializations.urls')), url(r'^users/', include('registration.backends.default.urls')), url(r'^users/', include('users.urls')), url(r'^admin/', admin.site.urls), diff --git a/assets/js/main.js b/assets/js/main.js index c95be8d..8a84a48 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -3,7 +3,8 @@ $(document).ready(function(){ $('.messd:first').addClass('mesAct'); $('.orderBlock:first').addClass('orAct'); - $('.resButtonF1').click(function(){ + $('.resButtonF1').click(function(e){ + e.preventDefault(); $('.slideRes').toggleClass('activeSlide'); if($('.slideRes').hasClass('activeSlide')) { $('.slideRes').slideUp(300); @@ -49,4 +50,4 @@ $(document).ready(function(){ width: '117px' }); -}); \ No newline at end of file +}); diff --git a/media/projects/portfolio/gal.jpg b/media/projects/portfolio/gal.jpg new file mode 100644 index 0000000..84a447a Binary files /dev/null and b/media/projects/portfolio/gal.jpg differ diff --git a/media/projects/portfolio/meet-the-team-image-2.jpg b/media/projects/portfolio/meet-the-team-image-2.jpg new file mode 100644 index 0000000..8327485 Binary files /dev/null and b/media/projects/portfolio/meet-the-team-image-2.jpg differ diff --git a/projects/admin.py b/projects/admin.py index 5e6a1b6..ad30f53 100644 --- a/projects/admin.py +++ b/projects/admin.py @@ -1,8 +1,20 @@ from django.contrib import admin -from .models import Project, Portfolio, PortfolioPhoto, Answer +from .models import Project, Portfolio, PortfolioPhoto, Answer, Realty, Candidate, Order + + +# class UserAdmin(admin.ModelAdmin): +# readonly_fields = ('pk',) +# list_display = ('email','is_active',) +# +# def get_groups(self, obj): +# return ', '.join(g.name for g in obj.groups.all()) + admin.site.register(Project) admin.site.register(Answer) admin.site.register(Portfolio) admin.site.register(PortfolioPhoto) +admin.site.register(Realty) +admin.site.register(Order) +admin.site.register(Candidate) diff --git a/projects/forms.py b/projects/forms.py index c522833..c4b5d51 100644 --- a/projects/forms.py +++ b/projects/forms.py @@ -1,18 +1,39 @@ -from django.forms import ModelForm, HiddenInput -from .models import Project, Portfolio, Answer +from django import forms +from django.forms import ModelForm, HiddenInput, Form +from django.forms.models import inlineformset_factory +from .models import Project, Portfolio, Answer, Realty, PortfolioPhoto + +# RealtyFormSet = inlineformset_factory(Project, Realty) class ProjectForm(ModelForm): class Meta: model = Project - fields = ( 'name', 'price', 'specialization', 'text', + 'type_work', + 'secure_transaction', ) + +class ProjectsForm(Form): + name = forms.CharField(max_length=255) + + +class RealtyForm(ModelForm): + class Meta: + model = Realty + fields = ( + 'name', + 'building_classification', + 'type_construction', + 'country', + 'city', + ) + class PortfolioForm(ModelForm): class Meta: model = Portfolio @@ -39,3 +60,6 @@ class AnswerForm(ModelForm): widgets = { 'project': HiddenInput(), } + +from django.forms.models import inlineformset_factory +PortfolioPhotoFormSet = inlineformset_factory(Portfolio, PortfolioPhoto, fields=('img',)) diff --git a/projects/migrations/0007_auto_20160525_0948.py b/projects/migrations/0007_auto_20160525_0948.py new file mode 100644 index 0000000..311806e --- /dev/null +++ b/projects/migrations/0007_auto_20160525_0948.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 09:48 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0006_auto_20160524_1208'), + ] + + operations = [ + migrations.AlterField( + model_name='answer', + name='created', + field=models.DateTimeField(default=datetime.datetime(2016, 5, 25, 9, 48, 35, 275911)), + ), + ] diff --git a/projects/migrations/0008_auto_20160525_1044.py b/projects/migrations/0008_auto_20160525_1044.py new file mode 100644 index 0000000..71edc9f --- /dev/null +++ b/projects/migrations/0008_auto_20160525_1044.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 10:44 +from __future__ import unicode_literals + +import datetime +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('projects', '0007_auto_20160525_0948'), + ] + + operations = [ + migrations.CreateModel( + name='Realty', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('building_classification', models.CharField(max_length=50)), + ('type_construction', models.CharField(max_length=50)), + ('country', models.CharField(max_length=50)), + ('city', models.CharField(max_length=50)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='realty', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AlterField( + model_name='answer', + name='created', + field=models.DateTimeField(default=datetime.datetime(2016, 5, 25, 10, 44, 29, 360210)), + ), + migrations.AddField( + model_name='project', + name='realty', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='projects', to='projects.Realty'), + ), + ] diff --git a/projects/migrations/0009_auto_20160525_1524.py b/projects/migrations/0009_auto_20160525_1524.py new file mode 100644 index 0000000..6f35dc9 --- /dev/null +++ b/projects/migrations/0009_auto_20160525_1524.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 15:24 +from __future__ import unicode_literals + +import datetime +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('projects', '0008_auto_20160525_1044'), + ] + + operations = [ + migrations.CreateModel( + name='Order', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('cost', models.DecimalField(decimal_places=2, max_digits=10)), + ('term', models.IntegerField(default=1)), + ('created', models.DateTimeField(default=django.utils.timezone.now, editable=False)), + ('status', models.BooleanField(default=False)), + ('contractor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('project', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='order', to='projects.Project')), + ], + ), + migrations.AlterModelOptions( + name='realty', + options={'verbose_name': 'Объект', 'verbose_name_plural': 'Объекты'}, + ), + migrations.AlterField( + model_name='answer', + name='created', + field=models.DateTimeField(default=datetime.datetime(2016, 5, 25, 15, 24, 2, 462642)), + ), + ] diff --git a/projects/migrations/0010_auto_20160525_1525.py b/projects/migrations/0010_auto_20160525_1525.py new file mode 100644 index 0000000..77bc8e9 --- /dev/null +++ b/projects/migrations/0010_auto_20160525_1525.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 15:25 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models +from django.utils.timezone import utc + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0009_auto_20160525_1524'), + ] + + operations = [ + migrations.AlterField( + model_name='answer', + name='created', + field=models.DateTimeField(default=datetime.datetime(2016, 5, 25, 15, 25, 42, 489763, tzinfo=utc)), + ), + ] diff --git a/projects/migrations/0011_auto_20160525_1526.py b/projects/migrations/0011_auto_20160525_1526.py new file mode 100644 index 0000000..601de14 --- /dev/null +++ b/projects/migrations/0011_auto_20160525_1526.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 15:26 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0010_auto_20160525_1525'), + ] + + operations = [ + migrations.AlterField( + model_name='answer', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/projects/models.py b/projects/models.py index 31ef9fe..dabf112 100644 --- a/projects/models.py +++ b/projects/models.py @@ -1,10 +1,33 @@ from datetime import datetime from django.db import models +from django.utils import timezone from users.models import User from specializations.models import Specialization +class Realty(models.Model): + BUILDING_CLASSIFICATION_CHOICES = ( + + ) + TYPE_CONSTRUCTION_CHOICES = ( + + ) + name = models.CharField(max_length=255) + building_classification = models.CharField(max_length=50) + type_construction = models.CharField(max_length=50) + country = models.CharField(max_length=50) + city = models.CharField(max_length=50) + user = models.ForeignKey(User, related_name='realty') + + def __str__(self): + return self.name + + class Meta: + verbose_name = 'Объект' + verbose_name_plural = 'Объекты' + + class Project(models.Model): TYPE_WORK_CHOICES = ( ('1', 'проектирование'), @@ -21,6 +44,7 @@ class Project(models.Model): type_work = models.CharField(max_length=20, choices=TYPE_WORK_CHOICES, default='1') term_cost = models.BooleanField(default=False) secure_transaction = models.BooleanField(default=False) + realty = models.ForeignKey(Realty, null=True, related_name='projects') def __str__(self): return self.name @@ -30,6 +54,22 @@ class Project(models.Model): verbose_name_plural = 'Проекты' +class Order(models.Model): + project = models.OneToOneField(Project, related_name='order') + contractor = models.ForeignKey(User) + cost = models.DecimalField(max_digits=10, decimal_places=2) + term = models.IntegerField(default=1) + created = models.DateTimeField(default=timezone.now, editable=False) + status = models.BooleanField(default=False) + + def __str__(self): + return self.project.name + + class Meta: + verbose_name = 'Заказ' + verbose_name_plural = 'Заказы' + + class Answer(models.Model): COST_TYPE_CHOICES = ( ('rur', 'rur'), @@ -50,7 +90,7 @@ class Answer(models.Model): term_type = models.CharField(max_length=10, choices=TERM_TYPE_CHOICES, default='hour') project = models.ForeignKey(Project, related_name='answers') user = models.ForeignKey(User, related_name='answers') - created = models.DateTimeField(default=datetime.now()) + created = models.DateTimeField(default=timezone.now) def __str__(self): return self.text @@ -75,7 +115,7 @@ class Candidate(models.Model): class Portfolio(models.Model): name = models.CharField(max_length=255) description = models.TextField() - user = models.ForeignKey(User) + user = models.ForeignKey(User,related_name='portfolio') def __str__(self): return self.name @@ -95,3 +135,6 @@ class PortfolioPhoto(models.Model): # def __str__(self): # return self.img + + + diff --git a/projects/templates/projects/project_form.html b/projects/templates/projects/project_form.html index 0bda307..9e5d3d0 100644 --- a/projects/templates/projects/project_form.html +++ b/projects/templates/projects/project_form.html @@ -1,244 +1,245 @@ {% extends "base.html" %} -{#

Добавление

#} -{#
#} -{##} -{# {{ form.errors }}#} -{# {% csrf_token %}#} -{##} -{# {% for field in form %}#} -{#
#} -{# {{ field.label }}#} -{# {{ field }}#} -{#
#} -{# {% endfor %}#} -{# #} -{#
#} {% block content %} -
-

Новый заказ

-
-
- {{ form.errors }} -
{% csrf_token %} -
-

Формирование заказа

-
-

Название заказа

- - -
-
-

Подробно опишите задание

- -
-
-
-
-

Дополнительно

-
-
- -
- -

+ добавить файл (до 100 файлов)

-
- -
    -
  • - Архитерурное 2.jpg - 7мб -
    -
  • -
  • - Архитерурное 2.jpg - 7мб -
    -
  • -
-
-

Тип работы:

-
-
- -

Проектирование

-
-
- -

Техническое сопровождение

-
-
- -
-
-
-
-
-
Специализация проекта:
-
-
-
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
Бюджет
-
-
-
-
- - -
-
- -
-
- -

или по договоренности

-
-
-
- -

Сделать для исполнителей обязательным для заполнения поля цена и срок

-
-
-
Способ оплаты
-
-
-
- -

- Безопасная сделка (с резервированием бюджета) -

-

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro vel suscipit eaque quidem voluptate aperiam enim aut libero, excepturi architecto maxime, placeat maiores, odio itaque, ex consectetur dignissimos dicta officia. -

-
-
- -

- Прямая оплата Исполнителю на его кошелек/счет -

-

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro vel suscipit eaque quidem voluptate aperiam enim aut libero, excepturi architecto maxime, placeat maiores, odio itaque, ex consectetur dignissimos dicta officia. -

-
-
-
-
-

Расширенный поиск

- -
-
-
-
-
-
-
-
Выбор объекта:
-
Наименование:
-
Классификация здания:
-
Вид строительства:
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
Местоположение:
-
-
-
- -
-
- -
-
- -

Требуется допуск СРО

-
-
- - -
-
- -
+
+

Новый заказ

+
+ +
+ {% csrf_token %} + + + +
+ + + {{ form.errors }} +
+

Формирование заказа

+
+

Название заказа

+ + {{ form.name.errors }} +
+
+

Подробно опишите задание

+ +
+
+
+
+

Дополнительно

+
+
+{# #} +{#
#} +{# #} +{#

+ добавить файл (до 100 файлов)

#} +{#
#} +{# #} +{# #} +
    +
  • + Архитерурное 2.jpg + 7мб +
    +
  • +
+
+

Тип работы:

+
+
+ +

Проектирование

+
+ +
+ +

Техническое сопровождение

+
+
+ +
+
+
+
+
+
Специализация проекта:
+
+
+
+
+ + +
+
+ {{ form.specialization }} +{# #} +
+
+{# #} +
+
+{# #} +
+
+{# #} +
+
+
+
Бюджет
+
+
+
+
+ + +
+
+ +
+
+ +

или по договоренности

+
+
+
+ +

Сделать для исполнителей обязательным для заполнения поля цена и срок

+
+
+
Способ оплаты
+
+
+
+ +

+ Безопасная сделка (с резервированием бюджета) +

+

+ Текст +

+
+
+ +

+ Прямая оплата Исполнителю на его кошелек/счет +

+

+ Текст +

+
+
+
+
+

Расширенный поиск

+ +
+
+
+
+
+
+
+
Выбор объекта:
+
Наименование:
+
Классификация здания:
+
Вид строительства:
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
Местоположение:
+
+
+
+ +
+
+ +
+
+ +

Требуется допуск СРО

+
+
+ + {# #} + +
+
+ +
+ + + + + + {% endblock %} diff --git a/projects/templates/projects/test.html b/projects/templates/projects/test.html new file mode 100644 index 0000000..04bb4c4 --- /dev/null +++ b/projects/templates/projects/test.html @@ -0,0 +1,7 @@ +

Test page

+
{% csrf_token %} + {{ form.as_p }} + {{ realty_form.errors}} + {{ realty_form.as_p }} + +
diff --git a/projects/templates/projects/testport.html b/projects/templates/projects/testport.html new file mode 100644 index 0000000..b21ecc8 --- /dev/null +++ b/projects/templates/projects/testport.html @@ -0,0 +1,18 @@ +
{% csrf_token %} + {{ form.as_p }} + +
+ Photos + {{ portfolio_photo_form.management_form }} + {{ portfolio_photo_form.non_form_errors }} + {% for form in portfolio_photo_form %} + {{ form.id }} +
+ {{ form.img.errors }} + {{ form.img.label_tag }} + {{ form.img }} +
+ {% endfor %} +
+ +
diff --git a/projects/urls.py b/projects/urls.py index 8157f22..f99957f 100644 --- a/projects/urls.py +++ b/projects/urls.py @@ -1,13 +1,17 @@ from django.conf import urls # from django.contrib.auth.views import login, logout -from .views import ProjectListView, ProjectDetailView, ProjectCreateView , PortfolioCreateView +from .views import ProjectListView, ProjectDetailView, \ + ProjectCreateView, PortfolioCreateView,\ + TestProjectView, manage_articles app_name = 'projects' urlpatterns = [ urls.url(r'^$', ProjectListView.as_view(), name='list'), + urls.url(r'^porttest/$', manage_articles, name='portfolio'), urls.url(r'^create/$', ProjectCreateView.as_view(), name='project-create'), + urls.url(r'^test/$', TestProjectView.as_view(), name='project-test'), urls.url(r'^portfolio/create/$', PortfolioCreateView.as_view(), name='portfolio-create'), urls.url(r'(?P\d+)$', ProjectDetailView.as_view(), name='detail'), ] diff --git a/projects/views.py b/projects/views.py index 43d7711..4d170f6 100644 --- a/projects/views.py +++ b/projects/views.py @@ -5,7 +5,7 @@ from django.views.generic import ListView, DetailView, CreateView from django.views.generic.edit import FormMixin from .models import Project, Portfolio -from .forms import ProjectForm, PortfolioForm, AnswerForm +from .forms import ProjectForm, PortfolioForm, AnswerForm, RealtyForm class ProjectListView(ListView): @@ -74,3 +74,63 @@ class PortfolioCreateView(PermissionRequiredMixin, CreateView): success_url = '/projects/' # import code; code.interact(local=dict(globals(), **locals())) + + +class TestProjectView(CreateView): + model = Project + form_class = ProjectForm + template_name = 'projects/test.html' + success_url = '/projects/' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['realty_form'] = RealtyForm(prefix='form_2') + return context + + # def get(self, request, *args, **kwargs): + # self.object = None + + def post(self, request, *args, **kwargs): + self.object = None + form_class = self.get_form_class() + form = self.get_form(form_class) + realty_form = RealtyForm(self.request.POST) + import code; code.interact(local=dict(globals(), **locals())) + if form.is_valid(): + return self.form_valid(form, realty_form) + else: + return self.form_invalid(form, realty_form) + # import code; code.interact(local=dict(globals(), **locals())) + + + def form_valid(self, form, realty_form): + status = 'form_valid' + + realty = realty_form.instance + realty.user = self.request.user + realty.save() + project = form.instance + project.user = self.request.user + project.realty = realty + project.save() + # import code; code.interact(local=dict(globals(), **locals())) + + def form_invalid(self, form, realty_form): + status = 'form_invalid' + return self.render_to_response( + self.get_context_data(form=form, + realty_form=realty_form)) + +from django.shortcuts import render +from .forms import PortfolioPhotoFormSet + +def manage_articles(request): + form = PortfolioForm + portfolio_photo_form = PortfolioPhotoFormSet() + if request.method == "POST": + form = PortfolioForm(request.POST) + portfolio_photo_form = PortfolioPhotoFormSet(request.POST, request.FILES) + import code; code.interact(local=dict(globals(), **locals())) + + + return render(request, 'projects/testport.html', {'form': form, 'portfolio_photo_form': portfolio_photo_form}) diff --git a/specializations/models.py b/specializations/models.py index 66d176e..03f8c1e 100644 --- a/specializations/models.py +++ b/specializations/models.py @@ -10,6 +10,10 @@ class Specialization(MPTTModel): def __str__(self): return self.name + + class Meta: + verbose_name = 'Специализация' + verbose_name_plural = 'Специализации' class MPTTMeta: order_insertion_by = ['name'] diff --git a/specializations/templates/specialization/specialization_list.html b/specializations/templates/specialization/specialization_list.html deleted file mode 100644 index 2f64781..0000000 --- a/specializations/templates/specialization/specialization_list.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "base.html" %} -{% block content %} -

Специализации

- {% load mptt_tags %} -{# {% for spec in object_list %}#} -{#

{{ spec }}

#} -{# {% endfor %}#} -{##} -{# {% load mptt_tags %}#} -{##} - {{ root }} - {% for ch in children %} -

{{ ch }}

- {% for ch1 in ch.get_children %} - {{ ch1 }} - {% endfor %} - {% endfor %} -{% endblock %} - diff --git a/specializations/templates/specializations/specialization_detail.html b/specializations/templates/specializations/specialization_detail.html new file mode 100644 index 0000000..aa5eb66 --- /dev/null +++ b/specializations/templates/specializations/specialization_detail.html @@ -0,0 +1,4 @@ +{% extends "base.html" %} +{% block content %} + {{ object }} +{% endblock %} diff --git a/specializations/templates/specializations/specialization_list.html b/specializations/templates/specializations/specialization_list.html new file mode 100644 index 0000000..c648e6f --- /dev/null +++ b/specializations/templates/specializations/specialization_list.html @@ -0,0 +1,67 @@ +{% extends "base.html" %} +{% block content %} +

Специализации

+ {% load mptt_tags %} + {# {% for spec in object_list %}#} + {#

{{ spec }}

#} + {# {% endfor %}#} + {##} + {% load mptt_tags %} + {##} + {% for ch in children %} +

{{ ch }}

+ {% for ch1 in ch.get_children %} + {# {{ ch1 }}#} + {% endfor %} + {% endfor %} + {% block js_block %} + + {% endblock %} +{% endblock %} + diff --git a/specializations/urls.py b/specializations/urls.py index 03cbe75..28730fd 100644 --- a/specializations/urls.py +++ b/specializations/urls.py @@ -1,8 +1,12 @@ from django.conf import urls # from django.contrib.auth.views import login, logout -from .views import SpecListView +from .views import SpecListView, SpecChildrenDetailView, test_page, test_spec urlpatterns = [ urls.url(r'^$', SpecListView.as_view(), name='spec-list'), -] \ No newline at end of file + urls.url(r'^test/$', test_page), + urls.url(r'^spectest/$', test_spec), + urls.url(r'^children/(?P\d+)$', SpecChildrenDetailView.as_view(), name='spec-children'), + +] diff --git a/specializations/views.py b/specializations/views.py index 9535523..8661d18 100644 --- a/specializations/views.py +++ b/specializations/views.py @@ -1,5 +1,8 @@ from django.shortcuts import render -from django.views.generic import ListView +from django.views.generic import ListView, DetailView +from django.http import JsonResponse +from django.views.generic import TemplateView +from django.http import HttpResponse from .models import Specialization class SpecListView(ListView): @@ -12,3 +15,43 @@ class SpecListView(ListView): context['children'] = root.get_children() context['roots'] = Specialization.objects.root_nodes() return context + + +def test_page(request): + if request.method == 'POST': + if request.is_ajax(): + spec_id = request.POST.get('spec_id') + spec = Specialization.objects.get(pk=spec_id) + children = spec.get_children() + return JsonResponse({"hello": 'yes'}) + else: + return JsonResponse({"hello":"python"}) + + +def test_spec(request): + spec = Specialization.objects.get(pk=2) + # children = spec.get_children() + return HttpResponse(request, {'mm':'hello'}) + +class SpecChildrenDetailView(DetailView): + model = Specialization + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + return context + + +class JSONResponseMixin(object): + def render_to_json_response(self, context, **response_kwargs): + return JsonResponse( + self.get_data(context), + **response_kwargs + ) + + def get_data(self, context): + return context + + +class JSONView(JSONResponseMixin, TemplateView): + def render_to_response(self, context, **response_kwargs): + return self.render_to_json_response(context, **response_kwargs) diff --git a/templates/base.html b/templates/base.html index 16a19c9..418b85d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -123,5 +123,6 @@ +{% block js_block %} {% endblock %} diff --git a/users/migrations/0006_auto_20160525_0948.py b/users/migrations/0006_auto_20160525_0948.py new file mode 100644 index 0000000..79ef51b --- /dev/null +++ b/users/migrations/0006_auto_20160525_0948.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 09:48 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0005_auto_20160524_1054'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='created', + field=models.DateTimeField(default=datetime.datetime(2016, 5, 25, 9, 48, 35, 257077)), + ), + ] diff --git a/users/migrations/0007_auto_20160525_1526.py b/users/migrations/0007_auto_20160525_1526.py new file mode 100644 index 0000000..f3c493a --- /dev/null +++ b/users/migrations/0007_auto_20160525_1526.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 15:26 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0006_auto_20160525_0948'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='created', + field=models.DateTimeField(default=datetime.datetime(2016, 5, 25, 15, 26, 33, 142994)), + ), + ] diff --git a/users/migrations/0008_auto_20160525_1527.py b/users/migrations/0008_auto_20160525_1527.py new file mode 100644 index 0000000..cd55854 --- /dev/null +++ b/users/migrations/0008_auto_20160525_1527.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-25 15:27 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0007_auto_20160525_1526'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/users/models.py b/users/models.py index 3fe0f86..ca17bb3 100644 --- a/users/models.py +++ b/users/models.py @@ -1,5 +1,6 @@ from datetime import datetime from django.db import models +from django.utils import timezone from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, AbstractUser, Group, PermissionsMixin class UserManager(BaseUserManager): @@ -19,14 +20,14 @@ class UserManager(BaseUserManager): return user -class PerformUserManager(models.Manager): +class ContractorUserManager(models.Manager): def get_queryset(self): - return super(PerformUserManager, self).get_queryset().filter(groups__name='Исполнитель') + return super(ContractorUserManager, self).get_queryset().filter(groups__name='Исполнители') class CustomerUserManager(models.Manager): def get_queryset(self): - return super(CustomerUserManager, self).get_queryset().filter(groups__name='Заказчик') + return super(CustomerUserManager, self).get_queryset().filter(groups__name='Заказчики') class User(AbstractBaseUser, PermissionsMixin): @@ -34,7 +35,7 @@ class User(AbstractBaseUser, PermissionsMixin): last_name = models.CharField(max_length=255, blank=True) email = models.EmailField(max_length=255, unique=True, db_index=True) is_active = models.BooleanField(default=True) - created = models.DateTimeField(default=datetime.now()) + created = models.DateTimeField(default=timezone.now) @property def is_staff(self): @@ -52,7 +53,7 @@ class User(AbstractBaseUser, PermissionsMixin): USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] objects = UserManager() - perform_objects = PerformUserManager() + contractor_objects = ContractorUserManager() customers_objects = CustomerUserManager() class Meta: diff --git a/users/templates/users/contractor.html b/users/templates/users/contractor.html new file mode 100644 index 0000000..efad0e5 --- /dev/null +++ b/users/templates/users/contractor.html @@ -0,0 +1,577 @@ +{% extends "base.html" %} + + +{% block content %} +

{{ user }}

+

{{ user.groups.all }}

+ +
+
+
+ +
+
+

+ Иванов Петр Иванович [ivanov_petr] +

+

Россия, Москва

+ +
Свободен
+ показать контакты +
+
+
+

+ Специализации: +

+
+ Интерьеры + 2-й +
+
+ Визуализация/3D + 45-й +
+
+ Экстерьеры + 10-й +
+
+ Архитектура + 3-й +
+
+ 3D Моделирование + 100-й +
+
+
+ +
+ +
+
+ +
+ {% for p in user.portfolio.all %} +
+
+
+
+
+
+
+

{{ p.name }}

+
+
+ +
+
+ +
+
+
+
+ {% endfor %} +
+ +
+
+ +
+
+
+
+
+
+
+
+ 35 000 +
+
+
+
+

+ Визуализация + загородного + дома 1500m2 +

+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+ 35 000 +
+
+
+
+

+ Визуализация + загородного + дома 1500m2 +

+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+ 35 000 +
+
+
+
+

+ Визуализация + загородного + дома 1500m2 +

+
+
+ +
+
+ +
+
+
+
+
+ +
+
+
+
+ +

Загрузить резюме

+
+
+ +

Загрузить файл

+
+
+
+
+
+ profile-image +
+
+
+
+

Иванов Петр Сергеевич

+ скачать резюме +

+ Мужчина, 24 года, 14 февраля 1991 +

+
+
+
    +
  • brilliantov.me
  • +
  • alex@brilliantov.me
  • +
  • +7 968 009 19 99
  • +
  • Россия, Москва
  • +
+
+
+
+

+ Специализации: +

+
+ Интерьеры + 2-й +
+
+ Визуализация/3D + 45-й +
+
+
+
+
+
+
+
+
+

Что я умею?

+ + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut perspiciatis ducimus ullam saepe sed! Architecto sit, repellendus illo ut odio amet facilis distinctio veniam nulla consequatur a sequi deleniti aperiam! + +
+
+

Что я умею?

+ + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut perspiciatis ducimus ullam saepe sed! Architecto sit, repellendus illo ut odio amet facilis distinctio veniam nulla consequatur a sequi deleniti aperiam! + +
+
+

Что я умею?

+ + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut perspiciatis ducimus ullam saepe sed! Architecto sit, repellendus illo ut odio amet facilis distinctio veniam nulla consequatur a sequi deleniti aperiam! + +
+
+
+
+

Дипломы / Сертификаты

+
+ +

Загрузить файл

+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+

Допуск СРО

+
+ +

Загрузить файл

+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+

+ Иванов Петр Иванович +

+ + Безопасная сделка + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra justo commodo. Proin sodales pulvinar tempor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam fermentum, nulla luctus pharetra vulputate, felis tellus mollis orci, sed rhoncus sapien nunc eget odio. +

+
+
+
+
+
+ +
+
+{% endblock %} diff --git a/users/templates/users/customer.html b/users/templates/users/customer.html new file mode 100644 index 0000000..4f080b2 --- /dev/null +++ b/users/templates/users/customer.html @@ -0,0 +1,4 @@ +{% extends 'base.html' %} +{% block content %} +

Заказчик

+{% endblock %} diff --git a/users/urls.py b/users/urls.py index ac04e3b..43ef580 100755 --- a/users/urls.py +++ b/users/urls.py @@ -1,12 +1,13 @@ from django.conf import urls from django.contrib.auth.views import login, logout -from .views import UserListView, UserDetailView, UserInfoListView - +from .views import UserListView, UserDetailView, UserInfoListView, UserView urlpatterns = [ urls.url(r'^profile/$', UserDetailView.as_view(), name='user-detail'), # urls.url(r'^login/?$', login, {'template_name': 'users/login.html'}), # urls.url(r'^logout/?$', logout), urls.url(r'^$', UserListView.as_view(), name='users_list'), urls.url(r'^info$', UserInfoListView.as_view(), name='users_info_list'), + urls.url(r'^contractor/(?P\d+)$$', UserView.as_view(), name='user_view'), + urls.url(r'^(?P\d+)$', UserView.as_view(), name='user_view'), ] diff --git a/users/views.py b/users/views.py index 163d282..da84eff 100644 --- a/users/views.py +++ b/users/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render from django.contrib.auth.models import Group -from django.views.generic import ListView, DetailView +from django.views.generic import ListView, DetailView, View, UpdateView from .models import User @@ -23,3 +23,33 @@ class UserInfoListView(ListView): class UserDetailView(DetailView): model = User + + + +class UserView(View): + template_name = 'users/contractor.html' + + def get(self, request, pk): + user = User.objects.get(pk=pk) + user_group = user.groups.all().first() + if 'Заказчики' in user_group.name: + self.template_name = 'users/customer.html' + + return render(request, self.template_name, {'user': user}) + # import code; code.interact(local=dict(globals(), **locals())) + + +class UserUpdateView(UpdateView): + model = User + +# class ContractorDetailView(DetailView): +# model = User +# template_name = 'users/contractor.html' +# +# def get_queryset(self): +# qs = super().get_queryset() +# return User.contractor_objects.get(self.pk) + + +class CustomerDetailView(DetailView): + model = User