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.
65 lines
2.7 KiB
65 lines
2.7 KiB
# -*- coding: utf-8 -*-
|
|
from django import forms
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from ckeditor.widgets import CKEditorWidget
|
|
from emencia.django.newsletter.models import Contact, ContactSettings, MailingList, Newsletter, Attachment
|
|
from city.models import City
|
|
from country.models import Country, Area
|
|
|
|
|
|
class ContactSettingsForm(forms.ModelForm):
|
|
city = forms.CharField(label=u'Город', widget=forms.HiddenInput() ,required=False)
|
|
periodic = forms.ChoiceField(choices=ContactSettings.PERIODIC_CHOICES,
|
|
label=_(u'Периодичность отправки'))
|
|
first_name = forms.CharField(label=_('first name'))
|
|
subscriber = forms.BooleanField(label=_('subscriber'), required=False)
|
|
valid = forms.BooleanField(label=_('valid email'), required=False)
|
|
tester = forms.BooleanField(label=_('contact tester'), required=False)
|
|
country = forms.MultipleChoiceField(choices=[(c.id,c.name) for c in list(set(Country.objects.language().all()))], required=False)
|
|
area = forms.MultipleChoiceField(choices=[(a.id, a.name) for a in list(set(Area.objects.language().all()))], required=False)
|
|
|
|
class Meta:
|
|
model = ContactSettings
|
|
fields = ('periodic', 'exponent_practicum', 'organiser_practicum', 'theme', 'area', 'country', 'city', )
|
|
|
|
def save(self, commit=True):
|
|
contactsettings = super(ContactSettingsForm, self).save(commit=False)
|
|
if commit:
|
|
contactsettings.save()
|
|
contact = contactsettings.contact
|
|
contact.first_name = self.cleaned_data['first_name']
|
|
contact.subscriber = self.cleaned_data['subscriber']
|
|
contact.valid = self.cleaned_data['valid']
|
|
contact.tester = self.cleaned_data['tester']
|
|
contact.save()
|
|
return contactsettings
|
|
|
|
def clean_periodic(self):
|
|
|
|
return int(self.cleaned_data['periodic'])
|
|
|
|
def clean_city(self):
|
|
return City.objects.none()
|
|
|
|
|
|
class MailingListForm(forms.ModelForm):
|
|
class Meta:
|
|
model = MailingList
|
|
fields = ('name', 'description')
|
|
|
|
|
|
class NewsletterForm(forms.ModelForm):
|
|
test_contacts = forms.ModelMultipleChoiceField(label=u'Тестовые контакты', required=False,
|
|
queryset=Contact.objects.filter(tester=True))
|
|
content = forms.CharField(label=_('content'), widget=CKEditorWidget(config_name='newsletters'))
|
|
|
|
class Meta:
|
|
model = Newsletter
|
|
fields = ('title', 'content', 'mailing_list', 'test_contacts', 'header_sender',
|
|
'header_reply', 'status', 'sending_date', 'slug')
|
|
|
|
|
|
class AttachmentForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Attachment
|
|
fields = ('title', 'file_attachment') |