class RecipeSource(EmbeddedMongoModel): name = fields.CharField() url = fields.URLField() image = fields.ImageField()
class RecipeActualization(MongoModel): photos = fields.ListField(fields.ImageField()) date_made = fields.DateTimeField() note_content = fields.CharField() made_by = fields.ReferenceField(User)
class PreDigitalPhoto(MongoModel): datetime_added = fields.DateTimeField() front_reproductions = fields.ListField(fields.ImageField(), blank=True) back_reproductions = fields.ListField(fields.ImageField(), blank=True) front_marking = fields.CharField(blank=True) back_marking = fields.CharField(blank=True) fuzzy_location = fields.EmbeddedModelField(FuzzyLocation, blank=True) fuzzy_datetime = fields.EmbeddedModelField(FuzzyDateTime, blank=True) notes = fields.EmbeddedModelListField(PreDigitalPhotoNote, blank=True) people = fields.ListField(fields.ReferenceField(Person), blank=True) class Meta: connection_alias = 'pre-digital-photos-connection' collection_name = 'photos'
class MAutore(MongoModel): #Titolo TITLES = ( ('Mr', 'Sig'), ('Mrs', 'Signora'), ('Dott', 'Dottore'), ('Dott.ssa', 'Dottoressa'), ('Prof', 'Professore'), ('Prof.ssa', 'Professoressa'), ) #Genere GENERE = ( ('male', 'Maschio'), ('female', 'Femmina'), ) #Lingua LINGUA = ( ('IT - Italiano', 'Italiano'), ('EN - Inglese', 'Inglese'), ('FR - Francese', 'Francese'), ('DE - Tedesco', 'Tedesco'), ('SP - Spagnolo', 'Spagnolo'), ('PT - Portoghese', 'Portoghese'), ) # === Campi === titolo = fields.CharField(max_length=20, choices=TITLES, blank=True) #Il titolo può essere vuoto cognome = fields.CharField(max_length=60, default='', help_text='Family name') nome = fields.CharField(max_length=60, default='', help_text='Name') nascita = fields.DateField(default='01/01/1900', blank=True, null=True, help_text='01/01/1988') #Dati di nascita della persona luogo_nascita = fields.CharField(max_length=100, blank=False, default='') stato_nascita = fields.CharField(max_length=100, blank=False, default='') genere = fields.CharField(max_length=10, choices=GENERE, default='') #Dati residenza autore indirizzo = fields.CharField(max_length=100, default='') citta = fields.CharField(max_length=100, default='') provincia = fields.CharField(max_length=60, default='') stato = fields.CharField(max_length=60, default='') zip_code = fields.CharField(max_length=60, default='') telefono = PhoneNumberField(default='', help_text='+393477093239 o 003321128832', blank=True, null=True) mobile = PhoneNumberField(default='', help_text='+393477093239 o 003321128832', blank=True, null=True) mail = fields.EmailField(max_length=100, default='', blank=True, null=True, unique=True) website = fields.CharField(default='', max_length=100, help_text='sitoweb www', blank=True, null=True) lingua = fields.CharField(default='IT', choices=LINGUA, blank=False, null=False, max_length=60) imagefile = fields.ImageField(db_column='imagefile', upload_to='pic_folder/autori', blank=True, help_text='immagine autore se presente') #history = HistoricalRecords() #Strutture accessorie #nome del record collegato alla vista del modello def __str__(self): return self.cognome + " " + self.nome class Meta: verbose_name_plural = "Autori" # === url === def url(self): # returns a URL for either internal stored or external image url if self.externalURL: return self.externalURL else: # is this the best way to do this?? return os.path.join('/', settings.MEDIA_URL, os.path.basename(str(self.image))) # === unicode === def __unicode__(self): return self.image.url # === str === def __str__(self): return self.cognome + " " + self.nome def image_(self): return u'<a href="/media/{0}" target="_blank"><img src="/media/{0}" style="max-width:150px;height:auto"></a>'.format( self.imagefile) image_.allow_tags = True def save_low(self, force_insert=False, force_update=False): self.cognome = self.cognome.capitalize() self.nome = self.nome.capitalize() super(MAutore, self).save(force_insert, force_update)
class MImmagini(MongoModel): """ Modello per la memorizzaizione dei dati, immagini delle opere d'arte. """ #Record base datestamp = fields.DateTimeField(auto_now_add=True) #Modello dati titolo = fields.ForeignKey('Opera', on_delete=fields.CASCADE, default='', blank=True, related_name="img_titolo_opera", null=True) commento = fields.TextField(default="", help_text="breve commento all'opera o note", blank=True) imagefile = fields.ImageField(db_column='imagefile', upload_to='pic_folder/opere', blank=True, default="logo_no_image.png") imagefile1 = fields.ImageField(db_column='imagefile1', upload_to='pic_folder/opere/im1', blank=True) imagefile2 = fields.ImageField(db_column='imagefile2', upload_to='pic_folder/opere/im2', blank=True) preview = fields.ImageField(db_column='preview', upload_to='pic_folder/opere/preview', blank=True) preview1 = fields.ImageField(db_column='preview1', upload_to='pic_folder/opere/preview1', blank=True) metainfo = fields.TextField(default='', blank=True) #history = HistoricalRecords() #Strutture accessorie def url(self): # returns a URL for either internal stored or external image url if self.externalURL: return self.externalURL else: return os.path.join('/', settings.MEDIA_URL, os.path.basename(str(self.imagefile))) def __unicode__(self): return self.imagefile.url def __str__(self): if (self.titolo): return self.titolo.posizione_archivio + " - " + self.titolo.autore.cognome + " - " + self.titolo.titolo_opera + " / " + self.titolo.anno_realizzazione.__str__( ) # self.titolo.titolo_opera else: return "RIFERIMENTO VUOTO" def image_(self): return mark_safe( '<a href="/media/{0}"><img src="/media/{0}" style="max-width:150px;height:auto"></a>' .format(self.preview)) image_.allow_tags = True def image_meta_(self): image_meta = PIL.Image.open(self.imagefile) weight = self.imagefile.file.size weight = weight / 1024 dpi = "" if image_meta: size = image_meta.size if hasattr(image_meta.info, 'dpi'): dpi = image_meta.info['dpi'] else: dpi = "Non presente" return mark_safe('Dimensione immagine:{0}x{1} DPI:{2} {3} KB'.format( size[0], size[1], dpi, round(weight))) def make_thumbnail(self): # original code for this method came from # http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/ # If there is no image associated with this. # do not create thumbnail if not self.imagefile: return from PIL import Image from io import StringIO from django.core.files.uploadedfile import SimpleUploadedFile import os # Set our max thumbnail size in a tuple (max width, max height) THUMBNAIL_SIZE = (400, 400) PIL_TYPE = 'tiff' FILE_EXTENSION = 'tiff' ''' DJANGO_TYPE = self.imagefile.file.content_type if DJANGO_TYPE == 'image/jpeg': PIL_TYPE = 'jpeg' FILE_EXTENSION = 'jpg' elif DJANGO_TYPE == 'image/png': PIL_TYPE = 'png' FILE_EXTENSION = 'png' elif DJANGO_TYPE == 'image/tiff': ''' # Open original photo which we want to thumbnail using PIL's Image image = Image.open("media/" + self.imagefile.name) # We use our PIL Image object to create the thumbnail, which already # has a thumbnail() convenience method that contrains proportions. # Additionally, we use Image.ANTIALIAS to make the image look better. # Without antialiasing the image pattern artifacts may result. image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS) # Save the thumbnail temp_handle = BytesIO() image.save(temp_handle, PIL_TYPE) temp_handle.seek(0) # Save image to a SimpleUploadedFile which can be saved into # ImageField suf = SimpleUploadedFile( os.path.split(self.imagefile.name)[-1], temp_handle.read()) # Save SimpleUploadedFile into image field self.preview.save('%s_thumbnail.%s' % (os.path.splitext(suf.name)[0], FILE_EXTENSION), suf, save=False) image_meta_.allow_tag = True class Meta: verbose_name_plural = "Immagini" def save(self): self.metainfo = self.image_meta_() #creazione immagine anteprima #self.make_thumbnail() super(MImmagini, self).save()