| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- from django.db import models
- from django.core.validators import MinValueValidator, MaxValueValidator
- from django.contrib.auth.models import User
- from imagekit.models import ImageSpecField
- from imagekit.processors import ResizeToFill
- from imagekit.processors import ResizeToCover
- from imagekit.processors import Thumbnail
- from imagekit.processors import ResizeToCover
- from imagekit.models import ProcessedImageField
- from django.core.files.storage import FileSystemStorage
- from django_countries.fields import CountryField
- import os
- import uuid
- from django.db import models
- from django.dispatch import receiver
- from django.db.models.signals import post_delete, post_save
- from django.conf import settings
- import datetime
- import shutil
- class Credit(models.Model):
- owner = models.CharField(verbose_name='Building or Product owner',blank=True,max_length = 300)
- architecture = models.CharField(verbose_name='Architecture',blank=True,max_length = 300)
- concept = models.CharField(verbose_name='Product artist/ concept/ design/ planning',blank=True,max_length = 300)
- structural_engeneering = models.CharField(verbose_name='Structural engineering',blank=True,max_length = 300)
- facade_design = models.CharField(verbose_name='Facade design',blank=True,max_length = 300)
- face_construction = models.CharField(verbose_name='Facade construction',blank=True,max_length = 300)
- kinetic_design = models.CharField(verbose_name='Kinetic engineering',blank = True,max_length = 300)
- light_design = models.CharField(verbose_name='Light design',blank = True,max_length = 300)
- tecnical_layout = models.CharField(verbose_name='Technical layout light',blank = True,max_length = 300)
- display_content = models.CharField(verbose_name='Display content/ visuals/ showreel',blank = True,max_length = 300)
- light_hardware = models.CharField(verbose_name='Light hardware (LED hardware)',blank = True,max_length = 300)
- lightning_software = models.CharField(verbose_name='Lighting control software',blank = True,max_length = 300)
- Product_coordination = models.CharField(verbose_name='Product co-ordination',blank = True,max_length = 300)
- membrane_skin = models.CharField(verbose_name='Membrane skin',blank = True,max_length = 300)
- interaction_design = models.CharField(verbose_name='Interaction design/ programming',blank = True,max_length = 300)
- sponsor = models.CharField(verbose_name='Product sponsor/ support',blank = True,max_length = 500)
- module_elems = models.CharField(verbose_name='Pixel or other basic module/ elements',blank = True,max_length = 300)
- def __iter__(self):
- for field in self._meta.fields:
- if field.value_to_string(self) is not '-' and field.value_to_string(self) is not 'N/A':
- yield (field.verbose_name, field.value_to_string(self))
- class Description(models.Model):
- facade = models.TextField(verbose_name='Facade type and geometry (structure)',blank = True,max_length = 900)
- light_creation = models.TextField(verbose_name='Kind of light creation',blank = True,max_length = 900)
- resolution = models.TextField(verbose_name='Resolution and transmitting behaviour',blank = True,max_length = 900)
- pixel_distance = models.CharField(verbose_name='Pixel distance',blank = True,max_length = 300)
- luminance = models.TextField(verbose_name='Luminace',blank = True,max_length = 900)
- urban_situation = models.TextField(verbose_name='Urban situation',blank = True,max_length = 900)
- description_showreel = models.TextField(verbose_name='Description of showreel',blank = True,max_length = 900)
- def __iter__(self):
- for field in self._meta.fields:
- if (field.value_to_string(self) is not '-') and (field.value_to_string(self) is not 'N/A'):
- yield (field.verbose_name, field.value_to_string(self))
- class Interaction(models.Model):
- communtity = models.TextField(verbose_name='Community or communities involved',blank = True,max_length = 900)
- host = models.CharField(verbose_name='Host organization',blank = True,max_length = 900)
- legal_form = models.CharField(verbose_name='Legal form',blank=True,max_length = 900)
- issues = models.TextField(verbose_name='Issues addressed',blank = True,max_length = 900)
- impact = models.TextField(verbose_name='Impact',blank = True,max_length = 900)
- tools = models.TextField(verbose_name='Tools developed',blank = True,max_length = 900)
- tools_used = models.TextField(verbose_name='Tools used',blank = True,max_length = 900)
- next_steps = models.TextField(verbose_name='Next steps',blank = True,max_length = 900)
- def __iter__(self):
- for field in self._meta.fields:
- if (field.value_to_string(self) is not '-') and (field.value_to_string(self) is not 'N/A'):
- yield (field.verbose_name, field.value_to_string(self))
- class Contact(models.Model):
- user = models.OneToOneField(User, on_delete=models.CASCADE,blank=True)
- first_name = models.CharField(verbose_name="Vorname", max_length = 100)
- last_name = models.CharField(verbose_name="Nachname", max_length = 100)
- adress = models.CharField(verbose_name="Adresse", blank=True,max_length = 100)
- postcode = models.CharField(verbose_name="Postleitzahl", blank=True, max_length = 100)
- city = models.CharField(verbose_name="Stadt", blank=True,max_length = 100)
- country = models.CharField(verbose_name="Land", blank=True,max_length = 100)
- email = models.EmailField(verbose_name="E-Mail-Addresse", unique=True)
- phonenumber = models.CharField(verbose_name="1. Telefonnummer", blank=True,max_length = 100)
- alternate_phonenumber = models.CharField(verbose_name="2. Telefonnummer", blank = True,max_length = 100)
- skype_name = models.CharField(verbose_name="Skype", blank=True,max_length = 300)
- website = models.URLField(verbose_name="Website", blank=True)
- def __str__(self):
- return self.first_name + ' ' + self.last_name
- def __iter__(self):
- for field in self._meta.fields:
- yield (field.verbose_name, field.value_to_string(self))
- class Category(models.Model):
- name = models.CharField(max_length=100)
- short_name = models.CharField(max_length=10)
- def __str__(self):
- return self.name
- class Product(models.Model):
- STATUS = [
- ('ENT', 'Entwicklung'),
- ('BET', 'In Betrieb'),
- ('ABG', 'Abgeschlossen'),
- ]
- FREI = [
- ('JAJA', 'Ja, bitte melden'),
- ('WART', 'Nein, aber es gibt eine Warteliste'),
- ('NEIN', 'Nein und es gibt keine Warteliste'),
- ]
- RECHTSFORM = [
- ('GMBH', 'GmbH'),
- ('VERE', 'Verein'),
- ('ANDE', 'Adere'),
- ]
- ORT = [
- ('1010', '1., Innere Stadt'),
- ('1020', '2., Leopoldstadt'),
- ('1030', '3., Landstraße'),
- ('1040', '4., Wieden'),
- ('1050', '5., Margareten'),
- ('1060', '6., Mariahilf'),
- ('1070', '7., Neubau'),
- ('1080', '8., Josefstadt'),
- ('1090', '9., Alsergrund'),
- ('1100', '10., Favoriten'),
- ('1110', '11., Simmering'),
- ('1120', '12., Meidling'),
- ('1130', '13., Hietzing'),
- ('1140', '14., Penzing'),
- ('1150', '15., Rudolfsheim-Fünfhaus'),
- ('1160', '16., Ottakring'),
- ('1170', '17., Hernals'),
- ('1180', '18., Währing'),
- ('1190', '19., Döbling'),
- ('1200', '20., Brigittenau'),
- ('1210', '21., Floridsdorf'),
- ('1220', '22., Donaustadt'),
- ('1230', '23., Liesing'),
- ('GERM', 'Deutschland'),
- ('SCHW', 'Schweiz'),
- ('GERM', 'Germany'),
- ('GERM', 'Germany'),
- ('VORA', 'Vorarlberg'),
- ('TIRO', 'Tirol'),
- ('SALZ', 'Salzburg'),
- ('KAER', 'Kärnten'),
- ('STEI', 'Steiermark'),
- ('OBER', 'Oberösterreich'),
- ('NIER', 'Niederösterreich'),
- ('BURG', 'Burgenland'),
- ('WELT', 'Welt'),
- ]
- ORGANIZATION = [
- ('SOZ', 'Soziokratie'),
- ('SON', 'Sonstiges'),
- ]
- name = models.CharField( 'Name', max_length = 128, help_text="Name des Projekts", null = True, blank=True )
- claim = models.CharField( 'Claim / Untertitel', max_length = 256, help_text="Claim / Untertitel", null = True, blank=True )
- beschreibung = models.CharField( 'Beschreibung', max_length = 256, help_text="Beschreibung des Projektes", null = True, blank=True )
- learning = models.CharField( 'Learning', max_length = 256, help_text="Learning", null = True, blank=True )
- gruendungsjahr = models.IntegerField('Gründungsjahr', help_text="Gründungsjahr des Projekts", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
- betriebgenommen = models.IntegerField('in Betrieb genommen in Jahr', help_text="Wann wurde das Projekt in Betrieb genommen?", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
- status = models.CharField( 'Status', max_length = 3, choices=STATUS, default='ENT', help_text="Was ist der Status des Projektes" , null = True, blank=True )
- adresse = models.CharField( 'Adresse', max_length = 256, help_text="Adresse des Projektes", null = True, blank=True )
- website = models.URLField ( 'Website', max_length = 2048, help_text="Website des des Projektes", null = True, blank=True )
- frei = models.CharField( 'Platz frei', max_length = 4, choices=FREI, default='NEIN', help_text="Gibt es freie Plätze?", null = True, blank=True )
- mitmachen = models.BooleanField( 'Mitmachen möglich', default=False, help_text="Kann jemand mitmachen?", null = True, blank=True )
- rechtsform = models.CharField( 'Rechtsform', max_length = 4, choices=RECHTSFORM, default='ANDE', help_text="Rechtsform des Projektes", null = True, blank=True )
- ort = models.CharField( 'Ort', max_length = 4, choices=ORT, default='WELT', help_text="Ort des Projektes", null = True, blank=True )
- orga = models.CharField( 'Organisationsform', max_length = 3, choices=ORGANIZATION, default='SON', help_text="Organisationsform des Projektes", null = True, blank=True )
- title = models.CharField('Product Title',max_length = 100)
- country = CountryField(blank=True,multiple=True, help_text="")
- city = models.CharField(max_length = 100,null = True, blank=True, help_text="")
- year = models.IntegerField('Year of Completion',null = True, blank=True, help_text="")
- owner = models.CharField(max_length = 300,null = True,blank=True, help_text="")
- teaser_txt = models.TextField(blank = True, max_length = 1050, help_text="")
- header = models.CharField(max_length = 900,null = True, help_text="")
- description_txt = models.TextField(max_length = 3000,null = True, help_text="")
- cid = models.IntegerField(null = True,blank=True, help_text="")
- class_cid = models.CharField(null = True,max_length = 3, blank=True, help_text="")
- sumbitted = models.CharField(null = True,max_length = 10, blank=True, help_text="")
- date_submitted = models.DateField(auto_now_add=True, help_text="")
- terms = models.NullBooleanField(help_text="")
- edit = models.NullBooleanField(help_text="")
- public = models.NullBooleanField(help_text="")
- photo = models.CharField(max_length=500, null=True, blank=True, help_text="")
- videocts = models.CharField(max_length=500, null=True, blank=True, help_text="")
- category = models.ManyToManyField(Category, null=True, help_text="")
- credits = models.ForeignKey(Credit, null = True,on_delete=models.SET_NULL, help_text="")
- description = models.ForeignKey(Description,null = True, on_delete=models.SET_NULL, help_text="")
- contact = models.ForeignKey(Contact, null = True,on_delete=models.SET_NULL, help_text="")
- interaction = models.ForeignKey(Interaction, null = True,on_delete = models.SET_NULL, help_text="")
- def __str__(self):
- return str(self.title)
- def __iter__(self):
- for field in self._meta.fields:
- yield (field.verbose_name, field.value_to_string(self))
- class Wohnprojekt(Product):
- BAUWEISE = [
- ('HOLZ', 'Holzbau'),
- ('ALTB', 'Altbau'),
- ('NEUB', 'Neubau'),
- ]
- EIGENTUM = [
- ('GEMIET', 'Generalmiete'),
- ('WOHNHM', 'Wohnheim'),
- ('EIGENT', 'Eigentum'),
- ('GTMIET', 'Getrennte Mietvertäge (Verein mietet GR)'),
- ]
- UNTERST = [
- ('GEFOR', 'Gefördert'),
- ('NICHT', 'Nicht Gefördert'),
- ]
- anzahlmitglieder = models.IntegerField('Anzahl der Mitglieder', help_text="Anzahl der Mitglieder", null = True, blank=True )
- eigentum = models.CharField( 'Rechtliche Konstruktion', max_length = 6, choices=EIGENTUM, default='GEMIET', help_text="Rechtliche Konstruktion", null = True, blank=True )
- @receiver(post_delete, sender=Product)
- def auto_delete_reverse_keys(sender, instance, **kwargs):
- if instance.credits:
- instance.credits.delete()
- if instance.description:
- instance.description.delete()
- if instance.interaction:
- instance.interaction.delete()
- class Link(models.Model):
- Product = models.ForeignKey(Product, on_delete=models.CASCADE)
- link_description = models.CharField(null=True, blank=True, max_length = 2048)
- link = models.URLField(null=True, blank=True, max_length = 2048)
- def Product_path(instance, filename):
- return 'marktplatz/media/{0}/{1}'.format(instance.Product.id, filename)
- class Media(models.Model):
- fs = FileSystemStorage(location=settings.MEDIA_ROOT)
- Product = models.ForeignKey(Product, on_delete=models.CASCADE)
- name_for = models.CharField(blank = True,max_length = 256)
- filename = models.CharField(max_length = 100)
- copyright = models.CharField(blank=True, max_length = 100)
- image = models.ImageField(upload_to=Product_path,storage=fs)
- image_small = ProcessedImageField(upload_to=Product_path,
- processors=[ResizeToCover(640, 360)],
- format='JPEG',
- options={'quality': 90})
- image_medium= ProcessedImageField(upload_to=Product_path,
- processors=[ResizeToCover(960, 540)],
- format='JPEG',
- options={'quality': 90})
- image_big = ProcessedImageField(upload_to=Product_path,
- processors=[ResizeToCover(1920, 1080)],
- format='JPEG',
- options={'quality': 90})
- image_norm = ProcessedImageField(upload_to=Product_path,
- processors=[Thumbnail(640, 360)],
- format='JPEG',
- options={'quality': 90},
- blank = True,
- null = True)
- def filename(self):
- return os.path.basename(self.image.name).split('.')[0]
- # These two auto-delete files from filesystem when they are unneeded:
- #
- @receiver(models.signals.post_delete, sender=Media)
- def auto_delete_file_on_delete(sender, instance, **kwargs):
- """
- Deletes file from filesystem
- when corresponding `MediaFile` object is deleted.
- """
- if instance.image:
- if os.path.isfile(instance.image.path):
- os.remove(instance.image.path)
- #
- if instance.image_small:
- if os.path.isfile(instance.image_small.path):
- os.remove(instance.image_small.path)
- #
- if instance.image_medium:
- if os.path.isfile(instance.image_medium.path):
- os.remove(instance.image_medium.path)
- #
- if instance.image_big:
- if os.path.isfile(instance.image_big.path):
- os.remove(instance.image_big.path)
- #
- if instance.image_norm:
- if os.path.isfile(instance.image_norm.path):
- os.remove(instance.image_norm.path)
- #
- #print(settings.MEDIA_ROOT+'/marktplatz/media/{0}/{1}'.format(instance.Product.id, instance.image.name))
- #print(instance.Product.id, instance.image.path)
- #os.remove(settings.MEDIA_ROOT+'/marktplatz/media/{0}/{1}_big'.format(instance.Product.id, instance.filename))
- #os.remove(settings.MEDIA_ROOT+'/marktplatz/media/{0}/{1}.jpg'.format(instance.Product.id, instance.image.name))
- #@receiver(models.signals.pre_save, sender=Media)
- #def auto_delete_file_on_change(sender, instance, **kwargs):
- # """
- # Deletes old file from filesystem
- # when corresponding `MediaFile` object is updated
- # with new file.
- # """
- # if not instance.pk:
- # return False
- #
- # try:
- # old_file = Media.objects.get(pk=instance.pk).image
- # except Media.DoesNotExist:
- # return False
- #
- # new_file = instance.image
- # if not old_file == new_file:
- # if os.path.isfile(old_file.path):
- # os.remove(old_file.path)
- #
- # try:
- # old_file = Media.objects.get(pk=instance.pk).image_small
- # except Media.DoesNotExist:
- # return False
- #
- # new_file = instance.image_small
- # if not old_file == new_file:
- # if os.path.isfile(old_file.path):
- # os.remove(old_file.path)
- #
- # try:
- # old_file = Media.objects.get(pk=instance.pk).image_medium
- # except Media.DoesNotExist:
- # return False
- #
- # new_file = instance.image_medium
- # if not old_file == new_file:
- # if os.path.isfile(old_file.path):
- # os.remove(old_file.path)
- #
- # try:
- # old_file = Media.objects.get(pk=instance.pk).image_big
- # except Media.DoesNotExist:
- # return False
- #
- # new_file = instance.image_big
- # if not old_file == new_file:
- # if os.path.isfile(old_file.path):
- # os.remove(old_file.path)
- #
- # try:
- # old_file = Media.objects.get(pk=instance.pk).image_norm
- # except Media.DoesNotExist:
- # return False
- #
- # new_file = instance.image_norm
- # if not old_file == new_file:
- # if os.path.isfile(old_file.path):
- # os.remove(old_file.path)
- #
- class Video(models.Model):
- Product = models.ForeignKey(Product, on_delete=models.CASCADE)
- name_for = models.CharField(blank=True, max_length=256)
- filename = models.CharField(max_length=100)
- copyright = models.CharField(blank=True, max_length=100)
- image = models.FileField(upload_to=Product_path)
- @receiver(models.signals.post_delete, sender=Video)
- def auto_delete_video_on_delete(sender, instance, **kwargs):
- """
- Deletes file from filesystem
- when corresponding `MediaFile` object is deleted.
- """
- if instance.image:
- if os.path.isfile(instance.image.path):
- os.remove(instance.image.path)
- #@receiver(models.signals.pre_save, sender=Video)
- #def auto_delete_video_on_change(sender, instance, **kwargs):
- # """
- # Deletes old file from filesystem
- # when corresponding `MediaFile` object is updated
- # with new file.
- # """
- # if not instance.pk:
- # return False
- #
- # try:
- # old_file = Video.objects.get(pk=instance.pk).image
- # except Media.DoesNotExist:
- # return False
- #
- # new_file = instance.image
- # if not old_file == new_file:
- # if os.path.isfile(old_file.path):
- # os.remove(old_file.path)
- class Vote(models.Model):
- Product = models.ForeignKey(Product, on_delete=models.CASCADE)
- juryMember = models.ForeignKey(User, on_delete = models.CASCADE)
- vote = models.PositiveSmallIntegerField(default=0)
- comment = models.CharField(blank=True, max_length =300)
- def __iter__(self):
- for field in self._meta.fields:
- yield (field.verbose_name, field.value_to_string(self))
|