Skip to content

Submission edit

hypha.apply.funds.views.submission_edit

User module-attribute

User = get_user_model()

BaseSubmissionEditView

Bases: UpdateView

Converts the data held on the submission into an editable format and knows how to save that back to the object. Shortcuts the normal update view save approach

model class-attribute instance-attribute

render_preview

render_preview(request, form)

Gets a rendered preview of a form

Creates a new revision on the ApplicationSubmission, removes the forms temporary files

Parameters:

  • request (HttpRequest) –

    Request used to trigger the preview to be used in the render

  • form (BaseModelForm) –

    Form to be rendered

Returns:

  • HttpResponse –

    An HttpResponse containing a preview of the given form

Source code in hypha/apply/funds/views/submission_edit.py
def render_preview(self, request: HttpRequest, form: BaseModelForm) -> HttpResponse:
    """Gets a rendered preview of a form

    Creates a new revision on the `ApplicationSubmission`, removes the
    forms temporary files

    Args:
        request:
            Request used to trigger the preview to be used in the render
        form:
            Form to be rendered

    Returns:
        An `HttpResponse` containing a preview of the given form
    """

    self.object.create_revision(draft=True, by=request.user)
    messages.success(self.request, _("Draft saved"))

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()

    context = self.get_context_data()
    return render(request, "funds/application_preview.html", context)

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    permission, _ = has_permission(
        "submission_edit",
        request.user,
        object=self.get_object(),
        raise_exception=True,
    )
    if not self.get_object().phase.permissions.can_edit(request.user):
        raise PermissionDenied
    return super().dispatch(request, *args, **kwargs)

buttons

buttons()

The buttons to be presented to the in the EditView

Returns:

  • str –

    A generator returning a tuple strings in the format of:

  • str –

    (

Source code in hypha/apply/funds/views/submission_edit.py
def buttons(
    self,
) -> Generator[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str]]:
    """The buttons to be presented to the in the EditView

    Returns:
        A generator returning a tuple strings in the format of:
        (<button type>, <button styling>, <button label>)
    """
    if settings.SUBMISSION_PREVIEW_REQUIRED:
        yield ("preview", "primary", _("Preview and submit"))
        yield ("save", "white", _("Save draft"))
    else:
        yield ("submit", "primary", _("Submit"))
        yield ("save", "white", _("Save draft"))
        yield ("preview", "white", _("Preview"))

get_object_fund_current_round

get_object_fund_current_round()
Source code in hypha/apply/funds/views/submission_edit.py
def get_object_fund_current_round(self):
    assigned_fund = self.object.round.get_parent().specific
    if assigned_fund.open_round:
        return assigned_fund.open_round
    return False

get_on_submit_transition

get_on_submit_transition(user)

Gets the transition that should be triggered when a form is submitted.

Checks all available status transitions for the current user and returns the first one that has trigger_on_submit=True in its custom settings.

Returns:

  • dict –

    The transition configuration dictionary with trigger_on_submit=True, or None if no matching transition is found.

Source code in hypha/apply/funds/views/submission_edit.py
def get_on_submit_transition(self, user):
    """Gets the transition that should be triggered when a form is submitted.

    Checks all available status transitions for the current user and returns the first
    one that has trigger_on_submit=True in its custom settings.

    Returns:
        dict: The transition configuration dictionary with trigger_on_submit=True,
            or None if no matching transition is found.
    """
    return next(
        (
            t
            for t in self.object.get_available_user_status_transitions(user)
            if t.custom.get("trigger_on_submit", False)
        ),
        None,
    )

form_valid

form_valid(form)

Handle the form returned from a SubmissionEditView.

Determine whether to return a form preview, draft the new edits, or submit and transition the ApplicationSubmission object

Parameters:

  • form (BaseModelForm) –

    The valid form

Returns:

  • HttpResponse –

    An HttpResponse depending on the actions taken in the edit view

Source code in hypha/apply/funds/views/submission_edit.py
def form_valid(self, form: BaseModelForm) -> HttpResponse:
    """Handle the form returned from a `SubmissionEditView`.

    Determine whether to return a form preview, draft the new edits,
    or submit and transition the `ApplicationSubmission` object

    Args:
        form: The valid form

    Returns:
        An `HttpResponse` depending on the actions taken in the edit view
    """

    self.object.form_data = form.cleaned_data

    is_draft = self.object.status == DRAFT_STATE

    # Handle a preview or a save (aka a draft)
    if "preview" in self.request.POST:
        return self.render_preview(self.request, form)

    if "save" in self.request.POST:
        return self.save_draft_and_refresh_page(form=form)

    # Handle an application being submitted from a DRAFT_STATE. This includes updating submit_time
    if is_draft and "submit" in self.request.POST:
        self.object.submit_time = timezone.now()
        if self.object.round:
            current_round = self.get_object_fund_current_round()
            if current_round:
                self.object.round = current_round
        self.object.save(update_fields=["submit_time", "round"])

    revision = self.object.create_revision(by=self.request.user)
    submitting_proposal = self.object.phase.name in STAGE_CHANGE_ACTIONS

    if submitting_proposal:
        messenger(
            MESSAGES.PROPOSAL_SUBMITTED,
            request=self.request,
            user=self.request.user,
            source=self.object,
        )
    elif revision and not self.object.status == DRAFT_STATE:
        messenger(
            MESSAGES.APPLICANT_EDIT,
            request=self.request,
            user=self.request.user,
            source=self.object,
            related=revision,
        )

    if "submit" in self.request.POST:
        if transition := self.get_on_submit_transition(self.request.user):
            notify = (
                not (revision or submitting_proposal)
                or self.object.status == DRAFT_STATE,
            )
            self.object.perform_transition(
                transition.target,
                self.request.user,
                request=self.request,
                notify=notify,  # Use the other notification
            )

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()
    return HttpResponseRedirect(self.get_success_url())

get_form_kwargs

get_form_kwargs()

Returns the keyword arguments for instantiating the form.

This method is called by the form mixin during form instantiation. It returns a dictionary of keyword arguments that will be passed to the form's constructor.

