Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.2 KB
Raw Blame
# Test cases for no-new-custom-admin-views.
# ruff: noqa


class TeamAdmin(admin.ModelAdmin):
    # ok: no-new-custom-admin-views
    list_display = ("id", "name")

    # ruleid: no-new-custom-admin-views
    change_form_template = "admin/posthog/team/change_form.html"

    # ruleid: no-new-custom-admin-views
    def get_urls(self):
        # ruleid: no-new-custom-admin-views
        return [path("<path:object_id>/rebuild/", self.admin_site.admin_view(self.rebuild))] + super().get_urls()

    # ok: no-new-custom-admin-views
    def has_delete_permission(self, request, obj=None):
        return False


urlpatterns = [
    # ruleid: no-new-custom-admin-views
    path("admin/tophog/", admin.site.admin_view(tophog_dashboard_view)),
]


class OrganizationAdmin(admin.ModelAdmin):
    # ruleid: no-new-custom-admin-views
    def get_urls(self):
        return [
            # A URL without admin_view still counts, because it skips Django admin's staff check.
            # ruleid: no-new-custom-admin-views
            path("<path:object_id>/report/", self.report),
            # ruleid: no-new-custom-admin-views
            re_path(r"^(?P<object_id>.+)/usage/$", self.usage),
        ] + super().get_urls()


api_urlpatterns = [
    # ok: no-new-custom-admin-views
    path("api/projects/", projects_view),
]


class DeletionRequestAdmin(admin.ModelAdmin):
    # ok: no-new-admin-workflow-hooks
    readonly_fields = ("status",)

    # ok: no-new-admin-workflow-hooks
    def get_readonly_fields(self, request, obj=None):
        return self.readonly_fields

    # ruleid: no-new-admin-workflow-hooks
    def save_model(self, request, obj, form, change):
        obj.status = "draft"
        super().save_model(request, obj, form, change)

    # ruleid: no-new-admin-workflow-hooks
    def save_form(self, request, form, change):
        return form.save(commit=False)

    # ruleid: no-new-admin-workflow-hooks
    def change_view(self, request, object_id, form_url="", extra_context=None):
        return super().change_view(request, object_id, form_url, extra_context)

    # ruleid: no-new-admin-workflow-hooks
    def response_change(self, request, obj):
        return super().response_change(request, obj)


# ok: no-new-admin-workflow-hooks
def save_model(request, obj):
    return obj