From 5440e8758a5748b1fecfdb44a6a364b6305692fb Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Fri, 29 Jul 2016 17:53:49 +0300 Subject: [PATCH] #ARC-23 Add models , forms and views for print documents --- archilance/urls.py | 1 + chat/templates/chat_contractor.html | 1 - common/admin.py | 4 +- common/forms.py | 28 +++++ common/migrations/0002_auto_20160729_1530.py | 49 +++++++++ common/migrations/0003_auto_20160729_1747.py | 30 ++++++ common/models.py | 36 +++++++ common/templates/document_email.html | 4 + common/templates/printdocument_create.html | 100 ++++++++++++++++++ common/urls.py | 11 ++ common/views.py | 50 ++++++++- templates/partials/base.html | 4 +- users/templates/contractor_profile.html | 6 +- users/templates/portfolio_create_form.html | 19 ++-- wallets/migrations/0003_auto_20160729_1209.py | 21 ++++ 15 files changed, 348 insertions(+), 16 deletions(-) create mode 100644 common/forms.py create mode 100644 common/migrations/0002_auto_20160729_1530.py create mode 100644 common/migrations/0003_auto_20160729_1747.py create mode 100644 common/templates/document_email.html create mode 100644 common/templates/printdocument_create.html create mode 100644 common/urls.py create mode 100644 wallets/migrations/0003_auto_20160729_1209.py diff --git a/archilance/urls.py b/archilance/urls.py index 0f7eead..a860e6a 100644 --- a/archilance/urls.py +++ b/archilance/urls.py @@ -18,6 +18,7 @@ urlpatterns = [ url(r'^chat/', include('chat.urls')), url(r'^specializations/', include('specializations.urls')), url(r'^users/', include('users.urls')), + url(r'^common/', include('common.urls')), url(r'^users/', include('registration.backends.default.urls')), url(r'^admin/', admin.site.urls), diff --git a/chat/templates/chat_contractor.html b/chat/templates/chat_contractor.html index 929734a..17a40da 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -149,7 +149,6 @@

Для заметок