Returns:

  • dict –

    A dictionary of keyword arguments for the form constructor.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_kwargs(self):
    """
    Returns the keyword arguments for instantiating the form.

    This method is called by the form mixin during form instantiation.
    It returns a dictionary of keyword arguments that will be passed to
    the form's constructor.

    Returns:
        dict: A dictionary of keyword arguments for the form constructor.
    """
    kwargs = super().get_form_kwargs()
    instance = kwargs.pop("instance").from_draft()
    initial = instance.raw_data
    for field_id in instance.file_field_ids:
        initial.pop(field_id + "-uploads", False)
        initial[field_id] = self.get_placeholder_file(
            instance.raw_data.get(field_id)
        )
    kwargs["initial"] = initial
    return kwargs

get_placeholder_file

get_placeholder_file(initial_file)
Source code in hypha/apply/funds/views/submission_edit.py
def get_placeholder_file(self, initial_file):
    if not isinstance(initial_file, list):
        return PlaceholderUploadedFile(
            initial_file.filename, size=initial_file.size, file_id=initial_file.name
        )
    return [
        PlaceholderUploadedFile(f.filename, size=f.size, file_id=f.name)
        for f in initial_file
    ]

save_draft_and_refresh_page

save_draft_and_refresh_page(form)
Source code in hypha/apply/funds/views/submission_edit.py
def save_draft_and_refresh_page(self, form) -> HttpResponseRedirect:
    self.object.create_revision(draft=True, by=self.request.user)
    form.delete_temporary_files()
    messages.success(self.request, _("Draft saved"))
    return HttpResponseRedirect(
        reverse_lazy("funds:submissions:edit", args=(self.object.id,))
    )

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get_context_data(self, **kwargs):
    return super().get_context_data(buttons=self.buttons(), **kwargs)

get_form_class

get_form_class()

Returns the form class for the view.

This method is called by the view during form instantiation. It returns the form class that will be used to render the form.

When trying to save as draft, this method will return a version of form class that doesn't validate required fields while saving.

The method also disables any group toggle fields in the form, as they are not supported on edit forms.

Returns:

  • class –

    The form class for the view.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_class(self):
    """
    Returns the form class for the view.

    This method is called by the view during form instantiation. It returns
    the form class that will be used to render the form.

    When trying to save as draft, this method will return a version of form
    class that doesn't validate required fields while saving.

    The method also disables any group toggle fields in the form, as they
    are not supported on edit forms.

    Returns:
        class: The form class for the view.
    """
    is_draft = True if "save" in self.request.POST else False
    form_fields = self.object.get_form_fields(
        draft=is_draft, form_data=self.object.raw_data, user=self.request.user
    )
    field_blocks = self.object.get_defined_fields()
    for field_block in field_blocks:
        if isinstance(field_block.block, GroupToggleBlock):
            # Disable group toggle field as it is not supported on edit forms.
            form_fields[field_block.id].disabled = True
    return type(
        "WagtailStreamForm", (self.object.submission_form_class,), form_fields
    )

AdminSubmissionEditView

Bases: BaseSubmissionEditView

model class-attribute instance-attribute

render_preview

render_preview(request, form)

Gets a rendered preview of a form

Creates a new revision on the ApplicationSubmission, removes the forms temporary files

Parameters:

  • request (HttpRequest) –

    Request used to trigger the preview to be used in the render

  • form (BaseModelForm) –

    Form to be rendered

Returns:

  • HttpResponse –

    An HttpResponse containing a preview of the given form

Source code in hypha/apply/funds/views/submission_edit.py
def render_preview(self, request: HttpRequest, form: BaseModelForm) -> HttpResponse:
    """Gets a rendered preview of a form

    Creates a new revision on the `ApplicationSubmission`, removes the
    forms temporary files

    Args:
        request:
            Request used to trigger the preview to be used in the render
        form:
            Form to be rendered

    Returns:
        An `HttpResponse` containing a preview of the given form
    """

    self.object.create_revision(draft=True, by=request.user)
    messages.success(self.request, _("Draft saved"))

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()

    context = self.get_context_data()
    return render(request, "funds/application_preview.html", context)

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    permission, _ = has_permission(
        "submission_edit",
        request.user,
        object=self.get_object(),
        raise_exception=True,
    )
    if not self.get_object().phase.permissions.can_edit(request.user):
        raise PermissionDenied
    return super().dispatch(request, *args, **kwargs)

get_object_fund_current_round

get_object_fund_current_round()
Source code in hypha/apply/funds/views/submission_edit.py
def get_object_fund_current_round(self):
    assigned_fund = self.object.round.get_parent().specific
    if assigned_fund.open_round:
        return assigned_fund.open_round
    return False

get_on_submit_transition

get_on_submit_transition(user)

Gets the transition that should be triggered when a form is submitted.

Checks all available status transitions for the current user and returns the first one that has trigger_on_submit=True in its custom settings.

Returns:

  • dict –

    The transition configuration dictionary with trigger_on_submit=True, or None if no matching transition is found.

Source code in hypha/apply/funds/views/submission_edit.py
def get_on_submit_transition(self, user):
    """Gets the transition that should be triggered when a form is submitted.

    Checks all available status transitions for the current user and returns the first
    one that has trigger_on_submit=True in its custom settings.

    Returns:
        dict: The transition configuration dictionary with trigger_on_submit=True,
            or None if no matching transition is found.
    """
    return next(
        (
            t
            for t in self.object.get_available_user_status_transitions(user)
            if t.custom.get("trigger_on_submit", False)
        ),
        None,
    )

form_valid

form_valid(form)

Handle the form returned from a SubmissionEditView.

Determine whether to return a form preview, draft the new edits, or submit and transition the ApplicationSubmission object

Parameters:

  • form (BaseModelForm) –

    The valid form

Returns:

  • HttpResponse –

    An HttpResponse depending on the actions taken in the edit view

