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.
119 lines
3.6 KiB
119 lines
3.6 KiB
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.utils.translation import ugettext as _, get_language
|
|
from country.models import Country
|
|
from city.models import City
|
|
from company.models import Company
|
|
|
|
|
|
class BaseForm(forms.ModelForm):
|
|
translation = False
|
|
|
|
class NameForm(BaseForm):
|
|
name = forms.CharField(label=_(u'Введите название компании'))
|
|
translation = True
|
|
class Meta:
|
|
model = Company._meta.translations_model
|
|
fields = ('name',)
|
|
|
|
|
|
class SpecializationForm(BaseForm):
|
|
translation = True
|
|
specialization = forms.CharField(label=_(u'Описание компании'))
|
|
class Meta:
|
|
model = Company._meta.translations_model
|
|
fields = ('specialization',)
|
|
|
|
|
|
class HomeForm(BaseForm):
|
|
city = forms.CharField(label='Город', required=False,
|
|
widget=forms.HiddenInput(attrs={'class': 'select2'}))
|
|
country = forms.ChoiceField(label=_(u'Страна'), choices=[(c.id, c.name) for c in Country.objects.all()], required=False,
|
|
widget=forms.Select(attrs={'class': 'select2'}))
|
|
def __init__(self, *args, **kwargs):
|
|
super(HomeForm, self).__init__(*args, **kwargs)
|
|
if self.instance.city:
|
|
self.fields['city'].widget = forms.HiddenInput(attrs={'class': 'select2', 'data-init-text': self.instance.city.name})
|
|
class Meta:
|
|
model = Company
|
|
fields = ('country', 'city')
|
|
|
|
def current_country(self):
|
|
return self.instance.country
|
|
|
|
def clean_city(self):
|
|
try:
|
|
return City.objects.get(id=self.cleaned_data['city'])
|
|
except City.DoesNotExist:
|
|
return None
|
|
|
|
def clean_country(self):
|
|
try:
|
|
return Country.objects.get(id=self.cleaned_data['country'])
|
|
except City.DoesNotExist:
|
|
return None
|
|
|
|
|
|
class PhoneForm(BaseForm):
|
|
phone = forms.CharField(label=_(u'Контактный телефон'), required=False)
|
|
class Meta:
|
|
model = Company
|
|
fields = ('phone',)
|
|
|
|
class EmailForm(BaseForm):
|
|
email = forms.EmailField(label=_(u'Ваш e-mail'), required=False)
|
|
|
|
class Meta:
|
|
model = Company
|
|
fields = ('email',)
|
|
|
|
class WebPageForm(BaseForm):
|
|
web_page = forms.CharField(label=_(u'Адрес вашего сайта'), required=False)
|
|
|
|
class Meta:
|
|
model = Company
|
|
fields = ('web_page',)
|
|
|
|
class SocialForm(BaseForm):
|
|
facebook = forms.CharField(label=_(u'Facebook'), required=False)
|
|
twitter = forms.CharField(label=_(u'Twitter'), required=False)
|
|
vk = forms.CharField(label=_(u'В контакте'), required=False)
|
|
linkedin = forms.CharField(label=_(u'LinkedIn'), required=False)
|
|
|
|
|
|
class Meta:
|
|
model = Company
|
|
fields = ('facebook', 'twitter', 'vk', 'linkedin')
|
|
|
|
|
|
class TagForm(BaseForm):
|
|
tag = forms.CharField(required=False, widget=forms.HiddenInput(attrs={'class': 'select2'}))
|
|
class Meta:
|
|
model = Company
|
|
fields = ('tag',)
|
|
|
|
|
|
class FoundationForm(BaseForm):
|
|
class Meta:
|
|
model = Company
|
|
fields = ('foundation',)
|
|
|
|
class StaffForm(BaseForm):
|
|
class Meta:
|
|
model = Company
|
|
fields = ('staff_number',)
|
|
|
|
|
|
class DescriptionForm(BaseForm):
|
|
translation = True
|
|
description = forms.CharField(label=_(u'Подробное описание компании'))
|
|
class Meta:
|
|
model = Company._meta.translations_model
|
|
fields = ('description',)
|
|
|
|
class AddressForm(BaseForm):
|
|
translation = True
|
|
address_inf = forms.CharField(label=_(u'Адрес компании'))
|
|
class Meta:
|
|
model = Company._meta.translations_model
|
|
fields = ('address_inf',)
|
|
|