diff --git a/common/admin.py b/common/admin.py index 12d32ef..01a9179 100644 --- a/common/admin.py +++ b/common/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from mptt.admin import MPTTModelAdmin -from .models import Location, MainPage, Settings +from .models import Location, MainPage, Settings, PrintOrder, PrintDocuments class LocationAdmin(MPTTModelAdmin): readonly_fields = ('pk', 'lft', 'rght', 'tree_id', 'level') @@ -9,3 +9,5 @@ class LocationAdmin(MPTTModelAdmin): admin.site.register(Location, LocationAdmin) admin.site.register(MainPage) admin.site.register(Settings) +admin.site.register(PrintOrder) +admin.site.register(PrintDocuments) diff --git a/common/forms.py b/common/forms.py new file mode 100644 index 0000000..80b0cc3 --- /dev/null +++ b/common/forms.py @@ -0,0 +1,28 @@ +from django import forms +from .models import PrintOrder, PrintDocuments + + +class PrintOrderForm(forms.ModelForm): + files = forms.ModelMultipleChoiceField( + queryset=PrintDocuments.objects.none(), + widget=forms.CheckboxSelectMultiple, + required=False, + ) + + class Meta: + model = PrintOrder + + fields = ( + 'sender', + 'phone', + 'address', + 'shipping', + 'files', + 'text', + ) + + def __init__(self, *args, **kwargs): + self.request = kwargs.pop('request') + super().__init__(*args, **kwargs) + if self.instance.pk: + self.fields['files'].queryset = self.instance.files diff --git a/common/migrations/0002_auto_20160729_1530.py b/common/migrations/0002_auto_20160729_1530.py new file mode 100644 index 0000000..6fb3c27 --- /dev/null +++ b/common/migrations/0002_auto_20160729_1530.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-07-29 12:30 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='PrintDocuments', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file', models.FileField(upload_to='common/printdocuments/')), + ], + options={ + 'verbose_name': 'Документы на распечатку', + 'verbose_name_plural': 'Документы на распечатку', + }, + ), + migrations.CreateModel( + name='PrintOrder', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sender', models.CharField(max_length=150)), + ('phone', models.CharField(max_length=50)), + ('address', models.CharField(max_length=255)), + ('created', models.DateTimeField(default=django.utils.timezone.now)), + ('shipping', models.CharField(choices=[('self_delivery', 'Самовывоз'), ('courier_delivery', 'Доставка курьером')], default='self_delivery', max_length=30)), + ('text', models.TextField()), + ], + options={ + 'verbose_name': 'Заявка на распечатку', + 'verbose_name_plural': 'Заявки на распечатку', + }, + ), + migrations.AddField( + model_name='printdocuments', + name='printorder', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='print_documents', to='common.PrintOrder'), + ), + ] diff --git a/common/migrations/0003_auto_20160729_1747.py b/common/migrations/0003_auto_20160729_1747.py new file mode 100644 index 0000000..0fa308b --- /dev/null +++ b/common/migrations/0003_auto_20160729_1747.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-07-29 14:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0002_auto_20160729_1530'), + ] + + operations = [ + migrations.AddField( + model_name='settings', + name='document_send_description', + field=models.TextField(blank=True), + ), + migrations.AddField( + model_name='settings', + name='document_send_email', + field=models.EmailField(default='muhtarzubanchi05@gmail.com', max_length=100), + ), + migrations.AddField( + model_name='settings', + name='document_send_time_remove', + field=models.IntegerField(default=14), + ), + ] diff --git a/common/models.py b/common/models.py index 57666a3..a1c6e8b 100644 --- a/common/models.py +++ b/common/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils import timezone from mptt.models import TreeForeignKey, MPTTModel @@ -36,6 +37,9 @@ class MainPage(models.Model): class Settings(models.Model): time_notification = models.IntegerField(default=180) + document_send_email = models.EmailField(max_length=100, default="muhtarzubanchi05@gmail.com") + document_send_description = models.TextField(blank=True) + document_send_time_remove = models.IntegerField(default=14) def __str__(self): return 'Настройки сайта' @@ -43,3 +47,35 @@ class Settings(models.Model): class Meta: verbose_name = 'Настройки сайта' verbose_name_plural = 'Настройки сайта' + + +class PrintOrder(models.Model): + SHIPPINGS = ( + ('self_delivery', 'Самовывоз'), + ('courier_delivery', 'Доставка курьером'), + ) + sender = models.CharField(max_length=150) + phone = models.CharField(max_length=50) + address = models.CharField(max_length=255) + created = models.DateTimeField(default=timezone.now) + shipping = models.CharField(max_length=30, default='self_delivery', choices=SHIPPINGS) + text = models.TextField() + + def __str__(self): + return self.sender + + class Meta: + verbose_name = 'Заявка на распечатку' + verbose_name_plural = 'Заявки на распечатку' + + +class PrintDocuments(models.Model): + printorder = models.ForeignKey(PrintOrder, related_name='print_documents') + file = models.FileField(upload_to='common/printdocuments/') + + def __str__(self): + return self.file.url + + class Meta: + verbose_name = 'Документы на распечатку' + verbose_name_plural = 'Документы на распечатку' diff --git a/common/templates/document_email.html b/common/templates/document_email.html new file mode 100644 index 0000000..547defd --- /dev/null +++ b/common/templates/document_email.html @@ -0,0 +1,4 @@ + +Welcome {{ username }}! + +Your username is {{ username }} and your password is {{ files }}. diff --git a/common/templates/printdocument_create.html b/common/templates/printdocument_create.html new file mode 100644 index 0000000..973bd99 --- /dev/null +++ b/common/templates/printdocument_create.html @@ -0,0 +1,100 @@ +{% extends 'partials/base.html' %} +{% load staticfiles %} +{% load thumbnail %} +{% block content %} + {% include 'partials/header.html' %} +
+
+

Услуга по распечатке документов

+ + {% csrf_token %} + +
+
+

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

+ + {% if form.non_field_errors %} +
{{ form.non_field_errors }}
+ {% endif %} +
+ +
+
+

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

+
+ +
    + +
+
+
+ +
+

Описание {{ form.text.errors.as_text }}

+ +
+ +
+
+ +

Самовывоз

+
+ +
+ + +

Доставка курьером

+ +
+
+ +
+

Получатель{{ form.sender.errors.as_text }}

+ +
+ +
+