Source code in hypha/apply/funds/views/submission_edit.py
def form_valid(self, form: BaseModelForm) -> HttpResponse:
    """Handle the form returned from a `SubmissionEditView`.

    Determine whether to return a form preview, draft the new edits,
    or submit and transition the `ApplicationSubmission` object

    Args:
        form: The valid form

    Returns:
        An `HttpResponse` depending on the actions taken in the edit view
    """

    self.object.form_data = form.cleaned_data

    is_draft = self.object.status == DRAFT_STATE

    # Handle a preview or a save (aka a draft)
    if "preview" in self.request.POST:
        return self.render_preview(self.request, form)

    if "save" in self.request.POST:
        return self.save_draft_and_refresh_page(form=form)

    # Handle an application being submitted from a DRAFT_STATE. This includes updating submit_time
    if is_draft and "submit" in self.request.POST:
        self.object.submit_time = timezone.now()
        if self.object.round:
            current_round = self.get_object_fund_current_round()
            if current_round:
                self.object.round = current_round
        self.object.save(update_fields=["submit_time", "round"])

    revision = self.object.create_revision(by=self.request.user)
    submitting_proposal = self.object.phase.name in STAGE_CHANGE_ACTIONS

    if submitting_proposal:
        messenger(
            MESSAGES.PROPOSAL_SUBMITTED,
            request=self.request,
            user=self.request.user,
            source=self.object,
        )
    elif revision and not self.object.status == DRAFT_STATE:
        messenger(
            MESSAGES.APPLICANT_EDIT,
            request=self.request,
            user=self.request.user,
            source=self.object,
            related=revision,
        )

    if "submit" in self.request.POST:
        if transition := self.get_on_submit_transition(self.request.user):
            notify = (
                not (revision or submitting_proposal)
                or self.object.status == DRAFT_STATE,
            )
            self.object.perform_transition(
                transition.target,
                self.request.user,
                request=self.request,
                notify=notify,  # Use the other notification
            )

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()
    return HttpResponseRedirect(self.get_success_url())

get_form_kwargs

get_form_kwargs()

Returns the keyword arguments for instantiating the form.

This method is called by the form mixin during form instantiation. It returns a dictionary of keyword arguments that will be passed to the form's constructor.

Returns:

  • dict –

    A dictionary of keyword arguments for the form constructor.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_kwargs(self):
    """
    Returns the keyword arguments for instantiating the form.

    This method is called by the form mixin during form instantiation.
    It returns a dictionary of keyword arguments that will be passed to
    the form's constructor.

    Returns:
        dict: A dictionary of keyword arguments for the form constructor.
    """
    kwargs = super().get_form_kwargs()
    instance = kwargs.pop("instance").from_draft()
    initial = instance.raw_data
    for field_id in instance.file_field_ids:
        initial.pop(field_id + "-uploads", False)
        initial[field_id] = self.get_placeholder_file(
            instance.raw_data.get(field_id)
        )
    kwargs["initial"] = initial
    return kwargs

get_placeholder_file

get_placeholder_file(initial_file)
Source code in hypha/apply/funds/views/submission_edit.py
def get_placeholder_file(self, initial_file):
    if not isinstance(initial_file, list):
        return PlaceholderUploadedFile(
            initial_file.filename, size=initial_file.size, file_id=initial_file.name
        )
    return [
        PlaceholderUploadedFile(f.filename, size=f.size, file_id=f.name)
        for f in initial_file
    ]

save_draft_and_refresh_page

save_draft_and_refresh_page(form)
Source code in hypha/apply/funds/views/submission_edit.py
def save_draft_and_refresh_page(self, form) -> HttpResponseRedirect:
    self.object.create_revision(draft=True, by=self.request.user)
    form.delete_temporary_files()
    messages.success(self.request, _("Draft saved"))
    return HttpResponseRedirect(
        reverse_lazy("funds:submissions:edit", args=(self.object.id,))
    )

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get_context_data(self, **kwargs):
    return super().get_context_data(buttons=self.buttons(), **kwargs)

get_form_class

get_form_class()

Returns the form class for the view.

This method is called by the view during form instantiation. It returns the form class that will be used to render the form.

When trying to save as draft, this method will return a version of form class that doesn't validate required fields while saving.

The method also disables any group toggle fields in the form, as they are not supported on edit forms.

Returns:

  • class –

    The form class for the view.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_class(self):
    """
    Returns the form class for the view.

    This method is called by the view during form instantiation. It returns
    the form class that will be used to render the form.

    When trying to save as draft, this method will return a version of form
    class that doesn't validate required fields while saving.

    The method also disables any group toggle fields in the form, as they
    are not supported on edit forms.

    Returns:
        class: The form class for the view.
    """
    is_draft = True if "save" in self.request.POST else False
    form_fields = self.object.get_form_fields(
        draft=is_draft, form_data=self.object.raw_data, user=self.request.user
    )
    field_blocks = self.object.get_defined_fields()
    for field_block in field_blocks:
        if isinstance(field_block.block, GroupToggleBlock):
            # Disable group toggle field as it is not supported on edit forms.
            form_fields[field_block.id].disabled = True
    return type(
        "WagtailStreamForm", (self.object.submission_form_class,), form_fields
    )

buttons

buttons()

The buttons to be presented in the AdminSubmissionEditView

Admins shouldn't be required to preview, but should have the option.

Returns:

  • str –

    A generator returning a tuple strings in the format of:

  • str –

    (

Source code in hypha/apply/funds/views/submission_edit.py
def buttons(
    self,
) -> Generator[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str]]:
    """The buttons to be presented in the `AdminSubmissionEditView`

    Admins shouldn't be required to preview, but should have the option.

    Returns:
        A generator returning a tuple strings in the format of:
        (<button type>, <button styling>, <button label>)
    """
    yield ("submit", "primary", _("Submit"))
    yield ("save", "white", _("Save draft"))
    yield ("preview", "white", _("Preview"))

ApplicantSubmissionEditView

Bases: BaseSubmissionEditView

model class-attribute instance-attribute

render_preview

render_preview(request, form)

Gets a rendered preview of a form

Creates a new revision on the ApplicationSubmission, removes the forms temporary files

Parameters:

  • request (HttpRequest) –

    Request used to trigger the preview to be used in the render

  • form (BaseModelForm) –

    Form to be rendered

Returns:

  • HttpResponse –

    An HttpResponse containing a preview of the given form

Source code in hypha/apply/funds/views/submission_edit.py
def render_preview(self, request: HttpRequest, form: BaseModelForm) -> HttpResponse:
    """Gets a rendered preview of a form

    Creates a new revision on the `ApplicationSubmission`, removes the
    forms temporary files

    Args:
        request:
            Request used to trigger the preview to be used in the render
        form:
            Form to be rendered

    Returns:
        An `HttpResponse` containing a preview of the given form
    """

    self.object.create_revision(draft=True, by=request.user)
    messages.success(self.request, _("Draft saved"))

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()

    context = self.get_context_data()
    return render(request, "funds/application_preview.html", context)

buttons

buttons()

The buttons to be presented to the in the EditView

Returns:

  • str –

    A generator returning a tuple strings in the format of:

  • str –

    (

Source code in hypha/apply/funds/views/submission_edit.py
def buttons(
    self,
) -> Generator[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str]]:
    """The buttons to be presented to the in the EditView

    Returns:
        A generator returning a tuple strings in the format of:
        (<button type>, <button styling>, <button label>)
    """
    if settings.SUBMISSION_PREVIEW_REQUIRED:
        yield ("preview", "primary", _("Preview and submit"))
        yield ("save", "white", _("Save draft"))
    else:
        yield ("submit", "primary", _("Submit"))
        yield ("save", "white", _("Save draft"))
        yield ("preview", "white", _("Preview"))

get_object_fund_current_round

get_object_fund_current_round()
Source code in hypha/apply/funds/views/submission_edit.py
def get_object_fund_current_round(self):
    assigned_fund = self.object.round.get_parent().specific
    if assigned_fund.open_round:
        return assigned_fund.open_round
    return False

get_on_submit_transition

get_on_submit_transition(user)

Gets the transition that should be triggered when a form is submitted.

Checks all available status transitions for the current user and returns the first one that has trigger_on_submit=True in its custom settings.

Returns:

  • dict –

    The transition configuration dictionary with trigger_on_submit=True, or None if no matching transition is found.

Source code in hypha/apply/funds/views/submission_edit.py
def get_on_submit_transition(self, user):
    """Gets the transition that should be triggered when a form is submitted.

    Checks all available status transitions for the current user and returns the first
    one that has trigger_on_submit=True in its custom settings.

    Returns:
        dict: The transition configuration dictionary with trigger_on_submit=True,
            or None if no matching transition is found.
    """
    return next(
        (
            t
            for t in self.object.get_available_user_status_transitions(user)
            if t.custom.get("trigger_on_submit", False)
        ),
        None,
    )

form_valid

form_valid(form)

Handle the form returned from a SubmissionEditView.

Determine whether to return a form preview, draft the new edits, or submit and transition the ApplicationSubmission object

Parameters:

  • form (BaseModelForm) –

    The valid form

Returns:

  • HttpResponse –

    An HttpResponse depending on the actions taken in the edit view

Source code in hypha/apply/funds/views/submission_edit.py
def form_valid(self, form: BaseModelForm) -> HttpResponse:
    """Handle the form returned from a `SubmissionEditView`.

    Determine whether to return a form preview, draft the new edits,
    or submit and transition the `ApplicationSubmission` object

    Args:
        form: The valid form

    Returns:
        An `HttpResponse` depending on the actions taken in the edit view
    """

    self.object.form_data = form.cleaned_data

    is_draft = self.object.status == DRAFT_STATE

    # Handle a preview or a save (aka a draft)
    if "preview" in self.request.POST:
        return self.render_preview(self.request, form)

    if "save" in self.request.POST:
        return self.save_draft_and_refresh_page(form=form)

    # Handle an application being submitted from a DRAFT_STATE. This includes updating submit_time
    if is_draft and "submit" in self.request.POST:
        self.object.submit_time = timezone.now()
        if self.object.round:
            current_round = self.get_object_fund_current_round()
            if current_round:
                self.object.round = current_round
        self.object.save(update_fields=["submit_time", "round"])

    revision = self.object.create_revision(by=self.request.user)
    submitting_proposal = self.object.phase.name in STAGE_CHANGE_ACTIONS

    if submitting_proposal:
        messenger(
            MESSAGES.PROPOSAL_SUBMITTED,
            request=self.request,
            user=self.request.user,
            source=self.object,
        )
    elif revision and not self.object.status == DRAFT_STATE:
        messenger(
            MESSAGES.APPLICANT_EDIT,
            request=self.request,
            user=self.request.user,
            source=self.object,
            related=revision,
        )

    if "submit" in self.request.POST:
        if transition := self.get_on_submit_transition(self.request.user):
            notify = (
                not (revision or submitting_proposal)
                or self.object.status == DRAFT_STATE,
            )
            self.object.perform_transition(
                transition.target,
                self.request.user,
                request=self.request,
                notify=notify,  # Use the other notification
            )

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()
    return HttpResponseRedirect(self.get_success_url())

get_form_kwargs

get_form_kwargs()

Returns the keyword arguments for instantiating the form.

This method is called by the form mixin during form instantiation. It returns a dictionary of keyword arguments that will be passed to the form's constructor.

Returns:

  • dict –

    A dictionary of keyword arguments for the form constructor.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_kwargs(self):
    """
    Returns the keyword arguments for instantiating the form.

    This method is called by the form mixin during form instantiation.
    It returns a dictionary of keyword arguments that will be passed to
    the form's constructor.

    Returns:
        dict: A dictionary of keyword arguments for the form constructor.
    """
    kwargs = super().get_form_kwargs()
    instance = kwargs.pop("instance").from_draft()
    initial = instance.raw_data
    for field_id in instance.file_field_ids:
        initial.pop(field_id + "-uploads", False)
        initial[field_id] = self.get_placeholder_file(
            instance.raw_data.get(field_id)
        )
    kwargs["initial"] = initial
    return kwargs

get_placeholder_file

get_placeholder_file(initial_file)
Source code in hypha/apply/funds/views/submission_edit.py
def get_placeholder_file(self, initial_file):
    if not isinstance(initial_file, list):
        return PlaceholderUploadedFile(
            initial_file.filename, size=initial_file.size, file_id=initial_file.name
        )
    return [
        PlaceholderUploadedFile(f.filename, size=f.size, file_id=f.name)
        for f in initial_file
    ]

save_draft_and_refresh_page

