|
|
|
|
@ -4,10 +4,10 @@ from django.http import HttpResponseRedirect |
|
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
from photologue.models import Photo, Gallery |
|
|
|
|
from photologue.models import Photo |
|
|
|
|
from exposition.models import Exposition, Statistic |
|
|
|
|
from wizard.models import Attachment |
|
|
|
|
from functions.form_check import translit_with_separator |
|
|
|
|
from accounts.models import User |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# defining different template for every form |
|
|
|
|
@ -16,20 +16,26 @@ TEMPLATES = { |
|
|
|
|
'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): |
|
|
|
|
|
|
|
|
|
"main view that handle all data from 3 forms(steps) and finally create an Exposition" |
|
|
|
|
|
|
|
|
|
# storing temporary files during upload |
|
|
|
|
location = os.path.join(settings.MEDIA_ROOT, 'temp') |
|
|
|
|
file_storage = FileSystemStorage(location, settings.MEDIA_URL) |
|
|
|
|
SUCCES_URL = "/" |
|
|
|
|
|
|
|
|
|
def get_template_names(self): |
|
|
|
|
return [TEMPLATES[self.steps.current]] |
|
|
|
|
|
|
|
|
|
def done(self, form_list, **kwargs): |
|
|
|
|
# getting data and files |
|
|
|
|
upload_logo = form_list[0].cleaned_data.get('logo') |
|
|
|
|
upload_images = self.request.FILES.getlist(u'2-attachments') |
|
|
|
|
data = self.get_all_cleaned_data() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# creating new exposition |
|
|
|
|
expo = Exposition.objects.language(self.request.LANGUAGE_CODE).create( |
|
|
|
|
name=data.get('name'), |
|
|
|
|
data_begin=data.get('date_start'), |
|
|
|
|
@ -59,9 +65,10 @@ class ExpoWizard(SessionWizardView): |
|
|
|
|
min_closed_equipped_area=data.get('equiped'), |
|
|
|
|
url=translit_with_separator(data.get('name')), |
|
|
|
|
quality_label=0, |
|
|
|
|
audience=0 |
|
|
|
|
audience=0, |
|
|
|
|
creator = User.objects.get(id=self.request.user.id) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# adding photo to gallery |
|
|
|
|
photos = [] |
|
|
|
|
for i, photo in enumerate(upload_images): |
|
|
|
|
photos.append(Photo.objects.language(self.request.LANGUAGE_CODE).create( |
|
|
|
|
@ -71,25 +78,16 @@ class ExpoWizard(SessionWizardView): |
|
|
|
|
for photo in photos: |
|
|
|
|
expo.upload_photo(photo) |
|
|
|
|
|
|
|
|
|
# many to many relations saving |
|
|
|
|
expo.tag = [data.get('tag')] |
|
|
|
|
expo.theme = [data.get('theme')] |
|
|
|
|
if data['membership1']: |
|
|
|
|
expo.quality_label = (expo.quality_label | Exposition.quality_label.exporating) |
|
|
|
|
if data['membership2']: |
|
|
|
|
expo.quality_label = (expo.quality_label | Exposition.quality_label.rsva) |
|
|
|
|
if data['membership3']: |
|
|
|
|
expo.quality_label = (expo.quality_label | Exposition.quality_label.ufi) |
|
|
|
|
|
|
|
|
|
if data['audience1']: |
|
|
|
|
expo.audience = (expo.audience | Exposition.audience.experts) |
|
|
|
|
if data['audience2']: |
|
|
|
|
expo.audience = expo.audience | getattr(Exposition.audience, 'experts and consumers') |
|
|
|
|
if data['audience3']: |
|
|
|
|
expo.audience = expo.audience | (getattr(Exposition.audience, 'general public')) |
|
|
|
|
|
|
|
|
|
# setting bit fields audience and quality_label |
|
|
|
|
self.set_flags(expo, data) |
|
|
|
|
expo.save() |
|
|
|
|
|
|
|
|
|
Statistic.objects.language().create( |
|
|
|
|
# ? |
|
|
|
|
Statistic.objects.language(self.request.LANGUAGE_CODE).create( |
|
|
|
|
exposition=expo, |
|
|
|
|
year=data.get('statistic_year'), |
|
|
|
|
visitors=data.get('visitors'), |
|
|
|
|
@ -98,26 +96,31 @@ class ExpoWizard(SessionWizardView): |
|
|
|
|
area=data.get('square') |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# remove temporary files if it has any |
|
|
|
|
if upload_logo: |
|
|
|
|
self.file_storage.delete(upload_logo.name) |
|
|
|
|
if upload_images: |
|
|
|
|
for f in upload_images: |
|
|
|
|
self.file_storage.delete(f.name) |
|
|
|
|
return HttpResponseRedirect('/') |
|
|
|
|
|
|
|
|
|
def get_template_names(self): |
|
|
|
|
return [TEMPLATES[self.steps.current]] |
|
|
|
|
return HttpResponseRedirect(self.SUCCES_URL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_flags(self, expo, data): |
|
|
|
|
if data['membership1']: |
|
|
|
|
expo.quality_label = (expo.quality_label | Exposition.quality_label.exporating) |
|
|
|
|
if data['membership2']: |
|
|
|
|
expo.quality_label = (expo.quality_label | Exposition.quality_label.rsva) |
|
|
|
|
if data['membership3']: |
|
|
|
|
expo.quality_label = (expo.quality_label | Exposition.quality_label.ufi) |
|
|
|
|
|
|
|
|
|
if data['audience1']: |
|
|
|
|
expo.audience = (expo.audience | Exposition.audience.experts) |
|
|
|
|
if data['audience2']: |
|
|
|
|
expo.audience = expo.audience | getattr(Exposition.audience, 'experts and consumers') |
|
|
|
|
if data['audience3']: |
|
|
|
|
expo.audience = expo.audience | (getattr(Exposition.audience, 'general public')) |
|
|
|
|
|
|
|
|
|
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 ajax_view(request): |
|
|
|
|
form = formlist[2](post, files, prefix='2') |
|
|
|
|
return HttpResponse(json.dumps({'posts':post,'files':files}), content_type='application/json') |
|
|
|
|
|