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.
80 lines
3.6 KiB
80 lines
3.6 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 = ['price', 'currency', 'logo', 'main_descr', 'place_photo',
|
|
'specialists', 'city', 'country', 'type', 'title', 'benefits', 'big_cities']
|
|
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,
|
|
'big_cities': CKEditorWidget,
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(SpecialistCatalogForm, self).__init__(*args, **kwargs)
|
|
if kwargs.get('instance'):
|
|
instance = kwargs['instance']
|
|
if instance.type == SpecialistCatalog._country:
|
|
qs = Specialist.objects.filter(country=instance.country)
|
|
else:
|
|
qs = Specialist.objects.filter(city=instance.city)
|
|
|
|
self.fields['specialists'] = forms.ModelMultipleChoiceField(label=u"Специалисты", required=False,
|
|
queryset=qs)
|
|
|
|
|
|
|
|
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 = ['name','country', 'city', 'photo', 'languages']
|
|
widgets = {
|
|
'city': forms.HiddenInput(attrs={'id': 'id_city'}),
|
|
'country': forms.Select(choices=country_choices, attrs={'id': 'id_country'})
|
|
}
|
|
|
|
|
|
class FeedbackForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
model = Feedback
|
|
fields = ['company', 'name', 'text', 'logo', 'catalog']
|
|
widgets = {
|
|
'text':CKEditorWidget
|
|
}
|
|
|
|
|