|
|
|
@ -1,27 +1,36 @@ |
|
|
|
from django.shortcuts import render_to_response, render |
|
|
|
|
|
|
|
from django.contrib.formtools.wizard.views import SessionWizardView |
|
|
|
from django.contrib.formtools.wizard.views import SessionWizardView |
|
|
|
from django.core.files.storage import FileSystemStorage |
|
|
|
from django.core.files.storage import FileSystemStorage |
|
|
|
|
|
|
|
from django.http import HttpResponseRedirect |
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
|
from proj import settings |
|
|
|
from photologue.models import Photo, Gallery |
|
|
|
from wizard import forms |
|
|
|
|
|
|
|
from exposition.models import Exposition, Statistic |
|
|
|
from exposition.models import Exposition, Statistic |
|
|
|
|
|
|
|
from wizard.models import Attachment |
|
|
|
from functions.form_check import translit_with_separator |
|
|
|
from functions.form_check import translit_with_separator |
|
|
|
from django.http import HttpResponseRedirect |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# defining different template for every form |
|
|
|
# defining different template for every form |
|
|
|
TEMPLATES = {'0':'client/wizard/first_step.html', '1':'client/wizard/second_step.html'} |
|
|
|
TEMPLATES = { |
|
|
|
|
|
|
|
'0': 'client/wizard/first_step.html', |
|
|
|
|
|
|
|
'1': 'client/wizard/second_step.html', |
|
|
|
|
|
|
|
'2': 'client/wizard/third_step.html' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
post = None |
|
|
|
|
|
|
|
files = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# main view that handle all data from 3 forms(steps) and finally create an Exposition |
|
|
|
class ExpoWizard(SessionWizardView): |
|
|
|
class ExpoWizard(SessionWizardView): |
|
|
|
location=os.path.join(settings.MEDIA_ROOT, 'temp', 'files') |
|
|
|
|
|
|
|
|
|
|
|
location = os.path.join(settings.MEDIA_ROOT, 'temp') |
|
|
|
file_storage = FileSystemStorage(location, settings.MEDIA_URL) |
|
|
|
file_storage = FileSystemStorage(location, settings.MEDIA_URL) |
|
|
|
|
|
|
|
|
|
|
|
def done(self, form_list, **kwargs): |
|
|
|
def done(self, form_list, **kwargs): |
|
|
|
upload_file = form_list[0].cleaned_data['logo'] |
|
|
|
upload_logo = form_list[0].cleaned_data.get('logo') |
|
|
|
|
|
|
|
upload_images = self.request.FILES.getlist(u'2-attachments') |
|
|
|
data = self.get_all_cleaned_data() |
|
|
|
data = self.get_all_cleaned_data() |
|
|
|
expo = Exposition.objects.language('ru').create( |
|
|
|
|
|
|
|
|
|
|
|
expo = Exposition.objects.language(self.request.LANGUAGE_CODE).create( |
|
|
|
name=data.get('name'), |
|
|
|
name=data.get('name'), |
|
|
|
data_begin=data.get('date_start'), |
|
|
|
data_begin=data.get('date_start'), |
|
|
|
data_end=data.get('date_end'), |
|
|
|
data_end=data.get('date_end'), |
|
|
|
@ -37,10 +46,10 @@ class ExpoWizard(SessionWizardView): |
|
|
|
|
|
|
|
|
|
|
|
foundation_year=data.get('found_year'), |
|
|
|
foundation_year=data.get('found_year'), |
|
|
|
area=data.get('square'), |
|
|
|
area=data.get('square'), |
|
|
|
price_day = '%i %s'%(data.get('one_day'), self.request.POST['oneDayCurrency1']), |
|
|
|
price_day=data.get('one_day'), |
|
|
|
price_all = '%i %s'%(data.get('all_days'), self.request.POST['allDaysCurrency1']), |
|
|
|
price_all=data.get('all_days'), |
|
|
|
price_day_bar = '%i %s'%(data.get('pre_one_day'),self.request.POST['oneDayCurrency1']), |
|
|
|
price_day_bar=data.get('pre_one_day'), |
|
|
|
price_all_bar = '%i %s'%(data.get('pre_all_days'),self.request.POST['allDaysCurrency1']), |
|
|
|
price_all_bar=data.get('pre_all_days'), |
|
|
|
|
|
|
|
|
|
|
|
min_area=data.get('min_square'), |
|
|
|
min_area=data.get('min_square'), |
|
|
|
registration_payment=data.get('registration_depos'), |
|
|
|
registration_payment=data.get('registration_depos'), |
|
|
|
@ -52,6 +61,16 @@ class ExpoWizard(SessionWizardView): |
|
|
|
quality_label=0, |
|
|
|
quality_label=0, |
|
|
|
audience=0 |
|
|
|
audience=0 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
photos = [] |
|
|
|
|
|
|
|
for i, photo in enumerate(upload_images): |
|
|
|
|
|
|
|
photos.append(Photo.objects.language(self.request.LANGUAGE_CODE).create( |
|
|
|
|
|
|
|
image=photo, |
|
|
|
|
|
|
|
title=data.get(u'pdescr_%i' % i, photo.name)) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
for photo in photos: |
|
|
|
|
|
|
|
expo.upload_photo(photo) |
|
|
|
|
|
|
|
|
|
|
|
expo.tag = [data.get('tag')] |
|
|
|
expo.tag = [data.get('tag')] |
|
|
|
expo.theme = [data.get('theme')] |
|
|
|
expo.theme = [data.get('theme')] |
|
|
|
if data['membership1']: |
|
|
|
if data['membership1']: |
|
|
|
@ -79,31 +98,26 @@ class ExpoWizard(SessionWizardView): |
|
|
|
area=data.get('square') |
|
|
|
area=data.get('square') |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if upload_file: |
|
|
|
if upload_logo: |
|
|
|
self.file_storage.delete(upload_file.name) |
|
|
|
self.file_storage.delete(upload_logo.name) |
|
|
|
|
|
|
|
if upload_images: |
|
|
|
return HttpResponseRedirect("add-photo") |
|
|
|
for f in upload_images: |
|
|
|
# return render_to_response('done.html', { |
|
|
|
self.file_storage.delete(f.name) |
|
|
|
# 'form_data': [form.cleaned_data for form in form_list], |
|
|
|
return HttpResponseRedirect('/') |
|
|
|
# }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_template_names(self): |
|
|
|
def get_template_names(self): |
|
|
|
return [TEMPLATES[self.steps.current]] |
|
|
|
return [TEMPLATES[self.steps.current]] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.core.context_processors import csrf |
|
|
|
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PATH_TO_FILE = os.path.join(settings.MEDIA_ROOT, 'exposition_foto/') |
|
|
|
from wizard.forms import formlist |
|
|
|
|
|
|
|
wizard_view = ExpoWizard.as_view(formlist) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.contrib.formtools.wizard.storage.session import SessionStorage |
|
|
|
|
|
|
|
from django.http import HttpResponse |
|
|
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
def add_photo_view(request): |
|
|
|
def ajax_view(request): |
|
|
|
if request.POST: |
|
|
|
form = formlist[2](post, files, prefix='2') |
|
|
|
for key, file in request.FILES.items(): |
|
|
|
return HttpResponse(json.dumps({'posts':post,'files':files}), content_type='application/json') |
|
|
|
loger.debug(key) |
|
|
|
|
|
|
|
loger.debug(len(request.FILES)) |
|
|
|
|
|
|
|
context = {} |
|
|
|
|
|
|
|
context.update(csrf(request)) |
|
|
|
|
|
|
|
return render(request, "client/wizard/third_step.html", context) |
|
|
|
|
|
|
|
|