81c2a0d259b86126d28053ef9cfcc7d9dd60ccce
[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_noop 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 am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
130         required=False
131     )
132     agree_data = forms.BooleanField(
133         label=_('Permission for data processing'),
134         help_text=_(
135             u'I hereby grant Modern Poland Foundation (Fundacja Nowoczesna Polska, ul. Marszałkowska 84/92, '
136             u'00-514 Warszawa) permission to process my personal data (name, e-mail address) for purposes '
137             u'of registration for CopyCamp conference.')
138     )
139     agree_license = forms.BooleanField(
140         label=_('Permission for publication'),
141         help_text=mark_safe_lazy(_(
142             u'I agree to having materials, recorded during the conference, released under the terms of '
143             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> license and '
144             u'to publishing my image.')),
145         required=False
146     )
147
148     def __init__(self, *args, **kwargs):
149         super(RegistrationForm, self).__init__(*args, **kwargs)
150         self.started = getattr(settings, 'REGISTRATION_STARTED', False)
151         self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= settings.REGISTRATION_LIMIT
152         try:
153             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
154             self.fields['agree_toc'] = forms.BooleanField(
155                 required=True,
156                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
157             )
158         except Entry.DoesNotExist:
159             pass
160
161     def clean_areas(self):
162         data = self.cleaned_data['areas']
163         if len(data) > 3:
164             raise forms.ValidationError(_('Select at most 3 areas'))
165         return data
166
167     def clean(self):
168         cleaned_data = self.cleaned_data
169         country = cleaned_data['country']
170         travel_grant = cleaned_data['travel_grant']
171         motivation = cleaned_data['travel_grant_motivation']
172         if country not in self.travel_grant_countries and travel_grant:
173             raise forms.ValidationError(_('Travel grant is not provided for the selected country'))
174         if travel_grant and not motivation:
175             self._errors['travel_grant_motivation'] = _('Please provide this information')
176             raise forms.ValidationError(_('To apply for a travel grant you must provide additional information.'))
177         if not travel_grant and motivation:
178             cleaned_data['motivation'] = ''
179         return cleaned_data
180
181     def main_fields(self):
182         return [self[name] for name in (
183             'first_name', 'last_name', 'contact', 'organization', 'country',
184             'travel_grant', 'travel_grant_motivation', 'days')]
185
186     def survey_fields(self):
187         return [self[name] for name in (
188             'times_attended', 'age',
189             'areas', 'areas_other', 'source', 'source_other', 'motivation', 'motivation_other')]
190
191     def agreement_fields(self):
192         return [self[name] for name in ('agree_mailing', 'agree_data', 'agree_license', 'agree_toc')]
193
194
195 tracks = (
196     (_('business models, heritage digitization, remix'),
197      _('What are the boundaries of appropriation in culture? '
198        'Who owns the past and whether these exclusive rights allow to '
199        'control present and future? How to make money from creativity without selling yourself?')),
200     (_('health, food, security, and exclusive rights'),
201      _('Who owns medicines and equipment necessary to provide health care? '
202        'Who owns grain and machines used to harvest it? '
203        'To what extent exclusive rights can affect what you eat, '
204        'how you exercise, whether you can apply a specific treatment?')),
205     (_('text and data mining, machine learning, online education'),
206      _('Do you think own the data you feed to algorithms? Or maybe you think you own these algorithms? '
207        'What if you can’t mine the data because you actually don’t own any of those rights? '
208        'What does it mean to own data about someone, or data necessary for that person’s education?')),
209     (_('IoT: autonomous cars, smart homes, wearables'),
210      _('What does it mean to own exclusive rights to software and data used to construct autonomous agents? '
211        'What will it mean in a near future?')),
212     (_('hacking government data, public procurement, public aid in culture'),
213      _('Who owns information created using public money? How can this information be appropriated? '
214        'What is the role of government in the development of information infrastructure?')),
215 )
216
217
218 class RegisterSpeaker(RegistrationForm):
219     form_tag = 'register-speaker'
220     save_as_tag = '2017-speaker'
221     form_title = _('Open call for presentations')
222     notify_on_register = False
223     mailing_field = 'agree_mailing'
224
225     # inherited fields included so they are not translated
226     first_name = forms.CharField(label=_('First name'), max_length=128)
227     last_name = forms.CharField(label=_('Last name'), max_length=128)
228     organization = forms.CharField(label=_('Organization'), max_length=256, required=False)
229     agree_mailing = forms.BooleanField(
230         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
231         required=False
232     )
233     agree_license = forms.BooleanField(
234         label=_('Permission for publication'),
235         help_text=mark_safe_lazy(_(
236             u'I agree to having materials, recorded during the conference, released under the terms of '
237             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> license and '
238             u'to publishing my image.')),
239         required=False
240     )
241
242     presentation_thematic_track = forms.ChoiceField(
243         label=_('Please select one thematic track'),
244         choices=[
245             (t, mark_safe('<strong>%s</strong><p style="margin-left: 20px;">%s</p>' % (t, desc)))
246             for t, desc in tracks],
247         widget=forms.RadioSelect())
248
249     bio = forms.CharField(label=_('Short biographical note in English (max. 500 characters)'), widget=forms.Textarea,
250                           max_length=500, required=False)
251     photo = forms.FileField(label=_('Photo'), required=False)
252     phone = forms.CharField(label=_('Phone number'), max_length=64,
253                             required=False,
254                             help_text=_('Used only for organizational purposes.'))
255
256     presentation_title = forms.CharField(
257         label=mark_safe_lazy(_('Title of the presentation in English')),
258         max_length=256, required=False)
259     presentation_summary = forms.CharField(label=_('Summary of presentation (max. 1800 characters)'),
260                                            widget=forms.Textarea, max_length=1800)
261
262     # presentation_post_conference_publication = forms.BooleanField(
263     #     label=_('I am interested in including my paper in the post-conference publication'),
264     #     required=False
265     # )
266
267     agree_data = None
268
269     agree_terms = forms.BooleanField(
270         label=mark_safe_lazy(_(u'I accept <a href="/en/info/terms-and-conditions/">'
271                                u'CopyCamp Terms and Conditions</a>.'))
272     )
273
274     # workshop = forms.BooleanField(label=_('Workshop'), required=False)
275     # workshop_title = forms.CharField(label=_('Title of workshop'),
276     #        max_length=256, required=False)
277     # workshop_summary = forms.CharField(label=_('Summary of workshop (max. 1800 characters)'),
278     #        widget=forms.Textarea, max_length=1800, required=False)
279
280     def __init__(self, *args, **kw):
281         super(RegisterSpeaker, self).__init__(*args, **kw)
282         self.started = getattr(settings, 'REGISTRATION_SPEAKER_STARTED', False)
283         self.closed = getattr(settings, 'REGISTRATION_SPEAKER_CLOSED', False)
284         self.fields.keyOrder = [
285             'first_name',
286             'last_name',
287             'contact',
288             'phone',
289             'organization',
290             'bio',
291             'photo',
292             'presentation_title',
293             'presentation_summary',
294             'presentation_thematic_track',
295             # 'presentation_post_conference_publication',
296             # 'workshop',
297             # 'workshop_title',
298             # 'workshop_summary',
299
300             'agree_mailing',
301             # 'agree_data',
302             'agree_license',
303             'agree_terms',
304         ]
305
306
307 class RemindForm(ContactForm):
308     form_tag = 'remind-me'
309     save_as_tag = 'remind-me-2018'
310     form_title = u'CopyCamp 2018'
311     notify_on_register = False
312     notify_user = False
313
314
315 class NextForm(ContactForm):
316     form_tag = '/next'
317     form_title = _('Next CopyCamp')
318
319     name = forms.CharField(label=_('Name'), max_length=128)
320     contact = forms.EmailField(label=_('E-mail'), max_length=128)
321     organization = forms.CharField(label=_('Organization'),
322                                    max_length=256, required=False)
323
324
325 def workshop_field(label):
326     return forms.BooleanField(label=_(label), required=False)
327
328
329 class WorkshopForm(ContactForm):
330     form_tag = 'workshops'
331     save_as_tag = 'workshops-2017'
332     conference_name = u'CopyCamp 2017'
333     form_title = _('Workshop')
334     notify_on_register = False
335     mailing_field = 'agree_mailing'
336
337     first_name = forms.CharField(label=_('First name'), max_length=128)
338     last_name = forms.CharField(label=_('Last name'), max_length=128)
339     contact = forms.EmailField(label=_('E-mail'), max_length=128)
340     organization = forms.CharField(label=_('Organization'), max_length=256, required=False)
341     country = forms.CharField(label=_('Country'), max_length=128)
342
343     _header = HeaderField(
344         label=mark_safe_lazy(_("<h3>I'll take a part in workshops</h3>")),
345         help_text=_('Only workshops with any spots left are visible here.'))
346
347     _h1 = HeaderField(label=mark_safe_lazy(_("<strong>Thursday, September 28th, 10 a.m.–12 noon</strong>")))
348
349     w_mileszyk = workshop_field(
350         u'Natalia Mileszyk, Dimitar Dimitrov, Diego Naranjo: School of Rock(ing) Copyright: United to #fixcopyright')
351     w_wang = workshop_field(
352         u'Jacob Riddersholm Wang, Pernille Feldt, Martin Appelt: Heritage gone digital - beyond legal rights')
353
354     _h2 = HeaderField(label=mark_safe_lazy(_("<strong>Thursday, September 28th, 12 noon–2 p.m.</strong>")))
355
356     w_vanderwaal = workshop_field(u'Sander van der Waal, Danny Lämmerhirt: Tackling open license proliferation')
357
358     _h2a = HeaderField(label=mark_safe_lazy(_("<strong>Friday, September 29th, 9 a.m.–11 noon</strong>")))
359
360     w_nobre = workshop_field(u'Teresa Nobre, Paul Keller, Sean Flynn: Researching the Impact of Copyright User Rights')
361     w_nobre_question = forms.CharField(
362         label=mark_safe_lazy(_(
363             u'Please describe the most important recent changes to copyright user rights in your national law. '
364             u'(max 1500 characters)')),
365         max_length=1500, widget=forms.Textarea, required=False)
366
367     _h3 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, September 29th, 10 a.m.–12 noon</strong>")))
368
369     w_youtube = workshop_field(
370         u'Kiki Ganzemüller: YouTube Songwriter Workshop: Rights Management & Building a Presence on YouTube')
371
372     _h4 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, September 29th, 12 noon–2 p.m.</strong>")))
373
374     w_murray = workshop_field(
375         u'Peter Murray-Rust: Wikidata, ContentMine and the automatic liberation of factual data: '
376         u'(The Right to Read is the Right To Mine)')  # 30
377
378     w_zimmermann = workshop_field(u'Jeremie Zimmermann: Hackers ethics and peer-to-peer philosophy in care')
379
380     _header_1 = HeaderField(label='')
381     _header_2 = HeaderField(label='')
382
383     start_workshops = ('mileszyk', 'wang', 'vanderwaal', 'nobre', 'youtube', 'murray', 'zimmermann')
384
385     slots = (
386         ('_h1', 'mileszyk', 'wang'),
387         ('_h2', 'vanderwaal'),
388         ('_h2a', 'nobre', '_h3', 'youtube'),
389         ('_h4', 'murray', 'zimmermann'),
390     )
391
392     limits = {
393         'mileszyk': 25,
394         'wang': 25,
395         'vanderwaal': 25,
396         'nobre': 25,
397         'youtube': 40,
398         'murray': 35,
399         'zimmermann': 35,
400     }
401
402     agree_mailing = forms.BooleanField(
403         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
404         required=False)
405     agree_data = forms.BooleanField(
406         label=_('Permission for data processing'),
407         help_text=_(
408             u'I hereby grant Modern Poland Foundation (Fundacja Nowoczesna Polska, ul. Marszałkowska 84/92, '
409             u'00-514 Warszawa) permission to process my personal data (name, e-mail address) for purposes of '
410             u'registration for CopyCamp conference.'))
411     agree_license = forms.BooleanField(
412         label=_('Permission for publication'),
413         help_text=mark_safe_lazy(_(
414             u'I agree to having materials, recorded during the conference, released under the terms of '
415             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> '
416             u'license and to publishing my image.')),
417         required=False)
418
419     def __init__(self, *args, **kwargs):
420         super(WorkshopForm, self).__init__(*args, **kwargs)
421         try:
422             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
423             self.fields['agree_toc'] = forms.BooleanField(
424                 required=True,
425                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
426             )
427         except Entry.DoesNotExist:
428             pass
429         counts = {k: 0 for k in self.start_workshops}
430         for contact in Contact.objects.filter(form_tag=self.save_as_tag):
431             for workshop in self.start_workshops:
432                 if contact.body.get('w_%s' % workshop, False):
433                     counts[workshop] += 1
434                     if workshop == 'youtube' and counts[workshop] == 30:
435                         send_mail(u'Warsztaty YouTube', u'Przekroczono limit 30 osób na warsztaty YouTube',
436                                   'no-reply@copycamp.pl',
437                                   ['krzysztof.siewicz@nowoczesnapolska.org.pl'],
438                                   fail_silently=True)
439
440         some_full = False
441         for k, v in counts.items():
442             if v >= self.limits[k]:
443                 some_full = True
444                 if 'w_%s' % k in self.fields:
445                     del self.fields['w_%s' % k]
446         if not some_full:
447             self.fields['_header'].help_text = None
448
449     def clean(self):
450         for slot in self.slots:
451             if sum(1 for w in slot if self.cleaned_data.get('w_%s' % w)) > 1:
452                 self._errors[slot[0]] = [_("You can't choose more than one workshop during the same period")]
453         if not any(self.cleaned_data.get('w_%s' % w) for w in self.start_workshops):
454             self._errors['_header'] = [_("Please choose at least one workshop.")]
455         return self.cleaned_data