Skip to content

Submission detail

hypha.apply.funds.views.submission_detail

AdminSubmissionDetailView

AdminSubmissionDetailView(*args, **kwargs)

Bases: ActivityContextMixin, DelegateableView, DetailView

Source code in hypha/apply/utils/views.py
def __init__(self, *args, **kwargs):
    self._form_views = {
        self.form_prefix + form_view.context_name: form_view
        for form_view in self.form_views
    }

form_prefix class-attribute instance-attribute

form_prefix = 'form-submitted-'

template_name_suffix class-attribute instance-attribute

template_name_suffix = '_admin_detail'

model class-attribute instance-attribute

form_views class-attribute instance-attribute

form_views = [CommentFormView]

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    return {
        "user": self.request.user,
        "instance": self.object,
    }

post

post(request, *args, **kwargs)
Source code in hypha/apply/utils/views.py
def post(self, request, *args, **kwargs):
    self.object = self.get_object()

    kwargs["object"] = self.object

    return super().post(request, *args, **kwargs)

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    if submission.status == DRAFT_STATE and not submission.can_view_draft(
        request.user
    ):
        raise Http404
    permission, _ = has_permission(
        "submission_view", request.user, object=submission, raise_exception=True
    )
    redirect = SubmissionSealedView.should_redirect(request, submission)
    return redirect or super().dispatch(request, *args, **kwargs)

get

