Ejemplo n.º 1
0
        def get_context_data(self, **kwargs):
            obj = self.crud if hasattr(self, 'crud') else self
            if hasattr(obj, 'model_set') and obj.model_set:
                count = self.object_list.count()
                context = MultipleObjectMixin.get_context_data(self, **kwargs)
                context['count'] = count
                if self.paginate_by:
                    page_obj = context['page_obj']
                    paginator = context['paginator']
                    context['page_range'] = make_pagination(
                        page_obj.number, paginator.num_pages)

                # rows
                object_list = context['object_list']
                context['headers'] = self.get_headers()
                context['rows'] = self.get_rows(object_list)

                context['NO_ENTRIES_MSG'] = self.no_entries_msg
            else:
                context = ContextMixin.get_context_data(self, **kwargs)
                if self.object:
                    context['object'] = self.object
                    context_object_name = self.get_context_object_name(
                        self.object)
                    if context_object_name:
                        context[context_object_name] = self.object
                context.update(kwargs)

            return context
Ejemplo n.º 2
0
        def get_context_data(self, **kwargs):
            obj = self.crud if hasattr(self, 'crud') else self
            if hasattr(obj, 'model_set') and obj.model_set:
                count = self.object_list.count()
                context = MultipleObjectMixin.get_context_data(self, **kwargs)
                context['count'] = count
                if self.paginate_by:
                    page_obj = context['page_obj']
                    paginator = context['paginator']
                    context['page_range'] = make_pagination(
                        page_obj.number, paginator.num_pages)

                # rows
                object_list = context['object_list']
                context['headers'] = self.get_headers()
                context['rows'] = self.get_rows(object_list)

                context['NO_ENTRIES_MSG'] = self.no_entries_msg
            else:
                context = ContextMixin.get_context_data(self, **kwargs)
                if self.object:
                    context['object'] = self.object
                    context_object_name = self.get_context_object_name(
                        self.object)
                    if context_object_name:
                        context[context_object_name] = self.object
                context.update(kwargs)

            return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):

        context = ContextMixin.get_context_data(self, **kwargs)

        if self.request.method == "POST":
            if self.request.POST.get("group"):
                context["group_form"] = self.get_form()
            else:
                context["user_form"] = self.get_form()

        context.setdefault("group_form", SecretGroupPermissionsForm())
        context.setdefault("user_form", SecretUserPermissionsForm())

        pk = context["pk"] = self.kwargs["pk"]
        context["tab"] = "permissions"
        context["object"] = Secret.objects.get(pk=self.kwargs["pk"])

        secret = Secret.objects.get(pk=pk)

        users = get_users_with_perms(
            secret,
            attach_perms=True,
            with_superusers=False,
            with_group_users=False,
            only_with_perms_in=[
                EDIT_SECRET_PERMISSION, VIEW_SECRET_PERMISSION
            ],
        )

        def select_perm(perms):
            return "change_secret" if "change_secret" in perms else "view_secret"

        context["users"] = [{
            "user":
            user,
            "form":
            SecretPermissionsForm(
                update_permission=True,
                initial={
                    "user": user,
                    "permission": select_perm(perms)
                },
            ),
        } for user, perms in users.items()]
        groups = get_groups_with_perms(secret, attach_perms=True)

        context["groups"] = [{
            "group":
            group,
            "form":
            SecretPermissionsForm(
                update_permission=True,
                initial={
                    "group": group,
                    "permission": select_perm(perms)
                },
            ),
        } for group, perms in groups.items()]

        return context
Ejemplo n.º 4
0
 def get_context_data(self, **kwargs):
     if 'object' not in kwargs:
         obj = self.get_object()
         if obj:
             context_object_name = self.get_context_object_name(obj)
             if context_object_name:
                 kwargs[context_object_name] = obj
             else:
                 kwargs['object'] = obj
     if 'form' not in kwargs:
         kwargs['form'] = self.get_form()
     return ContextMixin.get_context_data(self, **kwargs)
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        """
        If an object list has been supplied, inject it into the context with the
        supplied context_object_name name.
        """
        context = {}

        if self.object_list is not None:
            context['object_list'] = self.object_list
            context_object_name = self.get_context_object_name(self.object_list)
            if context_object_name:
                context[context_object_name] = self.object_list
        context.update(kwargs)

        # MultipleObjectMixin get_context_data() doesn't work when object_list
        # is not provided in kwargs, so we skip MultipleObjectMixin and call
        # ContextMixin directly.
        return ContextMixin.get_context_data(self, **context)
Ejemplo n.º 6
0
    def get_context_data(self, **kwargs):
        """
        If an object list has been supplied, inject it into the context with the
        supplied context_object_name name.
        """
        context = {}

        if self.object_list is not None:
            context['object_list'] = self.object_list
            context_object_name = self.get_context_object_name(self.object_list)
            if context_object_name:
                context[context_object_name] = self.object_list
        context.update(kwargs)

        # MultipleObjectMixin get_context_data() doesn't work when object_list
        # is not provided in kwargs, so we skip MultipleObjectMixin and call
        # ContextMixin directly.
        return ContextMixin.get_context_data(self, **context)
Ejemplo n.º 7
0
def get_full_context(react_view: ReactMixin, parent_view: ContextMixin, *args,
                     **kwargs):
    return {
        **parent_view.get_context_data(*args, **kwargs),
        **get_react_context(react_view)
    }