コード例 #1
0
class HPActionDocumentsAdmin(NoAddOrDeleteMixin, admin.ModelAdmin):
    """
    Admin for HP Action Documents. Ideally this would just be an inline
    admin for users, but because deletion is done by dissociating a
    user from the model, we basically have to make it a separate view.
    """

    list_display = ["id", "user", "user_full_legal_name", "kind", "created_at"]

    actions = [schedule_for_deletion]

    search_fields = [
        "id",
        "user__username",
        "user__first_name",
        "user__last_name",
        "user__preferred_first_name",
    ]

    readonly_fields = ["edit_user"]

    autocomplete_fields = ["user"]

    def user_full_legal_name(self, obj):
        if obj.user:
            return obj.user.full_legal_name

    inlines = (DocusignEnvelopeInline,)

    edit_user = make_edit_link("View/edit user details", field="user")
コード例 #2
0
class HPActionDocumentsInline(ReadOnlyMixin, admin.TabularInline):
    model = models.HPActionDocuments

    fields = ["pdf_file", "kind", "created_at", "docusign_status", "edit"]

    readonly_fields = fields

    ordering = ["-created_at"]

    edit = make_edit_link("Edit")

    def docusign_status(self, obj):
        if hasattr(obj, "docusignenvelope"):
            return obj.docusignenvelope.status
コード例 #3
0
 def test_it_returns_edit_link_for_field(self):
     obj = Blob(related_thing=Blob(admin_url="/blah", pk=1))
     edit_link = make_edit_link("edit", field="related_thing")
     assert edit_link(None, obj) == '<a class="button" href="/blah">edit</a>'
コード例 #4
0
 def test_it_returns_edit_link_for_obj(self):
     site = Site(pk=1)
     edit_link = make_edit_link("edit")
     assert (
         edit_link(None, site) == '<a class="button" href="/admin/sites/site/1/change/">edit</a>'
     )
コード例 #5
0
 def test_it_returns_empty_string_when_given_obj_without_pk(self):
     site = Site()
     edit_link = make_edit_link("edit")
     assert edit_link(None, site) == ""
コード例 #6
0
 def test_it_returns_empty_string_when_given_none(self):
     edit_link = make_edit_link("edit")
     assert edit_link(None, None) == ""