Skip to content

Admin

hypha.apply.utils.admin

ListRelatedMixin

Provides a used_by column which can be found by defining related models in the following format:

related_models = [ (, ), ]

e.g. This would be object._set.field

get_queryset

get_queryset(request)
Source code in hypha/apply/utils/admin.py
def get_queryset(self, request):
    qs = super().get_queryset(request)
    related = [f"{form}_set__{field}" for form, field in self.related_models]
    return qs.prefetch_related(*related)

used_by

used_by(obj)
Source code in hypha/apply/utils/admin.py
def used_by(self, obj):
    rows = []
    for form, field in self.related_models:
        related = self._list_related(obj, form, field)
        if related:
            rows.append(related)
    return ", ".join(rows)

RelatedFormsMixin

Provide columns for Application forms, Review forms, and Determination forms attached to the object.

Using to show the related forms in funds, labs and rounds listing.

application_forms

application_forms(obj)
Source code in hypha/apply/utils/admin.py
def application_forms(self, obj):
    def build_urls(application_forms):
        for application_form in application_forms:
            url = reverse(
                "funds_applicationform_modeladmin_edit",
                args=[application_form.form.id],
            )
            yield f'<a href="{url}">{application_form}</a>'

    urls = list(build_urls(obj.forms.all()))

    if not urls:
        return

    return mark_safe("<br />".join(urls))

review_forms

review_forms(obj)
Source code in hypha/apply/utils/admin.py
def review_forms(self, obj):
    def build_urls(review_forms):
        for review_form in review_forms:
            url = reverse(
                "review_reviewform_modeladmin_edit", args=[review_form.form.id]
            )
            yield f'<a href="{url}">{review_form}</a>'

    urls = list(build_urls(obj.review_forms.all()))

    if not urls:
        return

    return mark_safe("<br />".join(urls))

determination_forms

determination_forms(obj)
Source code in hypha/apply/utils/admin.py
def determination_forms(self, obj):
    def build_urls(determination_forms):
        for determination_form in determination_forms:
            url = reverse(
                "determinations_determinationform_modeladmin_edit",
                args=[determination_form.form.id],
            )
            yield f'<a href="{url}">{determination_form}</a>'

    urls = list(build_urls(obj.determination_forms.all()))

    if not urls:
        return

    return mark_safe("<br />".join(urls))