new register form
[prawokultury.git] / prawokultury / contact_forms.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from django.conf import settings
5 from django import forms
6 from django.core.mail import send_mail
7
8 from contact.forms import ContactForm
9 from contact.models import Contact
10 from contact.fields import HeaderField
11 from django.utils.functional import lazy
12 from django.utils.translation import ugettext_lazy as _
13 from django.utils.safestring import mark_safe
14 from migdal.models import Entry
15
16 from prawokultury.countries import COUNTRIES, TRAVEL_GRANT_COUNTRIES
17
18 mark_safe_lazy = lazy(mark_safe, unicode)
19
20
21 class RegistrationForm(ContactForm):
22     form_tag = 'register'
23
24     save_as_tag = '2018'
25     conference_name = u'CopyCamp 2018'
26     notify_on_register = False
27     
28     form_title = _('Registration')
29     admin_list = ['first_name', 'last_name', 'organization']
30
31     mailing_field = 'agree_mailing'
32
33     travel_grant_countries = TRAVEL_GRANT_COUNTRIES
34
35     first_name = forms.CharField(label=_('First name'), max_length=128)
36     last_name = forms.CharField(label=_('Last name'), max_length=128)
37     contact = forms.EmailField(label=_('E-mail'), max_length=128)
38     organization = forms.CharField(label=_('Organization'), max_length=256, required=False)
39     country = forms.ChoiceField(
40         label=_('Country of residence'), choices=[('', '--------')] + zip(COUNTRIES, COUNTRIES), required=False)
41     travel_grant = forms.BooleanField(
42         label=_('I require financial assistance to attend CopyCamp 2018.'), required=False)
43     travel_grant_motivation = forms.CharField(
44         label=_('Please write us about yourself and why you want to come to CopyCamp. '
45                 'This information will help us evaluate your travel grant application:'),
46         help_text=_('Financial assistance for German audience is possible '
47                     'thanks to the funds of the German Federal Foreign Office transferred by '
48                     'the Foundation for Polish-German Cooperation.'),
49         widget=forms.Textarea, max_length=600, required=False)
50
51     days = forms.ChoiceField(
52        label=_("I'm planning to show up on"),
53        choices=[
54            ('both', _('Both days of the conference')),
55            ('only-28th', _('October 5th only')),
56            ('only-29th', _('October 6th only')),
57        ], widget=forms.RadioSelect())
58
59     # ankieta
60     times_attended = forms.ChoiceField(
61         required=False,
62         label=_("1. How many times have you attended CopyCamp?"),
63         choices=[
64             ('0', _('not yet')),
65             ('1', _('once')),
66             ('2', _('twice')),
67             ('3', _('three times')),
68             ('4', _('four times')),
69             ('5', _('five times')),
70         ], widget=forms.RadioSelect())
71     age = forms.ChoiceField(
72         required=False,
73         label=_("2. Please indicate your age bracket:"),
74         choices=[
75             ('0-19', _('19 or below')),
76             ('20-25', _('20-25')),
77             ('26-35', _('26-35')),
78             ('36-45', _('36-45')),
79             ('46-55', _('46-55')),
80             ('56-65', _('56-65')),
81             ('66+', _('66 or above')),
82         ], widget=forms.RadioSelect())
83     areas = forms.MultipleChoiceField(
84         required=False,
85         label=_("3. Please indicate up to 3 areas you feel most affiliated with"),
86         choices=[
87             ('sztuki plastyczne', _('visual art')),
88             ('literatura', _('literature')),
89             ('muzyka', _('music')),
90             ('teatr', _('theatre')),
91             ('film', _('film production')),
92             ('wydawanie', _('publishing')),
93             ('prawo', _('law')),
94             ('ekonomia', _('economy')),
95             ('socjologia', _('sociology')),
96             ('technika', _('technology')),
97             ('edukacja', _('education')),
98             ('studia', _('higher education')),
99             ('nauka', _('academic research')),
100             ('biblioteki', _('library science')),
101             ('administracja', _('public administration')),
102             ('ngo', _('nonprofit organisations')),
103             ('other', _('other (please specify below)')),
104         ], widget=forms.CheckboxSelectMultiple())
105     areas_other = forms.CharField(required=False, label=_('Fill if you selected “other” above'))
106     source = forms.ChoiceField(
107         required=False,
108         label=_("4. Please indicate how you received information about the conference:"),
109         choices=[
110             ('znajomi', _('through friends sharing on the web')),
111             ('znajomi2', _('through friends by other means')),
112             ('prasa', _('through press')),
113             ('fnp', _('directly through the Foundation\'s facebook or website')),
114             ('www', _('through other websites (please specify below)')),
115             ('other', _('other (please specify below)')),
116         ], widget=forms.RadioSelect())
117     source_other = forms.CharField(required=False, label=_('Fill if you selected “other” or “other website” above'))
118     motivation = forms.ChoiceField(
119         required=False,
120         label=_("6. Please indicate the most important factor for your willingness to participate:"),
121         choices=[
122             ('speaker', _('listening to particular speaker(s)')),
123             ('networking', _('good networking occasion')),
124             ('partnering', _('partnering with organisations present at the event')),
125             ('other', _('other (please specify below)')),
126         ], widget=forms.RadioSelect())
127     motivation_other = forms.CharField(required=False, label=_('Fill if you selected “other” above'))
128
129     agree_mailing = forms.BooleanField(
130         label=_('I want to receive e-mails about future CopyCamps '
131                 'and similar activities of the Modern Poland Foundation'),
132         required=False
133     )
134     agree_license = forms.BooleanField(
135         label=_('Permission for publication'),
136         help_text=mark_safe_lazy(_(
137             u'I agree to having materials, recorded during the conference, released under the terms of '
138             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> license and '
139             u'to publishing my image.')),
140         required=False
141     )
142
143     def __init__(self, *args, **kwargs):
144         super(RegistrationForm, self).__init__(*args, **kwargs)
145         self.started = getattr(settings, 'REGISTRATION_STARTED', False)
146         self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= settings.REGISTRATION_LIMIT
147         try:
148             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
149             self.fields['agree_toc'] = forms.BooleanField(
150                 required=True,
151                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
152             )
153         except Entry.DoesNotExist:
154             pass
155
156     def clean_areas(self):
157         data = self.cleaned_data['areas']
158         if len(data) > 3:
159             raise forms.ValidationError(_('Select at most 3 areas'))
160         return data
161
162     def clean(self):
163         cleaned_data = self.cleaned_data
164         if 'travel_grant' in cleaned_data:
165             country = cleaned_data['country']
166             travel_grant = cleaned_data['travel_grant']
167             motivation = cleaned_data['travel_grant_motivation']
168             if country not in self.travel_grant_countries and travel_grant:
169                 raise forms.ValidationError(_('Travel grant is not provided for the selected country'))
170             if travel_grant and not motivation:
171                 self._errors['travel_grant_motivation'] = _('Please provide this information')
172                 raise forms.ValidationError(_('To apply for a travel grant you must provide additional information.'))
173             if not travel_grant and motivation:
174                 cleaned_data['motivation'] = ''
175         return cleaned_data
176
177     def main_fields(self):
178         return [self[name] for name in (
179             'first_name', 'last_name', 'contact', 'organization', 'country',
180             'travel_grant', 'travel_grant_motivation', 'days')]
181
182     def survey_fields(self):
183         return [self[name] for name in (
184             'times_attended', 'age',
185             'areas', 'areas_other', 'source', 'source_other', 'motivation', 'motivation_other')]
186
187     def agreement_fields(self):
188         return [self[name] for name in ('agree_mailing', 'agree_license', 'agree_toc')]
189
190
191 tracks = (
192     _('social security in the creative sector'),
193     _('100 years of the evolution of modern copyright law and industrial property law in Poland '
194       'and of cultural activities regulated by this law'),
195     _('EU copyright reform'),
196     _('blockchain use prospects'),
197     _('reuse of archives and cultural heritage'),
198 )
199
200
201 class RegisterSpeaker(RegistrationForm):
202     form_tag = 'register-speaker'
203     save_as_tag = '2018-speaker'
204     form_title = _('Open call for presentations')
205     notify_on_register = False
206     mailing_field = 'agree_mailing'
207
208     presentation_thematic_track = forms.ChoiceField(
209         label=_('Thematic track'),
210         choices=[(t, t) for t in tracks], widget=forms.RadioSelect())
211
212     bio = forms.CharField(label=mark_safe_lazy(
213         _('Short biographical note in Polish (max. 500 characters, not required)')),
214                           widget=forms.Textarea, max_length=500, required=False)
215     bio_en = forms.CharField(label=_('Short biographical note in English (max. 500 characters)'), widget=forms.Textarea,
216                              max_length=500)
217     photo = forms.FileField(label=_('Photo'), required=False)
218     phone = forms.CharField(label=_('Phone number'), max_length=64,
219                             required=False,
220                             help_text=_('(used only for organizational purposes)'))
221
222     presentation_title = forms.CharField(
223         label=mark_safe_lazy(_('Presentation title in Polish (not required)')),
224         max_length=256, required=False)
225     presentation_title_en = forms.CharField(
226         label=_('Presentation title in English'), max_length=256)
227     presentation_summary = forms.CharField(label=_('Presentation summary (max. 1800 characters)'),
228                                            widget=forms.Textarea, max_length=1800)
229
230     # presentation_post_conference_publication = forms.BooleanField(
231     #     label=_('I am interested in including my paper in the post-conference publication'),
232     #     required=False
233     # )
234
235     agree_data = None
236
237     agree_terms = forms.BooleanField(
238         label=mark_safe_lazy(
239             _(u'I accept <a href="/en/info/terms-and-conditions/">CopyCamp Terms and Conditions</a>.'))
240     )
241
242     def __init__(self, *args, **kw):
243         super(RegisterSpeaker, self).__init__(*args, **kw)
244         self.started = getattr(settings, 'REGISTRATION_SPEAKER_STARTED', False)
245         self.closed = getattr(settings, 'REGISTRATION_SPEAKER_CLOSED', False)
246         self.fields.keyOrder = [
247             'first_name',
248             'last_name',
249             'contact',
250             'phone',
251             'organization',
252             'bio',
253             'bio_en',
254             'photo',
255             'presentation_title',
256             'presentation_title_en',
257             'presentation_summary',
258             'presentation_thematic_track',
259             # 'presentation_post_conference_publication',
260
261             'agree_mailing',
262             # 'agree_data',
263             'agree_license',
264             'agree_terms',
265         ]
266
267
268 class RemindForm(ContactForm):
269     form_tag = 'remind-me'
270     save_as_tag = 'remind-me-2018'
271     form_title = u'CopyCamp 2018'
272     notify_on_register = False
273     notify_user = False
274
275
276 class NextForm(ContactForm):
277     form_tag = '/next'
278     form_title = _('Next CopyCamp')
279
280     name = forms.CharField(label=_('Name'), max_length=128)
281     contact = forms.EmailField(label=_('E-mail'), max_length=128)
282     organization = forms.CharField(label=_('Organization'),
283                                    max_length=256, required=False)
284
285
286 def workshop_field(label):
287     return forms.BooleanField(label=_(label), required=False)
288
289
290 class WorkshopForm(ContactForm):
291     form_tag = 'workshops'
292     save_as_tag = 'workshops-2018'
293     conference_name = u'CopyCamp 2018'
294     form_title = _('Workshop')
295     notify_on_register = False
296     mailing_field = 'agree_mailing'
297
298     first_name = forms.CharField(label=_('First name'), max_length=128)
299     last_name = forms.CharField(label=_('Last name'), max_length=128)
300     contact = forms.EmailField(label=_('E-mail'), max_length=128)
301     organization = forms.CharField(label=_('Organization'), max_length=256, required=False)
302     country = forms.CharField(label=_('Country'), max_length=128)
303
304     _header = HeaderField(
305         label=mark_safe_lazy(_("<h3>I'll take a part in workshops</h3>")),
306         help_text=_('Only workshops with any spots left are visible here.'))
307
308     _h1 = HeaderField(label=mark_safe_lazy(_("<strong>Thursday, September 28th, 10 a.m.–12 noon</strong>")))
309
310     w_mileszyk = workshop_field(
311         u'Natalia Mileszyk, Dimitar Dimitrov, Diego Naranjo: School of Rock(ing) Copyright: United to #fixcopyright')
312     w_wang = workshop_field(
313         u'Jacob Riddersholm Wang, Pernille Feldt, Martin Appelt: Heritage gone digital - beyond legal rights')
314
315     _h2 = HeaderField(label=mark_safe_lazy(_("<strong>Thursday, September 28th, 12 noon–2 p.m.</strong>")))
316
317     w_vanderwaal = workshop_field(u'Sander van der Waal, Danny Lämmerhirt: Tackling open license proliferation')
318
319     _h2a = HeaderField(label=mark_safe_lazy(_("<strong>Friday, September 29th, 9 a.m.–11 noon</strong>")))
320
321     w_nobre = workshop_field(u'Teresa Nobre, Paul Keller, Sean Flynn: Researching the Impact of Copyright User Rights')
322     w_nobre_question = forms.CharField(
323         label=mark_safe_lazy(_(
324             u'Please describe the most important recent changes to copyright user rights in your national law. '
325             u'(max 1500 characters)')),
326         max_length=1500, widget=forms.Textarea, required=False)
327
328     _h3 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, September 29th, 10 a.m.–12 noon</strong>")))
329
330     w_youtube = workshop_field(
331         u'Kiki Ganzemüller: YouTube Songwriter Workshop: Rights Management & Building a Presence on YouTube')
332
333     _h4 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, September 29th, 12 noon–2 p.m.</strong>")))
334
335     w_murray = workshop_field(
336         u'Peter Murray-Rust: Wikidata, ContentMine and the automatic liberation of factual data: '
337         u'(The Right to Read is the Right To Mine)')  # 30
338
339     w_zimmermann = workshop_field(u'Jeremie Zimmermann: Hackers ethics and peer-to-peer philosophy in care')
340
341     _header_1 = HeaderField(label='')
342     _header_2 = HeaderField(label='')
343
344     start_workshops = ('mileszyk', 'wang', 'vanderwaal', 'nobre', 'youtube', 'murray', 'zimmermann')
345
346     slots = (
347         ('_h1', 'mileszyk', 'wang'),
348         ('_h2', 'vanderwaal'),
349         ('_h2a', 'nobre', '_h3', 'youtube'),
350         ('_h4', 'murray', 'zimmermann'),
351     )
352
353     limits = {
354         'mileszyk': 25,
355         'wang': 25,
356         'vanderwaal': 25,
357         'nobre': 25,
358         'youtube': 40,
359         'murray': 35,
360         'zimmermann': 35,
361     }
362
363     agree_mailing = forms.BooleanField(
364         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
365         required=False)
366     agree_data = forms.BooleanField(
367         label=_('Permission for data processing'),
368         help_text=_(
369             u'I hereby grant Modern Poland Foundation (Fundacja Nowoczesna Polska, ul. Marszałkowska 84/92, '
370             u'00-514 Warszawa) permission to process my personal data (name, e-mail address) for purposes of '
371             u'registration for CopyCamp conference.'))
372     agree_license = forms.BooleanField(
373         label=_('Permission for publication'),
374         help_text=mark_safe_lazy(_(
375             u'I agree to having materials, recorded during the conference, released under the terms of '
376             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> '
377             u'license and to publishing my image.')),
378         required=False)
379
380     def __init__(self, *args, **kwargs):
381         super(WorkshopForm, self).__init__(*args, **kwargs)
382         try:
383             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
384             self.fields['agree_toc'] = forms.BooleanField(
385                 required=True,
386                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
387             )
388         except Entry.DoesNotExist:
389             pass
390         counts = {k: 0 for k in self.start_workshops}
391         for contact in Contact.objects.filter(form_tag=self.save_as_tag):
392             for workshop in self.start_workshops:
393                 if contact.body.get('w_%s' % workshop, False):
394                     counts[workshop] += 1
395                     if workshop == 'youtube' and counts[workshop] == 30:
396                         send_mail(u'Warsztaty YouTube', u'Przekroczono limit 30 osób na warsztaty YouTube',
397                                   'no-reply@copycamp.pl',
398                                   ['krzysztof.siewicz@nowoczesnapolska.org.pl'],
399                                   fail_silently=True)
400
401         some_full = False
402         for k, v in counts.items():
403             if v >= self.limits[k]:
404                 some_full = True
405                 if 'w_%s' % k in self.fields:
406                     del self.fields['w_%s' % k]
407         if not some_full:
408             self.fields['_header'].help_text = None
409
410     def clean(self):
411         for slot in self.slots:
412             if sum(1 for w in slot if self.cleaned_data.get('w_%s' % w)) > 1:
413                 self._errors[slot[0]] = [_("You can't choose more than one workshop during the same period")]
414         if not any(self.cleaned_data.get('w_%s' % w) for w in self.start_workshops):
415             self._errors['_header'] = [_("Please choose at least one workshop.")]
416         return self.cleaned_data