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.
86 lines
3.5 KiB
86 lines
3.5 KiB
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from hvad.forms import TranslatableModelForm
|
|
from .models import Specialist, SpecialistCatalog, Feedback, City, Country
|
|
from ckeditor.widgets import CKEditorWidget
|
|
from django.utils.translation import get_language
|
|
|
|
country_choices = [(c.id, c.name) for c in Country.objects.all()]
|
|
lang_code = get_language()[:2]
|
|
|
|
default_text = u"Планируете посетить выставку в %s?" \
|
|
u" Мы предлагаем Вам подобрать переводчика именно под Ваши цели и потребности. " \
|
|
u"Специализируясь уже более 7 лет на предоставлении переводчиков на выставки и конференции " \
|
|
u"%s, мы можем предоставить профессионалов со знанием разных " \
|
|
u"языков на гибких для Вас условиях. Каждый заказ индивидуален для нас, " \
|
|
u"и итоговая цена зависит от вида перевода, тематики, срочности подбора " \
|
|
u"специалиста, города и объема работы."
|
|
default_title = u"Переводчики в %s"
|
|
|
|
|
|
class SpecialistCatalogForm(TranslatableModelForm):
|
|
|
|
class Meta:
|
|
model = SpecialistCatalog
|
|
fields = '__all__'
|
|
widgets = {
|
|
'type': forms.Select(choices=(('1', 'Country'), ('2', 'City'))),
|
|
'city': forms.HiddenInput(attrs={'id': 'id_city'}),
|
|
'country': forms.Select(choices=country_choices, attrs={'id': 'id_country'}),
|
|
'main_descr': CKEditorWidget,
|
|
'benefits': CKEditorWidget,
|
|
}
|
|
|
|
def clean_city(self):
|
|
data = self.cleaned_data
|
|
if data.get('city'):
|
|
data['city'] = City.objects.language(lang_code).get(id=data['city'])
|
|
return data
|
|
|
|
def clean_country(self):
|
|
data = self.cleaned_data
|
|
if data.get('country'):
|
|
data['country'] = Country.objects.language(lang_code).get(id=data['country'])
|
|
return data
|
|
|
|
def save(self, commit=True):
|
|
place = self.cleaned_data.get('city') or self.cleaned_data.get('country')
|
|
place_inflect = place.inflect or place.name
|
|
if not self.cleaned_data['title']:
|
|
self.cleaned_data['title'] = default_title % place_inflect
|
|
if not self.cleaned_data['main_descr']:
|
|
self.cleaned_data['main_descr'] = default_text % (place_inflect, place_inflect)
|
|
return super(SpecialistCatalogForm, self).save(commit=True)
|
|
|
|
|
|
class SpecialistForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
model = Specialist
|
|
fields = '__all__'
|
|
widgets = {
|
|
'city': forms.HiddenInput(attrs={'id': 'id_city'}),
|
|
'country': forms.Select(choices=country_choices, attrs={'id': 'id_country'})
|
|
}
|
|
|
|
def clean_city(self):
|
|
data = self.cleaned_data
|
|
if data.get('city'):
|
|
data['city'] = City.objects.language(lang_code).get(id=data['city'])
|
|
return data
|
|
|
|
def clean_country(self):
|
|
data = self.cleaned_data
|
|
if data.get('country'):
|
|
data['country'] = Country.objects.language(lang_code).get(id=data['country'])
|
|
return data
|
|
|
|
|
|
class FeedbackForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
model = Feedback
|
|
fields = '__all__'
|
|
widgets = {
|
|
'text':CKEditorWidget
|
|
} |