forms.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. from django import forms
  2. from django.conf import settings
  3. from .models import Contact, Product, Credit, Description, Interaction, Link, Media, Video
  4. from django.contrib.auth.forms import UserCreationForm
  5. from django_file_form.forms import UploadedFileField, FileFormMixin, CharField, MultipleUploadedFileField
  6. from django.contrib.auth.models import User
  7. from crispy_forms.helper import FormHelper
  8. from crispy_forms.layout import Layout, Field, Fieldset, Div, Row, Column, HTML, ButtonHolder, Submit
  9. from crispy_forms.bootstrap import InlineField
  10. from django.forms.models import inlineformset_factory
  11. from django.forms import formset_factory
  12. from django import forms
  13. from captcha.fields import CaptchaField
  14. from django.core.files import File
  15. class VoteForm(forms.Form):
  16. aestethic = forms.DecimalField(label='Aesthetic Qualities', max_value=10, decimal_places =1,required=False)
  17. innovation = forms.DecimalField(label='Innovative Elements',max_value=10, decimal_places =1,required=False)
  18. technical = forms.DecimalField(label='Technical Qualities', max_value=10, decimal_places =1,required=False)
  19. integration = forms.DecimalField(label='Integration of diffrent Components',
  20. max_value=10, decimal_places=1,
  21. help_text='e.g. architecture,display and content',required=False)
  22. comment = forms.CharField(max_length=300, widget=forms.Textarea(), help_text = 'You can leave your written comment here!',required=False)
  23. def clean(self):
  24. cleaned_data = super(VoteForm, self).clean()
  25. aestethic =cleaned_data.get('aestethic')
  26. innovation = cleaned_data.get('innovation')
  27. technical = cleaned_data.get('technical')
  28. integration = cleaned_data.get('integration')
  29. comment = cleaned_data.get('comment')
  30. #initial can be specified with old value in db maybe
  31. class RegisterForm(forms.ModelForm):
  32. terms = forms.BooleanField(required=True, label= ('I accept and have read the <a href="https://www.mediaarchitecture.org/privacy-policy/">Privacy Policy.</a>'))
  33. class Meta:
  34. model = Contact
  35. fields = ('first_name','last_name','adress','postcode','city','country',
  36. 'email','phonenumber','alternate_phonenumber','skype_name','website', 'terms')
  37. class SignUpForm(UserCreationForm):
  38. captcha = CaptchaField( generator='captcha.helpers.math_challenge' )
  39. class Meta:
  40. model = User
  41. fields = ('username', 'password1', 'password2')
  42. class SubmissionForm(forms.ModelForm):
  43. terms = forms.BooleanField(required=True, label= ('I accept and have read the Terms of Participation.'))
  44. class Meta:
  45. model = Product
  46. fields = ('title','country','city','year','owner','teaser_txt','header','category', 'description_txt', 'terms', 'name','claim','beschreibung','learning','gruendungsjahr','betriebgenommen','status','adresse','website','frei','mitmachen','rechtsform','ort','orga')
  47. def __init__(self,*args, **kwargs):
  48. super(SubmissionForm, self).__init__(*args, **kwargs)
  49. self.fields['title'].help_text = ('<i>e.g. Sirius Tower</i>')
  50. self.fields['header'].help_text = ('<i>e.g. Skyscraper with heavenly forms </i>')
  51. self.fields['city'].help_text = ('<i>e.g. Beijing </i>')
  52. self.fields['year'].help_text = ('<i>e.g. 2019</i>')
  53. self.fields['owner'].help_text = ('<i>e.g. Cardinal Group</i>')
  54. self.fields['category'].help_text = ('<i>Hold CTRL/CMD for multiple selection</i>')
  55. self.fields['country'].help_text = ('<i>Hold CTRL/CMD for multiple selection</i>')
  56. self.fields['teaser_txt'].help_text = ('<i>e.g. A vibrant new landmark has appeared in the city of Beijing: the luxury shopping center Sirius Tower. Both out- side and inside, the building radiates dy- namism and the kind of bright perfection thatthearchitectreferstoasthe Made in Heaven Effect. Everything about the building moves the eye</i>')
  57. self.fields['description_txt'].help_text = ('<i>e.g. A wall of light measuring 3.000 square meters has turned the new head- quarters of the largest Chinese telecom- munications company CXN in Beijing into a spectacular attraction. The stunning building, designed by Domenico Torrone, was o cially opened in September 2008. Located near the freeway to Shanghai it can be seen from miles. The 100-meter- high and 40-meterwide sloping north facade is equipped with around 900 Op- ticron® flat-panel lamps. Because they can be controlled individually with elec- tronic control gear, they form the pixels of a gigantic monochrome display on which still and moving images can be created.</i>')
  58. self.fields['description_txt'].max_length = 2000
  59. self.fields['teaser_txt'].max_length = 750
  60. self.helper = FormHelper()
  61. #self.helper.field_class = 'form_border'
  62. self.helper.form_tag = False
  63. self.helper.layout = Layout(
  64. Fieldset(
  65. ('About your Product'),
  66. 'title',
  67. 'header',
  68. 'owner',
  69. Div(
  70. Div('country', css_class='form-group col-md-6 mb-0'),
  71. Div('city', css_class='form-group col-md-3 mb-0'),
  72. Div('year', css_class='form-group col-md-3 mb-0'),
  73. css_class='form-row'),
  74. 'category',
  75. 'teaser_txt',
  76. 'description_txt',
  77. 'name','claim','beschreibung',
  78. )
  79. )
  80. class CreditForm(forms.ModelForm):
  81. class Meta:
  82. model = Credit
  83. fields = ('owner','architecture','concept','structural_engeneering','facade_design',
  84. 'face_construction','kinetic_design','light_design','tecnical_layout',
  85. 'display_content','light_hardware','lightning_software','Product_coordination',
  86. 'membrane_skin','interaction_design','sponsor','module_elems')
  87. def __init__(self, *args, **kwargs):
  88. super(CreditForm, self).__init__(*args, **kwargs)
  89. self.fields['owner'].help_text = ('<i>e.g. Cardinal Group</i>')
  90. self.fields['architecture'].help_text = ('<i>e.g. Domenico Torrone and Partners</i>')
  91. self.fields['concept'].help_text = ('<i>e.g. Domenico Torrone and Partners</i>')
  92. self.fields['structural_engeneering'].help_text = ('<i>e.g. Osap Inc., Hongkong</i>')
  93. self.fields['facade_design'].help_text = ('<i>e.g. Mega Facades Inc, Beijing</i>')
  94. self.fields['face_construction'].help_text = ('<i>e.g. None</i>')
  95. self.fields['kinetic_design'].help_text = ('<i>e.g. Domenico Torrone and Osap, Hongkong</i>')
  96. self.fields['light_design'].help_text = ('<i>e.g. Domenico Torrone and Osap, Hongkong</i>')
  97. self.fields['tecnical_layout'].help_text = ('<i>e.g. Modul Labs, Berlin</i>')
  98. self.fields['display_content'].help_text = ('<i>e.g. Domenico Torrone;reality check, Munich;</i>')
  99. self.fields['light_hardware'].help_text = ('<i>e.g. Modul Labs, Berlin</i>')
  100. self.fields['lightning_software'].help_text = ('<i>e.g. Dimma DMX by Eflux</i>')
  101. self.fields['Product_coordination'].help_text = ('<i>e.g. Domenico Torrone and Partners</i>')
  102. self.fields['membrane_skin'].help_text = ('<i>e.g. none</i>')
  103. self.fields['interaction_design'].help_text = ('<i>e.g. pixeldings, Toronto</i>')
  104. self.fields['sponsor'].help_text = ('<i>e.g. none</i>')
  105. self.fields['module_elems'].help_text = ('<i>e.g. Maxi PIX 12 by Eflux</i>')
  106. self.fields['owner'].max_length = 100
  107. self.fields['architecture'].max_length = 100
  108. self.fields['concept'].max_length = 100
  109. self.fields['structural_engeneering'].max_length = 100
  110. self.fields['facade_design'].max_length = 100
  111. self.fields['face_construction'].max_length = 100
  112. self.fields['kinetic_design'].max_length = 100
  113. self.fields['light_design'].max_length = 100
  114. self.fields['tecnical_layout'].max_length = 100
  115. self.fields['display_content'].max_length = 100
  116. self.fields['light_hardware'].max_length = 100
  117. self.fields['lightning_software'].max_length = 100
  118. self.fields['Product_coordination'].max_length = 100
  119. self.fields['membrane_skin'].max_length = 100
  120. self.fields['interaction_design'].max_length = 100
  121. self.fields['sponsor'].max_length = 100
  122. self.fields['module_elems'].max_length = 100
  123. #
  124. self.helper = FormHelper()
  125. self.helper.field_class = 'form_border'
  126. self.helper.form_tag = False
  127. self.helper.layout = Layout(
  128. Fieldset(
  129. ('Credits'),
  130. Div( Div('owner',css_class='form-group col-md-5 mb-0'), Div('architecture',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  131. Div( Div('concept',css_class='form-group col-md-5 mb-0'), Div('structural_engeneering',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  132. Div( Div('facade_design',css_class='form-group col-md-5 mb-0'), Div('face_construction',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  133. Div( Div('kinetic_design',css_class='form-group col-md-5 mb-0'), Div('light_design',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  134. Div( Div('tecnical_layout',css_class='form-group col-md-5 mb-0'), Div('display_content',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  135. Div( Div('light_hardware',css_class='form-group col-md-5 mb-0'), Div('lightning_software',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  136. Div( Div('Product_coordination',css_class='form-group col-md-5 mb-0'), Div('membrane_skin',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  137. Div( Div('interaction_design',css_class='form-group col-md-5 mb-0'), Div('sponsor',css_class='form-group col-md-5 mb-0'), css_class='form-row'),
  138. Div( Div( 'module_elems',css_class='form-group col-md-5 mb-0'), css_class='form-row')
  139. ))
  140. class DescriptionForm(forms.ModelForm):
  141. class Meta:
  142. model = Description
  143. fields =('facade','light_creation','resolution','pixel_distance','luminance','urban_situation','description_showreel')
  144. def __init__(self, *args, **kwargs):
  145. super(DescriptionForm, self).__init__(*args, **kwargs)
  146. self.helper = FormHelper()
  147. self.helper.form_tag = False
  148. self.helper.layout = Layout(
  149. Fieldset(
  150. ('Concept Descriptions'),
  151. Div(Div('des_concept', css_class='form-group col-md-12 mb-0'), css_class='form-row'),
  152. Div(Div('des_scenario', css_class='form-group col-md-6 mb-0'),
  153. Div('des_approach', css_class='form-group col-md-6 mb-0'), css_class='form-row'),
  154. Div(Div('des_tech', css_class='form-group col-md-6 mb-0'),
  155. Div('des_visual', css_class='form-group col-md-6 mb-0'), css_class='form-row'),
  156. ))
  157. class InteractionForm(forms.ModelForm):
  158. class Meta:
  159. model = Interaction
  160. fields = ('communtity','host','legal_form','issues','impact','tools','tools_used','next_steps')
  161. def __init__(self, *args, **kwargs):
  162. super(InteractionForm, self).__init__(*args, **kwargs)
  163. self.helper = FormHelper()
  164. self.helper.form_tag = False
  165. self.helper.layout = Layout(
  166. Fieldset(
  167. ('Community Ascpects - not mandatory'),
  168. Div(Div('communtity', css_class='form-group col-md-6 mb-0'),
  169. Div('issues', css_class='form-group col-md-6 mb-0'), css_class='form-row'),
  170. Div(Div('legal_form', css_class='form-group col-md-6 mb-0'),
  171. Div('host', css_class='form-group col-md-6 mb-0'), css_class='form-row'),
  172. Div(Div('impact', css_class='form-group col-md-6 mb-0'),
  173. Div('tools', css_class='form-group col-md-6 mb-0'), css_class='form-row'),
  174. Div(Div('tools_used', css_class='form-group col-md-6 mb-0'),
  175. Div('next_steps', css_class='form-group col-md-6 mb-0'), css_class='form-row'),
  176. ))
  177. class LinkForm(forms.ModelForm):
  178. class Meta:
  179. model = Link
  180. fields = ('link_description','link')
  181. #def __init__(self, *args, **kwargs):
  182. # super(LinkForm, self).__init__(*args, **kwargs)
  183. # self.helper = FormHelper()
  184. # self.helper.field_class = 'form_border'
  185. # self.helper.form_tag = False
  186. # self.helper.layout = Layout(
  187. # Fieldset(
  188. # Div(Div('link_description', css_class='form-group col-md-5 mb-0'),
  189. # Div('link', css_class='form-group col-md-5 mb-0'),
  190. # css_class='form-row')
  191. # ))
  192. LinkFormSet = inlineformset_factory(Product,Link, fields = ['link_description','link'], form=LinkForm, extra=3, can_delete=False)
  193. class FormsetHelper(FormHelper):
  194. def __init__(self,*args, **kwargs):
  195. super(FormsetHelper, self).__init__(*args, **kwargs)
  196. #self.form_method = 'post'
  197. self.form_tag = False
  198. #self.render_hidden_fields = True
  199. #self.render_required_fields = True
  200. self.layout = Layout(
  201. Fieldset(
  202. (''),
  203. Div(
  204. Div('link_description', css_class='form-group col-md-4 mb-0'),
  205. Div('link', css_class='form-group col-md-6 mb-0')
  206. , css_class='form-row')
  207. ))
  208. class MediaForm(FileFormMixin, forms.Form):
  209. image = UploadedFileField()
  210. name_for = CharField()
  211. copyright = CharField()
  212. #prefix = 'upload'
  213. def __init__(self, *args, **kwargs):
  214. super(MediaForm, self).__init__(*args, **kwargs)
  215. self.helper = FormHelper()
  216. self.helper.form_tag = False
  217. self.fields['name_for'].label = 'Caption'
  218. self.fields['copyright'].label = 'Copyright of'
  219. self.fields['image'].label = 'Image or Video'
  220. self.fields['image'].help_text = 'Please upload Images in PNG or JPEG format. Upload Video in MP4 format.'
  221. self.layout = Layout(
  222. Fieldset(
  223. (''),
  224. Div(
  225. Div('name_for', css_class='form-group col-md-6 mb-0'),
  226. Div('copyright', css_class='form-group col-md-4 mb-0')
  227. , css_class='form-row'),
  228. Div(
  229. Div('image', css_class='form-group col-md-6 mb-0'),
  230. css_class='form-row'),
  231. ))
  232. #def is_valid(self):
  233. # super(MediaForm,self).is_valid()
  234. # return True
  235. #def clean(self):
  236. # cleaned_data = super(MediaForm,self).clean()
  237. # #test for valid formats
  238. # #if cleaned_data['image']
  239. # # raise ValidationError('Title field is required')
  240. # return cleaned_data
  241. #def save(self, Product_pk):
  242. # self.clean()
  243. # media = Media()
  244. # print('hallo')
  245. # media.Product= Product_pk
  246. # media.image=self.cleaned_data['image']
  247. # media.name_for=self.cleaned_data['name_for']
  248. # media.copyright =self.cleaned_data['copyright']
  249. # media.Product= Product_pk
  250. # media.save()
  251. ## self.delete_temporary_files()
  252. class MediaForm_test(FileFormMixin, forms.Form):
  253. image = UploadedFileField()
  254. name_for = CharField()
  255. copyright = CharField()
  256. def __init__(self, *args, **kwargs):
  257. super(MediaForm_test, self).__init__(*args, **kwargs)
  258. self.helper = FormHelper()
  259. self.helper.form_tag = False
  260. class MediaForm1(FileFormMixin, forms.Form):
  261. image = MultipleUploadedFileField()
  262. name_for = CharField()
  263. copyright = CharField()
  264. def __init__(self, *args, **kwargs):
  265. super(MediaForm1, self).__init__(*args, **kwargs)
  266. self.helper = FormHelper()
  267. self.helper.form_tag = False
  268. class MediaForm2(FileFormMixin,forms.Form):
  269. image = UploadedFileField()
  270. name_for = CharField()
  271. copyright = CharField()
  272. def __init__(self, *args, **kwargs):
  273. super(MediaForm2, self).__init__(*args, **kwargs)
  274. self.helper = FormHelper()
  275. self.helper.form_tag = False
  276. MediaFormSet = formset_factory(MediaForm_test, extra=3)
  277. class MediaFormsetHelper(FormHelper):
  278. def __init__(self,*args, **kwargs):
  279. super(MediaFormsetHelper, self).__init__(*args, **kwargs)
  280. self.form_tag = False
  281. self.layout = Layout(
  282. Fieldset(
  283. (''),
  284. Div(
  285. Div('name_for', css_class='form-group col-md-6 mb-0'),
  286. Div('copyright', css_class='form-group col-md-4 mb-0')
  287. , css_class='form-row'),
  288. Div(
  289. Div('image', css_class='form-group col-md-6 mb-0'),
  290. css_class='form-row'),
  291. ))
  292. class VideoForm(forms.ModelForm):
  293. class Meta:
  294. model = Video
  295. fields = ('name_for','copyright','image')