c977a6a46d5919a2f4d5ff926160c6547392c7af
[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 = '2019'
25     conference_name = u'CopyCamp 2019'
26     notify_on_register = False
27     
28     form_title = _('Registration')
29     admin_list = ['first_name', 'last_name', 'organization']
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     agree_license = forms.BooleanField(
36         label=_('Permission for publication'),
37         help_text=mark_safe_lazy(_(
38             u'I agree to having materials, recorded during the conference, released under the terms of '
39             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> license and '
40             u'to publishing my image.')),
41         required=False
42     )
43
44     def __init__(self, *args, **kwargs):
45         super(RegistrationForm, self).__init__(*args, **kwargs)
46         self.started = getattr(settings, 'REGISTRATION_STARTED', False)
47         self.limit_reached = Contact.objects.filter(form_tag=self.save_as_tag).count() >= settings.REGISTRATION_LIMIT
48         try:
49             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
50             self.fields['agree_toc'] = forms.BooleanField(
51                 required=True,
52                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
53             )
54         except Entry.DoesNotExist:
55             pass
56
57     def main_fields(self):
58         return [self[name] for name in (
59             'first_name', 'last_name', 'contact', 'organization')]
60
61     def survey_fields(self):
62         return []
63
64     def agreement_fields(self):
65         return [self[name] for name in ('agree_license', 'agree_toc')]
66
67
68 class RegisterSpeaker(RegistrationForm):
69     form_tag = 'register-speaker'
70     save_as_tag = '2019-speaker'
71     form_title = _('Open call for presentations')
72     notify_on_register = False
73     mailing_field = 'agree_mailing'
74
75     bio = forms.CharField(label=mark_safe_lazy(
76         _('Short biographical note in Polish (max. 500 characters)')),
77                           widget=forms.Textarea, max_length=500, required=True)
78     bio_en = forms.CharField(label=_('Short biographical note in English (max. 500 characters, not required)'), widget=forms.Textarea,
79                              max_length=500, required=False)
80     photo = forms.FileField(label=_('Photo'), required=False)
81     phone = forms.CharField(label=_('Phone number'), max_length=64,
82                             required=False,
83                             help_text=_('(used only for organizational purposes)'))
84
85     presentation_title = forms.CharField(
86         label=mark_safe_lazy(_('Presentation title in Polish')),
87         max_length=256)
88     presentation_title_en = forms.CharField(
89         label=_('Presentation title in English (not required)'), max_length=256, required=False)
90     presentation_summary = forms.CharField(label=_('Presentation summary (max. 1800 characters)'),
91                                            widget=forms.Textarea, max_length=1800)
92
93     # presentation_post_conference_publication = forms.BooleanField(
94     #     label=_('I am interested in including my paper in the post-conference publication'),
95     #     required=False
96     # )
97
98     agree_data = None
99
100     agree_terms = forms.BooleanField(
101         label=mark_safe_lazy(
102             _(u'I accept <a href="/en/info/terms-and-conditions/">CopyCamp Terms and Conditions</a>.'))
103     )
104
105     def __init__(self, *args, **kw):
106         super(RegisterSpeaker, self).__init__(*args, **kw)
107         self.started = getattr(settings, 'REGISTRATION_SPEAKER_STARTED', False)
108         self.closed = getattr(settings, 'REGISTRATION_SPEAKER_CLOSED', False)
109         self.fields.keyOrder = [
110             'first_name',
111             'last_name',
112             'contact',
113             'phone',
114             'organization',
115             'bio',
116             'bio_en',
117             'photo',
118             'presentation_title',
119             'presentation_title_en',
120             'presentation_summary',
121             # 'presentation_post_conference_publication',
122
123             'agree_mailing',
124             # 'agree_data',
125             'agree_license',
126             'agree_terms',
127         ]
128
129
130 class RemindForm(ContactForm):
131     form_tag = 'remind-me'
132     save_as_tag = 'remind-me-2019'
133     form_title = u'CopyCamp 2019'
134     notify_on_register = False
135     notify_user = False
136
137
138 class NextForm(ContactForm):
139     form_tag = '/next'
140     form_title = _('Next CopyCamp')
141
142     name = forms.CharField(label=_('Name'), max_length=128)
143     contact = forms.EmailField(label=_('E-mail'), max_length=128)
144     organization = forms.CharField(label=_('Organization'),
145                                    max_length=256, required=False)
146
147
148 def workshop_field(label, help=None):
149     return forms.BooleanField(label=_(label), required=False, help_text=help)
150
151
152 class WorkshopForm(ContactForm):
153     form_tag = 'workshops'
154     save_as_tag = 'workshops-2018'
155     conference_name = u'CopyCamp 2018'
156     form_title = _('Workshop')
157     notify_on_register = False
158     mailing_field = 'agree_mailing'
159
160     first_name = forms.CharField(label=_('First name'), max_length=128)
161     last_name = forms.CharField(label=_('Last name'), max_length=128)
162     contact = forms.EmailField(label=_('E-mail'), max_length=128)
163     organization = forms.CharField(label=_('Organization'), max_length=256, required=False)
164     country = forms.ChoiceField(
165         label=_('Country of residence'), choices=[('', '--------')] + zip(COUNTRIES, COUNTRIES), required=False)
166
167     _header = HeaderField(
168         label=mark_safe_lazy(_("<h3>I'll take a part in workshops</h3>")),
169         help_text=_('Only workshops with any spots left are visible here.'))
170
171     _h1 = HeaderField(label=mark_safe_lazy(_("<strong>Friday, October 5th, 11 a.m.–1 p.m.</strong>")))
172
173     w_dobosz = workshop_field(
174         u'Elżbieta Dobosz, Urząd Patentowy RP: Ochrona wzornictwa, co można chronić, co warto chronić i w jaki sposób',
175         u'Uczestnicy mogą przedstawić na warsztatach swoje wzory – '
176         u'rozwiązania wizualne ze wszystkich kategorii produktów.')
177     w_kozak = workshop_field(
178         u'Łukasz Kozak i Krzysztof Siewicz: Projekt : Upiór – wprowadzenie i warsztaty dla twórców gier')
179     w_secker = workshop_field(
180         u'Jane Secker and Chris Morrison: Embedding Copyright literacy using games-based learning',
181         _(u'The workshop will be conducted in English.'))
182
183     _h2 = HeaderField(label=mark_safe_lazy(_("<strong>Saturday, October 6th, 11 a.m.–1 p.m.</strong>")))
184
185     w_kakareko = workshop_field(
186         u'Ksenia Kakareko: Regulacje prawne dotyczące wykorzystania materiałów zdigitalizowanych')
187     w_kakareko_question = forms.CharField(
188         label=u'Możesz opisać sprawy, z którymi najczęściej spotykasz się jako pracownik instytucji posiadającej '
189               u'zdigitalizowane zbiory lub jako użytkownik tych zbiorów '
190               u'(max 800 znaków)',
191         max_length=800, widget=forms.Textarea, required=False)
192     w_sikorska = workshop_field(
193         u'Krzysztof Siewicz: Autor: projektant / prawo autorskie dla projektantów')
194     w_sikorska_question = forms.CharField(
195         label=u'Jeżeli chcesz, możesz przesłać prowadzącemu swoje pytanie dotyczące prawa autorskiego, '
196               u'co pomoże mu lepiej przygotować warsztaty '
197               u'(max 800 znaków)',
198         max_length=800, widget=forms.Textarea, required=False)
199     w_sztoldman = workshop_field(
200         u'dr Agnieszka Sztoldman, Aleksandra Burda, SMM Legal: Spory o pieniądze w branżach IP-driven')
201
202     _header_1 = HeaderField(label='')
203     _header_2 = HeaderField(label='')
204
205     start_workshops = ('dobosz', 'kozak', 'secker', 'kakareko', 'sikorska', 'sztoldman')
206
207     slots = (
208         ('_h1', 'dobosz', 'kozak', 'secker'),
209         ('_h2', 'kakareko', 'sikorska', 'sztoldman'),
210     )
211
212     limits = {
213         'dobosz': 30,
214         'kozak': 30,
215         'secker': 30,
216         'kakareko': 30,
217         'sikorska': 30,
218         'sztoldman': 30,
219     }
220
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     agree_license = forms.BooleanField(
225         label=_('Permission for publication'),
226         help_text=mark_safe_lazy(_(
227             u'I agree to having materials, recorded during the conference, released under the terms of '
228             u'<a href="http://creativecommons.org/licenses/by-sa/3.0/deed">CC\u00a0BY-SA</a> '
229             u'license and to publishing my image.')),
230         required=False)
231
232     def __init__(self, *args, **kwargs):
233         super(WorkshopForm, self).__init__(*args, **kwargs)
234         try:
235             url = Entry.objects.get(slug_pl='regulamin').get_absolute_url()
236             self.fields['agree_toc'] = forms.BooleanField(
237                 required=True,
238                 label=mark_safe(_('I accept <a href="%s">Terms and Conditions of CopyCamp</a>') % url)
239             )
240         except Entry.DoesNotExist:
241             pass
242         counts = {k: 0 for k in self.start_workshops}
243         for contact in Contact.objects.filter(form_tag=self.save_as_tag):
244             for workshop in self.start_workshops:
245                 if contact.body.get('w_%s' % workshop, False):
246                     counts[workshop] += 1
247                     # if workshop == 'youtube' and counts[workshop] == 30:
248                     #     send_mail(u'Warsztaty YouTube', u'Przekroczono limit 30 osób na warsztaty YouTube',
249                     #               'no-reply@copycamp.pl',
250                     #               ['krzysztof.siewicz@nowoczesnapolska.org.pl'],
251                     #               fail_silently=True)
252
253         some_full = False
254         for k, v in counts.items():
255             if v >= self.limits[k]:
256                 some_full = True
257                 if 'w_%s' % k in self.fields:
258                     del self.fields['w_%s' % k]
259         if not some_full:
260             self.fields['_header'].help_text = None
261
262     def clean(self):
263         for slot in self.slots:
264             if sum(1 for w in slot if self.cleaned_data.get('w_%s' % w)) > 1:
265                 self._errors[slot[0]] = [_("You can't choose more than one workshop during the same period")]
266         if not any(self.cleaned_data.get('w_%s' % w) for w in self.start_workshops):
267             self._errors['_header'] = [_("Please choose at least one workshop.")]
268         return self.cleaned_data