Телефон{{ form.phone.errors.as_text }}

+ +
+ +
+

Адрес{{ form.address.errors.as_text }}

+ +
+ + + +
+
+

Описание услуги и расценки

+
+
+ + {% include 'partials/footer.html' %} +
+
+{% endblock %} diff --git a/common/urls.py b/common/urls.py new file mode 100644 index 0000000..de30340 --- /dev/null +++ b/common/urls.py @@ -0,0 +1,11 @@ +from django.conf import urls + +from .views import ( + PrintDocumentCreate, +) + +app_name = 'common' + +urlpatterns = [ + urls.url(r'^printdocument/create/$', PrintDocumentCreate.as_view(), name='create'), +] diff --git a/common/views.py b/common/views.py index 91ea44a..ef0b94d 100644 --- a/common/views.py +++ b/common/views.py @@ -1,3 +1,49 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib import messages +from django.core.mail import send_mail +from django.template.loader import get_template +from django.template import Context +from django.http import HttpResponse +from django.views.generic import View +from archilance.mixins import BaseMixin -# Create your views here. +from .forms import PrintOrderForm +from .models import PrintDocuments, PrintOrder + + +class PrintDocumentCreate(BaseMixin, View): + form_class = PrintOrderForm + template_name = 'printdocument_create.html' + + def get(self, request, *args, **kwargs): + form = self.form_class(request=request) + return render(request, self.template_name, {'form': form}) + + def post(self, request, *args, **kwargs): + form = self.form_class(request.POST, request.FILES, request=request) + if form.is_valid(): + print_order = form.save(commit=False) + print_order.save() + + for file in request.FILES.getlist('new_files'): + print_doc = PrintDocuments.objects.create(file=file, printorder=print_order) + print_doc.save() + + send_mail('Заявка на распечатку', + get_template('document_email.html').render( + { + 'username': 'Mukhtar', + 'files': 'This is files list' + } + ), + 'dagdahzub@mail.ru', + ['muhtarzubanchi05@gmail.com'], + fail_silently=True + ) + messages.info(request, 'Заявка на распечатку принята') + return redirect('common:create') + # import code; code.interact(local=dict(globals(), **locals())) + else: + context = self.get_context_data(**kwargs) + context.update({'form': form}) + return render(request, self.template_name, context) diff --git a/templates/partials/base.html b/templates/partials/base.html index 276e662..a1fbf0d 100644 --- a/templates/partials/base.html +++ b/templates/partials/base.html @@ -60,8 +60,8 @@ -{##} -{##} + + diff --git a/users/templates/contractor_profile.html b/users/templates/contractor_profile.html index 8be9f98..e428bee 100644 --- a/users/templates/contractor_profile.html +++ b/users/templates/contractor_profile.html @@ -492,6 +492,10 @@ url: url, crossDomain: false, beforeSend: function (xhr, settings) { + $('#progress .progress-bar').css( + 'width', + '0%' + ); if (!csrfSafeMethod(settings.type)) { xhr.setRequestHeader("X-CSRFToken", csrftoken); } @@ -500,7 +504,7 @@ done: function (e, data) { console.log(data); $.each(data.result.files, function (index, file) { - var img = $('').attr('src', file.url).appendTo("#files"); + var img = $('').attr('src', file.url).appendTo("#files"); console.log(file); var currentValue = $("#upload-files-pk").val(); currentValue += file.id + ';'; diff --git a/users/templates/portfolio_create_form.html b/users/templates/portfolio_create_form.html index b304651..ab0a03f 100644 --- a/users/templates/portfolio_create_form.html +++ b/users/templates/portfolio_create_form.html @@ -81,12 +81,16 @@
- - - Выберите файлы - + +{# #} +{# #} +{# Выберите файлы#} +{# #} +{# #} +{# #} - + +

@@ -96,12 +100,9 @@

- - - + diff --git a/wallets/migrations/0003_auto_20160729_1209.py b/wallets/migrations/0003_auto_20160729_1209.py new file mode 100644 index 0000000..9833cda --- /dev/null +++ b/wallets/migrations/0003_auto_20160729_1209.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-07-29 09:09 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('wallets', '0002_auto_20160727_1835'), + ] + + operations = [ + migrations.AlterField( + model_name='invoicehistory', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ]