Example #1
0
 def _getrepr(self, name, instance):
     try:
         f, attr, value = lookup_field(name, instance, self.model_admin)
     except (AttributeError, ObjectDoesNotExist):
         result_repr = self.get_value(instance, name, sites.settings.DJPCMS_EMPTY_VALUE)
     else:
         if f is None:
             allow_tags = getattr(attr, 'allow_tags', False)
             boolean = getattr(attr, 'boolean', False)
             if boolean:
                 allow_tags = True
                 result_repr = _boolean_icon(value)
             else:
                 result_repr = force_str(value)
             # Strip HTML tags in the resulting text, except if the
             # function has an "allow_tags" attribute set to True.
             if not allow_tags:
                 result_repr = escape(result_repr)
             else:
                 result_repr = mark_safe(result_repr)
         else:
             if value is None:
                 result_repr = sites.settings.DJPCMS_EMPTY_VALUE
             if isinstance(f.rel, models.ManyToOneRel):
                 result_repr = escape(getattr(instance, f.name))
             else:
                 result_repr = display_for_field(value, f)
     return result_repr
Example #2
0
    def render(self, djp, plugin = None, wrapper = None):
        '''Render the plugin in the content block
This function call the plugin render function and wrap the resulting HTML
with the wrapper callable.'''
        html = ''
        try:
            plugin  = plugin or self.plugin
            wrapper = wrapper or self.wrapper
            if plugin:
                if has_permission(djp.request.user,get_view_permission(self), self):
                    djp.media += plugin.media
                    html = plugin(djp, self.arguments, wrapper = wrapper)
        except Exception, e:
            if getattr(djp.settings,'TESTING',False):
                raise
            exc_info = sys.exc_info()
            self.logger.error('%s - block %s -- %s' % (plugin,self,e),
                exc_info=exc_info,
                extra={'request':djp.request}
            )
            if djp.request.user.is_superuser:
                html = escape(u'%s' % e)