|
|
|
|
@ -1,12 +1,22 @@ |
|
|
|
|
from django.shortcuts import render, redirect |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from django.contrib.auth.models import Group |
|
|
|
|
from django.core.mail import send_mail, EmailMultiAlternatives |
|
|
|
|
from django.core.urlresolvers import reverse, reverse_lazy |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.shortcuts import render, redirect |
|
|
|
|
from django.template.loader import get_template, render_to_string |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
from django.views.generic import View, DetailView |
|
|
|
|
from archilance.mixins import BaseMixin |
|
|
|
|
from registration.backends.default.views import RegistrationView |
|
|
|
|
import json |
|
|
|
|
import jsonschema |
|
|
|
|
|
|
|
|
|
from .forms import PrintOrderForm |
|
|
|
|
from .models import PrintDocuments, PrintOrder, Settings |
|
|
|
|
from .forms import PrintOrderForm, CustomRegistrationForm |
|
|
|
|
from .models import PrintDocuments, PrintOrder, Settings, LiveImageUpload |
|
|
|
|
from archilance import util |
|
|
|
|
from archilance.mixins import BaseMixin |
|
|
|
|
from users.models import ContractorResume |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PrintOrderDetailView(DetailView): |
|
|
|
|
@ -68,3 +78,138 @@ class PrintDocumentCreate(BaseMixin, View): |
|
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
|
context.update({'form': form}) |
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LiveImageUploadCreateView(View): |
|
|
|
|
@method_decorator(csrf_exempt) |
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
# try: data = json.loads(request.body.decode('utf-8')) |
|
|
|
|
# except: data = {} |
|
|
|
|
# |
|
|
|
|
# crop = data.get('crop') |
|
|
|
|
# image_id = data.get('imageId') |
|
|
|
|
# |
|
|
|
|
# if crop and image_id: |
|
|
|
|
# old_pic = util.get_or_none(models.TmpAdvertPicture, pk=image_id) |
|
|
|
|
# |
|
|
|
|
# if old_pic: |
|
|
|
|
# try: img = pil.Image.open(old_pic.file) |
|
|
|
|
# except IOError: return http.JsonResponse({'files': [{'error': "Couldn't open an image"}]}) |
|
|
|
|
# |
|
|
|
|
# format = img.format |
|
|
|
|
# |
|
|
|
|
# # exif = img._getexif() |
|
|
|
|
# # |
|
|
|
|
# # if exif: |
|
|
|
|
# # orientation_exif_tag = 274 |
|
|
|
|
# # rotated_img = img.rotate({3: 180, 6: 270, 8: 90}[exif[orientation_exif_tag]]) |
|
|
|
|
# |
|
|
|
|
# rotation = -crop.get('rotate') |
|
|
|
|
# |
|
|
|
|
# if rotation: |
|
|
|
|
# img = img.rotate(rotation, expand=True) |
|
|
|
|
# |
|
|
|
|
# x, y = crop.get('x'), crop.get('y') |
|
|
|
|
# x2, y2 = x + crop.get('width'), y + crop.get('height') |
|
|
|
|
# |
|
|
|
|
# cropped_img = img.crop((x, y, x2, y2)) # Left, upper, right, lower |
|
|
|
|
# |
|
|
|
|
# with io.BytesIO() as f: |
|
|
|
|
# cropped_img.save(f, format=format) |
|
|
|
|
# pic = models.TmpAdvertPicture.objects.create() |
|
|
|
|
# pic.file.save(old_pic.file.name, ContentFile(f.getvalue())) |
|
|
|
|
# pic.save() |
|
|
|
|
# |
|
|
|
|
# old_pic.file.delete() |
|
|
|
|
# old_pic.delete() |
|
|
|
|
# else: |
|
|
|
|
# return http.JsonResponse({'files': [{'error': 'No image found'}]}) |
|
|
|
|
# else: |
|
|
|
|
# image = request.FILES.get('_images') |
|
|
|
|
# |
|
|
|
|
# if image: |
|
|
|
|
# pic = models.TmpAdvertPicture.objects.create(file=image) |
|
|
|
|
# else: |
|
|
|
|
# return http.JsonResponse({'files': [{'error': 'No image provided'}]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------ |
|
|
|
|
|
|
|
|
|
print('###########################################') |
|
|
|
|
print('Uploading a file...') |
|
|
|
|
print('###########################################') |
|
|
|
|
|
|
|
|
|
image = request.FILES.get('image') |
|
|
|
|
|
|
|
|
|
if image: |
|
|
|
|
img = LiveImageUpload.objects.create(file=image) |
|
|
|
|
else: |
|
|
|
|
return JsonResponse({'files': [{'error': 'No image provided'}]}) |
|
|
|
|
|
|
|
|
|
return JsonResponse({'files': [{ |
|
|
|
|
'id': img.pk, |
|
|
|
|
'name': img.file.name, |
|
|
|
|
'size': img.file.size, |
|
|
|
|
'url': img.file.url, |
|
|
|
|
'thumbnailUrl': img.file.url, |
|
|
|
|
'deleteUrl': reverse('common:live-image-upload-delete', kwargs={'pk': img.pk}), |
|
|
|
|
'deleteType': 'POST', |
|
|
|
|
}]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LiveImageUploadDeleteView(View): |
|
|
|
|
@method_decorator(csrf_exempt) |
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
img = util.get_or_none(LiveImageUpload, pk=kwargs.get('pk')) |
|
|
|
|
|
|
|
|
|
if img: |
|
|
|
|
img.file.delete() |
|
|
|
|
img.delete() |
|
|
|
|
return JsonResponse({'success': True}) |
|
|
|
|
else: |
|
|
|
|
return JsonResponse({'success': False}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomRegistrationView(RegistrationView): |
|
|
|
|
form_class = CustomRegistrationForm |
|
|
|
|
template_name = 'registration/registration_form.html' |
|
|
|
|
success_url = reverse_lazy('registration_complete') |
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self): |
|
|
|
|
kwargs = super().get_form_kwargs() |
|
|
|
|
kwargs['request'] = self.request |
|
|
|
|
return kwargs |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
|
|
|
|
|
if self.request.GET.get('type') in ('customer', 'contractor'): |
|
|
|
|
context['hide_user_type'] = True |
|
|
|
|
|
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
def register(self, form): |
|
|
|
|
user = super().register(form) |
|
|
|
|
|
|
|
|
|
if form.cleaned_data.get('customer'): |
|
|
|
|
group = Group.objects.get(name='Заказчики') |
|
|
|
|
elif form.cleaned_data.get('contractor'): |
|
|
|
|
group = Group.objects.get(name='Исполнители') |
|
|
|
|
else: |
|
|
|
|
group = None |
|
|
|
|
|
|
|
|
|
if group: |
|
|
|
|
user.groups.add(group) |
|
|
|
|
|
|
|
|
|
user.contractor_resume = ContractorResume.objects.create(text='') |
|
|
|
|
|
|
|
|
|
user.save() |
|
|
|
|
|
|
|
|
|
return user |
|
|
|
|
|