示例#1
0
文件: models.py 项目: albanm/djity
 def can_view(self, user):
     """
     check if a user can view a project,
     used to build parent hierarchy in update_context,
     we consider that a user can view a project if he can view at least 
     one of its modules
     """
     role = self.get_role(user)
     for module in self.modules.all():
         if has_perm('view', role, module.status):
             return True
     return False
示例#2
0
文件: models.py 项目: albanm/djity
 def can_view(self,user):
     """
     check if a user can view a project,
     used to build parent hierarchy in update_context,
     we consider that a user can view a project if he can view at least 
     one of its modules
     """
     role = self.get_role(user)
     for module in self.modules.all():
         if has_perm('view',role,module.status):
             return True
     return False
示例#3
0
文件: models.py 项目: albanm/djity
    def update_context(self, context):
        """
        Get context for all project templates or sub templates
        """
        # Get site level context
        SiteRoot.objects.get(label='home').update_context(context)

        # Fetch the role of the current user in this project
        context['role'] = self.get_role(context['user'])

        # Create dictionary of modules connected and their subnavigation menu,
        # and a list of the module tabs according to the role of the user
        # and check if the required permission is granted on the current module
        context['module_tabs'] = []
        context['modules'] = []
        for module in self.modules.order_by('tab_position'):
            name = module.name
            if name == context['module_name']:
                context['module'] = module
                context['perm'] = granted_perms(context['role'], module.status)
                context['tab_status'] = module.status
                context['status_display'] = settings.STATUS_DISPLAY
            if has_perm('view', context['role'], module.status):
                context['modules'].append(module)
                context['module_tabs'].append(name)
                context["%s_tab_display" % name] = module.label.capitalize()
                context["%s_tab_url" % name] = module.djity_url(context)

        # if no module name is declared we are in the project's context
        # for example the request might be for project.css
        # in this case permissions are asked for a current status of public
        if not 'module' in context:
            context['perm'] = granted_perms(context['role'], settings.PUBLIC)

        # get hierarchy of parent projects
        context['parent_projects'] = filter(
            lambda p: p.can_view(context['user']), self.get_parents())
        context['children_projects'] = filter(
            lambda p: p.can_view(context['user']), self.children.all())

        # get the awaiting memebea
        context['awaiting_members'] = self.count_awaiting_members()
示例#4
0
文件: models.py 项目: albanm/djity
    def update_context(self,context):
        """
        Get context for all project templates or sub templates
        """ 
        # Get site level context
        SiteRoot.objects.get(label='home').update_context(context)
      
        # Fetch the role of the current user in this project
        context['role'] = self.get_role(context['user'])
        
        # Create dictionary of modules connected and their subnavigation menu,
        # and a list of the module tabs according to the role of the user
        # and check if the required permission is granted on the current module
        context['module_tabs'] = []
        context['modules'] = []
        for module in self.modules.order_by('tab_position'):
            name = module.name
            if name == context['module_name']:
                context['module'] = module
                context['perm'] = granted_perms(context['role'],module.status)
                context['tab_status'] = module.status
                context['status_display'] = settings.STATUS_DISPLAY
            if has_perm('view',context['role'],module.status):
                context['modules'].append(module)
                context['module_tabs'].append(name)
                context["%s_tab_display"%name] = module.label.capitalize()
                context["%s_tab_url"%name] = module.djity_url(context)

        # if no module name is declared we are in the project's context
        # for example the request might be for project.css
        # in this case permissions are asked for a current status of public
        if not 'module' in context:
            context['perm'] = granted_perms(context['role'],settings.PUBLIC)

        # get hierarchy of parent projects
        context['parent_projects'] = filter(lambda p:p.can_view(context['user']) ,self.get_parents())
        context['children_projects'] = filter(lambda p:p.can_view(context['user']) ,self.children.all())
    
        # get the awaiting memebea
        context['awaiting_members'] = self.count_awaiting_members()