def render(self, context):
        args = [arg.resolve(context) for arg in self.args]
        kwargs = dict([(k, v.resolve(context)) for k, v in self.kwargs.items()])
        
        if self.displayTextNeedsResolving: self.display_text = self.dt_args[0].resolve(context)
        else:                              self.display_text = self.dt_args[0]  

        reverse_out = ''
        returnLink = []
        
        if self.urlTruncLength:
            trunkWords = truncate_words(self.display_text, self.urlTruncLength)
            if trunkWords[-3:] <> "...":    # django's truncate_words auto appends "..." if truncate happened
                return self.display_text
            else:                                
                returnLink.append(trunkWords[:-3])
                returnLink.append(' ')
                self.display_text = trunkWordToken

        request = resolve_variable('request', context)  # Interesting way to get the request variable from the context
        
        for k in context:
            try:
                urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
                reverse_out = reverse(self.view_name, args=args, kwargs=kwargs, urlconf=urlconf)
            except NoReverseMatch:
                print "*** appUrlNode NoReverseMatch Error: self.view_name = %s, args = %s, kwargs = %s, urlconf = %s" % (self.view_name, args, kwargs, urlconf)
#                try:
#                    project_name = settings.SETTINGS_MODULE.split('.')[0]
#                    reverse_out = reverse(project_name + '.' + self.view_name, args=args, kwargs=kwargs, urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF))
#                except NoReverseMatch:
#                    pass
                        
        if len(reverse_out):
            # check users security permissions to see if they have access to the view this URL is pointing at
            if engine_permissions.checkUserPermissions(request.META['citizen_rights'], self.funcString, self.args, self.kwargs, request):

                noUnderlineStyle = ''
                if self.noUnderline:
                    noUnderlineStyle = 'STYLE="text-decoration:none"'
                    
                # prepending link with site FormActionPrepend for absolute links NOT relative ones
                if len(self.oargs): returnLink.append("%s<a %s href='%s%s'>%s</a>%s" % (self.oargs[0], noUnderlineStyle, resolve_variable('request.META.duo_FormActionPrepend', context), reverse_out, self.display_text, self.oargs[1]))
                else:               returnLink.append("<a %s href='%s%s'>%s</a>"     % (noUnderlineStyle, resolve_variable('request.META.duo_FormActionPrepend', context), reverse_out, self.display_text))
            else:
                if settings.DEBUG: returnLink.append("<strike>" + str(self.display_text) + "</strike>")   
                else:              returnLink.append('')  
        else:
            if settings.DEBUG: returnLink.append("<blink>[" + self.display_text + "]</blink>")   
        
        return ''.join(returnLink)
Example #2
0
    def mw_view_checkViewSecurity(request, view_func, view_args, view_kwargs):
        if view_func.func_name <> settings.HOME_VIEW:
            
            # Hack to allow admin view for django-eve development
#            if view_func.func_name <> 'root':
            if view_func.func_name <> 'root' and view_func.func_name <> 'doc_index':
                if not engine_permissions.checkUserPermissions(request.META['citizen_rights'], view_func.func_name, view_args, view_kwargs, request):
                    print "*** mw_view_checkViewSecurity: user does not have rights for %s" % (view_func.func_name)
                    return a_base_02.redirectView(request, settings.HOME_VIEW, 'user_no')
                else:
                    return None
        else:
            return None
        return None
Example #3
0
    def mw_view_navMenu_02(request, view_func, view_args, view_kwargs):
        parentIndicatedAsSelectedByFoundChildSelected       = ''
        ultimateProperParentSelectedList                    = []
        
        # First extract appropriate child entries
        if navMenu_localDict.has_key(request.META['auto_currentApp_baseName']):
            for menuType, menuList in navMenu_localDict[request.META['auto_currentApp_baseName']].items():

                # get all child entries for the currentApp current menuType (i.e. LOCAL)
                working_childMenuList           = []
                aLocalChildWasFoundSelectedAndItsParentIs    = ''
                for x in menuList:
                    if engine_permissions.checkUserPermissions(request.META['citizen_rights'], x['view'], view_args, view_kwargs, request):
                        working_childMenuList.insert(0, x)
                        if x['view'] == request.META['auto_currentView']:
                            if x['parentViewList']:
                                aLocalChildWasFoundSelectedAndItsParentIs = x['parentViewList'][0]
                    
                # extract entries which have the properParent we are looking for        
                final_working_childMenuList = []
                if working_childMenuList:
                    if aLocalChildWasFoundSelectedAndItsParentIs:   properParent = aLocalChildWasFoundSelectedAndItsParentIs
                    else:                                           properParent = request.META['auto_currentView']
                    if properParent not in ultimateProperParentSelectedList:
                        ultimateProperParentSelectedList.append(properParent)
                    
                    for x in working_childMenuList:
                        if x['view'] == request.META['auto_currentView']:
                            x['selected'] = True
                            final_working_childMenuList.insert(0, [x['priority'], x])
                        elif properParent in x['parentViewList']:                       
                            x['selected'] = False
                            final_working_childMenuList.insert(0, [x['priority'], x])
                        elif not x['parentViewList']:
                            x['selected'] = False
                            final_working_childMenuList.insert(0, [x['priority'], x])
                        
                if final_working_childMenuList:
                    final_working_childMenuList.sort()
                    renderedList = []
                    for z in final_working_childMenuList:
                        x = z[1]                        
                        if x['criteriaMethod']: # there is a displayCriteriaMethod name, use it to get the actual method from the class
                            classObj = registeredClassInfo.get_classObject_fromBaseName('c_nav')
                            displayCriteriaMethod = getattr(classObj, x['criteriaMethod'])
                            displayCriteriaOk = displayCriteriaMethod(request)
                        else:
                            displayCriteriaOk = True
                        
                        if displayCriteriaOk:
                            if x['renderMethod']: # there is a renderMethod name, use it to get the actual method from the class
                                classObj = registeredClassInfo.get_classObject_fromBaseName(x['baseClassName'])
                                renderMethod = getattr(classObj, x['renderMethod'])
                                renderedList.append(renderMethod(request, view_func, view_args, view_kwargs))
                            else:
                                try:
