From 52bc32bd2af3d29927c7ac0c0dedac52d0eb33cf Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Thu, 7 Jul 2016 16:23:05 +0300 Subject: [PATCH] #ARC-6 edit and delete portfolio --- specializations/views.py | 1 + users/templates/contractor_profile.html | 27 +++-- users/templates/worksell_create_form.html | 10 +- .../migrations/0009_auto_20160707_1315.py | 56 ++++++++++ .../migrations/0010_auto_20160707_1401.py | 27 +++++ work_sell/models.py | 20 ++-- work_sell/templates/worksell_create.html | 59 +++++++++- work_sell/templates/worksell_edit.html | 102 ++++++++++++++++++ work_sell/templates/worksells_list.html | 9 +- work_sell/urls.py | 4 + work_sell/views.py | 44 +++++++- 11 files changed, 331 insertions(+), 28 deletions(-) create mode 100644 work_sell/migrations/0009_auto_20160707_1315.py create mode 100644 work_sell/migrations/0010_auto_20160707_1401.py create mode 100644 work_sell/templates/worksell_edit.html diff --git a/specializations/views.py b/specializations/views.py index a8a9f37..459fe4f 100644 --- a/specializations/views.py +++ b/specializations/views.py @@ -55,4 +55,5 @@ class JSONResponseMixin(object): class JSONView(JSONResponseMixin, TemplateView): def render_to_response(self, context, **response_kwargs): + context = {'test': 'data'} return self.render_to_json_response(context, **response_kwargs) diff --git a/users/templates/contractor_profile.html b/users/templates/contractor_profile.html index a413f05..3c3568c 100644 --- a/users/templates/contractor_profile.html +++ b/users/templates/contractor_profile.html @@ -182,7 +182,7 @@
- {{ ws.price }} + {{ ws.budget }}
@@ -190,7 +190,9 @@

{{ ws }}

- + + +
@@ -388,10 +390,7 @@

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. +

