8bd07ebf972df5bf508d609419c27f5021d26b21
[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 contact.forms import ContactForm
7 from contact.models import Contact
8 from contact.fields import HeaderField
9 from django.utils.functional import lazy
10 from django.utils.translation import ugettext_noop as _
11 from django.utils.safestring import mark_safe
12 from migdal.models import Entry
13
14 from prawokultury.countries import COUNTRIES, TRAVEL_GRANT_COUNTRIES
15
16 mark_safe_lazy = lazy(mark_safe, unicode)
17
18
19 class RegistrationForm(ContactForm):
20     form_tag = 'register'
21
22     save_as_tag = '2017'
23     conference_name = u'CopyCamp 2017'
24     notify_on_register = False
25     
26     form_title = _('Registration')
27     admin_list = ['first_name', 'last_name', 'organization']
28
29     travel_grant_countries = TRAVEL_GRANT_COUNTRIES
30
31     first_name = forms.CharField(label=_('First name'), max_length=128)
32     last_name = forms.CharField(label=_('Last name'), max_length=128)
33     contact = forms.EmailField(label=_('E-mail'), max_length=128)
34     organization = forms.CharField(label=_('Organization'), max_length=256, required=False)
35     country = forms.ChoiceField(label=_('Country of residence'), choices=zip(COUNTRIES, COUNTRIES))
36     travel_grant = forms.BooleanField(
37         label=_('I require financial assistance to attend CopyCamp 2017.'), required=False)
38     travel_grant_motivation = forms.CharField(
39         label=_('Please write us about yourself and why you want to come to CopyCamp. '
40                 'This information will help us evaluate your travel grant application:'),
41         help_text=_('Financial assistance for German audience is possible '
42                     'thanks to the funds of the German Federal Foreign Office transferred by '
43                     'the Foundation for Polish-German Cooperation.'),
44         widget=forms.Textarea, max_length=600, required=False)
45
46     days = forms.ChoiceField(
47        label=_("I'm planning to show up on"),
48        choices=[
49            ('both', _('Both days of the conference')),
50            ('only-28th', _('September 28th only')),
51            ('only-29th', _('September 29th only')),
52        ], widget=forms.RadioSelect())
53
54     # ankieta
55     times_attended = forms.ChoiceField(
56         required=False,
57         label=_("1. How many times have you attended CopyCamp?"),
58         choices=[
59             ('0', _('not yet')),
60             ('1', _('once')),
61             ('2', _('twice')),
62             ('3', _('three times')),
63             ('4', _('four times')),
64             ('5', _('five times')),
65         ], widget=forms.RadioSelect())
66     age = forms.ChoiceField(
67         required=False,
68         label=_("2. Please indicate your age bracket:"),
69         choices=[
70             ('0-19', _('19 or below')),
71             ('20-25', _('20-25')),
72             ('26-35', _('26-35')),
73             ('36-45', _('36-45')),
74             ('46-55', _('46-55')),
75             ('56-65', _('56-65')),
76             ('66+', _('66 or above')),
77         ], widget=forms.RadioSelect())
78     areas = forms.MultipleChoiceField(
79         required=False,
80         label=_("3. Please indicate up to 3 areas you feel most affiliated with"),
81         choices=[
82             ('sztuki plastyczne', _('visual art')),
83             ('literatura', _('literature')),
84             ('muzyka', _('music')),
85             ('teatr', _('theatre')),
86             ('film', _('film production')),
87             ('wydawanie', _('publishing')),
88             ('prawo', _('law')),
89             ('ekonomia', _('economy')),
90             ('socjologia', _('sociology')),
91             ('technika', _('technology')),
92             ('edukacja', _('education')),
93             ('studia', _('higher education')),
94             ('nauka', _('academic research')),
95             ('biblioteki', _('library science')),
96             ('administracja', _('public administration')),
97             ('ngo', _('nonprofit organisations')),
98             ('other', _('other (please specify below)')),
99         ], widget=forms.CheckboxSelectMultiple())
100     areas_other = forms.CharField(required=False, label=_('Fill if you selected “other” above'))
101     source = forms.ChoiceField(
102         required=False,
103         label=_("4. Please indicate how you received information about the conference:"),
104         choices=[
105             ('znajomi', _('through friends sharing on the web')),
106             ('znajomi2', _('through friends by other means')),
107             ('prasa', _('through press')),
108             ('fnp', _('directly through the Foundation\'s facebook or website')),
109             ('www', _('through other websites (please specify below)')),
110             ('other', _('other (please specify below)')),
111         ], widget=forms.RadioSelect())
112     source_other = forms.CharField(required=False, label=_('Fill if you selected “other” or “other website” above'))
113     motivation = forms.ChoiceField(
114         required=False,
115         label=_("6. Please indicate the most important factor for your willingness to participate:"),
116         choices=[
117             ('speaker', _('listening to particular speaker(s)')),
118             ('networking', _('good networking occasion')),
119             ('partnering', _('partnering with organisations present at the event')),
120             ('other', _('other (please specify below)')),
121         ], widget=forms.RadioSelect())
122     motivation_other = forms.CharField(required=False, label=_('Fill if you selected “other” above'))
123
124     agree_mailing = forms.BooleanField(
125         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
126         required=False
127     )
128     agree_data = forms.BooleanField(
129         label=_('Permission for data processing'),
130         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.')
131     )
132     agree_license = forms.BooleanField(
133         label=_('Permission for publication'),
134         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.')),
135         required=False
136     )
137
138     def __init__(self, *args, **kwargs):
139         super(RegistrationForm, self).__init__(*args, **kwargs)
140         self.started = getattr(settings, 'REGISTRATION_STARTED', False)
141         self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= settings.REGISTRATION_LIMIT
142         try:
143             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
144             self.fields['agree_toc'] = forms.BooleanField(
145                 required=True,
146                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
147             )
148         except Entry.DoesNotExist:
149             pass
150
151     def clean_areas(self):
152         data = self.cleaned_data['areas']
153         if len(data) > 3:
154             raise forms.ValidationError(_('Select at most 3 areas'))
155         return data
156
157     def clean(self):
158         cleaned_data = self.cleaned_data
159         country = cleaned_data['country']
160         travel_grant = cleaned_data['travel_grant']
161         motivation = cleaned_data['travel_grant_motivation']
162         if country not in self.travel_grant_countries and travel_grant:
163             raise forms.ValidationError(_('Travel grant is not provided for the selected country'))
164         if travel_grant and not motivation:
165             self._errors['travel_grant_motivation'] = _('Please provide this information')
166             raise forms.ValidationError(_('To apply for a travel grant you must provide additional information.'))
167         if not travel_grant and motivation:
168             cleaned_data['motivation'] = ''
169         return cleaned_data
170
171     def main_fields(self):
172         return [self[name] for name in (
173             'first_name', 'last_name', 'contact', 'organization', 'country',
174             'travel_grant', 'travel_grant_motivation', 'days')]
175
176     def survey_fields(self):
177         return [self[name] for name in (
178             'times_attended', 'age',
179             'areas', 'areas_other', 'source', 'source_other', 'motivation', 'motivation_other')]
180
181     def agreement_fields(self):
182         return [self[name] for name in ('agree_mailing', 'agree_data', 'agree_license', 'agree_toc')]
183
184
185 tracks = (
186     (_('business models, heritage digitization, remix'),
187      _('What are the boundaries of appropriation in culture? '
188        'Who owns the past and whether these exclusive rights allow to '
189        'control present and future? How to make money from creativity without selling yourself?')),
190     (_('health, food, security, and exclusive rights'),
191      _('Who owns medicines and equipment necessary to provide health care? '
192        'Who owns grain and machines used to harvest it? '
193        'To what extent exclusive rights can affect what you eat, '
194        'how you exercise, whether you can apply a specific treatment?')),
195     (_('text and data mining, machine learning, online education'),
196      _('Do you think own the data you feed to algorithms? Or maybe you think you own these algorithms? '
197        'What if you can’t mine the data because you actually don’t own any of those rights? '
198        'What does it mean to own data about someone, or data necessary for that person’s education?')),
199     (_('IoT: autonomous cars, smart homes, wearables'),
200      _('What does it mean to own exclusive rights to software and data used to construct autonomous agents? '
201        'What will it mean in a near future?')),
202     (_('hacking government data, public procurement, public aid in culture'),
203      _('Who owns information created using public money? How can this information be appropriated? '
204        'What is the role of government in the development of information infrastructure?')),
205 )
206
207
208 class RegisterSpeaker(RegistrationForm):
209     form_tag = 'register-speaker'
210     save_as_tag = '2017-speaker'
211     form_title = _('Open call for presentations')
212     notify_on_register = False
213
214     # inherited fields included so they are not translated
215     first_name = forms.CharField(label=_('First name'), max_length=128)
216     last_name = forms.CharField(label=_('Last name'), max_length=128)
217     organization = forms.CharField(label=_('Organization'),
218             max_length=256, required=False)
219     agree_mailing = forms.BooleanField(
220         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
221         required=False
222     )
223     agree_license = forms.BooleanField(
224         label=_('Permission for publication'),
225         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.')),
226         required=False
227     )
228
229     presentation_thematic_track = forms.ChoiceField(
230         label=_('Please select one thematic track'),
231         choices=[(t, mark_safe('<strong>%s</strong><p style="margin-left: 20px;">%s</p>' % (t, desc))) for t, desc in tracks],
232         widget=forms.RadioSelect())
233
234     bio = forms.CharField(label=_('Short biographical note in English (max. 500 characters)'), widget=forms.Textarea,
235                           max_length=500, required=False)
236     photo = forms.FileField(label=_('Photo'), required=False)
237     phone = forms.CharField(label=_('Phone number'), max_length=64,
238                             required=False,
239                             help_text=_('Used only for organizational purposes.'))
240
241     presentation_title = forms.CharField(
242         label=mark_safe_lazy(_('Title of the presentation in English')),
243         max_length=256, required=False)
244     presentation_summary = forms.CharField(label=_('Summary of presentation (max. 1800 characters)'),
245                                            widget=forms.Textarea, max_length=1800)
246
247     # presentation_post_conference_publication = forms.BooleanField(
248     #     label=_('I am interested in including my paper in the post-conference publication'),
249     #     required=False
250     # )
251
252     agree_data = None
253
254     agree_terms = forms.BooleanField(
255         label=mark_safe_lazy(_(u'I accept <a href="/en/info/terms-and-conditions/">'
256                                u'CopyCamp Terms and Conditions</a>.'))
257     )
258
259     # workshop = forms.BooleanField(label=_('Workshop'), required=False)
260     # workshop_title = forms.CharField(label=_('Title of workshop'),
261     #        max_length=256, required=False)
262     # workshop_summary = forms.CharField(label=_('Summary of workshop (max. 1800 characters)'),
263     #        widget=forms.Textarea, max_length=1800, required=False)
264
265     def __init__(self, *args, **kw):
266         super(RegisterSpeaker, self).__init__(*args, **kw)
267         self.started = getattr(settings, 'REGISTRATION_SPEAKER_STARTED', False)
268         self.closed = getattr(settings, 'REGISTRATION_SPEAKER_CLOSED', False)
269         self.fields.keyOrder = [
270             'first_name',
271             'last_name',
272             'contact',
273             'phone',
274             'organization',
275             'bio',
276             'photo',
277             'presentation_title',
278             'presentation_summary',
279             'presentation_thematic_track',
280             # 'presentation_post_conference_publication',
281             # 'workshop',
282             # 'workshop_title',
283             # 'workshop_summary',
284
285             'agree_mailing',
286             # 'agree_data',
287             'agree_license',
288             'agree_terms',
289         ]
290
291
292 class RemindForm(ContactForm):
293     form_tag = 'remind-me'
294     save_as_tag = 'remind-me-2017'
295     form_title = u'CopyCamp 2017'
296     notify_on_register = False
297     notify_user = False
298
299
300 class NextForm(ContactForm):
301     form_tag = '/next'
302     form_title = _('Next CopyCamp')
303
304     name = forms.CharField(label=_('Name'), max_length=128)
305     contact = forms.EmailField(label=_('E-mail'), max_length=128)
306     organization = forms.CharField(label=_('Organization'),
307                                    max_length=256, required=False)
308
309
310 class WorkshopForm(ContactForm):
311     form_tag = 'workshops'
312     save_as_tag = 'workshops-2017'
313     conference_name = u'CopyCamp 2017'
314     form_title = _('Workshop')
315
316     name = forms.CharField(label=_('Name'), max_length=128)
317     contact = forms.EmailField(label=_('E-mail'), max_length=128)
318     organization = forms.CharField(label=_('Organization'),
319                                    max_length=256, required=False)
320     country = forms.CharField(label=_('Country'), max_length=128)
321
322     _header = HeaderField(
323         label=mark_safe_lazy(_("<h3>I'll take a part in workshops</h3>")),
324         help_text=_('Only workshops with any spots left are visible here.'))
325
326     _h1 = HeaderField(label=mark_safe_lazy(_("<strong>Thursday, October 27th, 10 a.m.–12 noon</strong>")))
327
328     w_dimitrov = forms.BooleanField(label=_(u'Dimitar Dimitrov: Hacking Brussels'), required=False)
329     w_vangompel = forms.BooleanField(label=_(
330         u'Stef van Gompel: Methods and constraints for including evidence in IP lawmaking'), required=False)
331
332     _h2 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, October 28th, 10 a.m.–12 noon</strong>")))
333
334     w_siewicz = forms.BooleanField(label=_(
335         u'dr Krzysztof Siewicz, dr Marta Hoffman-Sommer: '
336         u'Legal aspects of using research data in the age of Open Data'), required=False)
337     w_siewicz_project = forms.CharField(
338         label=mark_safe(
339             u'<p style="margin-top: 0"><strong>Qualification for this workshop will be based on the answers '
340             u'for the following problem:</strong></p>'
341             u'Please choose a particular dataset from any research project you are involved in and provide '
342             u'a description (no more than 1800 characters). Selected datasets will be discussed during '
343             u'the workshop as case studies. In your description, please include the following information: '
344             u'What is the research goal of the project (in the context of the chosen dataset)? '
345             u'What data is being collected and how is it stored? What is the process of data collection '
346             u'or generation? Who is involved in collecting or producing the data and in what manner?'),
347         max_length=1800, widget=forms.Textarea, required=False)
348     w_google = forms.BooleanField(label=_(
349         u'Marcin Olender, Google: Prawo autorskie na YouTube (workshop in Polish)'), required=False)
350
351     _h3 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, October 28th, 12 noon–2 p.m.</strong>")))
352
353     w_patronite = forms.BooleanField(label=_(
354         u'Mateusz Górski, Michał Leksiński, Patronite: Jak zarabiać i się nie sprzedać – warsztaty dla twórców '
355         u'(workshop in Polish)'),
356         required=False)
357
358     w_gurionova = forms.BooleanField(label=_(
359         u'Olga Goriunova: The Lurker and the politics of knowledge in data culture'), required=False)
360
361     _header_1 = HeaderField(label='')
362
363     start_workshops = ('dimitrov', 'vangompel', 'siewicz', 'google', 'patronite', 'gurionova')
364
365     slots = (('_h1', 'dimitrov', 'vangompel'), ('_h2', 'siewicz', 'google'), ('_h3', 'patronite', 'gurionova'))
366
367     agree_mailing = forms.BooleanField(
368         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
369         required=False)
370     agree_data = forms.BooleanField(
371         label=_('Permission for data processing'),
372         help_text=_(
373             u'I hereby grant Modern Poland Foundation (Fundacja Nowoczesna Polska, ul. Marszałkowska 84/92, '
374             u'00-514 Warszawa) permission to process my personal data (name, e-mail address) for purposes of '
375             u'registration for CopyCamp conference.'))
376     agree_license = forms.BooleanField(
377         label=_('Permission for publication'),
378         help_text=mark_safe_lazy(_(
379             u'I agree to having materials, recorded during the conference, released under the terms of '
380             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> '
381             u'license and to publishing my image.')),
382         required=False)
383
384     def __init__(self, *args, **kwargs):
385         super(WorkshopForm, self).__init__(*args, **kwargs)
386         # self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= 60
387         try:
388             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
389             self.fields['agree_toc'] = forms.BooleanField(
390                 required=True,
391                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
392             )
393         except Entry.DoesNotExist:
394             pass
395         counts = {k: 0 for k in self.start_workshops}
396         for contact in Contact.objects.filter(form_tag=self.save_as_tag):
397             for workshop in self.start_workshops:
398                 if contact.body.get('w_%s' % workshop, False): counts[workshop] += 1
399         some_full = False
400         for k, v in counts.items():
401             if v >= 30:
402                 some_full = True
403                 if 'w_%s' % k in self.fields:
404                     del self.fields['w_%s' % k]
405                 # if k in self.workshops:
406                 #     self.workshops.remove(k)
407         if not some_full:
408             self.fields['_header'].help_text = None
409
410     def clean(self):
411         if self.cleaned_data.get('w_siewicz') and not self.cleaned_data.get('w_siewicz_project'):
412             self._errors['w_siewicz_project'] = [_("Please submit your answer to qualify for this workshop")]
413         for slot in self.slots:
414             if sum(1 for w in slot if self.cleaned_data.get('w_%s' % w)) > 1:
415                 self._errors[slot[0]] = [_("You can't choose more than one workshop during the same period")]
416         if not any(self.cleaned_data.get('w_%s' % w) for w in self.start_workshops):
417             self._errors['_header'] = [_("Please choose at least one workshop.")]
418         return self.cleaned_data