save_draft_and_refresh_page(form)
Source code in hypha/apply/funds/views/submission_edit.py
def save_draft_and_refresh_page(self, form) -> HttpResponseRedirect:
    self.object.create_revision(draft=True, by=self.request.user)
    form.delete_temporary_files()
    messages.success(self.request, _("Draft saved"))
    return HttpResponseRedirect(
        reverse_lazy("funds:submissions:edit", args=(self.object.id,))
    )

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get_context_data(self, **kwargs):
    return super().get_context_data(buttons=self.buttons(), **kwargs)

get_form_class

get_form_class()

Returns the form class for the view.

This method is called by the view during form instantiation. It returns the form class that will be used to render the form.

When trying to save as draft, this method will return a version of form class that doesn't validate required fields while saving.

The method also disables any group toggle fields in the form, as they are not supported on edit forms.

Returns:

  • class –

    The form class for the view.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_class(self):
    """
    Returns the form class for the view.

    This method is called by the view during form instantiation. It returns
    the form class that will be used to render the form.

    When trying to save as draft, this method will return a version of form
    class that doesn't validate required fields while saving.

    The method also disables any group toggle fields in the form, as they
    are not supported on edit forms.

    Returns:
        class: The form class for the view.
    """
    is_draft = True if "save" in self.request.POST else False
    form_fields = self.object.get_form_fields(
        draft=is_draft, form_data=self.object.raw_data, user=self.request.user
    )
    field_blocks = self.object.get_defined_fields()
    for field_block in field_blocks:
        if isinstance(field_block.block, GroupToggleBlock):
            # Disable group toggle field as it is not supported on edit forms.
            form_fields[field_block.id].disabled = True
    return type(
        "WagtailStreamForm", (self.object.submission_form_class,), form_fields
    )

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    if request.user != submission.user:
        raise PermissionDenied
    return super().dispatch(request, *args, **kwargs)

PartnerSubmissionEditView

Bases: ApplicantSubmissionEditView

model class-attribute instance-attribute

render_preview

render_preview(request, form)

Gets a rendered preview of a form

Creates a new revision on the ApplicationSubmission, removes the forms temporary files

Parameters:

  • request (HttpRequest) –

    Request used to trigger the preview to be used in the render

  • form (BaseModelForm) –

    Form to be rendered

Returns:

  • HttpResponse –

    An HttpResponse containing a preview of the given form

Source code in hypha/apply/funds/views/submission_edit.py
def render_preview(self, request: HttpRequest, form: BaseModelForm) -> HttpResponse:
    """Gets a rendered preview of a form

    Creates a new revision on the `ApplicationSubmission`, removes the
    forms temporary files

    Args:
        request:
            Request used to trigger the preview to be used in the render
        form:
            Form to be rendered

    Returns:
        An `HttpResponse` containing a preview of the given form
    """

    self.object.create_revision(draft=True, by=request.user)
    messages.success(self.request, _("Draft saved"))

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()

    context = self.get_context_data()
    return render(request, "funds/application_preview.html", context)

buttons

buttons()

The buttons to be presented to the in the EditView

Returns:

  • str –

    A generator returning a tuple strings in the format of:

  • str –

    (

Source code in hypha/apply/funds/views/submission_edit.py
def buttons(
    self,
) -> Generator[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str]]:
    """The buttons to be presented to the in the EditView

    Returns:
        A generator returning a tuple strings in the format of:
        (<button type>, <button styling>, <button label>)
    """
    if settings.SUBMISSION_PREVIEW_REQUIRED:
        yield ("preview", "primary", _("Preview and submit"))
        yield ("save", "white", _("Save draft"))
    else:
        yield ("submit", "primary", _("Submit"))
        yield ("save", "white", _("Save draft"))
        yield ("preview", "white", _("Preview"))

get_object_fund_current_round

get_object_fund_current_round()
Source code in hypha/apply/funds/views/submission_edit.py
def get_object_fund_current_round(self):
    assigned_fund = self.object.round.get_parent().specific
    if assigned_fund.open_round:
        return assigned_fund.open_round
    return False

get_on_submit_transition

get_on_submit_transition(user)

Gets the transition that should be triggered when a form is submitted.

Checks all available status transitions for the current user and returns the first one that has trigger_on_submit=True in its custom settings.

Returns:

  • dict –

    The transition configuration dictionary with trigger_on_submit=True, or None if no matching transition is found.

Source code in hypha/apply/funds/views/submission_edit.py
def get_on_submit_transition(self, user):
    """Gets the transition that should be triggered when a form is submitted.

    Checks all available status transitions for the current user and returns the first
    one that has trigger_on_submit=True in its custom settings.

    Returns:
        dict: The transition configuration dictionary with trigger_on_submit=True,
            or None if no matching transition is found.
    """
    return next(
        (
            t
            for t in self.object.get_available_user_status_transitions(user)
            if t.custom.get("trigger_on_submit", False)
        ),
        None,
    )

form_valid

form_valid(form)

Handle the form returned from a SubmissionEditView.

Determine whether to return a form preview, draft the new edits, or submit and transition the ApplicationSubmission object

Parameters:

  • form (BaseModelForm) –

    The valid form

Returns:

  • HttpResponse –

    An HttpResponse depending on the actions taken in the edit view

