|
|
|
|
@ -1,12 +1,12 @@ |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin |
|
|
|
|
from django.contrib.auth.models import Group |
|
|
|
|
from django.core.exceptions import PermissionDenied |
|
|
|
|
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 registration.backends.default.views import RegistrationView |
|
|
|
|
import json |
|
|
|
|
@ -16,6 +16,7 @@ from .forms import PrintOrderForm, CustomRegistrationForm |
|
|
|
|
from .models import PrintDocuments, PrintOrder, Settings, LiveImageUpload |
|
|
|
|
from archilance import util |
|
|
|
|
from archilance.mixins import BaseMixin |
|
|
|
|
from common.mixins import NoCsrfMixin |
|
|
|
|
from users.models import ContractorResume |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -81,100 +82,36 @@ class PrintDocumentCreate(BaseMixin, View): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 LiveImageUploadCreateView(NoCsrfMixin, LoginRequiredMixin, View): |
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
image = request.FILES.get('image') |
|
|
|
|
|
|
|
|
|
if not image: |
|
|
|
|
return JsonResponse({'files': [{'error': 'No image provided'}]}) |
|
|
|
|
|
|
|
|
|
live_img = LiveImageUpload.objects.create(file=image) |
|
|
|
|
|
|
|
|
|
return JsonResponse({'files': [{ |
|
|
|
|
'id': live_img.pk, |
|
|
|
|
'name': live_img.file.name, |
|
|
|
|
'size': live_img.file.size, |
|
|
|
|
'url': live_img.file.url, |
|
|
|
|
'thumbnailUrl': live_img.file.url, |
|
|
|
|
'deleteUrl': reverse('common:live-image-upload-delete', kwargs={'pk': live_img.pk}), |
|
|
|
|
'deleteType': 'POST', |
|
|
|
|
}]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LiveImageUploadDeleteView(NoCsrfMixin, LoginRequiredMixin, View): |
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
live_img = util.get_or_none(LiveImageUpload, pk=kwargs.get('pk')) |
|
|
|
|
|
|
|
|
|
if live_img: |
|
|
|
|
live_img.file.delete() |
|
|
|
|
live_img.delete() |
|
|
|
|
return JsonResponse({'status': 'success'}) |
|
|
|
|
else: |
|
|
|
|
return JsonResponse({'status': 'failure'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomRegistrationView(RegistrationView): |
|
|
|
|
|