main image code
This commit is contained in:
parent
21b06699cf
commit
724bbbd9ca
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user