models.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. import os
  2. import uuid
  3. import datetime
  4. import shutil
  5. from django.db.models import *
  6. from django.core.validators import MinValueValidator, MaxValueValidator
  7. from django.contrib.auth.models import User
  8. from django.core.files.storage import FileSystemStorage
  9. from django_countries.fields import CountryField
  10. from django.db import models
  11. from django.dispatch import receiver
  12. from django.db.models.signals import post_delete, post_save
  13. from django.conf import settings
  14. from multiselectfield import MultiSelectField
  15. from imagekit.models import ImageSpecField
  16. from imagekit.processors import ResizeToFill
  17. from imagekit.processors import ResizeToCover
  18. from imagekit.processors import Thumbnail
  19. from imagekit.processors import ResizeToCover
  20. from imagekit.models import ProcessedImageField
  21. from post_office import mail
  22. from constance import config
  23. from marktplatz.widgets import *
  24. class Credit(models.Model):
  25. owner = CharField(verbose_name='Building or Product owner',blank=True,max_length = 300)
  26. architecture = CharField(verbose_name='Architecture',blank=True,max_length = 300)
  27. concept = CharField(verbose_name='Product artist/ concept/ design/ planning',blank=True,max_length = 300)
  28. structural_engeneering = CharField(verbose_name='Structural engineering',blank=True,max_length = 300)
  29. facade_design = CharField(verbose_name='Facade design',blank=True,max_length = 300)
  30. face_construction = CharField(verbose_name='Facade construction',blank=True,max_length = 300)
  31. kinetic_design = CharField(verbose_name='Kinetic engineering',blank = True,max_length = 300)
  32. light_design = CharField(verbose_name='Light design',blank = True,max_length = 300)
  33. tecnical_layout = CharField(verbose_name='Technical layout light',blank = True,max_length = 300)
  34. display_content = CharField(verbose_name='Display content/ visuals/ showreel',blank = True,max_length = 300)
  35. light_hardware = CharField(verbose_name='Light hardware (LED hardware)',blank = True,max_length = 300)
  36. lightning_software = CharField(verbose_name='Lighting control software',blank = True,max_length = 300)
  37. product_coordination = CharField(verbose_name='Product co-ordination',blank = True,max_length = 300)
  38. membrane_skin = CharField(verbose_name='Membrane skin',blank = True,max_length = 300)
  39. interaction_design = CharField(verbose_name='Interaction design/ programming',blank = True,max_length = 300)
  40. sponsor = CharField(verbose_name='Product sponsor/ support',blank = True,max_length = 500)
  41. module_elems = CharField(verbose_name='Pixel or other basic module/ elements',blank = True,max_length = 300)
  42. def __iter__(self):
  43. for field in self._meta.fields:
  44. if field.value_to_string(self) != '-' and field.value_to_string(self) != 'N/A':
  45. yield (field.verbose_name, field.value_to_string(self))
  46. class Description(models.Model):
  47. facade = TextField(verbose_name='Facade type and geometry (structure)',blank = True,max_length = 900)
  48. light_creation = TextField(verbose_name='Kind of light creation',blank = True,max_length = 900)
  49. resolution = TextField(verbose_name='Resolution and transmitting behaviour',blank = True,max_length = 900)
  50. pixel_distance = CharField(verbose_name='Pixel distance',blank = True,max_length = 300)
  51. luminance = TextField(verbose_name='Luminace',blank = True,max_length = 900)
  52. urban_situation = TextField(verbose_name='Urban situation',blank = True,max_length = 900)
  53. description_showreel = TextField(verbose_name='Description of showreel',blank = True,max_length = 900)
  54. def __iter__(self):
  55. for field in self._meta.fields:
  56. if (field.value_to_string(self) != '-') and (field.value_to_string(self) != 'N/A'):
  57. yield (field.verbose_name, field.value_to_string(self))
  58. class Interaction(models.Model):
  59. communtity = TextField(verbose_name='Community or communities involved',blank = True,max_length = 900)
  60. host = CharField(verbose_name='Host organization',blank = True,max_length = 900)
  61. legal_form = CharField(verbose_name='Legal form',blank=True,max_length = 900)
  62. issues = TextField(verbose_name='Issues addressed',blank = True,max_length = 900)
  63. impact = TextField(verbose_name='Impact',blank = True,max_length = 900)
  64. tools = TextField(verbose_name='Tools developed',blank = True,max_length = 900)
  65. tools_used = TextField(verbose_name='Tools used',blank = True,max_length = 900)
  66. next_steps = TextField(verbose_name='Next steps',blank = True,max_length = 900)
  67. def __iter__(self):
  68. for field in self._meta.fields:
  69. if (field.value_to_string(self) != '-') and (field.value_to_string(self) != 'N/A'):
  70. yield (field.verbose_name, field.value_to_string(self))
  71. class Contact(models.Model):
  72. user = OneToOneField(User, on_delete=models.CASCADE,blank=True)
  73. first_name = CharField(verbose_name="Vorname", max_length = 100)
  74. last_name = CharField(verbose_name="Nachname", max_length = 100)
  75. adress = CharField(verbose_name="Adresse", blank=True,max_length = 100)
  76. postcode = CharField(verbose_name="Postleitzahl", blank=True, max_length = 100)
  77. city = CharField(verbose_name="Stadt", blank=True,max_length = 100)
  78. country = CharField(verbose_name="Land", blank=True,max_length = 100)
  79. email = EmailField(verbose_name="E-Mail-Addresse", unique=True)
  80. phonenumber = CharField(verbose_name="1. Telefonnummer", blank=True,max_length = 100)
  81. alternate_phonenumber = CharField(verbose_name="2. Telefonnummer", blank = True,max_length = 100)
  82. skype_name = CharField(verbose_name="Skype", blank=True,max_length = 300)
  83. website = URLField(verbose_name="Website", blank=True)
  84. def __str__(self):
  85. return self.first_name + ' ' + self.last_name
  86. def __iter__(self):
  87. for field in self._meta.fields:
  88. yield (field.verbose_name, field.value_to_string(self))
  89. class Category(models.Model):
  90. name = CharField(max_length=100)
  91. short_name = CharField(max_length=10)
  92. def __str__(self):
  93. return self.name
  94. class Product(models.Model):
  95. # def save(self, update_fields=None, *args, **kwargs):
  96. # print(kwargs)
  97. # print(args)
  98. # print (update_fields)
  99. # # update_fields = ['frei']
  100. # super().save(*args, **kwargs) # Call the "real" save() method.
  101. #https://stackoverflow.com/questions/1355150/when-saving-how-can-you-check-if-a-field-has-changed
  102. __original_frei = None
  103. def __init__(self, *args, **kwargs):
  104. super(Product, self).__init__(*args, **kwargs)
  105. self.__original_frei = self.frei
  106. def save(self, update_fields=None, *args, **kwargs):
  107. print ("is this workig?")
  108. print ('update_fields: ', update_fields)
  109. # post_save.connect(search_agent)
  110. if self.frei != self.__original_frei and self.frei == "JAJA":
  111. for agent in SearchAgent.objects.all():
  112. for agentOrt in agent.ort:
  113. print(agentOrt)
  114. if agentOrt == self.ort:
  115. print ('send_mail')
  116. context = {}
  117. context['product_name']=self.name
  118. context['product_claim']=self.claim
  119. context['product_beschreibung']=self.beschreibung
  120. context['product_learning']=self.learning
  121. context['product_gruendungsjahr']=self.gruendungsjahr
  122. context['product_betriebgenommen']=self.betriebgenommen
  123. context['product_status']=self.status
  124. context['product_adresse']=self.adresse
  125. context['product_plz']=self.plz
  126. context['product_adresse_zusatz']=self.adresse_zusatz
  127. context['product_ort']=self.ort
  128. context['product_website']=self.website
  129. context['product_email']=agent.hash
  130. context['agent_hash']=self.email
  131. context['recipient'] = [ agent.email, ]
  132. context['msg_subject' ] = ('Gemeinschaffen - ' + self.name )
  133. mail.send(
  134. context['recipient'],
  135. config.EMAIL_NOREPLY,
  136. context = context,
  137. template='generic',
  138. headers={ 'Reply-To': context['product_email'] },
  139. priority='now',
  140. )
  141. super().save( update_fields=update_fields, *args, **kwargs) # Call the "real" save() method.
  142. self.__original_frei = self.frei
  143. # super().save(update_fields=update_fields, *args, **kwargs) # Call the "real" save() method.
  144. # def save(self, *args, update_fields=[''], **kwargs):
  145. #
  146. #
  147. # # super(Product, self).save(force_insert, force_update, update_fields=['frei'], *args, **kwargs)
  148. # print ("savingg.....")
  149. # super().save(*args, update_fields=['frei'], **kwargs)
  150. # print ("saved ++++++++")
  151. #
  152. STATUS = [
  153. ('ENT', 'Entwicklung'),
  154. ('BET', 'In Betrieb'),
  155. ('ABG', 'Abgeschlossen'),
  156. ]
  157. FREI = [
  158. ('JAJA', 'Ja, bitte melden'),
  159. ('WART', 'Nein, aber es gibt eine Warteliste'),
  160. ('NEIN', 'Nein und es gibt keine Warteliste'),
  161. ]
  162. RECHTSFORM = [
  163. ('GmbH', 'GmbH'),
  164. ('Verein', 'Verein'),
  165. ('Genossenschaft', 'Genossenschaft'),
  166. ('GbR', 'GbR'),
  167. ('Sonstiges', 'Sonstiges'),
  168. ]
  169. ORT = [
  170. ('1010', '1., Innere Stadt'),
  171. ('1020', '2., Leopoldstadt'),
  172. ('1030', '3., Landstraße'),
  173. ('1040', '4., Wieden'),
  174. ('1050', '5., Margareten'),
  175. ('1060', '6., Mariahilf'),
  176. ('1070', '7., Neubau'),
  177. ('1080', '8., Josefstadt'),
  178. ('1090', '9., Alsergrund'),
  179. ('1100', '10., Favoriten'),
  180. ('1110', '11., Simmering'),
  181. ('1120', '12., Meidling'),
  182. ('1130', '13., Hietzing'),
  183. ('1140', '14., Penzing'),
  184. ('1150', '15., Rudolfsheim-Fünfhaus'),
  185. ('1160', '16., Ottakring'),
  186. ('1170', '17., Hernals'),
  187. ('1180', '18., Währing'),
  188. ('1190', '19., Döbling'),
  189. ('1200', '20., Brigittenau'),
  190. ('1210', '21., Floridsdorf'),
  191. ('1220', '22., Donaustadt'),
  192. ('1230', '23., Liesing'),
  193. ('GERM', 'Deutschland'),
  194. ('SCHW', 'Schweiz'),
  195. ('VORA', 'Vorarlberg'),
  196. ('TIRO', 'Tirol'),
  197. ('SALZ', 'Salzburg'),
  198. ('KAER', 'Kärnten'),
  199. ('STEI', 'Steiermark'),
  200. ('OBER', 'Oberösterreich'),
  201. ('NIER', 'Niederösterreich'),
  202. ('BURG', 'Burgenland'),
  203. ('WELT', 'Welt'),
  204. ]
  205. ORGANIZATION = [
  206. ('Soziokratie', 'Soziokratie'),
  207. ('Sonstiges', 'Sonstiges'),
  208. ]
  209. @property
  210. def kind_of_product(self):
  211. return "Allgemeines Produkt"
  212. name = CharField( 'Name', max_length = 128, help_text="Name des Projekts", null = True, blank=True )
  213. claim = CharField( 'Claim / Untertitel', max_length = 256, help_text="Claim / Untertitel", null = True, blank=True )
  214. beschreibung = TextField( 'Beschreibung', max_length = 2048, help_text="Beschreibung des Projektes", null = True, blank=True )
  215. learning = CharField( 'Learning', max_length = 256, help_text="Learning", null = True, blank=True )
  216. gruendungsjahr = IntegerField('Gründungsjahr', help_text="Gründungsjahr des Projekts", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
  217. betriebgenommen = IntegerField('in Betrieb genommen in Jahr', help_text="Wann wurde das Projekt in Betrieb genommen?", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
  218. status = CharField( 'Status', max_length = 3, choices=STATUS, default='ENT', help_text="Was ist der Status des Projektes" , null = True, blank=True )
  219. adresse = CharField( 'Adresse', max_length = 256, help_text="Adresse des Projektes", null = True, blank=True )
  220. plz = CharField ( 'Adresse', max_length = 256, help_text="PLZ des Projektes", null = True, blank=True )
  221. adresse_zusatz = CharField ( 'Adresse Zusatz', max_length = 256, help_text="Adresse Zusatz", null = True, blank=True )
  222. ort = CharField ( 'Ort', max_length = 4, choices=ORT, default='WELT', help_text="Ort des Projektes", null = True, blank=True )
  223. website = URLField ( 'Website', max_length = 2048, help_text="Website des Projektes", null = True, blank=True )
  224. email = EmailField ( 'Email', max_length = 2048, help_text="Email des Projektes", null = True, blank=True )
  225. frei = CharField ( 'Platz frei', max_length = 4, choices=FREI, default='NEIN', help_text="Gibt es freie Plätze?", null = True, blank=False )
  226. kfrei = CharField ( 'Platz frei - Kommentar', max_length = 2048, help_text="Kommentar", null = True, blank=True )
  227. rechtsform = CharField ( 'Rechtsform', max_length = 32, help_text="Rechtsform des Projektes", null = True, blank=True )
  228. orga = CharField ( 'Organisationsform', max_length = 256, help_text="Organisationsform des Projektes.", null = True, blank=True )
  229. mitmachen = BooleanField( 'Mitmachen möglich', default=False, help_text="Kann jemand mitmachen?", blank=False )
  230. terms = NullBooleanField(help_text="")
  231. title = CharField('Product Title',max_length = 100,null = True, blank=True)
  232. country = CountryField(blank=True,multiple=True, help_text="")
  233. city = CharField(max_length = 100,null = True, blank=True, help_text="")
  234. year = IntegerField('Year of Completion',null = True, blank=True, help_text="")
  235. owner = CharField(max_length = 300,null = True,blank=True, help_text="")
  236. teaser_txt = TextField(blank = True, max_length = 1050, help_text="")
  237. header = CharField(max_length = 900 , help_text="",null = True, blank=True)
  238. description_txt = TextField(max_length = 3000 ,null = True, blank=True, help_text="")
  239. #cid = IntegerField(null = True,blank=True, help_text="")
  240. class_cid = CharField(null = True,max_length = 3, blank=True, help_text="")
  241. sumbitted = CharField(null = True,max_length = 10, blank=True, help_text="")
  242. date_submitted = DateField(auto_now_add=True, help_text="")
  243. edit = NullBooleanField(help_text="")
  244. public = NullBooleanField(help_text="")
  245. photo = CharField(max_length=500, null=True, blank=True, help_text="")
  246. videocts = CharField(max_length=500, null=True, blank=True, help_text="")
  247. category = ManyToManyField(Category, help_text="",null = True, blank=True)
  248. credits = ForeignKey(Credit, null = True, blank=True, on_delete=models.SET_NULL, help_text="")
  249. description = ForeignKey(Description, on_delete=models.SET_NULL, help_text="",null = True, blank=True)
  250. contact = ForeignKey(Contact, null = True,on_delete=models.SET_NULL, help_text="")
  251. #interaction = ForeignKey(Interaction, null = True,on_delete = models.SET_NULL, help_text="")
  252. def __str__(self):
  253. return str(self.name)
  254. def __iter__(self):
  255. for field in self._meta.fields:
  256. yield (field.verbose_name, field.value_to_string(self))
  257. def get_field_verbose_name(self, fieldName):
  258. return self._meta.get_field(fieldName).verbose_name
  259. def meta(self):
  260. return self._meta
  261. @receiver(post_delete, sender=Product)
  262. def auto_delete_reverse_keys(sender, instance, **kwargs):
  263. if instance.credits:
  264. instance.credits.delete()
  265. if instance.description:
  266. instance.description.delete()
  267. if instance.interaction:
  268. instance.interaction.delete()
  269. class SearchAgent(models.Model):
  270. def hash_gen():
  271. return uuid.uuid1().hex
  272. email = EmailField ( 'Email', max_length = 2048, help_text="Email des Projektes", null = False, blank=False )
  273. ort = MultiSelectField ( 'Ort', max_length = 4096 , choices=Product.ORT, default='WELT', help_text="Ort des Projektes", null = True, blank=False )
  274. hash = CharField ( max_length=255, default=hash_gen )
  275. class Wohnprojekt(Product):
  276. EIGENTUM = [
  277. ('GEMIET', 'Generalmiete'),
  278. ('WOHNHM', 'Wohnheim'),
  279. ('EIGENT', 'Eigentum'),
  280. ('GTMIET', 'Getrennte Mietvertäge (Verein mietet GR)'),
  281. ]
  282. WOHNBAUFOERDERUNG = [
  283. ('Gefördert', 'Gefördert'),
  284. ('Nicht Gefördert', 'Nicht Gefördert'),
  285. ]
  286. ALTNEU = [
  287. ('ALTB', 'Altbau'),
  288. ('NEUB', 'Neubau'),
  289. ]
  290. ARTMODELL =[
  291. ('Die Wohnungen werden individiuell von einem Bauträger angemietet / Gemeinschaftsräume werden gemeinsam angemietetet', 'Die Wohnungen werden individiuell von einem Bauträger angemietet / Gemeinschaftsräume werden gemeinsam angemietetet'),
  292. ('Die Gemeinschaft mietet das ganze Haus oder Teile davon vom Bauträger (z.b. in Form eines Generalmietvetrages). Die Gemeinschaft schließt indiviudelle Nutzungsverträge mit den NutzerInnen ab. (Wird oft so bei Wohnheimen gemacht)', 'Die Gemeinschaft mietet das ganze Haus oder Teile davon vom Bauträger (z.b. in Form eines Generalmietvetrages). Die Gemeinschaft schließt indiviudelle Nutzungsverträge mit den NutzerInnen ab. (Wird oft so bei Wohnheimen gemacht)'),
  293. ('Der Bau erfolgt durch einen Bauträger. Die Gemeinschaft erwirbt das Gebäude und das Grundstück im Eigentum und schließt individuelle Nutzungsverträge mit den NutzerInenn ab.', 'Der Bau erfolgt durch einen Bauträger. Die Gemeinschaft erwirbt das Gebäude und das Grundstück im Eigentum und schließt individuelle Nutzungsverträge mit den NutzerInenn ab.'),
  294. ('Der Bau erfolgt ohne Bauträger. Die Gemeinschaft erwirbt das Grundstück im Eigentum und baut auf eigene Rechnung und Risiko. Die Gemeinschaft schließt individuelle Nutzungsverträge mit den NutzerInenn ab.', 'Der Bau erfolgt ohne Bauträger. Die Gemeinschaft erwirbt das Grundstück im Eigentum und baut auf eigene Rechnung und Risiko. Die Gemeinschaft schließt individuelle Nutzungsverträge mit den NutzerInenn ab.'),
  295. ('Es gibt ein individuelles Eigentum an den jeweiligen Wohnungen. Die Eigentümergemeinschaft nutzt und erhält Gemeinschaftsräume.', 'Es gibt ein individuelles Eigentum an den jeweiligen Wohnungen. Die Eigentümergemeinschaft nutzt und erhält Gemeinschaftsräume.'),
  296. ('Modell Habitat', 'Modell Habitat'),
  297. ('Anderes Modell', 'Anderes Modell'),
  298. ]
  299. BAUTRAEGER = [
  300. ('Altmannsdorf - Hetzendorf Gemn. Siedlungsgen.m.b.H', 'Altmannsdorf - Hetzendorf Gemn. Siedlungsgen.m.b.H'),
  301. ('EBG Gemn. Ein und Mehrfam. Häuser Baugen.reg..Gen.mbH', 'EBG Gemn. Ein und Mehrfam. Häuser Baugen.reg..Gen.mbH'),
  302. ('EGW-Heimstätte Gesellschaft m.b.H.', 'EGW-Heimstätte Gesellschaft m.b.H.'),
  303. ('FAMILIENWOHNBAU gemeinnützige Bau- und Siedlungsges. m.b.H.', 'FAMILIENWOHNBAU gemeinnützige Bau- und Siedlungsges. m.b.H.'),
  304. ('GARTENHEIM Gemeinn. Familienhäuser Bau- u. Wohnungen regGenmbH', 'GARTENHEIM Gemeinn. Familienhäuser Bau- u. Wohnungen regGenmbH'),
  305. ('Migra Gemn. Bau und SiedlungsgesmbH', 'Migra Gemn. Bau und SiedlungsgesmbH'),
  306. ('ÖVW Österr. Volkswohnungswerk Gemeinn. Ges mbH', 'ÖVW Österr. Volkswohnungswerk Gemeinn. Ges mbH'),
  307. ('SCHWARZATAL Gemeinnützige Wohnungs- u. Siedlungsanlagen GmbH', 'SCHWARZATAL Gemeinnützige Wohnungs- u. Siedlungsanlagen GmbH'),
  308. ('WBV-GPA Wohnbauvereinigung für Privatangestellte Gemn. Ges.m.b.H', 'WBV-GPA Wohnbauvereinigung für Privatangestellte Gemn. Ges.m.b.H'),
  309. ('WOGEN - Wohnprojekte-Genossenschaft e. Gen.', 'WOGEN - Wohnprojekte-Genossenschaft e. Gen.'),
  310. ('Sonstiges', 'Sonstiges'),
  311. ]
  312. GEMEINSCHAFTR = [
  313. ('Gemeinschaftsküche', 'Gemeinschaftsküche'),
  314. ('Kinderspielraum', 'Kinderspielraum'),
  315. ('Sauna / Wellness', 'Sauna / Wellness'),
  316. ('Fitnessraum', 'Fitnessraum'),
  317. ('Werkstatt', 'Werkstatt'),
  318. ('Waschküche', 'Waschküche'),
  319. ('Multifunktionsraum', 'Multifunktionsraum'),
  320. ('Musikraum', 'Musikraum'),
  321. ('Gästewohnung', 'Gästewohnung'),
  322. ('Raum für Home-Office', 'Raum für Home-Office'),
  323. ('Sonstiges', 'Sonstiges'),
  324. ]
  325. RAUMANGEBOT = [
  326. ('Co-Working', 'Co-Working'),
  327. ('Geschäftslokal(e)', 'Geschäftslokal(e)'),
  328. ('Büros', 'Büros'),
  329. ('Veranstaltungsraum', 'Veranstaltungsraum'),
  330. ('Gemeinschaftsküche', 'Gemeinschaftsküche'),
  331. ('Kinderspielraum', 'Kinderspielraum'),
  332. ('Sauna / Wellness', 'Sauna / Wellness'),
  333. ('Fitnessraum', 'Fitnessraum'),
  334. ('Werkstatt', 'Werkstatt'),
  335. ('Waschküche', 'Waschküche'),
  336. ('Musikraum', 'Musikraum'),
  337. ('Gästewohnung', 'Gästewohnung'),
  338. ]
  339. BAUWEISE = [
  340. ('Holz', 'Holz'),
  341. ('Beton', 'Beton'),
  342. ('Ziegel', 'Ziegel'),
  343. ('Mischbauweise', 'Mischbauweise'),
  344. ('Sonstiges', 'Sonstiges'),
  345. ]
  346. ZIELGRUPPEN = [
  347. ('Seniorinnen', 'Seniorinnen'),
  348. ('Alleinerziehende', 'Alleinerziehende'),
  349. ('Geflüchtete', 'Geflüchtete'),
  350. ('Sonstige', 'Sonstige'),
  351. ]
  352. GPROJEKTE = [
  353. ('Foodcoop', 'Foodcoop'),
  354. ('Carsharing', 'Carsharing'),
  355. ('Urban Gardening', 'Urban Gardening'),
  356. ('Sonstiges', 'Sonstiges'),
  357. ]
  358. FREIANGEBOT = [
  359. ('Dachterrasse', 'Dachterrasse'),
  360. ('Beete', 'Beete'),
  361. ('Kinderspielplatz', 'Kinderspielplatz'),
  362. ]
  363. @property
  364. def kind_of_product(self):
  365. return "Wohnprojekt"
  366. eigentum = CharField ( 'Rechtliche Konstruktion', max_length = 6, choices=EIGENTUM, default='GEMIET', help_text="Rechtliche Konstruktion", null = True, blank=True )
  367. inseratstext = TextField ( 'Inseratstext', max_length = 1024, help_text="Inseratstext", null = True, blank=True )
  368. altneu = CharField ( 'Altbau/Neubau', max_length = 4, choices=ALTNEU, help_text="Altbau/Neubau", null = True, blank=False )
  369. schwerpunkt = CharField ( 'Inhaltlicher Schwerpunkt', max_length = 1024, help_text="Inhaltlicher Schwerpunkt", null = True, blank=True )
  370. wohnbaufoerderung = CharField ( 'Wohnbauförderung', max_length = 1024, choices=WOHNBAUFOERDERUNG, help_text="Wohnbauförderung", null = True, blank=True )
  371. artmodell = TextField ( 'Art der Modells', max_length = 2048, choices=ARTMODELL, help_text="Art der Modells", null = True, blank=True )
  372. bautraeger = TextField ( 'Bauträger', max_length = 2048, choices=BAUTRAEGER, help_text="Bauträger", null = True, blank=True )
  373. aerwachsene = IntegerField( 'Anzahl an Erwachsenen', help_text="Anzahl an Erwachsenen", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
  374. akinder = IntegerField( 'Anzahl an Kinder', help_text="Anzahl an Kinder", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
  375. @property
  376. def amitglieder(self):
  377. return self.aerwachsene + self.akinder
  378. awohnungen = IntegerField( 'Anzahl an Wohnungen', help_text="Anzahl an Wohnungen", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
  379. wohnflaeche = IntegerField( 'Wohnfläche', help_text="Wohnfläche", validators=[MinValueValidator(0)], default = 0, null = True, )
  380. gewerbeflaechen = IntegerField( 'Gewerbeflächen', help_text="Gewerbeflächen", validators=[MinValueValidator(0)], default = 0, null = True, )
  381. gemeinschaftsflaeche = IntegerField( 'Gemeinschaftsflächen', help_text="Gemeinschaftsflächen", validators=[MinValueValidator(0)], default = 0, null = True, )
  382. sonstige_flaechen = IntegerField( 'Sonstige Flächen', help_text="Sonstige Flächen", validators=[MinValueValidator(0)], default = 0, null = True, )
  383. @property
  384. def flaeche(self):
  385. return self.wohnflaeche + self.gewerbeflaechen + self.gemeinschaftsflaeche + self.sonstige_flaechen
  386. kflaechen = CharField ( 'Flächen - Kommentar', max_length = 1024, help_text="Flächen - Kommentar", null = True, blank=True )
  387. gemeinschaftr = MultiSelectField ( 'Gemeinschaftsräume', max_length = 1024, choices=GEMEINSCHAFTR, help_text="Gemeinschaftsräume", null = True, blank=True )
  388. kgemeinschaftr = CharField ( 'Gemeinschaftsräume - Sonstiges', max_length = 1024, help_text="Gemeinschaftsräume - Sonstiges", null = True, blank=True )
  389. sonderwohnformen = CharField ( 'Sonderwohnformen', max_length = 1024, help_text="Sonderwohnformen, z.B. Wohncluster, WGs, Sonstiges", null = True, blank=True )
  390. raumangebot = MultiSelectField ( 'Raumangebot nach Außen', max_length = 1024, choices=RAUMANGEBOT, help_text="Raumangebot nach Außen", null = True, blank=True )
  391. kraumangebot = CharField ( 'Raumangebot nach Außen - Sonstiges', max_length = 1024, help_text="Raumangebot nach Außen - Sonstiges", null = True, blank=True )
  392. parbeiten = IntegerField ( 'Wie viele Personen arbeiten im Haus', help_text="Wie viele Personen arbeiten im Haus", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
  393. karbeiten = CharField ( 'Wie viele Personen arbeiten im Haus - Kommentar', max_length = 1024, help_text="Kommentar", null = True, blank=True )
  394. bauweise = CharField ( 'Bauweise', max_length = 64, choices=BAUWEISE, help_text="Bauweise", null = True, blank=True )
  395. zielgruppen = CharField ( 'Besondere Zielgruppen', max_length = 64, choices=ZIELGRUPPEN, help_text="Besondere Zielgruppen", null = True, blank=True )
  396. gprojekte = CharField ( 'Gemeinschaftliche Projekte', max_length = 64, choices=GPROJEKTE, help_text="Gemeinschaftliche Projekte", null = True, blank=True )
  397. oekologie = CharField ( 'Ökologie', max_length = 1024, help_text="Ökologie", null = True, blank=True )
  398. freiraumangebote = CharField ( 'Freiraumangebote', max_length = 64, choices=FREIANGEBOT, help_text="Freiraumangebote", null = True, blank=False )
  399. gaestwohnungen = IntegerField ( 'Anzahl an Gästewohnungen', help_text="Anzahl an Gästewohnungen", validators=[MinValueValidator(0)], default = 0 )
  400. class Link(models.Model):
  401. product = ForeignKey(Product, on_delete=models.CASCADE)
  402. link_description = CharField(null=True, blank=True, max_length = 2048)
  403. link = URLField(null=True, blank=True, max_length = 2048)
  404. def product_path(instance, filename):
  405. return 'marktplatz/media/{0}/{1}'.format(instance.product.id, filename)
  406. class Media(models.Model):
  407. fs = FileSystemStorage(location=settings.MEDIA_ROOT)
  408. product = ForeignKey(Product, on_delete=models.CASCADE)
  409. name_for = CharField(blank = True,max_length = 256)
  410. filename = CharField(max_length = 100)
  411. copyright = CharField(blank=True, max_length = 100)
  412. image = ImageField(upload_to=product_path,storage=fs)
  413. image_small = ProcessedImageField(upload_to=product_path,
  414. processors=[ResizeToCover(640, 360)],
  415. format='JPEG',
  416. options={'quality': 90})
  417. image_medium= ProcessedImageField(upload_to=product_path,
  418. processors=[ResizeToCover(960, 540)],
  419. format='JPEG',
  420. options={'quality': 90})
  421. image_big = ProcessedImageField(upload_to=product_path,
  422. processors=[ResizeToCover(1920, 1080)],
  423. format='JPEG',
  424. options={'quality': 90})
  425. image_norm = ProcessedImageField(upload_to=product_path,
  426. processors=[Thumbnail(640, 360)],
  427. format='JPEG',
  428. options={'quality': 90},
  429. blank = True,
  430. null = True)
  431. def filename(self):
  432. return os.path.basename(self.image.name).split('.')[0]
  433. # These two auto-delete files from filesystem when they are unneeded:
  434. #
  435. @receiver(models.signals.post_delete, sender=Media)
  436. def auto_delete_file_on_delete(sender, instance, **kwargs):
  437. """
  438. Deletes file from filesystem
  439. when corresponding `MediaFile` object is deleted.
  440. """
  441. if instance.image:
  442. if os.path.isfile(instance.image.path):
  443. os.remove(instance.image.path)
  444. #
  445. if instance.image_small:
  446. if os.path.isfile(instance.image_small.path):
  447. os.remove(instance.image_small.path)
  448. #
  449. if instance.image_medium:
  450. if os.path.isfile(instance.image_medium.path):
  451. os.remove(instance.image_medium.path)
  452. #
  453. if instance.image_big:
  454. if os.path.isfile(instance.image_big.path):
  455. os.remove(instance.image_big.path)
  456. #
  457. if instance.image_norm:
  458. if os.path.isfile(instance.image_norm.path):
  459. os.remove(instance.image_norm.path)
  460. #
  461. #print(settings.MEDIA_ROOT+'/marktplatz/media/{0}/{1}'.format(instance.Product.id, instance.image.name))
  462. #print(instance.Product.id, instance.image.path)
  463. #os.remove(settings.MEDIA_ROOT+'/marktplatz/media/{0}/{1}_big'.format(instance.Product.id, instance.filename))
  464. #os.remove(settings.MEDIA_ROOT+'/marktplatz/media/{0}/{1}.jpg'.format(instance.Product.id, instance.image.name))
  465. #@receiver(models.signals.pre_save, sender=Media)
  466. #def auto_delete_file_on_change(sender, instance, **kwargs):
  467. # """
  468. # Deletes old file from filesystem
  469. # when corresponding `MediaFile` object is updated
  470. # with new file.
  471. # """
  472. # if not instance.pk:
  473. # return False
  474. #
  475. # try:
  476. # old_file = Media.objects.get(pk=instance.pk).image
  477. # except Media.DoesNotExist:
  478. # return False
  479. #
  480. # new_file = instance.image
  481. # if not old_file == new_file:
  482. # if os.path.isfile(old_file.path):
  483. # os.remove(old_file.path)
  484. #
  485. # try:
  486. # old_file = Media.objects.get(pk=instance.pk).image_small
  487. # except Media.DoesNotExist:
  488. # return False
  489. #
  490. # new_file = instance.image_small
  491. # if not old_file == new_file:
  492. # if os.path.isfile(old_file.path):
  493. # os.remove(old_file.path)
  494. #
  495. # try:
  496. # old_file = Media.objects.get(pk=instance.pk).image_medium
  497. # except Media.DoesNotExist:
  498. # return False
  499. #
  500. # new_file = instance.image_medium
  501. # if not old_file == new_file:
  502. # if os.path.isfile(old_file.path):
  503. # os.remove(old_file.path)
  504. #
  505. # try:
  506. # old_file = Media.objects.get(pk=instance.pk).image_big
  507. # except Media.DoesNotExist:
  508. # return False
  509. #
  510. # new_file = instance.image_big
  511. # if not old_file == new_file:
  512. # if os.path.isfile(old_file.path):
  513. # os.remove(old_file.path)
  514. #
  515. # try:
  516. # old_file = Media.objects.get(pk=instance.pk).image_norm
  517. # except Media.DoesNotExist:
  518. # return False
  519. #
  520. # new_file = instance.image_norm
  521. # if not old_file == new_file:
  522. # if os.path.isfile(old_file.path):
  523. # os.remove(old_file.path)
  524. #
  525. class Video(models.Model):
  526. product = ForeignKey(Product, on_delete=models.CASCADE)
  527. name_for = CharField(blank=True, max_length=256)
  528. filename = CharField(max_length=100)
  529. copyright = CharField(blank=True, max_length=100)
  530. image = FileField(upload_to=product_path)
  531. @receiver(models.signals.post_delete, sender=Video)
  532. def auto_delete_video_on_delete(sender, instance, **kwargs):
  533. """
  534. Deletes file from filesystem
  535. when corresponding `MediaFile` object is deleted.
  536. """
  537. if instance.image:
  538. if os.path.isfile(instance.image.path):
  539. os.remove(instance.image.path)
  540. #@receiver(models.signals.pre_save, sender=Video)
  541. #def auto_delete_video_on_change(sender, instance, **kwargs):
  542. # """
  543. # Deletes old file from filesystem
  544. # when corresponding `MediaFile` object is updated
  545. # with new file.
  546. # """
  547. # if not instance.pk:
  548. # return False
  549. #
  550. # try:
  551. # old_file = Video.objects.get(pk=instance.pk).image
  552. # except Media.DoesNotExist:
  553. # return False
  554. #
  555. # new_file = instance.image
  556. # if not old_file == new_file:
  557. # if os.path.isfile(old_file.path):
  558. # os.remove(old_file.path)
  559. class Vote(models.Model):
  560. product = ForeignKey(Product, on_delete=models.CASCADE)
  561. juryMember = ForeignKey(User, on_delete = models.CASCADE)
  562. vote = PositiveSmallIntegerField(default=0)
  563. comment = CharField(blank=True, max_length =300)
  564. def __iter__(self):
  565. for field in self._meta.fields:
  566. yield (field.verbose_name, field.value_to_string(self))