Source code in hypha/apply/funds/views/submission_edit.py
def form_valid(self, form: BaseModelForm) -> HttpResponse:
    """Handle the form returned from a `SubmissionEditView`.

    Determine whether to return a form preview, draft the new edits,
    or submit and transition the `ApplicationSubmission` object

    Args:
        form: The valid form

    Returns:
        An `HttpResponse` depending on the actions taken in the edit view
    """

    self.object.form_data = form.cleaned_data

    is_draft = self.object.status == DRAFT_STATE

    # Handle a preview or a save (aka a draft)
    if "preview" in self.request.POST:
        return self.render_preview(self.request, form)

    if "save" in self.request.POST:
        return self.save_draft_and_refresh_page(form=form)

    # Handle an application being submitted from a DRAFT_STATE. This includes updating submit_time
    if is_draft and "submit" in self.request.POST:
        self.object.submit_time = timezone.now()
        if self.object.round:
            current_round = self.get_object_fund_current_round()
            if current_round:
                self.object.round = current_round
        self.object.save(update_fields=["submit_time", "round"])

    revision = self.object.create_revision(by=self.request.user)
    submitting_proposal = self.object.phase.name in STAGE_CHANGE_ACTIONS

    if submitting_proposal:
        messenger(
            MESSAGES.PROPOSAL_SUBMITTED,
            request=self.request,
            user=self.request.user,
            source=self.object,
        )
    elif revision and not self.object.status == DRAFT_STATE:
        messenger(
            MESSAGES.APPLICANT_EDIT,
            request=self.request,
            user=self.request.user,
            source=self.object,
            related=revision,
        )

    if "submit" in self.request.POST:
        if transition := self.get_on_submit_transition(self.request.user):
            notify = (
                not (revision or submitting_proposal)
                or self.object.status == DRAFT_STATE,
            )
            self.object.perform_transition(
                transition.target,
                self.request.user,
                request=self.request,
                notify=notify,  # Use the other notification
            )

    # Required for django-file-form: delete temporary files for the new files
    # uploaded while edit.
    form.delete_temporary_files()
    return HttpResponseRedirect(self.get_success_url())

get_form_kwargs

get_form_kwargs()

Returns the keyword arguments for instantiating the form.

This method is called by the form mixin during form instantiation. It returns a dictionary of keyword arguments that will be passed to the form's constructor.

Returns:

  • dict –

    A dictionary of keyword arguments for the form constructor.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_kwargs(self):
    """
    Returns the keyword arguments for instantiating the form.

    This method is called by the form mixin during form instantiation.
    It returns a dictionary of keyword arguments that will be passed to
    the form's constructor.

    Returns:
        dict: A dictionary of keyword arguments for the form constructor.
    """
    kwargs = super().get_form_kwargs()
    instance = kwargs.pop("instance").from_draft()
    initial = instance.raw_data
    for field_id in instance.file_field_ids:
        initial.pop(field_id + "-uploads", False)
        initial[field_id] = self.get_placeholder_file(
            instance.raw_data.get(field_id)
        )
    kwargs["initial"] = initial
    return kwargs

get_placeholder_file

get_placeholder_file(initial_file)
Source code in hypha/apply/funds/views/submission_edit.py
def get_placeholder_file(self, initial_file):
    if not isinstance(initial_file, list):
        return PlaceholderUploadedFile(
            initial_file.filename, size=initial_file.size, file_id=initial_file.name
        )
    return [
        PlaceholderUploadedFile(f.filename, size=f.size, file_id=f.name)
        for f in initial_file
    ]

save_draft_and_refresh_page

save_draft_and_refresh_page(form)
Source code in hypha/apply/funds/views/submission_edit.py
def save_draft_and_refresh_page(self, form) -> HttpResponseRedirect:
    self.object.create_revision(draft=True, by=self.request.user)
    form.delete_temporary_files()
    messages.success(self.request, _("Draft saved"))
    return HttpResponseRedirect(
        reverse_lazy("funds:submissions:edit", args=(self.object.id,))
    )

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get_context_data(self, **kwargs):
    return super().get_context_data(buttons=self.buttons(), **kwargs)

get_form_class

get_form_class()

Returns the form class for the view.

This method is called by the view during form instantiation. It returns the form class that will be used to render the form.

When trying to save as draft, this method will return a version of form class that doesn't validate required fields while saving.

The method also disables any group toggle fields in the form, as they are not supported on edit forms.

Returns:

  • class –

    The form class for the view.

Source code in hypha/apply/funds/views/submission_edit.py
def get_form_class(self):
    """
    Returns the form class for the view.

    This method is called by the view during form instantiation. It returns
    the form class that will be used to render the form.

    When trying to save as draft, this method will return a version of form
    class that doesn't validate required fields while saving.

    The method also disables any group toggle fields in the form, as they
    are not supported on edit forms.

    Returns:
        class: The form class for the view.
    """
    is_draft = True if "save" in self.request.POST else False
    form_fields = self.object.get_form_fields(
        draft=is_draft, form_data=self.object.raw_data, user=self.request.user
    )
    field_blocks = self.object.get_defined_fields()
    for field_block in field_blocks:
        if isinstance(field_block.block, GroupToggleBlock):
            # Disable group toggle field as it is not supported on edit forms.
            form_fields[field_block.id].disabled = True
    return type(
        "WagtailStreamForm", (self.object.submission_form_class,), form_fields
    )

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    # If the requesting user submitted the application, return the Applicant view.
    # Partners may somtimes be applicants as well.
    partner_has_access = submission.partners.filter(pk=request.user.pk).exists()
    if not partner_has_access and submission.user != request.user:
        raise PermissionDenied
    return super(ApplicantSubmissionEditView, self).dispatch(
        request, *args, **kwargs
    )

SubmissionEditView

Bases: ViewDispatcher

community_view class-attribute instance-attribute

community_view = None

finance_view class-attribute instance-attribute

finance_view = None

contracting_view class-attribute instance-attribute

contracting_view = None

admin_view class-attribute instance-attribute

applicant_view class-attribute instance-attribute

applicant_view = ApplicantSubmissionEditView

reviewer_view class-attribute instance-attribute

partner_view class-attribute instance-attribute

admin_check

admin_check(request)
Source code in hypha/apply/utils/views.py
def admin_check(self, request):
    return request.user.is_apply_staff

reviewer_check

reviewer_check(request)
Source code in hypha/apply/utils/views.py
def reviewer_check(self, request):
    return request.user.is_reviewer

partner_check

partner_check(request)
Source code in hypha/apply/utils/views.py
def partner_check(self, request):
    return request.user.is_partner

community_check

community_check(request)
Source code in hypha/apply/utils/views.py
def community_check(self, request):
    return request.user.is_community_reviewer

finance_check

finance_check(request)
Source code in hypha/apply/utils/views.py
def finance_check(self, request):
    return request.user.is_finance

contracting_check

contracting_check(request)
Source code in hypha/apply/utils/views.py
def contracting_check(self, request):
    return request.user.is_contracting

applicant_check

