diff --git a/templates/client/wizard/second_step.html b/templates/client/wizard/second_step.html index 5e75559b..dcd78540 100644 --- a/templates/client/wizard/second_step.html +++ b/templates/client/wizard/second_step.html @@ -6,305 +6,297 @@

Добавить событие

- {{ wizard.form.media }} -
-
-

Шаг 1. Основная информация

+
{% csrf_token %} -
+ {{ wizard.form.media }} +
+
+

Шаг 1. Основная информация

- изменить +
+ +
-
- -
-
-

Шаг 2. Статистика и условия участия

+
+
+

Шаг 2. Статистика и условия участия

-
-
+ 0,9 баллов к рейтингу
+
+
+ 0,9 баллов к рейтингу
+
-
- {% csrf_token %} - {{ wizard.management_form }} - {% if wizard.form.forms %} - {{ wizard.form.management_form }} - {% for form in wizard.form.forms %} - {{ form }} - {% endfor %} - {% else %} + {{ wizard.management_form }} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} + {% for form in wizard.form.forms %} + {{ form }} + {% endfor %} + {% else %} {% with wizard.form as form %} -
+
-
+
-
- - {{ form.found_year }} -
+
+ + {{ form.found_year }} +
-
-
+
+
-
+
-
+
-
- +
+ -
+
-
- {{ form.statistic_year }} -
+
+ {{ form.statistic_year }} +
-
+
-
- {{ form.visitors }} -
+
+ {{ form.visitors }} +
-
- {{ form.partisipants }} -
+
+ {{ form.partisipants }} +
+ +
+ {{ form.square }} + м² +
+
-
- {{ form.square }} - м²
-
-
- -
- +
+ -
+
-
-
-
-
- {{ form.countries }} +
+
+
+
+ {{ form.countries }} +
+
-
-
-
- - - -
- -
- -

Стоимость посещения и участия

+
-
-
+ -
-
+
-
Стоимость билетов
+
-
+

Стоимость посещения и участия

-
    +
    +
    -
  • - {{ form.one_day }} - -
  • +
    +
    -
  • - {{ form.all_days }} - -
  • +
    Стоимость билетов
    -
+
-
Предварительная регистрация
+
    -
