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