applicant_check(request)
Source code in hypha/apply/utils/views.py
def applicant_check(self, request):
    return request.user.is_applicant

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/utils/views.py
def dispatch(self, request, *args, **kwargs):
    view = None

    if self.admin_check(request):
        view = self.admin_view
    elif self.reviewer_check(request):
        view = self.reviewer_view
    elif self.partner_check(request):
        view = self.partner_view
    elif self.community_check(request):
        view = self.community_view
    elif settings.PROJECTS_ENABLED and self.finance_check(request):
        view = self.finance_view
    elif settings.PROJECTS_ENABLED and self.contracting_check(request):
        view = self.contracting_view
    elif self.applicant_check(request):
        view = self.applicant_view

    if view:
        return view.as_view()(request, *args, **kwargs)
    return HttpResponseForbidden()

ProgressSubmissionView

Bases: View

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    self.submission = get_object_or_404(ApplicationSubmission, id=kwargs.get("pk"))
    permission, reason = has_permission(
        "submission_edit",
        request.user,
        object=self.submission,
        raise_exception=False,
    )
    if not permission:
        messages.warning(self.request, reason)
        return HttpResponseRedirect(self.submission.get_absolute_url())
    return super(ProgressSubmissionView, self).dispatch(request, *args, **kwargs)

get

