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.
541 lines
24 KiB
541 lines
24 KiB
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.conf import settings
|
|
from ckeditor.widgets import CKEditorWidget
|
|
from django.core.exceptions import ValidationError
|
|
from django.core.validators import validate_email, URLValidator
|
|
#models
|
|
from models import PlaceConference, PlaceExposition, Hall, EXPOSITION_TYPE, CONFERENCE_TYPE
|
|
from file.models import FileModel, TmpFile
|
|
from country.models import Country
|
|
from city.models import City
|
|
from proj.models import Settings
|
|
#functions
|
|
from functions.translate import populate_all, fill_trans_fields_all
|
|
from functions.files import check_tmp_files
|
|
from functions.form_check import is_positive_integer
|
|
|
|
|
|
|
|
|
|
class ConferenceForm(forms.Form):
|
|
types = [(item1, item2) for item1, item2 in CONFERENCE_TYPE]
|
|
type = forms.ChoiceField(label='Краткое описание', required=False, choices=types)#2
|
|
#city = forms.ChoiceField(label='Город',choices=((None, 'Выберите страну'),))
|
|
city = forms.CharField(label='Город',
|
|
widget=forms.Select(choices=[('','')]))
|
|
|
|
latitude = forms.CharField(label='Широта')#7
|
|
longitude = forms.CharField(label='Долгота')#7
|
|
phone = forms.CharField(label='Телефон', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите телефон'}))#8
|
|
fax = forms.CharField(label='Факс', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите факс'}))#9
|
|
web_page = forms.CharField(label='Веб-сайт', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите адрес сайта'}))#10
|
|
email = forms.CharField(label='Email', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите email'}))#11
|
|
total_capacity = forms.CharField(label='Общая вместимость', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Общая вместимость'}))#12
|
|
amount_halls = forms.CharField(label='Количество залов', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Количество залов'}))#13
|
|
|
|
#halls information
|
|
hall_name = forms.CharField(label='Название зала', required=False)
|
|
hall_number = forms.IntegerField(label='Номер зала', min_value=1, initial='1', required=False)
|
|
hall_capacity = forms.IntegerField(label='Вместимость зала', min_value='1', required=False)
|
|
#
|
|
exposition_hall = forms.BooleanField(label='Выставочный зал', required=False)#14
|
|
exp_hall_area = forms.CharField(label='Площадь выст. зала', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Площадь выст. зала'}))#15
|
|
#
|
|
wifi = forms.BooleanField(label='Wi-fi', required=False)
|
|
multimedia_equipment = forms.BooleanField(label='Мультимедийное оборудование', required=False)
|
|
conference_call = forms.BooleanField(label='Конференц-связь', required=False)
|
|
translate_equipment = forms.BooleanField(label='Оборудование для синхронного перевода', required=False)
|
|
banquet_hall = forms.BooleanField(label='Банкетный зал', required=False)
|
|
catering = forms.BooleanField(label='Кейтеринг', required=False)
|
|
hotel = forms.BooleanField(label='Гостиница', required=False)
|
|
#
|
|
key = forms.CharField(required=False, widget=forms.HiddenInput())
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(ConferenceForm, self).__init__(*args, **kwargs)
|
|
# creates translated form fields, example: name_ru, name_en
|
|
# len(10) is a hack for detect if settings.LANGUAGES is not configured it return all langs
|
|
if len(settings.LANGUAGES) in range(10):
|
|
for lid, (code, name) in enumerate(settings.LANGUAGES):
|
|
# using enumerate for detect iteration number
|
|
# first iteration is a default lang so it required fields
|
|
required = True if lid == 0 else False
|
|
self.fields['name_%s' % code] = forms.CharField(label='Название', required=required) #1
|
|
self.fields['description_%s' % code] = forms.CharField(label='Полное описание', required=False, widget=CKEditorWidget)#5
|
|
self.fields['adress_%s' % code] = forms.CharField(label='Адрес', required=False, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
capacity_tmpl = Settings.objects.get(key='hall_template')
|
|
self.fields['hall_capacity_%s' % code] = forms.CharField(label='Шаблон вместимости', initial= capacity_tmpl.get_value(code),
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}), required=False)
|
|
#meta data
|
|
self.fields['title_%s' % code] = forms.CharField(label='Тайтл', required=required, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
self.fields['keywords_%s' % code] = forms.CharField(label='Дескрипшен', required=required, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
self.fields['descriptions_%s' % code] = forms.CharField(label='Кейвордс', required=required, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
|
|
countries = [(item.id, item.name) for item in Country.objects.all()]
|
|
|
|
self.fields['country'] = forms.ChoiceField(label='Страна', choices=countries)#3
|
|
|
|
|
|
|
|
|
|
def save(self, id=None):
|
|
|
|
data = self.cleaned_data
|
|
|
|
if not id:
|
|
place_conference = PlaceConference()
|
|
else:
|
|
place_conference = PlaceConference.objects.get(id=id)
|
|
|
|
#simple fields
|
|
place_conference.type = data['type']
|
|
place_conference.google_latitude = data['latitude']
|
|
place_conference.google_longitude = data['longitude']
|
|
place_conference.phone = data['phone']
|
|
place_conference.fax = data['fax']
|
|
place_conference.web_page = data['web_page']
|
|
place_conference.email = data['email']
|
|
place_conference.total_capacity = data['total_capacity']
|
|
place_conference.amount_halls = data['amount_halls']
|
|
place_conference.exposition_hall = data['exposition_hall']
|
|
place_conference.exp_hall_area = data['exp_hall_area']
|
|
place_conference.wifi = data['wifi']
|
|
place_conference.multimedia_equipment = data['multimedia_equipment']
|
|
place_conference.conference_call = data['conference_call']
|
|
place_conference.translate_equipment = data['translate_equipment']
|
|
place_conference.banquet_hall = data['banquet_hall']
|
|
place_conference.catering = data['catering']
|
|
place_conference.hotel = data['hotel']
|
|
if data.get('country'):
|
|
place_conference.country = Country.objects.get(id=data['country'])
|
|
if data.get('city'):
|
|
place_conference.city = City.objects.get(id=data['city'])
|
|
|
|
# uses because in the next loop data will be overwritten
|
|
place_conference.save()
|
|
#will be saved populated fields
|
|
zero_fields = {}
|
|
#fills all translated fields with data
|
|
#if saves new object, will fill city object. otherwise existing object of City model
|
|
fill_trans_fields_all(PlaceConference, place_conference, data, id, zero_fields)
|
|
#autopopulate
|
|
#populate empty fields and fields which was already populated
|
|
place_conference_id = getattr(place_conference, 'id')
|
|
populate_all(PlaceConference, data, place_conference_id, zero_fields)
|
|
#save files
|
|
check_tmp_files(place_conference, data['key'])
|
|
|
|
|
|
return PlaceConference.objects.get(id=place_conference_id)
|
|
|
|
|
|
|
|
def clean_latitude(self):
|
|
"""
|
|
latitude checking
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
latitude = cleaned_data.get('latitude')
|
|
latitude = latitude.replace(',', '.')
|
|
return latitude
|
|
|
|
def clean_longitude(self):
|
|
"""
|
|
longitude checking
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
longitude = cleaned_data.get('longitude')
|
|
longitude = longitude.replace(',', '.')
|
|
return longitude
|
|
|
|
def clean_web_page(self):
|
|
"""
|
|
web_page checking
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
web_page = cleaned_data.get('web_page')
|
|
if not web_page:
|
|
return ''
|
|
|
|
validate = URLValidator()
|
|
try:
|
|
validate(web_page)
|
|
except(ValidationError),e:
|
|
raise ValidationError(e.messages[0])
|
|
return web_page
|
|
|
|
def clean_email(self):
|
|
"""
|
|
email checking
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
email = cleaned_data.get('email')
|
|
if not email:
|
|
return ''
|
|
try:
|
|
validate_email(email)
|
|
except(ValidationError),e:
|
|
raise ValidationError(e.messages[0])
|
|
return email
|
|
|
|
def clean_phone(self):
|
|
"""
|
|
phone checking
|
|
"""
|
|
cleaned_data = super(ConferenceForm, 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 ValidationError('Введите правильный телефон')
|
|
|
|
def clean_fax(self):
|
|
"""
|
|
fax checking
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
fax = cleaned_data.get('fax')
|
|
if not fax:
|
|
return
|
|
|
|
deduct = ('-','(',')','.',' ')
|
|
|
|
for elem in deduct:
|
|
fax = fax.replace(elem, '')
|
|
|
|
if fax.isdigit():
|
|
return fax
|
|
else:
|
|
raise ValidationError('Введите правильный факс')
|
|
|
|
def clean_total_capacity(self):
|
|
"""
|
|
checking total_capacity
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
total_capacity = cleaned_data.get('total_capacity').strip()
|
|
return is_positive_integer(total_capacity)
|
|
|
|
def clean_amount_halls(self):
|
|
"""
|
|
checking amount_halls
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
amount_halls = cleaned_data.get('amount_halls').strip()
|
|
return is_positive_integer(amount_halls)
|
|
|
|
def clean_exp_hall_area(self):
|
|
"""
|
|
checking exp_hall_area
|
|
"""
|
|
cleaned_data = super(ConferenceForm, self).clean()
|
|
exp_hall_area = cleaned_data.get('exp_hall_area').strip()
|
|
return is_positive_integer(exp_hall_area)
|
|
|
|
class HallForm(forms.ModelForm):
|
|
"""
|
|
form for Hall model
|
|
"""
|
|
number = forms.CharField(widget=forms.TextInput(attrs={'style': 'width:30px'}),required=False)
|
|
capacity = forms.CharField(widget=forms.TextInput(attrs={'style': 'width:60px'}), required=False)
|
|
name = forms.CharField(required=False)
|
|
class Meta:
|
|
model = Hall
|
|
exclude = ('place_conference',)
|
|
|
|
def clean_number(self):
|
|
cleaned_data = super(HallForm, self).clean()
|
|
number = cleaned_data.get('number').strip()
|
|
return is_positive_integer(number)
|
|
|
|
def clean_capacity(self):
|
|
cleaned_data = super(HallForm, self).clean()
|
|
capacity = cleaned_data.get('capacity').strip()
|
|
return is_positive_integer(capacity)
|
|
|
|
|
|
|
|
class ExpositionForm(forms.Form):
|
|
types = [(item1, item2) for item1, item2 in EXPOSITION_TYPE]
|
|
type = forms.ChoiceField(required=False, choices=types)
|
|
|
|
latitude = forms.CharField(label='Широта')
|
|
longitude = forms.CharField(label='Долгота')
|
|
|
|
phone = forms.CharField(label='Телефон', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите телефон'}))
|
|
fax = forms.CharField(label='Факс', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите факс'}))
|
|
web_page = forms.CharField(label='Веб-сайт', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите адрес сайта'}))#
|
|
email = forms.CharField(label='Email', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Введите email'}))#
|
|
#
|
|
foundation_year = forms.CharField(label='Год основания', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Год основания'}))
|
|
total_area = forms.CharField(label='Общая выставочная площадь', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Общая выст. площадь'}))
|
|
closed_area = forms.CharField(label='Закрытая выствочная площадь', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Закр. выст. площадь'}))
|
|
open_area = forms.CharField(label='Открытая выставочная площадь', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Откр. выст. площадь'}))
|
|
total_pavilions = forms.CharField(label='Количество павильонов', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Количество павильонов'}))
|
|
total_halls = forms.CharField(label='Количество конференц залов', required=False,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Конференц залы'}))
|
|
#
|
|
wifi = forms.BooleanField(label='Wi-fi', required=False)
|
|
bank = forms.BooleanField(label='Банк/Банкоматы', required=False)
|
|
children_room = forms.BooleanField(label='Детская комната', required=False)
|
|
disabled_service = forms.BooleanField(label='Сервис для инвалидов', required=False)
|
|
conference_centre = forms.BooleanField(label='Конгресс-центр', required=False)
|
|
business_centre = forms.BooleanField(label='Бизнес центр', required=False)
|
|
online_registration = forms.BooleanField(label='Онлайн регистрация', required=False)
|
|
cafe = forms.BooleanField(label='Кафе', required=False)
|
|
terminals = forms.BooleanField(label='Информационые терминалы', required=False)
|
|
parking = forms.BooleanField(label='Парковка', required=False)
|
|
press_centre = forms.BooleanField(label='Пресс-центр', required=False)
|
|
mobile_application = forms.BooleanField(label='Мобильное приложение', required=False)
|
|
#
|
|
key = forms.CharField(required=False, widget=forms.HiddenInput())
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(ExpositionForm, self).__init__(*args, **kwargs)
|
|
# creates translated form fields, example: name_ru, name_en
|
|
# len(10) is a hack for detect if settings.LANGUAGES is not configured it return all langs
|
|
if len(settings.LANGUAGES) in range(10):
|
|
for lid, (code, name) in enumerate(settings.LANGUAGES):
|
|
# using enumerate for detect iteration number
|
|
# first iteration is a default lang so it required fields
|
|
required = True if lid == 0 else False
|
|
self.fields['name_%s' % code] = forms.CharField(label='Название', required=required)
|
|
self.fields['description_%s' % code] = forms.CharField(label='Полное описание', required=False, widget=CKEditorWidget)
|
|
self.fields['adress_%s' % code] = forms.CharField(label='Адрес', required=False, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
#
|
|
self.fields['total_year_action_%s' % code] = forms.CharField(label='Количество мероприятий в год', required=False, widget=CKEditorWidget)
|
|
#meta data
|
|
self.fields['title_%s' % code] = forms.CharField(label='Тайтл', required=required, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
self.fields['keywords_%s' % code] = forms.CharField(label='Дескрипшен', required=required, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
self.fields['descriptions_%s' % code] = forms.CharField(label='Кейвордс', required=required, max_length=255,
|
|
widget=forms.TextInput(attrs={'style':'width: 550px'}))
|
|
|
|
countries = [(item.id, item.name) for item in Country.objects.all()]
|
|
self.fields['country'] = forms.ChoiceField(label='Страна', choices=countries)#3
|
|
|
|
cities = [(item.id, item.name) for item in City.objects.all()]
|
|
self.fields['city'] = forms.ChoiceField(label='Город', choices=cities)
|
|
|
|
def save(self, id=None):
|
|
data = self.cleaned_data
|
|
|
|
if not id:
|
|
place_exposition = PlaceExposition()
|
|
else:
|
|
place_exposition = PlaceExposition.objects.get(id=id)
|
|
|
|
place_exposition.type = data['type']
|
|
place_exposition.google_latitude = data['latitude']
|
|
place_exposition.google_longitude = data['longitude']
|
|
place_exposition.phone = data['phone']
|
|
place_exposition.fax = data['fax']
|
|
place_exposition.web_page = data['web_page']
|
|
place_exposition.email = data['email']
|
|
place_exposition.foundation_year = data['foundation_year']
|
|
place_exposition.total_area = data['total_area']
|
|
place_exposition.closed_area = data['closed_area']
|
|
place_exposition.open_area = data['open_area']
|
|
place_exposition.total_pavilions = data['total_pavilions']
|
|
place_exposition.total_halls = data['total_halls']
|
|
place_exposition.wifi = data['wifi']
|
|
place_exposition.bank = data['bank']
|
|
place_exposition.children_room = data['children_room']
|
|
place_exposition.disabled_service = data['disabled_service']
|
|
place_exposition.conference_centre = data['conference_centre']
|
|
place_exposition.business_centre = data['business_centre']
|
|
place_exposition.online_registration = data['online_registration']
|
|
place_exposition.cafe = data['cafe']
|
|
place_exposition.terminals = data['terminals']
|
|
place_exposition.parking = data['parking']
|
|
place_exposition.press_centre = data['press_centre']
|
|
place_exposition.mobile_application = data['mobile_application']
|
|
|
|
if data.get('country'):
|
|
place_exposition.country = Country.objects.get(id=data['country'])
|
|
if data.get('city'):
|
|
place_exposition.city = City.objects.get(id=data['city'])
|
|
|
|
# uses because in the next loop data will be overwritten
|
|
place_exposition.save()
|
|
#will be saved populated fields
|
|
zero_fields = {}
|
|
#fills all translated fields with data
|
|
#if saves new object, will fill city object. otherwise existing object of City model
|
|
fill_trans_fields_all(PlaceExposition, place_exposition, data, id, zero_fields)
|
|
#autopopulate
|
|
#populate empty fields and fields which was already populated
|
|
place_exposition_id = getattr(place_exposition, 'id')
|
|
populate_all(PlaceConference, data, place_exposition_id, zero_fields)
|
|
#save files
|
|
check_tmp_files(place_exposition, data['key'])
|
|
|
|
return PlaceExposition.objects.get(id=place_exposition_id)
|
|
|
|
|
|
def clean_latitude(self):
|
|
"""
|
|
latitude checking
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
latitude = cleaned_data.get('latitude')
|
|
latitude = latitude.replace(',', '.')
|
|
return latitude
|
|
|
|
def clean_longitude(self):
|
|
"""
|
|
longitude checking
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
longitude = cleaned_data.get('longitude')
|
|
longitude = longitude.replace(',', '.')
|
|
return longitude
|
|
|
|
def clean_web_page(self):
|
|
"""
|
|
web_page checking
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
web_page = cleaned_data.get('web_page')
|
|
if not web_page:
|
|
return ''
|
|
|
|
validate = URLValidator()
|
|
try:
|
|
validate(web_page)
|
|
except(ValidationError),e:
|
|
raise ValidationError(e.messages[0])
|
|
return web_page
|
|
|
|
def clean_email(self):
|
|
"""
|
|
email checking
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
email = cleaned_data.get('email')
|
|
if not email:
|
|
return ''
|
|
try:
|
|
validate_email(email)
|
|
except(ValidationError),e:
|
|
raise ValidationError(e.messages[0])
|
|
return email
|
|
|
|
def clean_phone(self):
|
|
"""
|
|
phone checking
|
|
"""
|
|
cleaned_data = super(ExpositionForm, 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 ValidationError('Введите правильный телефон')
|
|
|
|
def clean_fax(self):
|
|
"""
|
|
fax checking
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
fax = cleaned_data.get('fax')
|
|
if not fax:
|
|
return
|
|
|
|
deduct = ('-','(',')','.',' ')
|
|
|
|
for elem in deduct:
|
|
fax = fax.replace(elem, '')
|
|
|
|
if fax.isdigit():
|
|
return fax
|
|
else:
|
|
raise ValidationError('Введите правильный факс')
|
|
|
|
|
|
|
|
def clean_foundation_year(self):
|
|
"""
|
|
checking foundation_year
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
foundation_year = cleaned_data.get('foundation_year').strip()
|
|
return is_positive_integer(foundation_year)
|
|
|
|
def clean_total_area(self):
|
|
"""
|
|
checking foundation_year
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
total_area = cleaned_data.get('total_area').strip()
|
|
return is_positive_integer(total_area)
|
|
|
|
def clean_closed_area(self):
|
|
"""
|
|
checking closed_area
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
closed_area = cleaned_data.get('closed_area').strip()
|
|
return is_positive_integer(closed_area)
|
|
|
|
def clean_open_area(self):
|
|
"""
|
|
checking open_area
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
open_area = cleaned_data.get('open_area').strip()
|
|
return is_positive_integer(open_area)
|
|
|
|
def clean_total_pavilions(self):
|
|
"""
|
|
checking total_pavilions
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
total_pavilions = cleaned_data.get('total_pavilions').strip()
|
|
return is_positive_integer(total_pavilions)
|
|
|
|
def clean_total_halls(self):
|
|
"""
|
|
checking total_halls
|
|
"""
|
|
cleaned_data = super(ExpositionForm, self).clean()
|
|
total_halls = cleaned_data.get('total_halls').strip()
|
|
return is_positive_integer(total_halls) |