@@ -414,7 +413,21 @@ $('#worksell-add-form').on('submit', function(e){ e.preventDefault(); var dataSerializer = $(this).serialize(); - alert(dataSerializer); + $.ajax({ + url: '/work_sell/test/', + method: 'POST', + data: dataSerializer, + dataType: 'json', + success: function(data){ + if (data.status == 'ok') { + location.reload(); + } + }, + error: function(jqXHR, exception){ + console.log(jqXHR.statusCode); + } + + }) }); diff --git a/users/templates/worksell_create_form.html b/users/templates/worksell_create_form.html index 28ea2cc..7327442 100644 --- a/users/templates/worksell_create_form.html +++ b/users/templates/worksell_create_form.html @@ -44,7 +44,7 @@
- {{ worksell_form.budget_type }} + {{ worksell_form.currency}}
@@ -71,6 +71,14 @@ {{ worksell_form.building_classification}} +
+ +
+ +
+ +
+ diff --git a/work_sell/migrations/0009_auto_20160707_1315.py b/work_sell/migrations/0009_auto_20160707_1315.py new file mode 100644 index 0000000..15bb2d8 --- /dev/null +++ b/work_sell/migrations/0009_auto_20160707_1315.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-07-07 10:15 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('work_sell', '0008_auto_20160706_1249'), + ] + + operations = [ + migrations.RemoveField( + model_name='worksell', + name='budget_by_agreement', + ), + migrations.AddField( + model_name='worksell', + name='currency', + field=models.CharField(blank=True, choices=[('rur', 'RUR'), ('usd', 'USD'), ('eur', 'EUR')], default='rur', max_length=20, null=True), + ), + migrations.AlterField( + model_name='worksell', + name='budget', + field=models.DecimalField(blank=True, decimal_places=0, default=0, max_digits=10, null=True), + ), + migrations.AlterField( + model_name='worksell', + name='building_classification', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='worksells', to='projects.BuildingClassfication'), + ), + migrations.AlterField( + model_name='worksell', + name='construction_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='worksells', to='projects.ConstructionType'), + ), + migrations.AlterField( + model_name='worksell', + name='specialization', + field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='worksells', to='specializations.Specialization'), + ), + migrations.AlterField( + model_name='worksell', + name='term', + field=models.IntegerField(blank=True, default=0, null=True), + ), + migrations.AlterField( + model_name='worksell', + name='term_type', + field=models.CharField(blank=True, choices=[('project', 'За проект'), ('hour', 'За час'), ('day', 'За день'), ('month', 'За месяц')], default='hour', max_length=20, null=True), + ), + ] diff --git a/work_sell/migrations/0010_auto_20160707_1401.py b/work_sell/migrations/0010_auto_20160707_1401.py new file mode 100644 index 0000000..321b296 --- /dev/null +++ b/work_sell/migrations/0010_auto_20160707_1401.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-07-07 11:01 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone +import sorl.thumbnail.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('work_sell', '0009_auto_20160707_1315'), + ] + + operations = [ + migrations.AlterField( + model_name='worksell', + name='created', + field=models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True), + ), + migrations.AlterField( + model_name='worksell', + name='img', + field=sorl.thumbnail.fields.ImageField(blank=True, null=True, upload_to='worksell/worksell'), + ), + ] diff --git a/work_sell/models.py b/work_sell/models.py index e3e467c..6aa6af2 100644 --- a/work_sell/models.py +++ b/work_sell/models.py @@ -5,24 +5,24 @@ from django.db import models from django.utils import timezone from users.models import User -from projects.models import BuildingClassfication, ConstructionType, TERMS +from projects.models import BuildingClassfication, ConstructionType, TERMS, CURRENCIES from specializations.models import Specialization class WorkSell(models.Model): name = models.CharField(max_length=255) description = models.TextField(blank=True) - img = ImageField(upload_to='worksell/worksell') - budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True) - budget_by_agreement = models.BooleanField(default=False) - specialization = TreeForeignKey(Specialization, related_name='worksells') - term = models.IntegerField(default=0) - term_type = models.CharField(max_length=20, choices=TERMS, default='hour') + img = ImageField(upload_to='worksell/worksell', null=True, blank=True) + budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True) + currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES, null=True, blank=True) + specialization = TreeForeignKey(Specialization, related_name='worksells', null=True, blank=True) + term = models.IntegerField(default=0, null=True, blank=True) + term_type = models.CharField(max_length=20, choices=TERMS, default='hour', null=True, blank=True) contractor = models.ForeignKey(User, related_name='work_sell') - building_classification = models.ForeignKey(BuildingClassfication, related_name='worksells') - construction_type = models.ForeignKey(ConstructionType, related_name='worksells') + building_classification = models.ForeignKey(BuildingClassfication, related_name='worksells', null=True, blank=True) + construction_type = models.ForeignKey(ConstructionType, related_name='worksells', null=True, blank=True) location = TreeForeignKey('common.Location', related_name='worksells', null=True, blank=True) - created = models.DateTimeField(default=timezone.now) + created = models.DateTimeField(default=timezone.now, null=True, blank=True) def __str__(self): return self.name diff --git a/work_sell/templates/worksell_create.html b/work_sell/templates/worksell_create.html index afcca69..752e85f 100644 --- a/work_sell/templates/worksell_create.html +++ b/work_sell/templates/worksell_create.html @@ -1,4 +1,55 @@ -
{% csrf_token %} - {{ form.as_p }} - -
+{% extends 'partials/base.html' %} +{% block content %} +
{% csrf_token %} + +
+ + + + Add files... + + +
+ +
+{% endblock %} + +{% block js_block %} + + +{% endblock %} diff --git a/work_sell/templates/worksell_edit.html b/work_sell/templates/worksell_edit.html new file mode 100644 index 0000000..8a52a84 --- /dev/null +++ b/work_sell/templates/worksell_edit.html @@ -0,0 +1,102 @@ +{% extends 'partials/base.html' %} + +{% load common_tags %} + +{% block content %} + {% include 'partials/header.html' %} + +
+
+
+

Изменение готового проекта

+
+ +
{% csrf_token %} +
+

Название заказа {{ form.name.errors.as_text }}

+ +
+ +
+

Подробно опишите задание {{ form.description.errors.as_text }}

+ +
+ +
+

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

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

Бюджет{{ form.budget.errors.as_text }}

+
+
+ +
+
+ {{ form.currency}} +
+
+
+ +
+

Срок выполнения{{ form.budget.errors.as_text }}

+
+
+ +
+
+ {{ form.term_type }} +
+
+
+ +
+
+
+

Вид строительства

+ {{ form.construction_type}} +
+ +
+

Классификация здания

+ {{ form.building_classification}} +
+ +
+ +
+ +
+ +
+ + + +
+ {% include 'partials/footer.html' %} +
+
+{% endblock %} diff --git a/work_sell/templates/worksells_list.html b/work_sell/templates/worksells_list.html index 00003fe..b3cf2f9 100644 --- a/work_sell/templates/worksells_list.html +++ b/work_sell/templates/worksells_list.html @@ -127,11 +127,12 @@

{{ work }}

-
-
- -
+ +
+ +
+
diff --git a/work_sell/urls.py b/work_sell/urls.py index bc1261e..a560133 100644 --- a/work_sell/urls.py +++ b/work_sell/urls.py @@ -4,6 +4,8 @@ from .views import ( WorkSellsView, WorkSellDetail, WorkSellCreateView, + WorkSellUpdateView, + work_sell_create, ) app_name = 'work_sell' @@ -11,5 +13,7 @@ app_name = 'work_sell' urlpatterns = [ urls.url(r'^$', WorkSellsView.as_view(), name='list'), urls.url(r'^create/$', WorkSellCreateView.as_view(), name='create'), + urls.url(r'^(?P\d+)/edit/$', WorkSellUpdateView.as_view(), name='edit'), + urls.url(r'^test/$', work_sell_create, name='test'), urls.url(r'^(?P\d+)/$', WorkSellDetail.as_view(), name='detail'), ] diff --git a/work_sell/views.py b/work_sell/views.py index 7209dc6..63093ae 100644 --- a/work_sell/views.py +++ b/work_sell/views.py @@ -1,5 +1,8 @@ +import json from django.shortcuts import render -from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView +from django.core.urlresolvers import reverse +from django.http import JsonResponse, HttpResponse +from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView, TemplateView from .models import WorkSell from .forms import WorkSellForm @@ -21,15 +24,52 @@ class WorkSellDetail(DetailView): return context +def work_sell_create(request): + if request.is_ajax(): + form = WorkSellForm(data=request.POST) + if form.is_valid(): + instance = form.save(commit=False) + instance.save() + data = {'status': 'ok'} + else: + data = {'status': 'no', 'form_errors': form.errors} + return HttpResponse(json.dumps(data), content_type='application/json') + return HttpResponse("HEllo") + + class WorkSellCreateView(CreateView): model = WorkSell form_class = WorkSellForm template_name = 'worksell_create.html' -class WorkSellUpdateView(CreateView): +class WorkSellUpdateView(UpdateView): model = WorkSell + form_class = WorkSellForm + template_name = 'worksell_edit.html' + + def get_success_url(self): + return reverse('work_sell:list') class WorkSellDeleteView(CreateView): model = WorkSell + + +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): + context = {'test': 'data'} + return context + + +class JSONView(JSONResponseMixin, TemplateView): + def render_to_response(self, context, **response_kwargs): + return self.render_to_json_response(context, **response_kwargs) + +