Ejemplo n.º 1
0
    def __init__(self, request):
        super(CardPanel, self).__init__('cardpanel', request)

        self.items = []

        from djangoplus.cache import loader
        for model, list_shortcut in loader.card_panel_models:

            if type(list_shortcut) == bool:
                add_model = list_shortcut
            else:
                if not type(list_shortcut) in (list, tuple):
                    list_shortcut = list_shortcut,
                add_model = request.user.in_group(*list_shortcut)

            if add_model or request.user.is_superuser:
                if permissions.has_list_permission(request, model):
                    self.add_model(model)

                if model in loader.subsets:
                    icon = get_metadata(model, 'icon')
                    title = get_metadata(model, 'verbose_name_plural')
                    app_label = get_metadata(model, 'app_label')
                    model_name = model.__name__.lower()
                    for item in loader.subsets[model]:
                        can_view = item['can_view']
                        # TODO False
                        if False and permissions.check_group_or_permission(
                                self.request, can_view):
                            attr_name = item['function'].__func__.__name__
                            qs = model.objects.all(self.request.user)
                            qs = getattr(qs, attr_name)()
                            count = qs.count()
                            if count:
                                url = '/list/{}/{}/{}/'.format(
                                    app_label, model_name, attr_name)
                                self.add(icon, title, count, url, 'bg-info',
                                         None, item['title'])

        for item in loader.views:
            if False:  # TODO False
                if permissions.check_group_or_permission(
                        request, item['can_view']):
                    self.add(item['icon'], item['menu'], None, item['url'],
                             'bg-info', item['can_view'], item['style'])
Ejemplo n.º 2
0
    def __init__(self, request):
        super(CardPanel, self).__init__('cardpanel', request)

        self.items = []

        from djangoplus.cache import CACHE
        for model, list_shortcut in CACHE['CARD_PANEL_MODELS']:

            if type(list_shortcut) == bool:
                add_model = list_shortcut
            else:
                if not type(list_shortcut) in (list, tuple):
                    list_shortcut = list_shortcut,
                add_model = request.user.in_group(*list_shortcut)

            if add_model or request.user.is_superuser:
                if permissions.has_list_permission(request, model):
                    self.add_model(model)

                if model in CACHE['SUBSETS']:
                    icon = get_metadata(model, 'icon')
                    title = get_metadata(model, 'verbose_name_plural')
                    app_label = get_metadata(model, 'app_label')
                    model_name = model.__name__.lower()
                    for item in CACHE['SUBSETS'][model]:
                        can_view = item['can_view']
                        # TODO False
                        if False and permissions.check_group_or_permission(
                                self.request, can_view):
                            attr_name = item['function'].__func__.__name__
                            qs = model.objects.all(self.request.user)
                            qs = getattr(qs, attr_name)()
                            count = qs.count()
                            if count:
                                url = '/list/{}/{}/{}/'.format(
                                    app_label, model_name, attr_name)
                                self.add(icon, title, count, url, '', None,
                                         item['verbose_name'])
        for item in CACHE['SUBSET_WIDGETS']:
            if item.get('shortcut'):
                if permissions.check_group_or_permission(
                        request, item['can_view']):
                    icon = item.get('icon', get_metadata(model, 'icon'))
                    self.add(item['icon'], item['verbose_name'], None,
                             item['url'], item['can_view'], '')
Ejemplo n.º 3
0
 def can_show_actions(self):
     return permissions.has_list_permission(self.request, self.qs.model)