From b72228dbb361d3a2cf00688d1ec497f0fdd94114 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 19:54:04 +0530 Subject: [PATCH 01/11] thumbnails --- itf/bestpractices/models.py | 8 ++++++-- .../modules/bestpractices/bestpractice.html | 13 +++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index f1b348d..3768b2a 100644 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -42,7 +42,8 @@ class BestPractice(ItfModel): 'theatre': self.theatre, 'quick_howto': self.quick_howto, 'category': self.category.name, - 'category_id': self.category.id + 'category_id': self.category.id, + 'images': self.get_images() } def list_dict(self): @@ -64,11 +65,14 @@ class BestPractice(ItfModel): def get_images(self): images = [] for i in BestPracticeImage.objects.filter(bestpractice=self): + images.append(i) + ''' images.append({ 'url': i.image.url, 'caption': i.caption, 'thumb': i.get_thumb() }) + ''' return images ''' @@ -93,7 +97,7 @@ class BestPracticeStory(models.Model): def get_dict(self): return { 'text': self.text, - 'image': self.image.url if self.image.name != '' else '' + 'image': self.image if self.image.name != '' else None } class BestPracticeFAQ(ItfModel): diff --git a/itf/templates/modules/bestpractices/bestpractice.html b/itf/templates/modules/bestpractices/bestpractice.html index 2cde61d..ac7c909 100644 --- a/itf/templates/modules/bestpractices/bestpractice.html +++ b/itf/templates/modules/bestpractices/bestpractice.html @@ -1,16 +1,21 @@ +{% load thumbnail %}
{% for s in stories %} Story: {{ s.text }} - + {% thumbnail s.image "100x100" crop="center" as im %} + + {% endthumbnail %}

{% endfor %} Law: {{ law }} {% if law_image %} - + {% thumbnail law_image "100x100" crop="center" as im %} + + {% endthumbnail %} {% endif %}

- Relevance to Theatre: {{ theatre|linebreaks }} - Quick Howto: {{ quick_howto }}

+ Relevance to Theatre: {{ theatre|linebreaksbr }} + Quick Howto: {{ quick_howto|linebreaksbr }}

From 97bef34948dbd77c03e6736f19d378197eb6b23a Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 19:58:48 +0530 Subject: [PATCH 02/11] er, image --- itf/templates/modules/bestpractices/bestpractice.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/itf/templates/modules/bestpractices/bestpractice.html b/itf/templates/modules/bestpractices/bestpractice.html index ac7c909..ed04fad 100644 --- a/itf/templates/modules/bestpractices/bestpractice.html +++ b/itf/templates/modules/bestpractices/bestpractice.html @@ -2,9 +2,11 @@
{% for s in stories %} Story: {{ s.text }} - {% thumbnail s.image "100x100" crop="center" as im %} - - {% endthumbnail %} + {% for img in images %} + {% thumbnail img "100x100" crop="center" as im %} + + {% endthumbnail %} + {% endfor %}

{% endfor %} Law: {{ law }} From 7d690e145d5f55aa8c48b25e8040c21cf69b5a8c Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 20:01:43 +0530 Subject: [PATCH 03/11] ups --- .../modules/bestpractices/bestpractice.html | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/itf/templates/modules/bestpractices/bestpractice.html b/itf/templates/modules/bestpractices/bestpractice.html index ed04fad..cdd6f23 100644 --- a/itf/templates/modules/bestpractices/bestpractice.html +++ b/itf/templates/modules/bestpractices/bestpractice.html @@ -2,11 +2,11 @@
{% for s in stories %} Story: {{ s.text }} - {% for img in images %} - {% thumbnail img "100x100" crop="center" as im %} + {% if s.image %} + {% thumbnail s.image "100x100" crop="center" as im %} {% endthumbnail %} - {% endfor %} + {% endif %}

{% endfor %} Law: {{ law }} @@ -18,6 +18,13 @@

Relevance to Theatre: {{ theatre|linebreaksbr }} Quick Howto: {{ quick_howto|linebreaksbr }}

+ + {% for img in images %} + {% thumbnail img "100x100" crop="center" as im %} + + {% endthumbnail %} + {% endfor %} +
From de9c875013ecd65b1bc1f302a19aaeaf7b8841a2 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 20:06:42 +0530 Subject: [PATCH 04/11] ups --- itf/templates/modules/bestpractices/bestpractice.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itf/templates/modules/bestpractices/bestpractice.html b/itf/templates/modules/bestpractices/bestpractice.html index cdd6f23..7cb410d 100644 --- a/itf/templates/modules/bestpractices/bestpractice.html +++ b/itf/templates/modules/bestpractices/bestpractice.html @@ -20,7 +20,7 @@ Quick Howto: {{ quick_howto|linebreaksbr }}

{% for img in images %} - {% thumbnail img "100x100" crop="center" as im %} + {% thumbnail img.image "100x100" crop="center" as im %} {% endthumbnail %} {% endfor %} From 21b06699cf12aafcb63bade7bb7c89562dcf79e3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 20:09:13 +0530 Subject: [PATCH 05/11] styling --- .../modules/bestpractices/bestpractice.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/itf/templates/modules/bestpractices/bestpractice.html b/itf/templates/modules/bestpractices/bestpractice.html index 7cb410d..4e20b6c 100644 --- a/itf/templates/modules/bestpractices/bestpractice.html +++ b/itf/templates/modules/bestpractices/bestpractice.html @@ -1,7 +1,7 @@ {% load thumbnail %}
{% for s in stories %} - Story: {{ s.text }} + Story: {{ s.text }} {% if s.image %} {% thumbnail s.image "100x100" crop="center" as im %} @@ -9,21 +9,23 @@ {% endif %}

{% endfor %} - Law: {{ law }} + Law: {{ law }} {% if law_image %} {% thumbnail law_image "100x100" crop="center" as im %} {% endthumbnail %} {% endif %}

- Relevance to Theatre: {{ theatre|linebreaksbr }} - Quick Howto: {{ quick_howto|linebreaksbr }}

+ Relevance to Theatre: {{ theatre|linebreaksbr }}

+ Quick Howto: {{ quick_howto|linebreaksbr }}

+
{% for img in images %} {% thumbnail img.image "100x100" crop="center" as im %} - + {% endthumbnail %} {% endfor %} +
From 724bbbd9ca3ea3057cda5be98ea37de61a7fe54b Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 20:57:02 +0530 Subject: [PATCH 06/11] main image code --- itf/app/models.py | 32 +++++++++++++++++++++++++++----- itf/bestpractices/models.py | 3 +++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 7f90a15..819dbcc 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -8,6 +8,7 @@ from django.template.loader import render_to_string from django.contrib.contenttypes.models import ContentType from insidepages.models import ModuleTab, ModelExtra from os.path import exists +from sorl.thumbnail import get_thumbnail def splitSearch(string): ret = [] @@ -45,15 +46,19 @@ class ItfModel(models.Model): return self.get(self.title_field) def get_tab(self): + modelextra = self.get_modelextra() + tab = ModuleTab.objects.filter(model=modelextra)[0] + return tab + + + def get_modelextra(self): try: ctype = ContentType.objects.get(model=self.__class__._meta.module_name) except:#FIXME: ideally catch only MultipleObjectsReturned (figure out where to import that from :/ ) #FUCKING way ugly hack to get clashing model ctype names with django internal models working (get_real_ctypes simply checks, if there are multiple content objects with the same 'module_name', which one is_itf_model, and returns that). ctype = get_real_ctype(self.__class__._meta.module_name) - # modelextra = ModelExtra.objects.filter(model=ctype)[0] modelextra = ctype.modelextra_set.all()[0] - tab = ModuleTab.objects.filter(model=modelextra)[0] - return tab + return modelextra def get_absolute_url(self): return "%s/?tab=%s&object_id=%d" % (self.get_module().get_absolute_url(), self.get_tab().slug, self.id) @@ -68,11 +73,28 @@ class ItfModel(models.Model): def get_main_image(self): + main_image = self.main_image() + if main_image is not None: + imgfield = main_image.image + elif self.get_modelextra().default_image: + imgfield = self.get_modelextra().default_image + else: + imgfield = None + if imgfield is not None: + try: + thumb = get_thumbnail(imgfield, "150x142", crop="center") + except: + thumb = '' + else: + thumb = '' return { - 'url': '', - 'caption': '' + 'thumb': thumb } + + def main_image(self): + return None + def get_template_path(self): kls = self.__class__ return "modules/%s/%s.html" % (kls._meta.app_label, kls._meta.module_name) diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index 3768b2a..f589a0c 100644 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -46,6 +46,9 @@ class BestPractice(ItfModel): 'images': self.get_images() } + def main_image(self): + return self.get_images()[0] + def list_dict(self): return { 'id': self.id, From 1b60c71be98e42b45c726eb19ddf876a9b69cada Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 20:58:14 +0530 Subject: [PATCH 07/11] main image code --- itf/app/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itf/app/models.py b/itf/app/models.py index 819dbcc..e14d689 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -82,7 +82,7 @@ class ItfModel(models.Model): imgfield = None if imgfield is not None: try: - thumb = get_thumbnail(imgfield, "150x142", crop="center") + thumb = get_thumbnail(imgfield, "150x142", crop="center").url except: thumb = '' else: From 2f6cad4fc00cac1b87cc780c8386ad974da8f771 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 21:00:56 +0530 Subject: [PATCH 08/11] main image js --- itf/static/js/insidepage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index a17c0e1..4bc424f 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -14,6 +14,7 @@ $('#listLeft ul li a').live("click", function() { 'tab': tab, 'object_id': objId }, function(data) { + $('#pin').attr("src", data.main_image); $('#textRight').text(data.title).formatTitle(); var searchTerm = $('.searchListField').val(); var html = data.html; From 9a2b4c3259882665ad8fce1c29a97f0632996b6b Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 21:02:13 +0530 Subject: [PATCH 09/11] er, js ups --- itf/static/js/insidepage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index 4bc424f..21c6c55 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -14,7 +14,7 @@ $('#listLeft ul li a').live("click", function() { 'tab': tab, 'object_id': objId }, function(data) { - $('#pin').attr("src", data.main_image); + $('#imageInside').attr("src", data.main_image.thumb); $('#textRight').text(data.title).formatTitle(); var searchTerm = $('.searchListField').val(); var html = data.html; From 39565b61c6e588a57faf83a0bddbd7e9fff694d9 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 21:05:19 +0530 Subject: [PATCH 10/11] js --- itf/app/models.py | 2 +- itf/static/js/insidepage.js | 2 +- itf/templates/noel/insidepage.html | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index e14d689..97d5abf 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -82,7 +82,7 @@ class ItfModel(models.Model): imgfield = None if imgfield is not None: try: - thumb = get_thumbnail(imgfield, "150x142", crop="center").url + thumb = get_thumbnail(imgfield, "142x150", crop="center").url except: thumb = '' else: diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index 21c6c55..3244e38 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -14,7 +14,7 @@ $('#listLeft ul li a').live("click", function() { 'tab': tab, 'object_id': objId }, function(data) { - $('#imageInside').attr("src", data.main_image.thumb); + $('#imageInside').css({'backgroundImage': data.main_image.thumb}); $('#textRight').text(data.title).formatTitle(); var searchTerm = $('.searchListField').val(); var html = data.html; diff --git a/itf/templates/noel/insidepage.html b/itf/templates/noel/insidepage.html index 6e5792e..1efb8ab 100644 --- a/itf/templates/noel/insidepage.html +++ b/itf/templates/noel/insidepage.html @@ -116,6 +116,7 @@
+
From bfcb370a2988ca6b2588102b818afa4d4c4cdf63 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 5 Oct 2011 21:06:58 +0530 Subject: [PATCH 11/11] foo bar --- itf/static/js/insidepage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index 3244e38..a1232e8 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -14,7 +14,7 @@ $('#listLeft ul li a').live("click", function() { 'tab': tab, 'object_id': objId }, function(data) { - $('#imageInside').css({'backgroundImage': data.main_image.thumb}); + $('#imageInside').css({'backgroundImage': 'url(' + data.main_image.thumb + ')'}); $('#textRight').text(data.title).formatTitle(); var searchTerm = $('.searchListField').val(); var html = data.html;