Ejemplo n.º 1
0
 def render(self, context):
     try:
         collection = Variable(self.url).resolve(context)
     except VariableDoesNotExist:
         collection = None
     try:
         if not collection:
             collection = Collection.objects.get(url=self.url)
         object_list = collection.get_collection_objects()[:self.limit]
         result = []
         for obj in object_list:
             try:
                 obj = obj.content_object
             except AttributeError:
                 pass
             app_label = obj._meta.app_label
             module_name = obj._meta.module_name
             context['object'] = obj
             t = template.loader.select_template(['news/collections/%s/%s_%s_%s.html' % (collection.id, app_label, module_name, obj.id), 'news/collections/%s/%s_%s.html' % (collection.id, app_label, module_name), 'news/collections/%s_%s.html' % (app_label, module_name)])
             response = mark_safe(t.render(context))
             result.append(response)
         context[self.varname] = result
         return ''
     except Exception, e:
         return "<!-- ERROR: %s -->" % e