From 2449ade7c0c7849048241a85f72324777258c3d6 Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Wed, 4 Sep 2013 21:17:18 +0530 Subject: [PATCH] get main images --- itf/app/models.py | 20 ++++++++++++++++---- itf/events/models.py | 3 +++ itf/itfprofiles/models.py | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index a1d427a..5961b2b 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -115,6 +115,17 @@ class ItfModel(models.Model): return d + def get_gallery_image(self): + from mediagallery.models import Photo + if self.galleries: + qset = Photo.objects.filter(album__in=self.galleries.all()) + if qset.count() == 0: + return None + else: + return qset[0].image + else: + return None + def get_videos(self): from mediagallery.models import YoutubeVideo @@ -240,10 +251,11 @@ class ItfModel(models.Model): imgfield = self.get_modelextra().default_image if imgfield: - try: - thumb = get_thumbnail(imgfield, size, crop="center").url - except: - thumb = 'http://placehold.it/%s' % size + #try: + thumb = get_thumbnail(imgfield, size, crop="center").url + #except: + # print imgfield.url + # thumb = 'http://placehold.it/%s' % size else: thumb = 'http://placehold.it/%s' % size # Add default image for site return { diff --git a/itf/events/models.py b/itf/events/models.py index e2c06bd..94c7e4a 100644 --- a/itf/events/models.py +++ b/itf/events/models.py @@ -56,6 +56,9 @@ class Event(ItfModel): def get_title(self): return self.__unicode__() + def main_image(self): + return self.image + def get_dict(self): # links = self.connections.all().order_by('link_type') # link_keys = self.connections.all().values_list['link_type'].distinct() diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index c456a53..67d1c58 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -76,6 +76,9 @@ class Person(ItfModel): def get_title(self): return self.__unicode__() + def main_image(self): + return self.image + def get_dict(self): #lconnections = [obj for obj in self.connections.all()] #rconnections = [ obj for obj in PersonPerson.objects.filter(person2=self) @@ -435,6 +438,9 @@ class Production(ItfModel): return True return self.group.user_has_perms(user) + def main_image(self): + return self.get_gallery_image() + def get_people(self): persons = [{"person":self.director, "role":"director", "assoc_type":'production', "assoc_name":self.name }, {"person":self.playwright, "role":"playwright", "assoc_type":'production', "assoc_name":self.name }