Example #1
0
def first_tab(request,context):
    """
    Redirect the default view of a project to the first tab's view of the project.
    """
    modules = context['modules']
    if len(modules) > 0:
        return HttpResponseRedirect(modules[0].djity_url(context))
    if not context['user'].is_authenticated():
        return HttpResponseRedirect("%s?%s=%s"%(djreverse('login',context),REDIRECT_FIELD_NAME,context['path']))
    context.message(_("You can't view any page on this project !\nYou can subscribe using the button on the top left corner."))
    context["module"] = {'label':_('Subscribe')}
    return render_to_response('djity/base.html',context)
Example #2
0
 def djity_url(self, context):
     """
     Return the module's start page
     """
     return djreverse('simplepage-view', context, module_name=self.name)
Example #3
0
 def djity_url(self,context):
     """
     Return the module's start page
     """
     return djreverse('simplepage-view',context,module_name=self.name)
Example #4
0
 def djity_url(self, context=None):
     """
     return the url of this project
     """
     return djreverse('first_tab', {'project_name': self.name})
Example #5
0
 def djity_url(self,context=None):
     """
     return the url of this project
     """
     return djreverse('first_tab',{'project_name':self.name})
Example #6
0
 def djity_url(self,context):
     """
     return the application's start page
     """
     return djreverse('cowst-main',context)
Example #7
0
 def djity_url(self, context=None):
     """
     return the url of this project
     """
     return djreverse("first_tab", {"project_name": self.name})
Example #8
0
        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)