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