예제 #1
0
    def register_c_nav_02_menuItems(request, navMenuList, baseClassName):
        classObj = registeredClassInfo.get_classObject_fromBaseName(baseClassName)
        
        temp_localDict = {}
        
        for x in navMenuList:
            
            # if specified determine if renderMethod   exists
            if x['renderMethod']:
                try:    
                    renderMethod = getattr(classObj, x['renderMethod'])
                except AttributeError:
                    print "*** ERROR: %s renderMethod '%s' not found" % (classObj.__name__, x['renderMethod']) 
            
            # if specified determine if criteriaMethod exists
            if x['criteriaMethod']:
                try:
                    c_nav_classObj = registeredClassInfo.get_classObject_fromBaseName('c_nav')
                    criteriaMethod = getattr(c_nav_classObj, x['criteriaMethod'])
                except AttributeError:
                    print "*** ERROR: %s criteriaMethod '%s' not found" % (classObj.__name__, x['criteriaMethod']) 
            
#            # if isLocal then parentViewList must be specified
#            if x['isLocal'] and not x['parentViewList']:
#                print "*** NOTE: %s parentViewList not specified for local menu view '%s'" % (classObj.__name__, x['view'])
#                print "          Therefore treating this as a new-ish LOCAL_ALWAYS menu item which is always displayed when current application = (%s)" % (baseClassName)
            
            # generic fields
            x['selected']       = False
            x['baseClassName']  = baseClassName
            
            # calculate reversed link if not static
            if x['required_viewParamsList']:
                x['staticLink']      = False
                x['reversedLink']    = 'failed_global_non_static_menu_item'
            else:
                x['staticLink']      = True
                x['reversedLink']    = reverse(x['view'], urlconf=getattr(request, "urlconf", settings.ROOT_URLCONF))

            if x['isLocal']:
                if temp_localDict.has_key(x['menu']):       temp_localDict[x['menu']].append(x)
                else:                                       temp_localDict[x['menu']] = [x]
            else:
                if navMenu_globalDict.has_key(x['menu']):   navMenu_globalDict[x['menu']].append(x)
                else:                                       navMenu_globalDict[x['menu']] = [x]   
                
        if len(temp_localDict): 
            navMenu_localDict[baseClassName] = temp_localDict
예제 #2
0
    def process_response(self, request, response):
        if self.continueForViewOnly(request, 'response'):
            for x in mwMethods['response']:
##                print "*** %-12s: x[0] = %3s, x[1] = %-20s, x[2] = %-40s" % ('RESPONSE', x[0], x[1], x[2]) 
                methodToCall = getattr(registeredClassInfo.get_classObject_fromBaseName(x[1]), x[2])
                response = methodToCall(request, response)              
        return response  
예제 #3
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        rv = None
        if self.continueForViewOnly(request, 'view'):
            for x in mwMethods['view']:
##                print "*** %-12s: x[0] = %3s, x[1] = %-20s, x[2] = %-40s" % ('VIEW', x[0], x[1], x[2]) 
                methodToCall = getattr(registeredClassInfo.get_classObject_fromBaseName(x[1]), x[2])
                rv = methodToCall(request, view_func, view_args, view_kwargs)                
                if rv is not None: break
        return rv      
예제 #4
0
    def process_request(self, request):
        rv = None
        if self.continueForViewOnly(request, 'request'):
            for x in mwMethods['request']:
##                print "*** %-12s: x[0] = %3s, x[1] = %-20s, x[2] = %-40s" % ('REQUEST', x[0], x[1], x[2]) 
                methodToCall = getattr(registeredClassInfo.get_classObject_fromBaseName(x[1]), x[2])
                rv = methodToCall(request)
                if rv is not None: break
        return rv
예제 #5
0
 def clean(self):
     error_list = []
     
     if 'basename' in self.cleaned_data:
         try:
             classObj = registeredClassInfo.get_classObject_fromBaseName(self.cleaned_data['basename'])
         except KeyError:
             error_list.append("basename %s not found in registeredClassInfo" % (self.cleaned_data['basename'])) 
         
     if 'homeview' in self.cleaned_data:
         try:
             url = reverse(self.cleaned_data['homeview'])
         except NoReverseMatch:
             error_list.append("reverse for homeview %s not found" % (self.cleaned_data['homeview'])) 
     
     if error_list: raise ValidationError(error_list)
     return self.cleaned_data         
예제 #6
0
    def mw_view_sidebar_methods(request, view_func, view_args, view_kwargs):
        request.META['a_mgrSidebar_displayList'] = []

        # get a list of applications citizen is subscribed to
        subscribedApplicationsByBaseName = []
        QS = subscription_01.objects.filter(auto_citizen__exact=request.META['duo_citizen'])
        for x in QS:
            subscribedApplicationsByBaseName.append(x.application.basename)
            
        for x in sbMethods:
            methodDict = x[1]
            securityAccessGranted = False

            if request.META['citizen_rights']['value'] >= secDict[methodDict['security']]['value']:            
                securityAccessGranted = True
            elif methodDict['security'] == 's_subscribed' and request.META['citizen_rights']['value'] >= secDict['s_citizen']['value']: # because only citizens can subscribe
                if methodDict['className'] in subscribedApplicationsByBaseName:
                    securityAccessGranted = True
                         
            if securityAccessGranted:
                # Now see if this sidebar method should be displayed by the view and app we are in
                
                displayByCurrentSiteLocation = True
                if methodDict['valid_app_baseName_list']:
                    if request.META['auto_currentApp_baseName'] not in methodDict['valid_app_baseName_list']:
                        displayByCurrentSiteLocation = False
#                        print "*** displayByCurrentSiteLocation FAILED because current app (%s) is not in valid_app_baseName_list" % (request.META['auto_currentApp_baseName'])
                elif methodDict['valid_view_list']:
                    if request.META['auto_currentView'] not in methodDict['valid_view_list']:
                        displayByCurrentSiteLocation = False
#                        print "*** displayByCurrentSiteLocation FAILED because current view (%s) is not in valid_view_list" % (request.META['auto_currentView'])

                if displayByCurrentSiteLocation:
                    classObj = registeredClassInfo.get_classObject_fromBaseName(methodDict['className'])
                    sbMethod = getattr(classObj, methodDict['methodName'])
#                    request.META['a_mgrSidebar_displayList'].append(sbMethod(request, view_func, view_args, view_kwargs))
                    sbReturn = sbMethod(request, view_func, view_args, view_kwargs)
                    if sbReturn:
                        request.META['a_mgrSidebar_displayList'].append(sbReturn)
                    

            else:
#                print "*** mw_view_sidebar_methods: Insufficient security for %s" % (methodDict['methodName'])
                pass
        return None  
예제 #7
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