get(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
    self.object = self.get_object()

    extra_context = {}

    # Check for language params - if they exist and are valid then update the context
    if lang_params := get_translation_params(request=request):
        from_lang, to_lang = lang_params
        try:
            self.object.form_data = translate_application_form_data(
                self.object, from_lang, to_lang
            )
            extra_context.update(
                {
                    "from_lang_name": get_lang_name(from_lang),
                    "to_lang_name": get_lang_name(to_lang),
                }
            )
        except ValueError:
            # Language package isn't valid or installed, redirect to the submission w/o params
            return redirect(self.object.get_absolute_url())

    context = self.get_context_data(object=self.object, **extra_context)
    return self.render_to_response(context)

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def get_context_data(self, **kwargs):
    other_submissions = (
        self.model.objects.filter(user=self.object.user)
        .current()
        .exclude(id=self.object.id)
        .order_by("-submit_time")
    )
    if self.object.next:
        other_submissions = other_submissions.exclude(id=self.object.next.id)

    return super().get_context_data(
        other_submissions=other_submissions,
        archive_access_groups=get_archive_view_groups(),
        can_archive=can_alter_archived_submissions(self.request.user),
        **kwargs,
    )

ReviewerSubmissionDetailView

ReviewerSubmissionDetailView(*args, **kwargs)

Bases: ActivityContextMixin, DelegateableView, DetailView

Source code in hypha/apply/utils/views.py
def __init__(self, *args, **kwargs):
    self._form_views = {
        self.form_prefix + form_view.context_name: form_view
        for form_view in self.form_views
    }

form_prefix class-attribute instance-attribute

form_prefix = 'form-submitted-'

template_name_suffix class-attribute instance-attribute

template_name_suffix = '_reviewer_detail'

model class-attribute instance-attribute

form_views class-attribute instance-attribute

form_views = [CommentFormView]

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    return {
        "user": self.request.user,
        "instance": self.object,
    }

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/activity/views.py
def get_context_data(self, **kwargs):
    extra = {
        # Do not prefetch on the related_object__author as the models
        # are not homogeneous and this will fail
        "comments": services.get_related_comments_for_user(
            self.object, self.request.user
        ),
        "comments_count": services.get_comment_count(
            self.object, self.request.user
        ),
    }
    return super().get_context_data(**extra, **kwargs)

post

post(request, *args, **kwargs)
Source code in hypha/apply/utils/views.py
def post(self, request, *args, **kwargs):
    self.object = self.get_object()

    kwargs["object"] = self.object

    return super().post(request, *args, **kwargs)

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    # If the requesting user submitted the application, return the Applicant view.
    # Reviewers may sometimes be applicants as well.
    if submission.user == request.user:
        return ApplicantSubmissionDetailView.as_view()(request, *args, **kwargs)
    if submission.status == DRAFT_STATE:
        raise Http404

    permission, _ = has_permission(
        "submission_view", request.user, object=submission, raise_exception=True
    )

    reviewer_settings = ReviewerSettings.for_request(request)
    if reviewer_settings.use_settings:
        queryset = ApplicationSubmission.objects.for_reviewer_settings(
            request.user, reviewer_settings
        )
        # Reviewer can't view submission which is not listed in ReviewerSubmissionsTable
        if not queryset.filter(id=submission.id).exists():
            raise PermissionDenied

    return super().dispatch(request, *args, **kwargs)

PartnerSubmissionDetailView

PartnerSubmissionDetailView(*args, **kwargs)

Bases: ActivityContextMixin, DelegateableView, DetailView

Source code in hypha/apply/utils/views.py
def __init__(self, *args, **kwargs):
    self._form_views = {
        self.form_prefix + form_view.context_name: form_view
        for form_view in self.form_views
    }

form_prefix class-attribute instance-attribute

form_prefix = 'form-submitted-'

model class-attribute instance-attribute

form_views class-attribute instance-attribute

form_views = [CommentFormView]

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    return {
        "user": self.request.user,
        "instance": self.object,
    }

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/activity/views.py
def get_context_data(self, **kwargs):
    extra = {
        # Do not prefetch on the related_object__author as the models
        # are not homogeneous and this will fail
        "comments": services.get_related_comments_for_user(
            self.object, self.request.user
        ),
        "comments_count": services.get_comment_count(
            self.object, self.request.user
        ),
    }
    return super().get_context_data(**extra, **kwargs)

post

post(request, *args, **kwargs)
Source code in hypha/apply/utils/views.py
def post(self, request, *args, **kwargs):
    self.object = self.get_object()

    kwargs["object"] = self.object

    return super().post(request, *args, **kwargs)

get_object

get_object()
Source code in hypha/apply/funds/views/submission_detail.py
def get_object(self):
    return super().get_object().from_draft()

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    permission, _ = has_permission(
        "submission_view", request.user, object=submission, raise_exception=True
    )
    # If the requesting user submitted the application, return the Applicant view.
    # Partners may sometimes be applicants as well.
    if submission.user == request.user:
        return ApplicantSubmissionDetailView.as_view()(request, *args, **kwargs)
    # Only allow partners in the submission they are added as partners
    partner_has_access = submission.partners.filter(pk=request.user.pk).exists()
    if not partner_has_access:
        raise PermissionDenied
    if submission.status == DRAFT_STATE:
        raise Http404
    return super().dispatch(request, *args, **kwargs)

CommunitySubmissionDetailView

CommunitySubmissionDetailView(*args, **kwargs)

Bases: ActivityContextMixin, DelegateableView, DetailView

Source code in hypha/apply/utils/views.py
def __init__(self, *args, **kwargs):
    self._form_views = {
        self.form_prefix + form_view.context_name: form_view
        for form_view in self.form_views
    }

form_prefix class-attribute instance-attribute

form_prefix = 'form-submitted-'

template_name_suffix class-attribute instance-attribute

template_name_suffix = '_community_detail'

model class-attribute instance-attribute

form_views class-attribute instance-attribute

form_views = [CommentFormView]

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    return {
        "user": self.request.user,
        "instance": self.object,
    }

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/activity/views.py
def get_context_data(self, **kwargs):
    extra = {
        # Do not prefetch on the related_object__author as the models
        # are not homogeneous and this will fail
        "comments": services.get_related_comments_for_user(
            self.object, self.request.user
        ),
        "comments_count": services.get_comment_count(
            self.object, self.request.user
        ),
    }
    return super().get_context_data(**extra, **kwargs)

post

post(request, *args, **kwargs)
Source code in hypha/apply/utils/views.py
def post(self, request, *args, **kwargs):
    self.object = self.get_object()

    kwargs["object"] = self.object

    return super().post(request, *args, **kwargs)

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    permission, _ = has_permission(
        "submission_view", request.user, object=submission, raise_exception=True
    )
    # If the requesting user submitted the application, return the Applicant view.
    # Reviewers may sometimes be applicants as well.
    if submission.user == request.user:
        return ApplicantSubmissionDetailView.as_view()(request, *args, **kwargs)
    # Only allow community reviewers in submission with a community review state.
    if not submission.community_review:
        raise PermissionDenied
    if submission.status == DRAFT_STATE:
        raise Http404
    return super().dispatch(request, *args, **kwargs)

ApplicantSubmissionDetailView

ApplicantSubmissionDetailView(*args, **kwargs)

Bases: ActivityContextMixin, DelegateableView, DetailView

Source code in hypha/apply/utils/views.py
def __init__(self, *args, **kwargs):
    self._form_views = {
        self.form_prefix + form_view.context_name: form_view
        for form_view in self.form_views
    }

form_prefix class-attribute instance-attribute

form_prefix = 'form-submitted-'

model class-attribute instance-attribute

form_views class-attribute instance-attribute

form_views = [CommentFormView]

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    return {
        "user": self.request.user,
        "instance": self.object,
    }

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/activity/views.py
def get_context_data(self, **kwargs):
    extra = {
        # Do not prefetch on the related_object__author as the models
        # are not homogeneous and this will fail
        "comments": services.get_related_comments_for_user(
            self.object, self.request.user
        ),
        "comments_count": services.get_comment_count(
            self.object, self.request.user
        ),
    }
    return super().get_context_data(**extra, **kwargs)

post

post(request, *args, **kwargs)
Source code in hypha/apply/utils/views.py
def post(self, request, *args, **kwargs):
    self.object = self.get_object()

    kwargs["object"] = self.object

    return super().post(request, *args, **kwargs)

get_object

get_object()
Source code in hypha/apply/funds/views/submission_detail.py
def get_object(self):
    return super().get_object().from_draft()

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def dispatch(self, request, *args, **kwargs):
    submission = self.get_object()
    permission, _ = has_permission(
        "submission_view", request.user, object=submission, raise_exception=True
    )
    # This view is only for applicants.
    if submission.user != request.user:
        raise PermissionDenied
    return super().dispatch(request, *args, **kwargs)

SubmissionDetailView

Bases: ViewDispatcher

finance_view class-attribute instance-attribute

finance_view = None

contracting_view class-attribute instance-attribute

contracting_view = None

admin_view class-attribute instance-attribute

reviewer_view class-attribute instance-attribute

partner_view class-attribute instance-attribute

community_view class-attribute instance-attribute

applicant_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()

SubmissionSealedView

Bases: DetailView

template_name class-attribute instance-attribute

template_name = 'funds/submission_sealed.html'

model class-attribute instance-attribute

get

get(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def get(self, request, *args, **kwargs):
    submission = self.get_object()
    if not self.round_is_sealed(submission):
        return self.redirect_detail(submission)
    return super().get(request, *args, **kwargs)

post

post(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def post(self, request, *args, **kwargs):
    submission = self.get_object()
    if self.can_view_sealed(request.user):
        self.peeked(submission)
    return self.redirect_detail(submission)

redirect_detail

redirect_detail(submission)
Source code in hypha/apply/funds/views/submission_detail.py
def redirect_detail(self, submission):
    return HttpResponseRedirect(
        reverse_lazy("funds:submissions:detail", args=(submission.id,))
    )

peeked

peeked(submission)
Source code in hypha/apply/funds/views/submission_detail.py
def peeked(self, submission):
    messenger(
        MESSAGES.OPENED_SEALED,
        request=self.request,
        user=self.request.user,
        source=submission,
    )
    self.request.session.setdefault("peeked", {})[str(submission.id)] = True
    # Dictionary updates do not trigger session saves. Force update
    self.request.session.modified = True

can_view_sealed

can_view_sealed(user)
Source code in hypha/apply/funds/views/submission_detail.py
def can_view_sealed(self, user):
    return user.is_superuser

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def get_context_data(self, **kwargs):
    return super().get_context_data(
        can_view_sealed=self.can_view_sealed(self.request.user),
        **kwargs,
    )

round_is_sealed classmethod

round_is_sealed(submission)
Source code in hypha/apply/funds/views/submission_detail.py
@classmethod
def round_is_sealed(cls, submission):
    try:
        return submission.round.specific.is_sealed
    except AttributeError:
        # Its a lab - cant be sealed
        return False

has_peeked classmethod

has_peeked(request, submission)
Source code in hypha/apply/funds/views/submission_detail.py
@classmethod
def has_peeked(cls, request, submission):
    return str(submission.id) in request.session.get("peeked", {})

should_redirect classmethod

should_redirect(request, submission)
Source code in hypha/apply/funds/views/submission_detail.py
@classmethod
def should_redirect(cls, request, submission):
    if cls.round_is_sealed(submission) and not cls.has_peeked(request, submission):
        return HttpResponseRedirect(
            reverse_lazy("funds:submissions:sealed", args=(submission.id,))
        )

SubmissionDetailPDFView

Bases: SingleObjectMixin, View

model class-attribute instance-attribute

get_object

get_object(queryset=None)
Source code in hypha/apply/funds/views/submission_detail.py
def get_object(self, queryset=None):
    obj = super().get_object(queryset)

    if not hasattr(obj, "project"):
        raise Http404

    return obj

get

get(request, *args, **kwargs)
Source code in hypha/apply/funds/views/submission_detail.py
def get(self, request, *args, **kwargs):
    self.object = self.get_object()
    pdf_page_settings = PDFPageSettings.load(request_or_site=request)
    content = draw_submission_content(self.object.output_text_answers())
    pdf = make_pdf(
        title=self.object.title,
        sections=[
            {
                "content": content,
                "title": "Submission",
                "meta": [
                    self.object.stage,
                    self.object.page,
                    self.object.round,
                    f"Lead: { self.object.lead }",
                ],
            },
        ],
        pagesize=pdf_page_settings.download_page_size,
    )
    return FileResponse(
        pdf,
        as_attachment=True,
        filename=self.object.title + ".pdf",
    )