8ce6aa69f8c4fb35b98e2f56af1fb717343bac12
[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_lazy as _
11 from django.utils.safestring import mark_safe
12 from migdal.models import Entry
13
14 mark_safe_lazy = lazy(mark_safe, unicode)
15
16
17 class RegistrationForm(ContactForm):
18     form_tag = 'register'
19
20     save_as_tag = '2016'
21     conference_name = u'CopyCamp 2016'
22     
23     form_title = _('Registration')
24     admin_list = ['first_name', 'last_name', 'organization']
25
26     first_name = forms.CharField(label=_('First name'), max_length=128)
27     last_name = forms.CharField(label=_('Last name'), max_length=128)
28     contact = forms.EmailField(label=_('E-mail'), max_length=128)
29     organization = forms.CharField(label=_('Organization'), 
30             max_length=256, required=False)
31     country = forms.CharField(label=_('Country'), max_length=128)
32
33     # days = forms.ChoiceField(
34     #    label = _("I'm planning to show up on"),
35     #    choices=[
36     #        ('both', _('Both days of the conference')),
37     #        ('only-6th', _('November 6th only')),
38     #        ('only-7th', _('November 7th only')),
39     #    ], widget=forms.RadioSelect())
40
41     agree_mailing = forms.BooleanField(
42         label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
43         required=False
44     )
45     agree_data = forms.BooleanField(
46         label=_('Permission for data processing'),
47         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.')
48     )
49     agree_license = forms.BooleanField(
50         label=_('Permission for publication'),
51         help_text=_('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 BY-SA</a> license and to publishing my image.'),
52         required=False
53     )
54
55     def __init__(self, *args, **kwargs):
56         super(RegistrationForm, self).__init__(*args, **kwargs)
57         self.started = getattr(settings, 'REGISTRATION_STARTED', False)
58         self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= settings.REGISTRATION_LIMIT
59         try:
60             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
61             self.fields['agree_toc'] = forms.BooleanField(
62                 required=True,
63                 label = mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
64             )
65         except Entry.DoesNotExist:
66             pass
67
68
69 tracks = (
70     _('Copyright and Art'),
71     _('Remuneration Models'),
72     _('Copyright, Education and Science'),
73     _('Technology, Innovation and Copyright'),
74     _('Copyright and Human Rights'),
75     _('Copyright Enforcement'),
76     _('Copyright Debate'),
77     _('Copyright Lawmaking'),
78 )
79
80
81 class RegisterSpeaker(RegistrationForm):
82     form_tag = 'register-speaker'
83     save_as_tag = '2016-speaker'
84     form_title = _('Open call for presentations')
85
86     presentation_thematic_track = forms.ChoiceField(
87         label=_('Please select one thematic track'),
88         choices=[(t, t) for t in tracks], widget=forms.RadioSelect())
89
90     bio = forms.CharField(label=mark_safe_lazy(
91         _('Short biographical note in Polish (max. 500 characters, fill <strong>at least</strong> one bio)')),
92                           widget=forms.Textarea, max_length=500, required=False)
93     bio_en = forms.CharField(label=_('Short biographical note in English (max. 500 characters)'), widget=forms.Textarea,
94                              max_length=500, required=False)
95     photo = forms.FileField(label=_('Photo'), required=False)
96     phone = forms.CharField(label=_('Phone number'), max_length=64,
97                             required=False,
98                             help_text=_('Used only for organizational purposes.'))
99
100     # presentation = forms.BooleanField(label=_('Presentation'), required=False)
101     presentation_title = forms.CharField(
102         label=mark_safe_lazy(_('Title of the presentation in Polish (fill <strong>at least</strong> one title)')),
103         max_length=256, required=False)
104     presentation_title_en = forms.CharField(label=_('Title of the presentation in English'),
105                                             max_length=256, required=False)
106     # presentation = forms.FileField(label=_('Presentation'), required=False)
107     presentation_summary = forms.CharField(label=_('Summary of presentation (max. 1800 characters)'),
108                                            widget=forms.Textarea, max_length=1800)
109
110     presentation_post_conference_publication = forms.BooleanField(
111         label=_('I am interested in including my paper in the post-conference publication'),
112         required=False
113     )
114
115     agree_data = None
116
117     agree_terms = forms.BooleanField(
118         label=mark_safe_lazy(_(u'I accept <a href="/en/info/terms-and-conditions/">'
119                                    u'CopyCamp Terms and Conditions</a>.'))
120     )
121
122     # workshop = forms.BooleanField(label=_('Workshop'), required=False)
123     # workshop_title = forms.CharField(label=_('Title of workshop'),
124     #        max_length=256, required=False)
125     # workshop_summary = forms.CharField(label=_('Summary of workshop (max. 1800 characters)'),
126     #        widget=forms.Textarea, max_length=1800, required=False)
127
128     def __init__(self, *args, **kw):
129         super(RegisterSpeaker, self).__init__(*args, **kw)
130         self.closed = getattr(settings, 'REGISTRATION_SPEAKER_CLOSED', False)
131         self.fields.keyOrder = [
132             'first_name',
133             'last_name',
134             'contact',
135             'phone',
136             'organization',
137             'bio',
138             'bio_en',
139             'photo',
140             # 'presentation',
141             'presentation_title',
142             'presentation_title_en',
143             'presentation_summary',
144             'presentation_thematic_track',
145             'presentation_post_conference_publication',
146             # 'workshop',
147             # 'workshop_title',
148             # 'workshop_summary',
149
150             'agree_mailing',
151             # 'agree_data',
152             'agree_license',
153             'agree_terms',
154         ]
155
156     def clean(self):
157         cleaned_data = super(RegisterSpeaker, self).clean()
158         errors = []
159         if not cleaned_data.get('bio') and not cleaned_data.get('bio_en'):
160             errors.append(forms.ValidationError(_('Fill at least one bio!')))
161         if not cleaned_data.get('presentation_title') and not cleaned_data.get('presentation_title_en'):
162             errors.append(forms.ValidationError(_('Fill at least one title!')))
163         if errors:
164             raise forms.ValidationError(errors)
165         return cleaned_data
166
167
168 class NextForm(ContactForm):
169     form_tag = '/next'
170     form_title = _('Next CopyCamp')
171
172     name = forms.CharField(label=_('Name'), max_length=128)
173     contact = forms.EmailField(label=_('E-mail'), max_length=128)
174     organization = forms.CharField(label=_('Organization'),
175                                    max_length=256, required=False)
176
177
178 class WorkshopForm(ContactForm):
179     form_tag = 'workshop'
180     save_as_tag = 'workshop-2016'
181     conference_name = u'CopyCamp 2016'
182     form_title = _('Workshop')
183
184     name = forms.CharField(label=_('Name'), max_length=128)
185     contact = forms.EmailField(label=_('E-mail'), max_length=128)
186     organization = forms.CharField(label=_('Organization'),
187                                    max_length=256, required=False)
188
189     _#header = HeaderField(label=mark_safe_lazy(_("<h3>I'll take a part in workshops</h3>")), help_text=_('Only workshops with any spots left are visible here.'))
190
191     #_h1 = HeaderField(label=mark_safe_lazy(_("<strong>Thursday, November 6th, 10 a.m.–12 noon</strong>")))
192
193     #w_rysiek = forms.BooleanField(label=_(u'Michał „rysiek” Woźniak, Koalicja Otwartej Edukacji KOED: Wprowadzenie do prawa autorskiego i wolnych licencji'), required=False)
194     #w_bartsch = forms.BooleanField(label=_(u'Natalia Bartsch: Wykorzystywanie istniejących utworów w tworzeniu przedstawienia teatralnego'), required=False)
195     #w_samsung = forms.BooleanField(label=_(u'Rafał Sikorski: Prywatny użytek w prawie autorskim w XXI wieku. Jak powinien wyglądać w\u00a0Unii Europejskiej?'), required=False)
196
197     #_h2 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, November 7th, 10 a.m.–12 noon</strong>")))
198
199     #w_mezei = forms.BooleanField(label=_(u'Péter Mezei: European copyright alternatives – 2014 (Workshop will be held in English)'), required=False)
200     #w_sliwowski = forms.BooleanField(label=_(u'Kamil Śliwowski, Koalicja Otwartej Edukacji KOED: Prawo autorskie w Sieci - ćwiczenia praktyczne'), required=False)
201
202     #_h3 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, November 7th, 12 noon–2 p.m.</strong>")))
203
204     #w_zaiks = forms.BooleanField(label=_(u'Łukasz Łyczkowski, Adam Pacuski, Stowarzyszenie Autorów ZAiKS: Praktyczne aspekty dozwolonego użytku'), required=False)
205     #w_creativepoland = forms.BooleanField(label=_(u'Paweł Kaźmierczyk i Dagmara Białek, Creative Poland: Sektor kreatywny – pomysły są w cenie'), required=False)
206
207     #_header_1 = HeaderField(label='')
208
209     # agree_mailing = forms.BooleanField(
210     #    label=_('I am interested in receiving information about the Modern Poland Foundation\'s activities by e-mail'),
211     #    required=False
212     # )
213     agree_data = forms.BooleanField(
214         label=_('Permission for data processing'),
215         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.')
216     )
217     agree_license = forms.BooleanField(
218         label=_('Permission for publication'),
219         help_text=_('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 BY-SA</a> license and to publishing my image.'),
220         required=False
221     )
222
223     def __init__(self, *args, **kwargs):
224         super(WorkshopForm, self).__init__(*args, **kwargs)
225         self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= 60
226
227         # counts = {k: 0 for k in self.start_workshops}
228         # for contact in Contact.objects.filter(form_tag=self.save_as_tag):
229         #     for workshop in self.start_workshops:
230     #            if contact.body.get('w_%s' % workshop, False): counts[workshop] += 1
231         # some_full = False
232         # for k, v in counts.items():
233         #     if v >= 60:
234         #         some_full = True
235         #         if 'w_%s' % k in self.fields:
236         #             del self.fields['w_%s' % k]
237         #         if k in self.workshops:
238         #             self.workshops.remove(k)
239         # if not some_full:
240         #     self.fields['_header'].help_text = None
241
242     # def clean(self):
243     #     any_workshop = False
244     #     for w in self.start_workshops:
245     #         if self.cleaned_data.get('w_%s' % w):
246     #             any_workshop = True
247     #     if not any_workshop:
248     #         self._errors['_header'] = [_("Please choose at least one workshop.")]
249     #     return self.cleaned_data