diff --git a/accounts/models.py b/accounts/models.py index 188748c4..66435c7f 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -82,6 +82,7 @@ class UserManager(BaseUserManager): user.save(using=self._db) return user + def safe_get(self, **kwargs): model = self.model try: diff --git a/exposition/management/commands/exposition_load.py b/exposition/management/commands/exposition_load.py index d96cd9db..515b103c 100644 --- a/exposition/management/commands/exposition_load.py +++ b/exposition/management/commands/exposition_load.py @@ -22,7 +22,7 @@ def to_country(value): try: #query = get_translation_aware_manager(Country) #country = query.filter(name=value)[0] - country = Country.objects.filter(translations__name=value)[0] + country = Country.objects.filter(translations__name=value.strip())[0] return country except IndexError: return None @@ -32,7 +32,7 @@ def to_city(value, lang, country): # get city by name #objects = get_translation_aware_manager(City) # except IndexError if no found - city = City.objects.filter(translations__name=value, country=country)[0] + city = City.objects.filter(translations__name=value.strip(), country=country)[0] return city except IndexError: return None @@ -283,11 +283,12 @@ event_sett = { class Command(BaseCommand): def handle(self, *args, **options): - f = open(settings.MEDIA_ROOT+'/import/expositions_ru.xlsx', 'r') + f = open(settings.MEDIA_ROOT+'/import/Places Eng Upd.xlsx', 'r') book = xlrd.open_workbook(file_contents=f.read()) sheet = book.sheet_by_index(0) row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] labels = [label for label in row_list[0]] + print(123) @@ -368,12 +369,15 @@ class Command(BaseCommand): if not flag: + object.save() + """ try: print('pre save %s'% str(object)) object.save() except: print('saving error') continue + """ print('post save %s'% str(object)) else: print('bad city') diff --git a/exposition/urls.py b/exposition/urls.py index dfb3eb09..c29a150a 100644 --- a/exposition/urls.py +++ b/exposition/urls.py @@ -3,11 +3,16 @@ from django.conf.urls import patterns, include, url from views import ExpositionView, ExpositionVisitors, ExpositionMembers, ExpositionStatistic, ExpositionPrice,\ ExpositionProgramme, ExpositionSearchView +from views import ExpositionServiceView + + urlpatterns = patterns('', - url(r'expositions/search/', ExpositionSearchView.as_view()), + url(r'expositions/search/', ExpositionSearchView.as_view()), + url(r'expositions/(?P.*)/(?P\d+)/$', ExpositionView.as_view()), url(r'expositions/(?P\d+)/$', ExpositionView.as_view()), # + url(r'expositions/(?P.*)/service/(?P.*)/$', ExpositionServiceView.as_view()), url(r'expositions/(?P.*)/statistic/$', ExpositionStatistic.as_view()), url(r'expositions/(?P.*)/price/$', ExpositionPrice.as_view()), url(r'expositions/(?P.*)/program/$', ExpositionProgramme.as_view()), @@ -18,8 +23,6 @@ urlpatterns = patterns('', url(r'expositions/$', ExpositionView.as_view()), # url(r'exposition-add-calendar/(?P\d+)/$', 'exposition.views.exposition_add_calendar'), - url(r'exposition-remove-calendar/(?P\d+)/$', 'exposition.views.exposition_remove_calendar'), url(r'exposition-visit/(?P\d+)/$', 'exposition.views.exposition_visit'), - url(r'exposition-unvisit/(?P\d+)/$', 'exposition.views.exposition_unvisit'), ) diff --git a/exposition/views.py b/exposition/views.py index 420f25b9..05e479ad 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -1,20 +1,114 @@ # -*- coding: utf-8 -*- -from django.shortcuts import render_to_response from django.http import HttpResponseRedirect, HttpResponse -from django.template import RequestContext -from django.shortcuts import get_object_or_404 -from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage +from django.contrib import messages #models from models import Exposition -from accounts.models import User -from functions.custom_views import ExpoListView, ExpoMixin, EventDetail -from django.views.generic import ListView, DetailView +from functions.custom_views import ExpoListView, ExpoMixin, EventDetail, single_page_filter +from django.views.generic import ListView, DetailView, FormView from haystack.query import EmptySearchQuerySet from functions.search_forms import ExpositionSearchForm +from service.views import order_forms +from django.shortcuts import get_object_or_404 +from django.http import Http404 # +from service.models import Service +from country.models import Country +from city.models import City +from company.models import Company +from theme.models import Theme, Tag import json from django.utils.translation import ugettext as _ + +class ExpositionServiceView(FormView, ExpoMixin): + params = None + search_form = ExpositionSearchForm + model = Exposition + obj = None + service = None + + + def get_form_class(self): + url = self.kwargs.get('url') + form = order_forms.get(url) + if not form: + raise Http404 + + service = get_object_or_404(Service, url=url) + self.service = service + self.template_name = service.template + params = self.get_params() + for param in params: + + if param.get('type') == 'country': + country = Country.objects.safe_get(url=param.get('url')) + if country: + param['name'] = country.name + + if param.get('type') == 'city': + city = City.objects.safe_get(url=param.get('url')) + if city: + param['name'] = city.name + + if param.get('type') == 'theme': + theme = Theme.objects.safe_get(url=param.get('url')) + if theme: + param['name'] = theme.name + + if param.get('type') == 'tag': + tag = Tag.objects.safe_get(url=param.get('url')) + if tag: + param['name'] = tag.name + + if param.get('type') == 'year': + param['name'] = param.get('url') + + if param.get('type') == 'month': + monthes = {'jan': 1, 'feb': 2, 'mar': 3, 'apr': 4, 'may': 5, 'jun': 6, + 'jul': 7, 'aug': 8, 'sep': 9, 'oct': 10, 'nov': 11, 'dec': 12} + + param['name'] = param.get('url') + + if param.get('type') == 'member' and self.model != Company: + param['name'] = param.get('url') + company = Company.objects.safe_get(url=param.get('url')) + if company: + param['name'] = company.name + + if param.get('type') == single_page_filter.get(self.model): + try: + self.obj = self.model.objects.get(url=param.get('url')) + + except self.model.DoesNotExist: + raise Http404 + + + param['name'] = self.obj.name + + params.append({'type':'service', 'name':service.name}) + self.params = params + return form + + def get_context_data(self, **kwargs): + context = super(ExpositionServiceView, self).get_context_data(**kwargs) + context['search_form'] = ExpositionSearchForm() + context['search_action'] = '/expositions/search/' + context['event'] = self.obj + context['service'] = self.service + context['filter'] = self.params + return context + + def form_valid(self, form): + form.save() + messages.success(self.request, _(u'Ваш запрос был успешно отправлен')) + return HttpResponseRedirect(self.request.path) + + #def form_invalid(self, form): + # return HttpResponse(form.errors) + + + + class ExpositionSearchView(ListView): paginate_by = 2 template_name = 'exposition/search.html' @@ -145,29 +239,17 @@ def exposition_add_calendar(request, id): if user.is_authenticated(): exp = Exposition.objects.safe_get(id=id) - if exp: + if exp in user.calendar.expositions.all(): + user.calendar.expositions.remove(exp) + args['in'] = False + else: user.calendar.expositions.add(exp) - args['success'] = True - else: - args['not_authorized'] = True + args['in'] = True args['success'] = True - - return HttpResponse(json.dumps(args), content_type='application/json') - -def exposition_remove_calendar(request, id): - args = {'success': False} - user = request.user - - if user.is_authenticated(): - exp = Exposition.objects.safe_get(id=id) - if exp: - user.calendar.expositions.remove(exp) - args['success'] = True else: args['not_authorized'] = True args['success'] = True - return HttpResponse(json.dumps(args), content_type='application/json') def exposition_visit(request, id): @@ -175,23 +257,20 @@ def exposition_visit(request, id): user = request.user if user.is_authenticated(): exp = Exposition.objects.safe_get(id=id) - if exp: + if user in exp.users.all(): + exp.users.remove(user) + args['in'] = False + else: exp.users.add(user) - args['success'] = True + args['in'] = True - else: - args['not_authorized'] = True args['success'] = True - - return HttpResponse(json.dumps(args), content_type='application/json') - -def exposition_unvisit(request, id): - args = {'success': False} - user = request.user - if user.is_authenticated(): - exp = Exposition.objects.safe_get(id=id) + """ if exp: - exp.users.remove(user) + exp.users.add(user) + args['success'] = True + """ + else: args['not_authorized'] = True args['success'] = True diff --git a/functions/custom_views.py b/functions/custom_views.py index b11dd4ce..c3a8f53c 100644 --- a/functions/custom_views.py +++ b/functions/custom_views.py @@ -218,6 +218,10 @@ class ExpoMixin(object): single_page_filter = {Exposition:'event', Conference:'event', Seminar:'event', Webinar:'event', Company:'member', User:'visitor', Photoreport: 'photoreport'} + + + + class ExpoListView(ExpoMixin, ListView): """ """ diff --git a/media/import/.~lock.expositions_ru.xlsx# b/media/import/.~lock.expositions_ru.xlsx# deleted file mode 100644 index 1254c366..00000000 --- a/media/import/.~lock.expositions_ru.xlsx# +++ /dev/null @@ -1 +0,0 @@ -kotzilla ,kotzilla,kotzilla-Satellite-L300,27.05.2014 19:59,file:///home/kotzilla/.config/libreoffice/3; \ No newline at end of file diff --git a/media/import/.~lock.places_ru.xlsx# b/media/import/.~lock.places_ru.xlsx# deleted file mode 100644 index e09b85da..00000000 --- a/media/import/.~lock.places_ru.xlsx# +++ /dev/null @@ -1 +0,0 @@ -kotzilla ,kotzilla,kotzilla-Satellite-L300,27.05.2014 19:16,file:///home/kotzilla/.config/libreoffice/3; \ No newline at end of file diff --git a/media/import/Places Eng Upd.xlsx b/media/import/Places Eng Upd.xlsx new file mode 100644 index 00000000..a632b498 Binary files /dev/null and b/media/import/Places Eng Upd.xlsx differ diff --git a/organiser/event_forms.py b/organiser/event_forms.py new file mode 100644 index 00000000..ba6ea4da --- /dev/null +++ b/organiser/event_forms.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from django import forms +from theme.models import Theme +from country.models import Country +from django.utils.translation import ugettext as _ + + +class AddEventForm1(forms.Form): + event_type = forms.ChoiceField(choices=[]) + theme = forms.ModelMultipleChoiceField(queryset=Theme.objects.all(), label=_(u'Тематика')) + tag = forms.CharField(widget=forms.SelectMultiple(), label=_(u'Теги'), required=False) + name = forms.CharField(label=_(u'Имя'), + widget=forms.TextInput(attrs={'placeholder':_(u'Введите назввание выставки')})) + main_title = forms.CharField(label=_(u'Краткое описание'), required=False, + widget=forms.TextInput(attrs={'placeholder':_(u'Краткое описание выставки (необязательно)')})) + description = forms.CharField(label=_(u'Полное описание'), required=False, + widget=forms.Textarea(attrs={'placeholder':_(u'Полное описание выставки')})) + date_begin = forms.DateTimeField(label=_(u'c')) + date_begin = forms.DateTimeField(label=_(u'по')) + country = forms.ModelChoiceField(label=_(u'Страна'),queryset=Country.objects.all()) + city = forms.CharField(label=_(u'Город'), widget=forms.SelectMultiple()) + place = forms.CharField(label=_(u'Локация'), required=False) + audience = forms.MultipleChoiceField(label=_(u'Аудитория'), choices=[], required=False) + periodic = forms.ChoiceField(label=_(u'Периодичность'), choices=[], required=False) + quality_label = forms.MultipleChoiceField(label=_(u'Членства и знаки качества'), choices=[], required=False) + web_page = forms.URLField(label=_(u'Веб сайт'), required=False) + products = forms.CharField(label=_(u'Экспонируемые продукты'), required=False, + widget=forms.TextInput()) + logo = forms.ImageField(label=_(u'Логотип'), required=False) diff --git a/organiser/urls.py b/organiser/urls.py new file mode 100644 index 00000000..875f1064 --- /dev/null +++ b/organiser/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import patterns, include, url +from views import AddEventView + +urlpatterns = patterns('', + url(r'add-event/$', AddEventView.as_view()), + ) + diff --git a/organiser/views.py b/organiser/views.py new file mode 100644 index 00000000..ee32e15c --- /dev/null +++ b/organiser/views.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +from django.http import HttpResponseRedirect, HttpResponse +#models +from functions.custom_views import ExpoListView, ExpoMixin, EventDetail +from django.views.generic import ListView, DetailView +from haystack.query import EmptySearchQuerySet +from functions.search_forms import ExpositionSearchForm +from django.views.generic import FormView, TemplateView +from event_forms import AddEventForm1 +# +import json +from django.utils.translation import ugettext as _ + +class AddEventView(FormView): + template_name = 'organiser/add_event.html' + form_class = AddEventForm1 diff --git a/proj/urls.py b/proj/urls.py index 21923971..af64cda9 100644 --- a/proj/urls.py +++ b/proj/urls.py @@ -15,6 +15,7 @@ urlpatterns = patterns('', url(r'^', include('webinar.urls')), url(r'^', include('company.urls')), url(r'^', include('photoreport.urls')), + url(r'^organiser/', include('organiser.urls')), url(r'^', include('file.urls')), diff --git a/service/forms.py b/service/forms.py index 334a29ba..1f3febd7 100644 --- a/service/forms.py +++ b/service/forms.py @@ -26,9 +26,11 @@ class ServiceForm(forms.Form): # city = forms.MultipleChoiceField(required=False, choices="") url = forms.CharField(label='url', required=False) + price = forms.IntegerField(label='Цена', required=False, + widget=forms.TextInput(attrs={'placeholder':'Валюта'})) + #price = forms.CharField(label='Цена', required=False, + # widget=forms.TextInput(attrs={'placeholder':'Валюта'})) - price = forms.CharField(label='Цена', required=False, - widget=forms.TextInput(attrs={'placeholder':'Цена'})) currency_list = [('USD','USD'), ('EUR','EUR'), ('RUB','RUB')] currency = forms.ChoiceField(choices=currency_list) @@ -70,9 +72,10 @@ class ServiceForm(forms.Form): service.url = translit_with_separator(data['url']).lower() if data['url']\ else translit_with_separator(data['name_ru'].lower()) - service.price = data['price']+' '+data['currency']#%s %s'%(data['price'], data['currency']) - # uses because in the next loop data will be overwritten + #service.price = data['price']+' '+data['currency']#%s %s'%(data['price'], data['currency']) + service.price = data['price'] + service.currency = data['currency'] fill_with_signal(Service, service, data) diff --git a/service/models.py b/service/models.py index 988ae42c..ae3d2d19 100644 --- a/service/models.py +++ b/service/models.py @@ -1,12 +1,16 @@ # -*- coding: utf-8 -*- from django.db import models from hvad.models import TranslatableModel, TranslatedFields +from functions.custom_fields import EnumField + + +CURENCIES = ('USD', 'RUB', 'EUR') class Service(TranslatableModel): url = models.SlugField(unique=True) - - price = models.CharField(max_length=20, blank=True) + currency = EnumField(values=CURENCIES, blank=True, default='USD') + price = models.PositiveIntegerField(blank=True, null=True) params = models.CharField(max_length=255, blank=True) template = models.CharField(max_length=255, blank=True) #translated fields @@ -33,8 +37,76 @@ class Service(TranslatableModel): return '/service/%s/'%self.url - from django.db.models.signals import post_save from functions.signal_handlers import post_save_handler -post_save.connect(post_save_handler, sender=Service) \ No newline at end of file +post_save.connect(post_save_handler, sender=Service) + +class AbstractOrder(models.Model): + person = models.ForeignKey('accounts.User') + phone = models.BigIntegerField() + city = models.CharField(max_length=255) + country = models.CharField(max_length=255) + person_inf = models.CharField(max_length=255) + price = models.IntegerField(blank=True, null=True) + currency = EnumField(values=CURENCIES, blank=True) + exposition = models.ForeignKey('exposition.Exposition', null=True) + conference = models.ForeignKey('conference.Conference', null=True) + seminar = models.ForeignKey('seminar.Seminar', null=True) + + class Meta: + abstract = True + + + +class Catalog(AbstractOrder): + pass + + +class Tickets(AbstractOrder): + days = models.SmallIntegerField() + people = models.SmallIntegerField() + +class Remote(AbstractOrder): + interested_participants = models.TextField(blank=True) + additional = models.CharField(max_length=255) + + +class Participation(AbstractOrder): + area = models.IntegerField(null=True) + area_type = models.CharField(max_length=255) + company_inf = models.TextField() + +class Translation(AbstractOrder): + days = models.IntegerField() + hours = models.IntegerField() + fr = models.DateField() + to = models.DateField() + languages = models.TextField() + themes = models.TextField() + +class Visit(AbstractOrder): + fr = models.DateField() + to = models.DateField() + people = models.IntegerField() + hotel_additional = models.TextField(blank=True) + city_from = models.CharField(max_length=255, blank=True) + hotel_stars = models.CharField(max_length=30, blank=True) + hotel_location = models.CharField(max_length=255, blank=True) + hotel_budget = models.CharField(max_length=255, blank=True) + hotel_budget_add = models.CharField(max_length=255, blank=True) + + avia_tickets = models.BooleanField() + avia_type = models.CharField(max_length=255) + visa = models.BooleanField() + transfer = models.BooleanField() + event_tickets = models.BooleanField() + # + translator = models.BooleanField() + languages = models.CharField(max_length=255, blank=True) + themes = models.CharField(max_length=255, blank=True) + tr_employment_days = models.PositiveIntegerField(blank=True, null=True) + tr_employment_hours = models.PositiveIntegerField(blank=True, null=True) + + excursion = models.BooleanField() + notes = models.TextField(blank=True) diff --git a/service/order_forms.py b/service/order_forms.py index e69de29b..8b459adb 100644 --- a/service/order_forms.py +++ b/service/order_forms.py @@ -0,0 +1,198 @@ +# -*- coding: utf-8 -*- +from django import forms +from django.utils.translation import ugettext as _ +from accounts.models import User +from models import Catalog, Tickets, Remote, Participation, Translation, Visit, CURENCIES +from exposition.models import Exposition +from conference.models import Conference +from seminar.models import Seminar + + +class AbstractOrderForm(forms.ModelForm): + person_inf = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _(u'Контактное лицо')})) + country = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _(u'Страна')})) + city = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _(u'Город')})) + phone = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _(u'Контактный номер телефона')})) + + person = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': _(u'Электронная почта')})) + currency = forms.CharField(widget=forms.HiddenInput()) + + exposition = forms.CharField(widget=forms.HiddenInput(), required=False) + conference = forms.CharField(widget=forms.HiddenInput(), required=False) + seminar = forms.CharField(widget=forms.HiddenInput(), required=False) + + def clean_exposition(self): + exp_id = self.cleaned_data.get('exposition') + if not exp_id: + return None + try: + return Exposition.objects.get(id=exp_id) + + except Exposition.DoesNotExist: + return None + + def clean_seminar(self): + sem_id = self.cleaned_data.get('seminar') + if not sem_id: + return None + try: + return Seminar.objects.get(id=sem_id) + except Seminar.DoesNotExist: + return None + + def clean_conference(self): + conf_id = self.cleaned_data.get('conference') + if not conf_id: + return None + try: + return Conference.objects.get(id=conf_id) + except Conference.DoesNotExist: + return None + + def clean_person(self): + cleaned_data = super(AbstractOrderForm, self).clean() + email = cleaned_data.get('person') + + try: + user = User.objects.get(username=email) + except User.DoesNotExist: + fname = '' + lname = '' + person_inf = cleaned_data.get('person_inf') + if person_inf: + person_inf = person_inf.split(' ') + fname = person_inf[0] + lname = ' '.join(person_inf[1:]) + user = User.objects.create_user(email, fname, lname) + + + return user + + def clean_phone(self): + cleaned_data = super(AbstractOrderForm, self).clean() + phone = cleaned_data.get('phone') + if not phone: + return + + deduct = ('-','(',')','.',' ') + for elem in deduct: + phone = phone.replace(elem, '') + if phone.isdigit(): + return phone + else: + raise forms.ValidationError(_(u'Введите правильный телефон')) + + + + +class CatalogForm(AbstractOrderForm): + class Meta: + model = Catalog + + +class TicketsForm(AbstractOrderForm): + class Meta: + model = Tickets + + +ADDITIONAL_REMOTE_CHOICES = [(_(u'официальный каталог'), _(u'официальный каталог')), + (_(u'фотоотчет'), _(u'фотоотчет')), + (_(u'видеоотчет'), _(u'видеоотчет')) + ] + +class RemoteForm(AbstractOrderForm): + additional = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=ADDITIONAL_REMOTE_CHOICES) + class Meta: + model = Remote + + def clean_additional(self): + additional = self.cleaned_data.get('additional') + if not additional: + return '' + else: + return ', '.join(additional) + +AREA_TYPE_CHOICES=[(_(u'оборудованная'), _(u'оборудованная')), + (_(u'не оборудованная'), _(u'не оборудованная')) + ] +class ParticipationForm(AbstractOrderForm): + area_type = forms.ChoiceField(choices=AREA_TYPE_CHOICES, required=False) + company_inf = forms.CharField(required=False, + widget=forms.Textarea(attrs={'placeholder': _(u'Краткое описание, вид деятельности компании')})) + class Meta: + model = Participation + +LANGS = [(_(u'Русский'), _(u'Русский'))] +from theme.models import Theme + +class TranslationForm(AbstractOrderForm): + languages = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), + choices=LANGS) + themes = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), + choices=[(theme.id, theme.id) for theme in Theme.objects.language().filter()]) + fr = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateFrom', 'placeholder': _(u'дд.мм.гггг')})) + to = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateTo', 'placeholder': _(u'дд.мм.гггг')})) + class Meta: + model = Translation + + + +HOTEL_ADDITIONAL_CHOICES = [('', _(u'Выберите')),(_(u'Условие1'), _(u'Условие1')), + (_(u'Условие2'), _(u'Условие2')),(_(u'Условие3'), _(u'Условие3'))] + +AVIA_TYPE_CHOICES = [(_(u'Прямой'), _(u'Прямой')), (_(u'С пересадкой'), _(u'С пересадкой')), + (_(u'Бизнес-класс'), _(u'Бизнес-класс')), (_(u'Эконом-класс'), _(u'Эконом-класс'))] + +HOTEL_LOCATION_CHOICES = [('', _(u'Выберите')), (_(u'Расположение1'), _(u'Расположение1')), + (_(u'Расположение2'), _(u'Расположение2'))] + +HOTEL_BUDGET_ADD = [('', _(u'Выберите')), (_(u'В сутки'), _(u'В сутки')), (_(u'В неделю'), _(u'В неделю'))] + + +class VisitForm(AbstractOrderForm): + fr = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateFrom', 'placeholder': _(u'дд.мм.гггг')})) + to = forms.DateField(widget=forms.DateInput(attrs={'class': 'date dateTo', 'placeholder': _(u'дд.мм.гггг')})) + hotel_additional = forms.ChoiceField(choices=HOTEL_ADDITIONAL_CHOICES, required=False) + hotel_stars = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), + choices=[('1','1'),('2','2'),('3','3'),('4','4'),('5','5')]) + + hotel_location = forms.ChoiceField(choices=HOTEL_LOCATION_CHOICES, required=False) + hotel_budget_add = forms.ChoiceField(choices=HOTEL_BUDGET_ADD, required=False) + languages = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), + choices=LANGS) + themes = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), + choices=[(theme.name, theme.name) for theme in Theme.objects.all()]) + + + avia_type = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), + choices=AVIA_TYPE_CHOICES) + class Meta: + model = Visit + + def clean_hotel_stars(self): + hotel_stars = self.cleaned_data.get('hotel_stars') + if not hotel_stars: + return '' + else: + return ', '.join(hotel_stars) + + def clean_languages(self): + languages = self.cleaned_data.get('languages') + if not languages: + return '' + else: + return ', '.join(languages) + + def clean_themes(self): + themes = self.cleaned_data.get('themes') + if not themes: + return '' + else: + return ', '.join(themes) + + def clean_avia_type(self): + avia_type = self.cleaned_data.get('avia_type') + if not avia_type: + return '' + else: + return ', '.join(avia_type) \ No newline at end of file diff --git a/service/views.py b/service/views.py index 6e3c6c15..605a14a2 100644 --- a/service/views.py +++ b/service/views.py @@ -5,11 +5,27 @@ from functions.custom_views import ExpoListView from django.views.generic import ListView, FormView, TemplateView from haystack.query import EmptySearchQuerySet from django.shortcuts import get_object_or_404 +from django.http import Http404 import json from functions.search_forms import CompanySearchForm +from order_forms import TranslationForm, CatalogForm, VisitForm, RemoteForm, ParticipationForm, TicketsForm + + +order_forms = {'translator': TranslationForm, 'catalog': CatalogForm, 'participation': ParticipationForm, + 'remote': RemoteForm, 'tickets': TicketsForm, 'visit': VisitForm} + +class ServiceView(FormView): + + def get_form_class(self): + url = self.kwargs.get('url') + form = order_forms.get(url) + if form: + return form + else: + raise Http404 + -class ServiceView(TemplateView): def get_template_names(self): url = self.kwargs.get('url') @@ -18,4 +34,3 @@ class ServiceView(TemplateView): return service.template - diff --git a/settings/templatetags/template_filters.py b/settings/templatetags/template_filters.py index 00da2f24..72c419ec 100644 --- a/settings/templatetags/template_filters.py +++ b/settings/templatetags/template_filters.py @@ -1,6 +1,16 @@ from django import template import phonenumbers import datetime +from datetime import timedelta +from django import template +from dateutil.relativedelta import relativedelta +from exposition.models import Exposition +from conference.models import Conference +from seminar.models import Seminar +from webinar.models import Webinar +from company.models import Company +from photoreport.models import Photoreport + register = template.Library() @@ -36,13 +46,6 @@ def int_format(value, decimal_points=3, seperator=u' '): def subtract(value, arg): return value - arg -from exposition.models import Exposition -from conference.models import Conference -from seminar.models import Seminar -from webinar.models import Webinar -from company.models import Company -from photoreport.models import Photoreport - @register.filter def generate_url(value, arg=None): @@ -75,10 +78,13 @@ def duration(event, month=None): else: return event.duration_days() + + @register.filter def in_event(event, day): beg = event.data_begin end = event.data_end + beg = datetime.date(beg.year, beg.month, beg.day) end = datetime.date(end.year, end.month, end.day) day = datetime.date(day.year, day.month, day.day) @@ -87,7 +93,6 @@ def in_event(event, day): return True return False -from dateutil.relativedelta import relativedelta @register.filter def add_month(date, month=1): @@ -101,11 +106,6 @@ def in_calendar(event, user): return True return False -from datetime import datetime, timedelta -from django import template -from django.utils.timesince import timesince - - @register.filter def timesince_exp(value, date=None): diff --git a/static/client/css/main.css b/static/client/css/main.css index bab58406..c29ce11a 100644 --- a/static/client/css/main.css +++ b/static/client/css/main.css @@ -4109,6 +4109,7 @@ form.s-message { line-height: 15px; } +.c-select-box .csb-menu .places-list > ul > li.active > a, .c-select-box .csb-menu .places-list > ul > li.active > label { color: #ff6600; } diff --git a/static/client/js/main.js b/static/client/js/main.js index 53ab39b0..99cf7506 100644 --- a/static/client/js/main.js +++ b/static/client/js/main.js @@ -81,24 +81,58 @@ function addError(inputId, msg){ }); - $('.visit').on('click', function(event){ + $('.visit, .unvisit').on('click', function(event){ event.preventDefault(); + var $this = $(this); var url = $(this).attr('href'); $.get(url, function(data){ if (data.not_authorized){ $.fancybox.open('#pw-login'); } + else{ + if(data.success){ + if(data.in){ + if($this.hasClass('visit')){ + $this.hide(); + $this.siblings('.unvisit').show() + } + } + else{ + if($this.hasClass('unvisit')){ + $this.hide(); + $this.siblings('.visit').show() + } + } + } + } }); }); - $('.addcalendar').on('click', function(event){ + $('.addcalendar, .removecalendar').on('click', function(event){ event.preventDefault(); - var url = $(this).attr('href'); + var $this = $(this); + var url = $this.attr('href'); $.get(url, function(data){ if (data.not_authorized){ $.fancybox.open('#pw-login'); } + else{ + if(data.success){ + if(data.in){ + if($this.hasClass('addcalendar')){ + $this.hide(); + $this.siblings('.removecalendar').show() + } + } + else{ + if($this.hasClass('removecalendar')){ + $this.hide(); + $this.siblings('.addcalendar').show() + } + } + } + } }); }); diff --git a/templates/client/includes/calendar_button.html b/templates/client/includes/calendar_button.html new file mode 100644 index 00000000..7c2bc0b7 --- /dev/null +++ b/templates/client/includes/calendar_button.html @@ -0,0 +1,15 @@ +{% load i18n %} +{% load template_filters %} +{% if user.is_authenticated %} + {% if event|in_calendar:user %} + + {% trans 'из расписание' %} + {% else %} + {% trans 'в расписание' %} + + {% endif %} +{% else %} + {% trans 'в расписание' %} + +{% endif %} + diff --git a/templates/client/includes/event_list.html b/templates/client/includes/event_list.html index ea89e76a..9f8830c7 100644 --- a/templates/client/includes/event_list.html +++ b/templates/client/includes/event_list.html @@ -78,17 +78,10 @@ - - {% if user.is_authenticated %} - {% if obj|in_calendar:user %} - {% trans 'из расписания' %} - {% else %} - {% trans 'в расписание' %} - {% endif %} - {% else %} - {% trans 'в расписание' %} - {% endif %} - + {% with event=obj user=user %} + {% include 'client/includes/calendar_button.html' %} + {% endwith %} + {% trans 'заметка' %} diff --git a/templates/client/includes/event_object.html b/templates/client/includes/event_object.html index a8d8bca4..9c9eb007 100644 --- a/templates/client/includes/event_object.html +++ b/templates/client/includes/event_object.html @@ -69,8 +69,13 @@
- {% trans 'Я планирую посетить' %} - {% trans 'в расписание' %} + {% with event=exposition user=user %} + {% include 'client/includes/visit_button.html' %} + {% endwith %} + + {% with event=exposition user=user %} + {% include 'client/includes/calendar_button.html' %} + {% endwith %} {% trans 'заметка' %}