forms.py 17 KB

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