X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/1c6b6f643fb3a9f50fe2752b3b2ee3390b321d78..010b648653d39191fb25b93424d408a95289826e:/edumed/contact_forms.py diff --git a/edumed/contact_forms.py b/edumed/contact_forms.py index 87fc591..196e5e4 100644 --- a/edumed/contact_forms.py +++ b/edumed/contact_forms.py @@ -10,7 +10,6 @@ from django.core.validators import validate_email from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ - WOJEWODZTWA = ( u'dolnośląskie', u'kujawsko-pomorskie', @@ -227,7 +226,7 @@ class WTEMForm(ContactForm): except ValidationError: pass else: - send_mail(mail_subject, mail_body, 'edukacjamedialna@nowoczesnapolska.org.pl', [email], + send_mail(mail_subject, mail_body, 'olimpiada@nowoczesnapolska.org.pl', [email], fail_silently=True) return contact @@ -254,6 +253,7 @@ class OlimpiadaForm(ContactForm): przewodniczacy = forms.CharField(label=u'Imię i nazwisko Przewodniczącego/Przewodniczącej', max_length=128) school = forms.CharField(label=u'Nazwa szkoły', max_length=255) school_address = forms.CharField(label=u'Adres szkoły', widget=forms.Textarea, max_length=1000) + school_wojewodztwo = forms.ChoiceField(label=u'Województwo', choices=WOJEWODZTWO_CHOICES) school_email = forms.EmailField(label=u'Adres e-mail szkoły', max_length=128) school_phone = forms.CharField(label=u'Numer telefonu szkoły', max_length=32) school_www = forms.URLField(label=u'Strona WWW szkoły', max_length=255, required=False) @@ -270,13 +270,16 @@ class OlimpiadaForm(ContactForm): u'oświadczam, że zostałam/em poinformowana/y o tym, że mam prawo wglądu w treść swoich danych ' u'i możliwość ich poprawiania oraz że ich podanie jest dobrowolne, ale niezbędne do dokonania ' u'zgłoszenia.') + zgoda_newsletter = forms.BooleanField( + label=u'Chcę otrzymywać newsletter: Edukacja medialna', required=False) extract_types = (dict(slug='extended', label=_('extended')),) @staticmethod def get_extract_fields(contact, extract_type_slug): fields = contact.body.keys() - fields.remove('student') + if 'student' in fields: + fields.remove('student') fields.extend(['contact', 'student_first_name', 'student_last_name', 'student_email']) return fields @@ -293,31 +296,33 @@ class OlimpiadaForm(ContactForm): toret[0][field_name] = val current = toret[0] - for student in contact.body['student']: - for attr in ('first_name', 'last_name', 'email'): - current['student_' + attr] = student[attr] - if current not in toret: - toret.append(current) - current = {} + if 'student' in contact.body: + for student in contact.body['student']: + for attr in ('first_name', 'last_name', 'email'): + current['student_' + attr] = student[attr] + if current not in toret: + toret.append(current) + current = {} return toret def save(self, request, formsets=None): + from wtem.models import Confirmation contact = super(OlimpiadaForm, self).save(request, formsets) - mail_subject = render_to_string('contact/olimpiada/student_mail_subject.html').strip() - mail_body = render_to_string('contact/olimpiada/student_mail_body.html') for formset in formsets or []: if formset.prefix == 'student': for f in formset.forms: email = f.cleaned_data.get('email', None) - try: - validate_email(email) - except ValidationError: - pass - else: - send_mail(mail_subject, mail_body, 'edukacjamedialna@nowoczesnapolska.org.pl', [email], - fail_silently=True) - + if email: + try: + Confirmation.objects.get(email=email) + except Confirmation.DoesNotExist: + first_name = f.cleaned_data.get('first_name', None) + last_name = f.cleaned_data.get('last_name', None) + if first_name and last_name: + confirmation = Confirmation.create( + first_name=first_name, last_name=last_name, email=email, contact=contact) + confirmation.send_mail() return contact @@ -533,6 +538,7 @@ class CybernauciForm(ContactForm): class WLEMForm(ContactForm): + disabled = True form_tag = 'wlem' form_title = u"WLEM - szkolenie dla warszawskich liderów edukacji medialnej" admin_list = ['nazwisko', 'instytucja', 'contact']