X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/30343946f333b9b63113bdda185c30924bab0337..b6c1cde7edcd6c43b53bba93342b3f07b357f152:/edumed/contact_forms.py diff --git a/edumed/contact_forms.py b/edumed/contact_forms.py index 1884d0d..7e7faca 100644 --- a/edumed/contact_forms.py +++ b/edumed/contact_forms.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from django import forms from django.forms.formsets import BaseFormSet +from django.utils.safestring import mark_safe + from contact.forms import ContactForm from django.core.mail import send_mail from django.core.exceptions import ValidationError @@ -128,19 +130,15 @@ class WTEMStudentForm(forms.Form): form_tag = "student" -# FIXME: doesn't do what is says anymore. -class NoEmptyFormsAllowedBaseFormSet(BaseFormSet): +class NonEmptyBaseFormSet(BaseFormSet): """ Won't allow formset_factory to be submitted with no forms """ def clean(self): - needed = 3 for form in self.forms: if form.cleaned_data: - needed -= 1 - # return - if needed > 0: - raise forms.ValidationError(u"ProszÄ podaÄ dane przynajmniej trzech osób.") + return + forms.ValidationError(u"ProszÄ podaÄ dane przynajmniej jednej osoby.") class WTEMForm(ContactForm): @@ -150,8 +148,10 @@ class WTEMForm(ContactForm): form_title = u"WTEM - rejestracja uczestników" submit_label = u"WyÅlij zgÅoszenie" admin_list = ['imie', 'nazwisko', 'institution'] - form_formsets = (forms.formsets.formset_factory( - WTEMStudentForm, formset=NoEmptyFormsAllowedBaseFormSet, max_num=5, validate_max=True, extra=5),) + form_formsets = { + 'student': forms.formsets.formset_factory( + WTEMStudentForm, formset=NonEmptyBaseFormSet, max_num=5, validate_max=True, extra=5), + } contact = forms.EmailField(label=u'Adres e-mail opiekuna/opiekunki', max_length=128) imie = forms.CharField(label=u'ImiÄ', max_length=128) @@ -233,6 +233,96 @@ class WTEMForm(ContactForm): return contact +class CommissionForm(forms.Form): + name = forms.CharField(label=u'ImiÄ i nazwisko CzÅonka Komisji', max_length=128) + form_tag = "commission" + + +class OlimpiadaForm(ContactForm): + disabled = True + disabled_template = 'wtem/disabled_contact_form.html' + form_tag = "olimpiada" + form_title = u"Olimpiada Cyfrowa - Elektroniczny System ZgÅoszeÅ" + submit_label = u"WyÅlij zgÅoszenie" + admin_list = ['nazwisko', 'school'] + form_formsets = { + 'student': forms.formsets.formset_factory(WTEMStudentForm, formset=NonEmptyBaseFormSet), + 'commission': forms.formsets.formset_factory(CommissionForm, formset=BaseFormSet), + } + + contact = forms.EmailField(label=u'Adres e-mail PrzewodniczÄ cego/PrzewodniczÄ cej', max_length=128) + 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_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) + + zgoda_regulamin = forms.BooleanField( + label=u'Znam i akceptujÄ Regulamin Olimpiady Cyfrowej.', + help_text=u'Zobacz ' + u'regulamin Olimpiady Cyfrowej.' + ) + zgoda_dane = forms.BooleanField( + label=u'OÅwiadczam, że wyrażam zgodÄ na przetwarzanie danych osobowych zawartych w niniejszym formularzu ' + u'zgÅoszeniowym przez FundacjÄ Nowoczesna Polska (administratora danych) z siedzibÄ w Warszawie (00-514) ' + u'przy ul. MarszaÅkowskiej 84/92 lok. 125 na potrzeby organizacji Olimpiady Cyfrowej. JednoczeÅnie ' + 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.') + + extract_types = (dict(slug='extended', label=_('extended')),) + + @staticmethod + def get_extract_fields(contact, extract_type_slug): + fields = contact.body.keys() + if 'student' in fields: + fields.remove('student') + fields.extend(['contact', 'student_first_name', 'student_last_name', 'student_email']) + return fields + + @staticmethod + def get_extract_records(keys, contact, extract_type_slug): + toret = [{}] + for field_name in keys: + if field_name.startswith('student_'): + continue + if field_name == 'contact': + val = contact.contact + else: + val = contact.body[field_name] + toret[0][field_name] = val + + current = toret[0] + 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): + 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) + + return contact + + class MILForm(ContactForm): form_tag = 'mil' form_title = _('Share your thoughts on the "Media and information literacy competencies catalogue"') @@ -445,6 +535,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'] @@ -481,3 +572,81 @@ class WLEMForm(ContactForm): required=False, label=u'Wyrażam zgodÄ na otrzymywanie informacji od Fundacji Nowoczesna Polska ' u'zwiÄ zanych z edukacjÄ medialnÄ .') + + +def textarea_field(label, max_length=500): + return forms.CharField(label=label, widget=forms.Textarea, max_length=max_length) + + +def ordered_textarea_field(start, pre_label=u'', label=u'', max_length=500): + return textarea_field( + mark_safe(u'%s