You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.9 KiB
49 lines
1.9 KiB
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
|
|
|
|
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)
|
|
|