Skip to content

Admin helpers

hypha.apply.funds.admin_helpers

VerboseLabelModelChoiceField

Bases: ModelChoiceField

label_from_instance

label_from_instance(str, obj)
Source code in hypha/apply/funds/admin_helpers.py
def label_from_instance(str, obj):
    return "[{}] {}".format(obj._meta.verbose_name, obj.title)

FundChooserForm

Bases: ParentChooserForm

Changes the default chooser to be fund orientated

parent_page class-attribute instance-attribute

parent_page = VerboseLabelModelChoiceField(label=gettext_lazy('Fund or RFP'), required=True, empty_label=None, queryset=none(), widget=RadioSelect())

RoundFundChooserView

Bases: ChooseParentView

get_form

get_form(request)
Source code in hypha/apply/funds/admin_helpers.py
def get_form(self, request):
    parents = self.permission_helper.get_valid_parent_pages(request.user).specific()
    return FundChooserForm(parents, request.POST or None)

ButtonsWithPreview

Bases: PageButtonHelper

preview_button

preview_button(obj, classnames_add, classnames_exclude)
Source code in hypha/apply/funds/admin_helpers.py
def preview_button(self, obj, classnames_add, classnames_exclude):
    classname = self.copy_button_classnames + classnames_add
    cn = self.finalise_classname(classname, classnames_exclude)
    return {
        "url": reverse("wagtailadmin_pages:view_draft", args=(obj.id,)),
        "label": "Preview",
        "classname": cn,
        "title": "Preview this %s" % self.verbose_name,
    }

get_buttons_for_obj

get_buttons_for_obj(obj, exclude=None, classnames_add=None, classnames_exclude=None)
Source code in hypha/apply/funds/admin_helpers.py
def get_buttons_for_obj(
    self, obj, exclude=None, classnames_add=None, classnames_exclude=None
):
    btns = super().get_buttons_for_obj(
        obj, exclude, classnames_add, classnames_exclude
    )

    # Put preview before delete
    btns.insert(-1, self.preview_button(obj, classnames_add, classnames_exclude))

    return btns

FormsFundRoundListFilter

Bases: SimpleListFilter

title class-attribute instance-attribute

title = 'usage'

parameter_name class-attribute instance-attribute

parameter_name = 'form-usage'

lookups

lookups(request, model_admin)
Source code in hypha/apply/funds/admin_helpers.py
def lookups(self, request, model_admin):
    return (
        ("applicationbase", _("Funds & RFP")),
        ("roundbase", _("Rounds and Sealed Rounds")),
        ("labbase", _("Labs")),
    )

queryset

queryset(request, queryset)
Source code in hypha/apply/funds/admin_helpers.py
def queryset(self, request, queryset):
    value = self.value()
    if value:
        query = {f"{value}form__isnull": False}
        return queryset.filter(**query).distinct()
    return queryset

RoundStateListFilter

Bases: SimpleListFilter

title class-attribute instance-attribute

title = 'state'

parameter_name class-attribute instance-attribute

parameter_name = 'form-state'

lookups

lookups(request, model_admin)
Source code in hypha/apply/funds/admin_helpers.py
def lookups(self, request, model_admin):
    return (
        ("open", _("Open")),
        ("closed", _("Closed")),
    )

queryset

queryset(request, queryset)
Source code in hypha/apply/funds/admin_helpers.py
def queryset(self, request, queryset):
    value = self.value()
    if value == "open":
        return queryset.open()
    elif value == "closed":
        return queryset.closed()
    return queryset

ApplicationFormButtonHelper

Bases: ButtonHelper

prepare_classnames

prepare_classnames(start=None, add=None, exclude=None)

Parse classname sets into final css classes list.

Source code in hypha/apply/funds/admin_helpers.py
def prepare_classnames(self, start=None, add=None, exclude=None):
    """Parse classname sets into final css classes list."""
    classname = start or []
    classname.extend(add or [])
    return self.finalise_classname(classname, exclude or [])

copy_form_button

copy_form_button(pk, form_name, **kwargs)
Source code in hypha/apply/funds/admin_helpers.py
def copy_form_button(self, pk, form_name, **kwargs):
    classname = self.prepare_classnames(
        start=self.edit_button_classnames,
        add=kwargs.get("classnames_add"),
        exclude=kwargs.get("classnames_exclude"),
    )
    return {
        "classname": classname,
        "label": "Copy",
        "title": f"Copy {form_name}",
        "url": self.url_helper.get_action_url("copy_form", admin.utils.quote(pk)),
    }

get_buttons_for_obj

get_buttons_for_obj(obj, exclude=None, *args, **kwargs)

Override the getting of buttons, appending copy form button.

Source code in hypha/apply/funds/admin_helpers.py
def get_buttons_for_obj(self, obj, exclude=None, *args, **kwargs):
    """Override the getting of buttons, appending copy form button."""
    buttons = super().get_buttons_for_obj(obj, *args, **kwargs)

    copy_form_button = self.copy_form_button(
        pk=getattr(obj, self.opts.pk.attname), form_name=obj.name, **kwargs
    )
    buttons.append(copy_form_button)

    return buttons

RoundAdminURLHelper

Bases: PageAdminURLHelper

index_url

index_url()
Source code in hypha/apply/funds/admin_helpers.py
@cached_property
def index_url(self):
    # By default set open filter and sort on end date
    # for Round listing page's index URL
    params = {"form-state": "open", "o": "-3"}
    return f"{self.get_action_url('index')}?{urlencode(params)}"