#                                    templateName = 'BLOCK_menu_%s.html'%(menuType)
                                    templateName = 'B_menu.html'                                    
                                    
                                    # if not a staticLink then 
                                    # verify necessary parameters can be found in view_kwargs
                                    # calculate reverseLink
                                    if not x['staticLink']:
                                        allParametersFound = True
                                        kwargs_dict = {}
                                        for param in x['required_viewParamsList']:
                                            if param not in view_kwargs: 
                                                print "*** ERROR: non-static local menu item '%s' view parameter '%s' not found in view_kwargs" % (x['view'], param)
                                                allParametersFound = False
                                            else:
                                                kwargs_dict[param] = view_kwargs[param]
                                        if allParametersFound:
                                            x['reversedLink']    = reverse(x['view'], kwargs=kwargs_dict, urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF))
                                    
                                    renderedList.append(c_nav_02.processTemplate_01(request, templateName, {'object': x}))
                                except TemplateDoesNotExist:
                                    renderedList.append("ERROR: %s does not exist" % (templateName))   
                    request.META['baseContext_navigationMenu_%s' % (menuType)] = ''.join(renderedList)  
                    # ----------------                           

        # Next check non-child entries for a selection match
        for menuType, menuList in navMenu_globalDict.items():
            working_nonChildMenuList  = []

            for x in menuList:
                if engine_permissions.checkUserPermissions(request.META['citizen_rights'], x['view'], view_args, view_kwargs, request):
                    working_nonChildMenuList.insert(0, [x['priority'], x])

            if working_nonChildMenuList:
                for z in working_nonChildMenuList:
                    x = z[1]
                    if x['baseClassName'] == request.META['auto_currentApp_baseName'] and x['view'] == request.META['auto_currentView'] : x['selected'] = True
                    elif x['view'] in ultimateProperParentSelectedList:                                                                   x['selected'] = True
                    else:           
                        # New-ish conditional here testing if the optional list in x['altSelectOnViewList'] contains the basename and current view. 
                        # This optional list was added April 27 and is defined in class.models and contains all the views for which this global button shoudl be selected on.
                        if x['baseClassName'] == request.META['auto_currentApp_baseName'] and request.META['auto_currentView'] in x['altSelectOnViewList']  : x['selected'] = True
                        else:                                                                                                                                 x['selected'] = False

                working_nonChildMenuList.sort()
                
                renderedList = []
                for z in working_nonChildMenuList:
                    x = z[1]
                    if x['criteriaMethod']: # there is a displayCriteriaMethod name, use it to get the actual method from the class
                        classObj = registeredClassInfo.get_classObject_fromBaseName('c_nav')
                        displayCriteriaMethod = getattr(classObj, x['criteriaMethod'])
                        displayCriteriaOk = displayCriteriaMethod(request)
                    else:
                        displayCriteriaOk = True
                    
                    if displayCriteriaOk:
                        if x['renderMethod']: # there is a renderMethod name, use it to get the actual method from the class
                            classObj = registeredClassInfo.get_classObject_fromBaseName(x['baseClassName'])
                            renderMethod = getattr(classObj, x['renderMethod'])
#                            print "+++ view_func = %s" % (view_func)
#                            print "+++ view_args = %s" % (view_args,)
#                            print "+++ view_kwargs = %s" % (view_kwargs,)
                            renderedList.append(renderMethod(request, view_func, view_args, view_kwargs))
                        else:
                            try:
#                                templateName = 'BLOCK_menu_%s.html'%(menuType)
                                templateName = 'B_menu.html'
                                
                                # ----------------- COPIED FROM LOCAL 
                                if not x['staticLink']:
                                    allParametersFound = True
                                    kwargs_dict = {}
                                    for param in x['required_viewParamsList']:
                                        if param not in view_kwargs: 
#                                            print "*** ERROR: non-static global menu item '%s' view parameter '%s' not found in view_kwargs" % (x['view'], param)
                                            allParametersFound = False
                                        else:
                                            kwargs_dict[param] = view_kwargs[param]
                                    if allParametersFound:
                                        x['reversedLink']    = reverse(x['view'], kwargs=kwargs_dict, urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF))                                
                                # ----------------- COPIED FROM LOCAL 
                                
                                renderedList.append(c_nav_02.processTemplate_01(request, templateName, {'object': x}))
                            except TemplateDoesNotExist:
                                renderedList.append("ERROR: %s does not exist" % (templateName))    
                request.META['baseContext_navigationMenu_%s' % (menuType)] = ''.join(renderedList)                             

        return None