def update_context(self, context): """ Provide a context for all portal templates or sub templates """ context.update({ 'site_name': self.name, 'MEDIA_URL': settings.MEDIA_URL, }) # Add context of site root level portlets update_portlets_context(self, context)
def update_context(self,context): """ Provide a context for all portal templates or sub templates """ context.update({ 'site_name':self.name, 'MEDIA_URL':settings.MEDIA_URL, }) # Add context of site root level portlets update_portlets_context(self,context)
def _new_func(*args,**kwargs): # init context using request arguments request = args[0] context = DjityContext(request) # Get project_name and module_name, standard parameters of djity # module views. Put them in the context. project_name = kwargs.get('project_name',None) context['project_name'] = project_name if project_name: del kwargs['project_name'] module_name = kwargs.get('module_name',None) context['module_name'] = module_name if 'module_name' in kwargs: del kwargs['module_name'] context['required_perm'] = perm # if the origin path is specified, clean it and set it if 'path' in kwargs: path = urllib.unquote(kwargs['path']) context['origin_path'] = path.split('?')[0] del kwargs['path'] path = urlquote(request.get_full_path()) context['path'] = path # Fetch project, or 404 try: project = Project.objects.get(name=project_name) except Project.DoesNotExist: raise Http404 # Check if a JS target is present js_target = kwargs.get('js_target',None) if js_target : context['js_target'] = JSTarget(js_target,request) kwargs['js_target'] = context['js_target'] # set user, path and laguange values in context user = request.user context['user'] = request.user LANGUAGE_CODE = kwargs.get('LANGUAGE_CODE',None) if LANGUAGE_CODE : del kwargs['LANGUAGE_CODE'] from django.utils.translation import activate activate(LANGUAGE_CODE) else: LANGUAGE_CODE = request.LANGUAGE_CODE context['LANGUAGE_CODE'] = LANGUAGE_CODE context['LANGUAGES'] = settings.LANGUAGES # the project itselt goes in the context context['project'] = project # the project also contributes to the context # actually permissions are resolved here project.update_context(context) # if the user is not allowed to use this view, redirect or ask for # authentication of return error if not perm in context['perm']: if not user.is_authenticated(): tup = djreverse('login',context), REDIRECT_FIELD_NAME, path messages.add_message(request, messages.INFO,unicode(_("You were redirected because you lacked a permission: "))+unicode(perm)) return HttpResponseRedirect('%s?%s=%s' % tup) else: messages.add_message(request, messages.INFO,unicode(_("You were redirected because you lacked a permission: "))+unicode(perm)) return HttpResponseRedirect(djreverse('forbidden',context)) # Add context of project and module level portlets update_portlets_context(context['project'],context) if 'module' in context: update_portlets_context(context['module'],context) #add info message from url in context if request.method == 'GET': if 'info_message' in request.GET: context['info_message'] = request.GET['info_message'] kwargs['context'] = context # if module was not found by projet.update_context() raise 404 if module_name and not 'module' in context: context.message(_("This page does not exist on this project !")) context["module"] = {'label':_('Page not found')} templ = loader.get_template('djity/base.html') return HttpResponseNotFound(templ.render(context)) if 'js_target' in context: func(*args,**kwargs) return context['js_target'].json() return func(*args,**kwargs)