get(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get(self, *args, **kwargs):
    project_creation_form = ProgressSubmissionForm(
        instance=self.submission, user=self.request.user
    )
    return render(
        self.request,
        "funds/includes/progress_form.html",
        context={
            "form": project_creation_form,
            "value": _("Progress"),
            "object": self.submission,
        },
    )

post

post(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def post(self, *args, **kwargs):
    form = ProgressSubmissionForm(
        self.request.POST, instance=self.submission, user=self.request.user
    )
    if form.is_valid():
        action = form.cleaned_data.get("action")
        redirect = DeterminationCreateOrUpdateView.should_redirect(
            self.request, self.submission, action
        )
        message_storage = messages.get_messages(self.request)
        if redirect:
            return HttpResponseClientRedirect(redirect.url, content=message_storage)

        self.submission.perform_transition(
            action, self.request.user, request=self.request
        )
        form.save()
        return HttpResponseClientRefresh()
    return render(
        self.request,
        "funds/includes/progress_form.html",
        context={"form": form, "value": _("Progress"), "object": self.submission},
        status=400,
    )

CreateProjectView

Bases: View

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    self.submission = get_object_or_404(ApplicationSubmission, id=kwargs.get("pk"))
    permission, reason = has_permission(
        "submission_edit",
        request.user,
        object=self.submission,
        raise_exception=False,
    )
    if not permission:
        messages.warning(self.request, reason)
        return HttpResponseRedirect(self.submission.get_absolute_url())
    return super(CreateProjectView, self).dispatch(request, *args, **kwargs)

get

get(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get(self, *args, **kwargs):
    project_creation_form = ProjectCreateForm(instance=self.submission)
    return render(
        self.request,
        "funds/includes/create_project_form.html",
        context={
            "form": project_creation_form,
            "value": _("Confirm"),
            "object": self.submission,
        },
    )

post

post(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def post(self, *args, **kwargs):
    form = ProjectCreateForm(self.request.POST, instance=self.submission)
    if form.is_valid():
        project = form.save()
        # Record activity
        messenger(
            MESSAGES.CREATED_PROJECT,
            request=self.request,
            user=self.request.user,
            source=project,
            related=project.submission,
        )
        # add task for staff to add PAF to the project
        add_task_to_user(
            code=PROJECT_WAITING_PF,
            user=project.lead,
            related_obj=project,
        )
        if self.submission.page.specific.sow_forms.first():
            # Add SOW task if one exists on the parent
            add_task_to_user(
                code=PROJECT_WAITING_SOW,
                user=project.lead,
                related_obj=project,
            )
        return HttpResponseClientRedirect(project.get_absolute_url())
    return render(
        self.request,
        "funds/includes/create_project_form.html",
        context={"form": form, "value": _("Confirm"), "object": self.object},
        status=400,
    )

UpdateLeadView

Bases: View

model class-attribute instance-attribute

form_class class-attribute instance-attribute

context_name class-attribute instance-attribute

context_name = 'lead_form'

template class-attribute instance-attribute

template = 'funds/modals/update_lead_form.html'

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    self.object = get_object_or_404(ApplicationSubmission, id=kwargs.get("pk"))
    permission, reason = has_permission(
        "submission_edit", request.user, object=self.object, raise_exception=False
    )
    if not permission:
        messages.warning(self.request, reason)
        return HttpResponseRedirect(self.object.get_absolute_url())
    return super().dispatch(request, *args, **kwargs)

get

get(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get(self, *args, **kwargs):
    lead_form = UpdateSubmissionLeadForm(instance=self.object)
    return render(
        self.request,
        self.template,
        context={
            "form": lead_form,
            "value": _("Update"),
            "object": self.object,
        },
    )

post

post(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def post(self, *args, **kwargs):
    form = UpdateSubmissionLeadForm(self.request.POST, instance=self.object)
    old_lead = copy(self.object.lead)
    if form.is_valid():
        form.save()
        messenger(
            MESSAGES.UPDATE_LEAD,
            request=self.request,
            user=self.request.user,
            source=form.instance,
            related=old_lead,
        )
        return HttpResponse(
            status=204,
            headers={
                "HX-Trigger": json.dumps(
                    {"leadUpdated": None, "showMessage": "Submission Lead updated."}
                ),
            },
        )
    return render(
        self.request,
        self.template,
        context={"form": form, "value": _("Update"), "object": self.object},
        status=400,
    )

UpdateReviewersView

Bases: View

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    self.submission = get_object_or_404(ApplicationSubmission, id=kwargs.get("pk"))
    permission, reason = has_permission(
        "submission_edit",
        request.user,
        object=self.submission,
        raise_exception=False,
    )
    if not permission:
        messages.warning(self.request, reason)
        return HttpResponseRedirect(self.submission.get_absolute_url())
    return super(UpdateReviewersView, self).dispatch(request, *args, **kwargs)

get

get(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get(self, *args, **kwargs):
    reviewer_form = UpdateReviewersForm(
        user=self.request.user, instance=self.submission
    )
    return render(
        self.request,
        "funds/includes/update_reviewer_form.html",
        context={
            "form": reviewer_form,
            "value": _("Update"),
            "object": self.submission,
        },
    )

post

post(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def post(self, *args, **kwargs):
    form = UpdateReviewersForm(
        self.request.POST, user=self.request.user, instance=self.submission
    )
    old_reviewers = {copy(reviewer) for reviewer in form.instance.assigned.all()}
    if form.is_valid():
        form.save()
        new_reviewers = set(form.instance.assigned.all())
        added = new_reviewers - old_reviewers
        removed = old_reviewers - new_reviewers
        messenger(
            MESSAGES.REVIEWERS_UPDATED,
            request=self.request,
            user=self.request.user,
            source=self.submission,
            added=added,
            removed=removed,
        )
        # Update submission status if needed.
        services.set_status_after_reviewers_assigned(
            submission=form.instance,
            updated_by=self.request.user,
            request=self.request,
        )
        return HttpResponse(
            status=204,
            headers={
                "HX-Trigger": json.dumps(
                    {"reviewerUpdated": None, "showMessage": "Reviewers updated."}
                ),
            },
        )

    return render(
        self.request,
        "funds/includes/update_reviewer_form.html",
        context={"form": form, "value": _("Update"), "object": self.submission},
    )

UpdatePartnersView

Bases: View

model class-attribute instance-attribute

form_class class-attribute instance-attribute

form_class = UpdatePartnersForm

context_name class-attribute instance-attribute

context_name = 'partner_form'

template class-attribute instance-attribute

template = 'funds/modals/update_partner_form.html'

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    self.submission = get_object_or_404(ApplicationSubmission, id=kwargs.get("pk"))
    permission, reason = has_permission(
        "submission_edit",
        request.user,
        object=self.submission,
        raise_exception=False,
    )
    if not permission:
        messages.warning(self.request, reason)
        return HttpResponseRedirect(self.submission.get_absolute_url())
    return super(UpdatePartnersView, self).dispatch(request, *args, **kwargs)

get

get(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get(self, *args, **kwargs):
    partner_form = UpdatePartnersForm(
        user=self.request.user, instance=self.submission
    )
    return render(
        self.request,
        self.template,
        context={
            "form": partner_form,
            "value": _("Update"),
            "object": self.submission,
        },
    )

post

post(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def post(self, *args, **kwargs):
    form = UpdatePartnersForm(
        self.request.POST, user=self.request.user, instance=self.submission
    )
    old_partners = set(self.submission.partners.all())
    if form.is_valid():
        form.save()
        new_partners = set(form.instance.partners.all())

        added = new_partners - old_partners
        removed = old_partners - new_partners
        messenger(
            MESSAGES.PARTNERS_UPDATED,
            request=self.request,
            user=self.request.user,
            source=self.submission,
            added=added,
            removed=removed,
        )

        messenger(
            MESSAGES.PARTNERS_UPDATED_PARTNER,
            request=self.request,
            user=self.request.user,
            source=self.submission,
            added=added,
            removed=removed,
        )

        return HttpResponse(
            status=204,
            headers={
                "HX-Trigger": json.dumps(
                    {
                        "partnerUpdated": None,
                        "showMessage": "Partners updated successfully.",
                    }
                ),
            },
        )

    return render(
        self.request,
        self.template,
        context={"form": form, "value": _("Update"), "object": self.submission},
        status=400,
    )

UpdateMetaTermsView

Bases: View

template class-attribute instance-attribute

template = 'funds/includes/update_meta_terms_form.html'

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def dispatch(self, request, *args, **kwargs):
    self.submission = get_object_or_404(ApplicationSubmission, id=kwargs.get("pk"))
    permission, reason = has_permission(
        "submission_edit",
        request.user,
        object=self.submission,
        raise_exception=False,
    )
    if not permission:
        messages.warning(self.request, reason)
        return HttpResponseRedirect(self.submission.get_absolute_url())
    return super(UpdateMetaTermsView, self).dispatch(request, *args, **kwargs)

get

get(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def get(self, *args, **kwargs):
    metaterms_form = UpdateMetaTermsForm(
        user=self.request.user, instance=self.submission
    )
    return render(
        self.request,
        self.template,
        context={
            "form": metaterms_form,
            "value": _("Update"),
            "object": self.submission,
        },
    )

post

post(*args, **kwargs)
Source code in hypha/apply/funds/views/submission_edit.py
def post(self, *args, **kwargs):
    form = UpdateMetaTermsForm(
        self.request.POST, instance=self.submission, user=self.request.user
    )
    if form.is_valid():
        form.save()

        return HttpResponse(
            status=204,
            headers={
                "HX-Trigger": json.dumps(
                    {
                        "metaTermsUpdated": None,
                        "showMessage": "Meta terms updated successfully.",
                    }
                ),
            },
        )
    return render(
        self.request,
        self.template,
        context={"form": form, "value": _("Update"), "object": self.submission},
        status=400,
    )

htmx_archive_unarchive_submission

htmx_archive_unarchive_submission(request, pk)
Source code in hypha/apply/funds/views/submission_edit.py
@login_required
@user_passes_test(is_apply_staff)
@require_http_methods(["GET", "POST"])
def htmx_archive_unarchive_submission(request, pk):
    submission = get_object_or_404(ApplicationSubmission, id=pk)
    permission, reason = has_permission(
        "archive_alter", request.user, object=submission, raise_exception=False
    )
    if not permission:
        return HttpResponse(reason)

    if submission.is_archive:
        template = "funds/includes/modal_unarchive_submission_confirm.html"
    else:
        template = "funds/includes/modal_archive_submission_confirm.html"

    if request.method == "POST":
        if submission.is_archive:
            submission.is_archive = False
            submission.save()
            messenger(
                MESSAGES.UNARCHIVE_SUBMISSION,
                request=request,
                user=request.user,
                source=submission,
            )
        else:
            submission.is_archive = True
            submission.save()
            messenger(
                MESSAGES.ARCHIVE_SUBMISSION,
                request=request,
                user=request.user,
                source=submission,
            )

        return redirect(submission.get_absolute_url())

    return render(
        request,
        template,
        context={"submission": submission},
    )