X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/9c2076643cf26963a4263f59e48813ce16157c58..d7a837460bba76055e9954717cbbd294e179b1e8:/edumed/contact_forms.py diff --git a/edumed/contact_forms.py b/edumed/contact_forms.py index d969929..e5ceff2 100644 --- a/edumed/contact_forms.py +++ b/edumed/contact_forms.py @@ -1,72 +1,139 @@ # -*- coding: utf-8 -*- from django import forms +from django.forms.formsets import BaseFormSet + from contact.forms import ContactForm +from django.utils.translation import ugettext_lazy as _ + +WOJEWODZTWA = ( + u'dolnoÅlÄ skie', + u'kujawsko-pomorskie', + u'lubelskie', + u'lubuskie', + u'Åódzkie', + u'maÅopolskie', + u'mazowieckie', + u'opolskie', + u'podkarpackie', + u'podlaskie', + u'pomorskie', + u'ÅlÄ skie', + u'ÅwiÄtokrzyskie', + u'warmiÅsko-mazurskie', + u'wielkopolskie', + u'zachodniopomorskie', +) + +WOJEWODZTWO_CHOICES = [(u'', u'(wybierz)')] + [(w, w) for w in WOJEWODZTWA] + + +class WTEMStudentForm(forms.Form): + first_name = forms.CharField(label=u'ImiÄ', max_length=128) + last_name = forms.CharField(label=u'Nazwisko', max_length=128) + email = forms.EmailField(label=u'Adres e-mail', max_length=128) + form_tag = "student" + + +class NonEmptyBaseFormSet(BaseFormSet): + """ + Won't allow formset_factory to be submitted with no forms + """ + def clean(self): + for form in self.forms: + if form.cleaned_data: + return + forms.ValidationError(u"ProszÄ podaÄ dane przynajmniej jednej osoby.") + +class CommissionForm(forms.Form): + name = forms.CharField(label=u'ImiÄ i nazwisko CzÅonka Komisji', max_length=128) + form_tag = "commission" + + +class OlimpiadaForm(ContactForm): + ends_on = (2017, 11, 17, 0, 5) + 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), + } + + 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_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) -class RegistrationForm(ContactForm): - form_tag = 'sugestie' - form_title = u"ZgÅoÅ sugestiÄ" - admin_list = ['podpis', 'contact', 'temat'] - - contact = forms.EmailField(label=u'E-mail', max_length=128, required=False) - podpis = forms.CharField(label=u'Podpis', max_length=128, required=False) - temat = forms.CharField(label=u'Temat zgÅoszenia', max_length=255) - tresc = forms.CharField(label=u'TreÅÄ', widget=forms.Textarea, max_length=1800) - - -class CooperateForm(ContactForm): - form_tag = 'wspolpraca' - form_title = u"BÄ dź z nami w kontakcie" - admin_list = ['podpis', 'contact'] - - contact = forms.EmailField(label=u'E-mail', max_length=128) - podpis = forms.CharField(label=u'Podpis', max_length=128) - uwagi = forms.CharField(label=u'Uwagi', widget=forms.Textarea, max_length=1800, required=False) - - -class ContestForm(ContactForm): - form_tag = 'konkurs' - form_title = u"ZgÅoÅ siÄ do konkursu" - admin_list = ['name', 'organization', 'title'] - - nazwisko = forms.CharField(label=u'ImiÄ i nazwisko', max_length=128) - contact = forms.EmailField(label=u'Adres e-mail', max_length=128) - instytucja = forms.CharField(label=u'Instytucja (nazwa, adres)', - widget=forms.Textarea, max_length=1000) - tytul = forms.CharField(label=u'TytuÅ przeprowadzonej lekcji', - help_text=u'proszÄ wymieniÄ wszystkie, jeÅli zostaÅy przeprowadzone wiÄcej niż jedne zajÄcia', - widget=forms.Textarea, max_length=1000) - uczestnicy = forms.CharField(label=u'Liczba uczestników', max_length=64) - trudnosci = forms.CharField(label=u'Czy w trakcie zajÄÄ pojawiÅy siÄ jakieÅ trudnoÅci? JeÅli tak, to jakie?', - widget=forms.Textarea, max_length=2000) - pomocne = forms.CharField(label=u'Co w materiaÅach okazaÅo siÄ najbardziej pomocne w przygotowaniu i prowadzeniu lekcji?', - widget=forms.Textarea, max_length=2000) - nieprzydatne = forms.CharField(label=u'Co w materiaÅach okazaÅo siÄ nieprzydatne w przygotowaniu i prowadzeniu lekcji?', - widget=forms.Textarea, max_length=2000) - poprawic = forms.CharField(label=u'Jak możemy poprawiÄ serwis edukacjamedialna.edu.pl?', - widget=forms.Textarea, max_length=2000, - required=False) - inne = forms.CharField(label=u'Inne uwagi i komentarze', - widget=forms.Textarea, max_length=2000, - required=False) zgoda_regulamin = forms.BooleanField( - label=u'Znam i akceptujÄ regulamin konkursu Medialog.', - help_text=u'Zobacz <a href="/media/chunks/attachment/Regulamin_konkursu_MediaLog_1.pdf">regulamin konkursu MediaLog</a>.' - ) - zgoda_informacje = forms.BooleanField( - label=u'Wyrażam zgodÄ na otrzymywanie informacji od Fundacji Nowoczesna Polska zwiÄ zanych z edukacjÄ medialnÄ .', - required=False + label=u'Znam i akceptujÄ Regulamin Olimpiady Cyfrowej.', + help_text=u'Zobacz <a href="https://olimpiadacyfrowa.pl/regulamin/" target="_blank">' + u'regulamin Olimpiady Cyfrowej</a>.' ) + 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.') + 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() + 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 -class UdzialForm(ContactForm): - form_tag = 'udzial' - form_title = u"UdziaÅ" - admin_list = ['nazwisko', 'miejscowosc', 'instytucja'] + def save(self, request, formsets=None): + from wtem.models import Confirmation + contact = super(OlimpiadaForm, self).save(request, formsets) - nazwisko = forms.CharField(label=u'ImiÄ i nazwisko', max_length=128) - miejscowosc = forms.CharField(label=u'MiejscowoÅÄ', max_length=128) - instytucja = forms.CharField(label=u'Nazwa organizacji/instytucji', max_length=128) - contact = forms.EmailField(label=u'Adres e-mail', max_length=128) - telefon = forms.CharField(label=u'Telefon', max_length=32) - uczestnicy = forms.IntegerField(label=u'Przewidywana liczba uczestników zajÄÄ') + for formset in formsets or []: + if formset.prefix == 'student': + for f in formset.forms: + email = f.cleaned_data.get('email', None) + 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