This commit is contained in:
Karen 2011-10-05 22:36:49 +05:30
commit cb69f1e3c3
5 changed files with 60 additions and 13 deletions

View File

@ -8,6 +8,7 @@ from django.template.loader import render_to_string
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from insidepages.models import ModuleTab, ModelExtra from insidepages.models import ModuleTab, ModelExtra
from os.path import exists from os.path import exists
from sorl.thumbnail import get_thumbnail
def splitSearch(string): def splitSearch(string):
ret = [] ret = []
@ -45,15 +46,19 @@ class ItfModel(models.Model):
return self.get(self.title_field) return self.get(self.title_field)
def get_tab(self): def get_tab(self):
modelextra = self.get_modelextra()
tab = ModuleTab.objects.filter(model=modelextra)[0]
return tab
def get_modelextra(self):
try: try:
ctype = ContentType.objects.get(model=self.__class__._meta.module_name) 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). 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) ctype = get_real_ctype(self.__class__._meta.module_name)
# modelextra = ModelExtra.objects.filter(model=ctype)[0] # modelextra = ModelExtra.objects.filter(model=ctype)[0]
modelextra = ctype.modelextra_set.all()[0] modelextra = ctype.modelextra_set.all()[0]
tab = ModuleTab.objects.filter(model=modelextra)[0] return modelextra
return tab
def get_absolute_url(self): def get_absolute_url(self):
return "%s/?tab=%s&object_id=%d" % (self.get_module().get_absolute_url(), self.get_tab().slug, self.id) 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): 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, "142x150", crop="center").url
except:
thumb = ''
else:
thumb = ''
return { return {
'url': '', 'thumb': thumb
'caption': ''
} }
def main_image(self):
return None
def get_template_path(self): def get_template_path(self):
kls = self.__class__ kls = self.__class__
return "modules/%s/%s.html" % (kls._meta.app_label, kls._meta.module_name) return "modules/%s/%s.html" % (kls._meta.app_label, kls._meta.module_name)

View File

@ -42,9 +42,13 @@ class BestPractice(ItfModel):
'theatre': self.theatre, 'theatre': self.theatre,
'quick_howto': self.quick_howto, 'quick_howto': self.quick_howto,
'category': self.category.name, 'category': self.category.name,
'category_id': self.category.id 'category_id': self.category.id,
'images': self.get_images()
} }
def main_image(self):
return self.get_images()[0]
def list_dict(self): def list_dict(self):
return { return {
'id': self.id, 'id': self.id,
@ -64,11 +68,14 @@ class BestPractice(ItfModel):
def get_images(self): def get_images(self):
images = [] images = []
for i in BestPracticeImage.objects.filter(bestpractice=self): for i in BestPracticeImage.objects.filter(bestpractice=self):
images.append(i)
'''
images.append({ images.append({
'url': i.image.url, 'url': i.image.url,
'caption': i.caption, 'caption': i.caption,
'thumb': i.get_thumb() 'thumb': i.get_thumb()
}) })
'''
return images return images
''' '''
@ -93,7 +100,7 @@ class BestPracticeStory(models.Model):
def get_dict(self): def get_dict(self):
return { return {
'text': self.text, 'text': self.text,
'image': self.image.url if self.image.name != '' else '' 'image': self.image if self.image.name != '' else None
} }
class BestPracticeFAQ(ItfModel): class BestPracticeFAQ(ItfModel):

View File

@ -14,6 +14,7 @@ $('#listLeft ul li a').live("click", function() {
'tab': tab, 'tab': tab,
'object_id': objId 'object_id': objId
}, function(data) { }, function(data) {
$('#imageInside').css({'backgroundImage': 'url(' + data.main_image.thumb + ')'});
$('#textRight').text(data.title).formatTitle(); $('#textRight').text(data.title).formatTitle();
var searchTerm = $('.searchListField').val(); var searchTerm = $('.searchListField').val();
var html = data.html; var html = data.html;

View File

@ -1,16 +1,32 @@
{% load thumbnail %}
<div class="itfInfo"> <div class="itfInfo">
{% for s in stories %} {% for s in stories %}
<span class="itfInfoSub">Story: </span><span class="ifInfoInfo">{{ s.text }}</span> <span class="orange">Story: </span><span class="ifInfoInfo">{{ s.text }}</span>
<img class="itfInfoImg" src="{{ s.image }}" /> {% if s.image %}
<br /><br /> {% thumbnail s.image "100x100" crop="center" as im %}
{% endfor %} <img class="itfInfoImg" src="{{ im.url }}" />
<span class="itfInfoSub">Law: </span><span class="itfInfoInfo">{{ law }}</span> {% endthumbnail %}
{% if law_image %}
<img class="itfInfoImg" src="{{ law_image }}" />
{% endif %} {% endif %}
<br /><br /> <br /><br />
<span class="itfInfoSub">Relevance to Theatre: </span><span class="itfInfoInfo">{{ theatre|linebreaks }}</span> {% endfor %}
<span class="itfInfoSub">Quick Howto: </span><span class="itfInfoInfo">{{ quick_howto }}</span><br /><br /> <span class="orange">Law: </span><span class="itfInfoInfo">{{ law }}</span>
{% if law_image %}
{% thumbnail law_image "100x100" crop="center" as im %}
<img class="itfInfoImg" src="{{ im.url }}" />
{% endthumbnail %}
{% endif %}
<br /><br />
<span class="orange">Relevance to Theatre: </span><span class="itfInfoInfo">{{ theatre|linebreaksbr }}</span> <br /><br />
<span class="orange">Quick Howto: </span><span class="itfInfoInfo">{{ quick_howto|linebreaksbr }}</span><br /><br />
<div class="thumbsGallery">
{% for img in images %}
{% thumbnail img.image "100x100" crop="center" as im %}
<img class="itfInfoImg" src="{{ im.url }}" class="thumbsDetails" />
{% endthumbnail %}
{% endfor %}
</div>
</div> </div>

View File

@ -116,6 +116,7 @@
<div id="imageLeft"> <div id="imageLeft">
<div id="imageInside"> <div id="imageInside">
</div> </div>
</div> </div>