+
  • + {{ form.one_day }} + +
  • -
    +
  • + {{ form.all_days }} + +
  • -
    + -
      +
      Предварительная регистрация
      -
    • - {{ form.pre_one_day }} - -
    • - -
    • - {{ form.pre_all_days }} - -
    • +
    - +
    -
    Регистрация на стойке
    +
    -
    +
      -
    +
  • + {{ form.pre_one_day }} + +
  • -
    +
  • + {{ form.pre_all_days }} + +
  • -
    -
    - -
    Стоимость аренды 1м²
    - -
      - -
    • - {{ form.equiped }} - -
    • - -
    • - {{ form.unequiped }} - -
    • - -
    • - {{ form.open_square }} - -
    • - -
    + -
    +
    Регистрация на стойке
    -
    - +
    -
    - {{ form.min_square }} - м²
    +
    -
    +
    +
    + +
    Стоимость аренды 1м²
    + +
      + +
    • + {{ form.equiped }} + +
    • + +
    • + {{ form.unequiped }} + +
    • + +
    • + {{ form.open_square }} + +
    • + +
    + +
    + +
    + + +
    + {{ form.min_square }} + м² +
    +
    -
    - +
    -
    - {{ form.registration_depos }} - -
    -
    +
    + -
    +
    + {{ form.registration_depos }} + +
    +
    -
    - +
    -
    -
    -
    - {{ form.deadline_date }} +
    + + +
    +
    +
    + {{ form.deadline_date }} +
    +
    +
    -
    -
    +
    -
    +
    -
    +
    +
    + {# #} -
    -
    - +
    +

    более полная информация повышает рейтинг вашего мероприятия и позволяет + ранжировать + его выше других

    +
    +
    -
    -

    более полная информация повышает рейтинг вашего мероприятия и позволяет ранжировать - его выше других

    -
    + -
    - - {% if wizard.steps.prev %} - - - {% endif %} - +
    -
    - +
    +
    +
    +

    Шаг 3. Добавление фото

    -
    -
    -
    -

    Шаг 3. Добавление фото

    -
    -
    -
    -
    -{% endwith %} -{% endif %} + +
    + + {% endwith %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/templates/client/wizard/third_step.html b/templates/client/wizard/third_step.html index 4ddd325e..df135d76 100644 --- a/templates/client/wizard/third_step.html +++ b/templates/client/wizard/third_step.html @@ -2,114 +2,147 @@ {% block styles %} - + {% endblock %} {% block content_list %} + {{ wizard.form.media }} - -
    -

    Добавить событие

    -
    - -
    - -
    -
    -

    Шаг 1. Основная информация

    - -
    +
    +

    Добавить событие

    -
    -
    -

    Шаг 2. Статистика и условия участия

    - -
    -
    -
    -
    -

    Шаг 3. Добавление фото

    -
    -
    + 1,2 балла к рейтингу
    -
    -
    +
    {% csrf_token %} -
    -
    -
    -
    - -
    -
    -

    более полная информация повышает рейтинг вашего мероприятия и позволяет ранжировать его выше других

    +
    +
    +

    Шаг 1. Основная информация

    + +
    +
    -
    +
    - -
      -
      - -
      - пропустить этот шаг +
      +
      +

      Шаг 2. Статистика и условия участия

      + +
      + +
      +
      +
      +
      +

      Шаг 3. Добавление фото

      -
      - +
      +
      + 1,2 балла к рейтингу
      +
      + {{ form.errors }} + {{ wizard.management_form }} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} + {% for form in wizard.form.forms %} + {{ form }} + {% endfor %} + {% else %} + {% with wizard.form as form %} +
      +
      +
      +
      + {{ form.attachments }} +
      + +
      +

      более полная информация повышает рейтинг вашего мероприятия и позволяет + ранжировать его выше других

      +
      +
      -
      - -
      +
      -
      -{% endcomment %} + + + cnt +=1 ; + document.getElementById('list').insertBefore(div, null); + }; + })(f); + + // Read in the image file as a data URL. + reader.readAsDataURL(f); + } + } + + document.getElementById('files').addEventListener('change', handleFileSelect, false); + {% endblock %} \ No newline at end of file diff --git a/wizard/forms.py b/wizard/forms.py index c71149ec..c65a248a 100644 --- a/wizard/forms.py +++ b/wizard/forms.py @@ -4,6 +4,8 @@ from theme.models import Theme, Tag from place_exposition.models import PlaceExposition from city.models import City from country.models import Country +from multiupload.fields import MultiFileField, MultiFileInput + choices = ((0, ''), (1.0, u'Ежегодно'), (2.0, u'2 раза в год'), (3.0, u'3 раза в год'), (4.0, u'4 раза в год'), (5.0, u'5 раз в год'), (0.5, u'Раз в 2 года'), ( @@ -64,3 +66,10 @@ class ExpoForm2(forms.Form): deadline_date = forms.DateField(widget=forms.TextInput(attrs={'placeholder':'дд.мм.гг'})) +class ExpoForm3(forms.Form): + attachments = MultiFileField(min_num=0, max_num=2, max_file_size=1024*1024*5, widget=MultiFileInput( + attrs={'class':'button big icon-camera', 'value':u'выберите фотографии', 'id':'files'} + )) + + +formlist = [ExpoForm1, ExpoForm2, ExpoForm3] \ No newline at end of file diff --git a/wizard/models.py b/wizard/models.py index 71a83623..74b18b8a 100644 --- a/wizard/models.py +++ b/wizard/models.py @@ -1,3 +1,8 @@ from django.db import models - +from django.conf import settings +import os # Create your models here. + + +class Attachment(models.Model): + file = models.FileField(upload_to=os.path.join(settings.MEDIA_ROOT,'attachments_files')) \ No newline at end of file diff --git a/wizard/urls.py b/wizard/urls.py index 4140c730..6bd3e9eb 100644 --- a/wizard/urls.py +++ b/wizard/urls.py @@ -1,9 +1,8 @@ from django.conf.urls import patterns, url, include -from wizard.forms import ExpoForm1, ExpoForm2 -from wizard.views import ExpoWizard, add_photo_view +from wizard.views import wizard_view urlpatterns = patterns('', - url(r'^add-photo/', add_photo_view, name="add-photo"), - url(r'^$', ExpoWizard.as_view([ExpoForm1, ExpoForm2])) + url(r'^ajax/$', 'wizard.views.ajax_view'), + url(r'^$', wizard_view) ) \ No newline at end of file diff --git a/wizard/views.py b/wizard/views.py index 34203aa4..df29d8f8 100644 --- a/wizard/views.py +++ b/wizard/views.py @@ -1,65 +1,84 @@ -from django.shortcuts import render_to_response, render from django.contrib.formtools.wizard.views import SessionWizardView from django.core.files.storage import FileSystemStorage +from django.http import HttpResponseRedirect +from django.conf import settings + import os -from proj import settings -from wizard import forms +from photologue.models import Photo, Gallery from exposition.models import Exposition, Statistic +from wizard.models import Attachment from functions.form_check import translit_with_separator -from django.http import HttpResponseRedirect # 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): - location=os.path.join(settings.MEDIA_ROOT, 'temp', 'files') + + location = os.path.join(settings.MEDIA_ROOT, 'temp') file_storage = FileSystemStorage(location, settings.MEDIA_URL) 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() - expo = Exposition.objects.language('ru').create( - name = data.get('name'), - data_begin = data.get('date_start'), - data_end = data.get('date_end'), - main_title = data.get('main_title'), - description = data.get('description'), - products = data.get('products'), - country = data.get('country', 1), - city = data.get('city', 1), - place = data.get('place', 1), - periodic = data.get('periodic'), - web_page = data.get('web_site'), - logo = data.get('logo'), - - foundation_year = data.get('found_year'), - area = data.get('square'), - price_day = '%i %s'%(data.get('one_day'), self.request.POST['oneDayCurrency1']), - price_all = '%i %s'%(data.get('all_days'), self.request.POST['allDaysCurrency1']), - price_day_bar = '%i %s'%(data.get('pre_one_day'),self.request.POST['oneDayCurrency1']), - price_all_bar = '%i %s'%(data.get('pre_all_days'),self.request.POST['allDaysCurrency1']), - - min_area = data.get('min_square'), - registration_payment = data.get('registration_depos'), - application_deadline = data.get('deadline_date'), - min_closed_area = data.get('unequiped'), - min_open_area = data.get('open_square'), - min_closed_equipped_area = data.get('equiped'), - url = translit_with_separator(data.get('name')), - quality_label= 0, - audience = 0 + + expo = Exposition.objects.language(self.request.LANGUAGE_CODE).create( + name=data.get('name'), + data_begin=data.get('date_start'), + data_end=data.get('date_end'), + main_title=data.get('main_title'), + description=data.get('description'), + products=data.get('products'), + country=data.get('country', 1), + city=data.get('city', 1), + place=data.get('place', 1), + periodic=data.get('periodic'), + web_page=data.get('web_site'), + logo=data.get('logo'), + + foundation_year=data.get('found_year'), + area=data.get('square'), + price_day=data.get('one_day'), + price_all=data.get('all_days'), + price_day_bar=data.get('pre_one_day'), + price_all_bar=data.get('pre_all_days'), + + min_area=data.get('min_square'), + registration_payment=data.get('registration_depos'), + application_deadline=data.get('deadline_date'), + min_closed_area=data.get('unequiped'), + min_open_area=data.get('open_square'), + min_closed_equipped_area=data.get('equiped'), + url=translit_with_separator(data.get('name')), + quality_label=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.theme = [data.get('theme')] if data['membership1']: - expo.quality_label = (expo.quality_label| Exposition.quality_label.exporating) + expo.quality_label = (expo.quality_label | Exposition.quality_label.exporating) if data['membership2']: - expo.quality_label = (expo.quality_label| Exposition.quality_label.rsva) + expo.quality_label = (expo.quality_label | Exposition.quality_label.rsva) if data['membership3']: - expo.quality_label = (expo.quality_label| Exposition.quality_label.ufi) + expo.quality_label = (expo.quality_label | Exposition.quality_label.ufi) if data['audience1']: expo.audience = (expo.audience | Exposition.audience.experts) @@ -71,39 +90,34 @@ class ExpoWizard(SessionWizardView): expo.save() Statistic.objects.language().create( - exposition = expo, - year = data.get('statistic_year'), - visitors = data.get('visitors'), - members = data.get('partisipants'), - countries = data.get('countries'), - area = data.get('square') + exposition=expo, + year=data.get('statistic_year'), + visitors=data.get('visitors'), + members=data.get('partisipants'), + countries=data.get('countries'), + area=data.get('square') ) - if upload_file: - self.file_storage.delete(upload_file.name) - - return HttpResponseRedirect("add-photo") - # return render_to_response('done.html', { - # 'form_data': [form.cleaned_data for form in form_list], - # }) + 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]] -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): - if request.POST: - for key, file in request.FILES.items(): - loger.debug(key) - loger.debug(len(request.FILES)) - context = {} - context.update(csrf(request)) - return render(request, "client/wizard/third_step.html", context) \ No newline at end of file +def ajax_view(request): + form = formlist[2](post, files, prefix='2') + return HttpResponse(json.dumps({'posts':post,'files':files}), content_type='application/json')