def has_permission(self, request = None, page = None, obj = None): '''Check if view can be displayed. ''' if request and page: return has_permission(request.user,get_view_permission(page),page) else: return True
def edit_form(self, djp, site_content = None, **kwargs): if site_content: try: obj = SiteContent.objects.get(id = int(site_content)) except Exception, e: return None # Check for permissions if has_permission(djp.request.user,get_change_permission(obj), obj): return EditContentForm(**form_kwargs(request = djp.request, instance = obj, withrequest = True, **kwargs)) else: raise PermissionDenied("Cannot edit '%s'. You don't have the right permissions" % obj)
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)
def has_delete_permission(self, user, obj=None): return has_permission(user, self.get_delete_permission(), obj)
def has_view_permission(self, user, obj = None): return has_permission(user, self.get_view_permission(), obj)
def has_change_permission(self, user, obj=None): return has_permission(user, self.get_change_permission(), obj)