Exemplo n.º 1
0
def get_context(user, model):
    return {
        "verbose_name":
        model._meta.verbose_name,
        "verbose_name_plural":
        model._meta.verbose_name_plural,
        "model_name":
        model.__name__.lower(),
        "create_url":
        reverse("core:management_create", args=[model.__name__.lower()]),
        "can_update":
        is_allowed(user, model, "update"),
        "can_delete":
        is_allowed(user, model, "delete"),
        "can_create":
        is_allowed(user, model, "create"),
        "can_download_cover":
        model == LectureNote,
        "can_download_file":
        model == LectureNote,
        "editable_fields":
        len(get_columns(user, model)) != len(get_disabled_columns(user,
                                                                  model)),
        "ordering":
        model._meta.ordering,
    }
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        self.model = get_model(kwargs["model"])

        if not is_allowed(request.user, self.model, "delete"):
            raise Http404

        return super().post(request, *args, **kwargs)
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        self.model = get_model(kwargs["model"])

        if not is_allowed(request.user, self.model, "update"):
            raise Http404

        self.form_class = get_form(request.user, self.model)
        return super().post(request, *args, **kwargs)
Exemplo n.º 4
0
def get_context(user, model, pk):
    return {
        "verbose_name":
        model._meta.verbose_name,
        "mode":
        "update",
        "abort_url":
        reverse("core:management_list", args=[model.__name__.lower()]),
        "delete_url":
        reverse("core:management_delete", args=[model.__name__.lower(), pk])
        if is_allowed(user, model, "delete") else None,
        "fieldsets":
        get_fieldsets(user, model),
    }
Exemplo n.º 5
0
    def get(self, request, model):
        model = get_model(model)

        if not is_allowed(request.user, model, "list"):
            raise Http404

        context = get_context(request.user, model)

        query, page = get_pagination(
            get_formset(request.user, model)(), request)

        formset = get_formset(request.user, model)(queryset=query)

        context["page"] = page
        context["formset"] = formset

        return render(request, "core/management/list_model.html", context)
Exemplo n.º 6
0
    def post(self, request, model):
        model = get_model(model)

        if not is_allowed(request.user, model, "list"):
            raise Http404

        context = get_context(request.user, model)

        query, page = get_pagination(
            get_formset(request.user, model)(), request)

        if "save" in request.POST:
            formset = get_formset(request.user, model)(request.POST,
                                                       queryset=query)
            if formset.is_valid():
                formset.save()
        else:
            formset = get_formset(request.user, model)(queryset=query)

        context["page"] = page
        context["formset"] = formset

        return render(request, "core/management/list_model.html", context)