You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

126 lines
4.7 KiB

# -*- coding: utf-8 -*-
from django import forms
from expobanner.models import URL, BannerGroup, Banner, Paid
from exposition.models import Exposition
from country.models import Country
from city.models import City
from theme.models import Theme, Tag
class UrlCreateForm(forms.ModelForm):
verbose = u'Создать урл'
class Meta:
model = URL
exclude = ['created_at', 'updated_at', 'sites']
class BannerCreateGroupForm(forms.ModelForm):
verbose = u'Создать групу'
class Meta:
model = BannerGroup
exclude = ['created_at', 'updated_at', 'speed']
class BannerGroupUpdateForm(BannerCreateGroupForm):
verbose = u'Изменить групу'
class Meta:
model = BannerGroup
exclude = ['created_at', 'updated_at', 'slug', 'speed']
class BannerCreateForm(forms.ModelForm):
verbose = u'Создать банер'
#country = forms.ChoiceField(label=u'Страна', choices=[('', ' ')] + [(c.id, c.name) for c in Country.objects.all()], required=False)
#theme = forms.ChoiceField(label=u'Тематика', required=False,
# choices=[('', ' ')] + [(item.id, item.name) for item in Theme.objects.language().all()])
#city = forms.CharField(label=u'Город', widget=forms.HiddenInput(), required=False)
#tag = forms.CharField(label=u'Тег', widget=forms.HiddenInput(), required=False)
class Meta:
model = Banner
exclude = ['created_at', 'updated_at', 'often', 'paid', 'stat_pswd']
class ClientStatForm(forms.Form):
stat_pswd = forms.CharField(label=u'Введите пароль:')
def check_pass(self, obj):
pswd = self.cleaned_data['stat_pswd']
return obj.stat_pswd == pswd
class PaidCreateForm(forms.ModelForm):
verbose = u'Создать проплаченую выставку'
exposition = forms.CharField(label=u'Выставка', widget=forms.HiddenInput())
tickets = forms.URLField(label=u'Линк на билеты')
participation = forms.URLField(label=u'Линк на участие')
official = forms.URLField(label=u'Линк на официальный сайт')
class Meta:
model = Paid
fields = ['logo', 'organiser', 'public']
def save(self, commit=True):
paid = super(PaidCreateForm, self).save(commit=False)
if commit:
expo = self.cleaned_data['exposition']
tickets = self.cleaned_data['tickets']
tickets_link = Banner.objects.create_for_paid(expo, tickets, 'tickets')
participation = self.cleaned_data['participation']
participation_link = Banner.objects.create_for_paid(expo, participation, 'participation')
official = self.cleaned_data['official']
official_link = Banner.objects.create_for_paid(expo, official, 'official')
catalog = expo.get_permanent_url()
catalog_link = Banner.objects.create_for_paid(expo, catalog, 'catalog')
paid.tickets = tickets_link
paid.participation = participation_link
paid.official = official_link
paid.catalog = catalog_link
paid.save()
expo.paid_new = paid
expo.save()
return paid
def clean_exposition(self):
expo_id = self.cleaned_data['exposition']
try:
expo = Exposition.objects.get(id=expo_id)
except Exposition.DoesNotExist:
raise forms.ValidationError(u'Такой выставки не существует')
return expo
class PaidUpdateForm(forms.ModelForm):
tickets = forms.URLField(label=u'Линк на билеты')
participation = forms.URLField(label=u'Линк на участие')
official = forms.URLField(label=u'Линк на официальный сайт')
class Meta:
model = Paid
fields = ['logo', 'organiser', 'public']
def save(self, commit=True):
paid = super(PaidUpdateForm, self).save(commit=False)
if commit:
tickets = self.cleaned_data['tickets']
b_tickets = paid.tickets
if tickets != b_tickets.url:
b_tickets.url = tickets
b_tickets.save()
participation = self.cleaned_data['participation']
b_participation = paid.participation
if participation != b_participation.url:
b_participation.url = participation
b_participation.save()
official = self.cleaned_data['official']
b_official = paid.official
if official != b_official.url:
b_official.url = official
b_official.save()
paid.save()
return paid