forms.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. from django import forms
  2. from django.conf import settings
  3. from django.core.files import File
  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 django.urls import reverse, reverse_lazy
  8. from django.forms import *
  9. from django.forms.widgets import HiddenInput
  10. from django.forms.models import inlineformset_factory
  11. # from django.views.generic.edit.FormMixin
  12. # from crispy_forms.layout.buttons import Submit, InputButton
  13. from crispy_forms.layout import Layout, Field, Fieldset, Div, Row, Column, HTML, ButtonHolder, Submit
  14. from crispy_forms.bootstrap import InlineField
  15. from crispy_forms.helper import FormHelper
  16. from captcha.fields import CaptchaField
  17. from newsletter.forms import *
  18. from marktplatz.widgets import *
  19. from .models import *
  20. from .urls import *
  21. def extend_help_text( help_text, myList ):
  22. extended_text = help_text
  23. extended_text += " z.B. "
  24. for x in myList:
  25. extended_text += x[1] + ", "
  26. extended_text = extended_text[:-2]
  27. extended_text += "."
  28. return extended_text
  29. class GeneralFields(forms.Form):
  30. terms = forms.BooleanField(required=True, )
  31. def __init__(self, *args, **kwargs):
  32. super(GeneralFields, self).__init__(*args, **kwargs)
  33. drurl = reverse_lazy( 'pages-generic', kwargs= { 'page': 'DATENSCHUTZRICHTLINIE' } )
  34. tmurl = reverse_lazy( 'pages-generic', kwargs= { 'page': 'TEILNAHME' } )
  35. self.fields ['terms'].label = 'Ich akzeptiere die <a target="_blank" href="{}"> Datenschutzrichtlinie</a> sowie die <a target="_blank" href="{}"> Teilnahmebedingungen</a> und habe sie gelesen.'.format(drurl, tmurl)
  36. class textSearchForm(forms.Form):
  37. mywidget = forms.TextInput( attrs={'onfocus': "this.value=''", 'class' : "border-thin"} )
  38. searchText = forms.CharField ( label='', widget = mywidget, max_length = 2048, min_length=3, empty_value="Suche...", initial='Suche...' )
  39. def __init__(self, *args, **kwargs):
  40. super(textSearchForm, self).__init__(*args, **kwargs)
  41. self.helper = FormHelper()
  42. self.helper.form_tag = False
  43. self.helper.layout = Layout(
  44. Div(
  45. Div('searchText', css_class='col-sm-6 col-6'),
  46. Div(
  47. ButtonHolder(
  48. Submit('submit', 'Suche', css_class='border-thin mybtn')
  49. ),
  50. css_class='col-sm-6 col-6'),
  51. css_class='form-row row mab-search-bar'),
  52. )
  53. class searchAgentForm(forms.ModelForm):
  54. agent_layout = Layout()
  55. class Meta:
  56. model = SearchAgent
  57. fields = ('ort', 'email')
  58. def __init__(self,*args, **kwargs):
  59. super().__init__(*args, **kwargs)
  60. # self.fields['ort'].widget = CheckboxSelectMultiple( attrs= { 'style' : "min-height: 250px;"} )
  61. self.agent_layout = Layout(
  62. Fieldset(
  63. ('Suchagent einrichten'),
  64. # 'ort',
  65. Div(
  66. Div('ort', css_class='col-sm-6 col-6 checkbox-ort'),
  67. Div(
  68. HTML("""
  69. <button onclick=" ganz_wien()" class="btn btn-primary border-thin border-dark mybtn">Ganz Wien</button>
  70. <script>
  71. function ganz_wien(){
  72. $(".checkbox-ort .custom-control-label:contains('Wien')").each(function() {
  73. $this = $(this);
  74. var selector = "#" + $this.attr('for') ;
  75. $( selector ).prop('checked', true);
  76. });
  77. }
  78. </script>
  79. <br>
  80. """),
  81. # HTML("""
  82. # <div id="div_id_ort" class="form-group">
  83. # <label for="" class=" requiredField">Ort<span class="asteriskField">*</span> </label>
  84. # <div class="">
  85. # <div class="row">
  86. # <div class="col-sm-6 col-6 checkbox-ort">
  87. #
  88. # <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_1" value="1010" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_1">
  89. # Wien 1
  90. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_2" value="1020" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_2">
  91. # Wien 2
  92. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_3" value="1030" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_3">
  93. # Wien 3
  94. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_4" value="1040" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_4">
  95. # Wien 4
  96. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_5" value="1050" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_5">
  97. # Wien 5
  98. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_6" value="1060" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_6">
  99. # Wien 6
  100. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_7" value="1070" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_7">
  101. # Wien 7
  102. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_8" value="1080" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_8">
  103. # Wien 8
  104. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_9" value="1090" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_9">
  105. # Wien 9
  106. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_10" value="1100" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_10">
  107. # Wien 10
  108. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_11" value="1110" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_11">
  109. # Wien 11
  110. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_12" value="1120" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_12">
  111. # Wien 12
  112. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_13" value="1130" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_13">
  113. # Wien 13
  114. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_14" value="1140" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_14">
  115. # Wien 14
  116. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_15" value="1150" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_15">
  117. # Wien 15
  118. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_16" value="1160" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_16">
  119. # Wien 16
  120. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_17" value="1170" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_17">
  121. # Wien 17
  122. # </label> </div>
  123. # </div>
  124. # <div class="col-sm-6 col-6 checkbox-ort">
  125. #
  126. #
  127. # <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_18" value="1180" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_18">
  128. # Wien 18
  129. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_19" value="1190" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_19">
  130. # Wien 19
  131. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_20" value="1200" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_20">
  132. # Wien 20
  133. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_21" value="1210" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_21">
  134. # Wien 21
  135. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_22" value="1220" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_22">
  136. # Wien 22
  137. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_23" value="1230" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_23">
  138. # Wien 23
  139. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_24" value="GERM" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_24">
  140. # Deutschland
  141. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_25" value="SCHW" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_25">
  142. # Schweiz
  143. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_26" value="VORA" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_26">
  144. # Vorarlberg
  145. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_27" value="TIRO" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_27">
  146. # Tirol
  147. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_28" value="SALZ" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_28">
  148. # Salzburg
  149. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_29" value="KAER" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_29">
  150. # Kärnten
  151. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_30" value="STEI" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_30">
  152. # Steiermark
  153. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_31" value="OBER" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_31">
  154. # Oberösterreich
  155. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_32" value="NIER" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_32">
  156. # Niederösterreich
  157. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_33" value="BURG" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_33">
  158. # Burgenland
  159. # </label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" name="ort" id="id_ort_34" value="WELT" style="min-height: 250px;"> <label class="custom-control-label" for="id_ort_34">
  160. # Welt
  161. # </label> </div>
  162. # </div>
  163. # </div>
  164. # <small id="hint_id_ort" class="form-text text-muted">Ort des Projektes</small>
  165. # </div>
  166. # </div>
  167. #
  168. # """),
  169. css_class='col-sm-6 col-6'),
  170. css_class='form-row row'),
  171. ),
  172. )
  173. class AgentNewslwtterForm( searchAgentForm, GeneralFields):
  174. email_field = forms.EmailField( label = 'Email', help_text="Du kannst den Suchagenten und den Newsletter jederzeit abbestellen - über einen Link in den Mails.", required=True, max_length=254 )
  175. subscribe = forms.BooleanField( label = 'Newsletter abonnieren', help_text='', required = False )
  176. captcha = CaptchaField( label = 'Bitte lösen Sie die Gleichung', generator='captcha.helpers.math_challenge' )
  177. def __init__(self, *args, **kwargs):
  178. # super(searchAgentForm, self).__init__(*args, **kwargs)
  179. super(AgentNewslwtterForm, self).__init__(*args, **kwargs)
  180. self.helper = FormHelper(self)
  181. self.helper.attrs = { 'enctype' : "multipart/form-data" }
  182. self.helper.form_action = reverse('agent-newsletter-create', kwargs={'newsletter_slug': "gemeinschaffen-newsletter"} )
  183. self.helper.layout = Layout(
  184. self.agent_layout,
  185. 'email_field',
  186. 'subscribe',
  187. 'terms',
  188. 'captcha',
  189. ButtonHolder(
  190. Submit('submit', 'Suchagent aktivieren', css_class='border-thin border-dark mybtn')
  191. ),
  192. )
  193. class RegisterForm(forms.ModelForm, GeneralFields):
  194. class Meta:
  195. model = Contact
  196. fields = ('first_name','last_name','email','adress','postcode','city','country',
  197. 'phonenumber','alternate_phonenumber','skype_name','website', 'terms')
  198. class SignUpForm(UserCreationForm):
  199. captcha = CaptchaField( generator='captcha.helpers.math_challenge' )
  200. class Meta:
  201. model = User
  202. fields = ('username', 'password1', 'password2')
  203. class ProductForm(forms.ModelForm, GeneralFields):
  204. # terms = forms.BooleanField(required=True, label= ('Ich habe die Teilnahmebedingungen gelesen und akzeptiert.'))
  205. product_fields = ( 'terms', 'name','claim','beschreibung','learning','gruendungsjahr','betriebgenommen','status','adresse','website','email','frei','kfrei','ort','rechtsform','orga','mitmachen','edit','public', )
  206. product_layout = Layout(
  207. Fieldset(
  208. ('Über dein Projekt'),
  209. 'name','claim','beschreibung',
  210. Div(
  211. Div('frei', css_class='col-sm-6 col-6 '),
  212. Div('kfrei', css_class='col-sm-6 col-6 ' ),
  213. css_class='form-row row mab-field-highlight'),
  214. 'learning','status',
  215. Div(
  216. Div('adresse', css_class='col-sm-6 col-6'),
  217. Div('ort', css_class='col-sm-6 col-6'),
  218. css_class='form-row row'),
  219. 'rechtsform','orga',
  220. Div(
  221. Div('website', css_class='col-sm-6 col-6'),
  222. Div('email', css_class='col-sm-6 col-6'),
  223. css_class='form-row row'),
  224. Div(
  225. Div('gruendungsjahr', css_class='col-sm-6 col-6'),
  226. Div('betriebgenommen', css_class='col-sm-6 col-6'),
  227. css_class='form-row row'),
  228. 'edit','public', 'mitmachen',
  229. ),
  230. )
  231. class Meta:
  232. model = Product
  233. fields = (
  234. 'terms',
  235. 'name','claim','beschreibung','learning','gruendungsjahr','betriebgenommen','status','adresse','website','email','frei','kfrei', 'mitmachen','rechtsform','ort','orga',
  236. )
  237. def __init__(self,*args, **kwargs):
  238. super(ProductForm, self).__init__(*args, **kwargs)
  239. self.fields['orga'].widget = ListTextWidget(data_list=Product.ORGANIZATION, name='orga_list')
  240. self.fields['rechtsform'].widget = ListTextWidget(data_list=Product.RECHTSFORM, name='rechtsform_list')
  241. self.fields['edit'].widget = HiddenInput()
  242. self.fields['public'].widget = HiddenInput()
  243. #
  244. # extend_help_text
  245. #
  246. self.fields['orga'].help_text = extend_help_text (self.fields['orga'].help_text, Product.ORGANIZATION)
  247. self.fields['rechtsform'].help_text = extend_help_text (self.fields['rechtsform'].help_text, Product.RECHTSFORM)
  248. self.helper = FormHelper()
  249. self.helper.form_tag = False
  250. class WohnprojektForm(ProductForm):
  251. terms = forms.BooleanField(required=True, label= ('Ich habe die Teilnahmebedingungen gelesen und akzeptiert.'))
  252. class Meta:
  253. model = Wohnprojekt
  254. fields = ProductForm.product_fields + (
  255. 'eigentum', 'inseratstext', 'altneu', 'schwerpunkt', 'wohnbaufoerderung', 'artmodell', 'bautraeger', 'aerwachsene', 'akinder', 'awohnungen', 'wohnflaeche', 'gewerbeflaechen', 'gemeinschaftsflaeche', 'sonstige_flaechen', 'kflaechen', 'gemeinschaftr', 'kgemeinschaftr', 'sonderwohnformen', 'raumangebot', 'kraumangebot', 'parbeiten', 'karbeiten', 'bauweise', 'zielgruppen', 'gprojekte', 'oekologie', 'freiraumangebote', 'gaestwohnungen', 'urbanem',
  256. )
  257. def __init__(self,*args, **kwargs):
  258. super(WohnprojektForm, self).__init__(*args, **kwargs)
  259. #
  260. #
  261. self.fields['artmodell'].widget = ListTextWidget(data_list=Wohnprojekt.ARTMODELL, name='artmodell_list')
  262. self.fields['bautraeger'].widget = ListTextWidget(data_list=Wohnprojekt.BAUTRAEGER, name='bautraeger_list')
  263. self.fields['bauweise'].widget = ListTextWidget(data_list=Wohnprojekt.BAUWEISE, name='bauweise_list')
  264. self.fields['zielgruppen'].widget = ListTextWidget(data_list=Wohnprojekt.ZIELGRUPPEN, name='zielgruppen_list')
  265. self.fields['gprojekte'].widget = ListTextWidget(data_list=Wohnprojekt.GPROJEKTE, name='gprojekte_list')
  266. self.fields['freiraumangebote'].widget = ListTextWidget(data_list=Wohnprojekt.FREIANGEBOT, name='freiraumangebote_list')
  267. #
  268. #
  269. self.fields['bauweise'].help_text = extend_help_text (self.fields['bauweise'].help_text, Wohnprojekt.BAUWEISE)
  270. self.fields['zielgruppen'].help_text = extend_help_text (self.fields['zielgruppen'].help_text, Wohnprojekt.ZIELGRUPPEN)
  271. self.fields['gprojekte'].help_text = extend_help_text (self.fields['gprojekte'].help_text, Wohnprojekt.GPROJEKTE)
  272. #
  273. #
  274. self.fields['frei'].label = "Wohnung Frei"
  275. self.helper = FormHelper()
  276. self.helper.form_tag = False
  277. self.helper.layout = Layout(
  278. self.product_layout,
  279. Fieldset( 'Wohnprojekt',
  280. 'eigentum',
  281. 'artmodell',
  282. 'altneu',
  283. 'schwerpunkt',
  284. 'wohnbaufoerderung',
  285. 'bautraeger',
  286. Div(
  287. Div('aerwachsene', css_class='col-sm-6 col-6'),
  288. Div('akinder', css_class='col-sm-6 col-6'),
  289. css_class='form-row row'),
  290. 'awohnungen',
  291. 'gaestwohnungen',
  292. Fieldset ( 'Flächen',
  293. Div(
  294. Div('wohnflaeche', css_class='col-sm-3 col-3'),
  295. Div('gewerbeflaechen', css_class='col-sm-3 col-3'),
  296. Div('gemeinschaftsflaeche', css_class='col-sm-3 col-3'),
  297. Div('sonstige_flaechen', css_class='col-sm-3 col-3'),
  298. css_class='form-row row'),
  299. 'kflaechen',
  300. ),
  301. Div(
  302. Div('gemeinschaftr', css_class='col-sm-6 col-6'),
  303. Div('raumangebot', css_class='col-sm-6 col-6'),
  304. Div('kgemeinschaftr', css_class='col-sm-6 col-6'),
  305. Div('kraumangebot', css_class='col-sm-6 col-6'),
  306. css_class='form-row row'),
  307. Div('inseratstext', css_class = "mab-field-highlight"),
  308. 'sonderwohnformen',
  309. Div(
  310. Div('parbeiten', css_class='col-sm-6 col-6'),
  311. Div('karbeiten', css_class='col-sm-6 col-6'),
  312. css_class='form-row row'),
  313. 'bauweise', 'zielgruppen', 'gprojekte', 'oekologie', 'freiraumangebote', 'urbanem',
  314. )
  315. )
  316. class MediaForm(FileFormMixin, forms.Form):
  317. image = UploadedFileField()
  318. name_for = forms.CharField()
  319. copyright = forms.CharField()
  320. #prefix = 'upload'
  321. def __init__(self, *args, **kwargs):
  322. super(MediaForm, self).__init__(*args, **kwargs)
  323. self.helper = FormHelper()
  324. self.helper.form_tag = False
  325. self.fields['name_for'].label = 'Bildbeschriftung'
  326. self.fields['copyright'].label = 'Urheberrechte'
  327. self.fields['image'].label = 'Bild oder Video'
  328. self.fields['image'].help_text = 'Bitte laden Sie Bilder im PNG- oder JPEG-Format hoch. Laden Sie Videos im MP4-Format hoch.'
  329. self.layout = Layout(
  330. Fieldset(
  331. (''),
  332. Div(
  333. Div('name_for', css_class='form-group col-md-6 mb-0'),
  334. Div('copyright', css_class='form-group col-md-4 mb-0')
  335. , css_class='form-row'),
  336. Div(
  337. Div('image', css_class='form-group col-md-6 mb-0'),
  338. css_class='form-row'),
  339. ))
  340. class VideoForm(forms.ModelForm):
  341. class Meta:
  342. model = Video
  343. fields = ('name_for','copyright','image')