Skip to content

Project

hypha.apply.projects.views.project

SendForApprovalView

Bases: DelegatedViewMixin, UpdateView

context_name class-attribute instance-attribute

context_name = 'request_approval_form'

form_class class-attribute instance-attribute

form_class = SetPendingForm

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    project = self.kwargs["object"]
    old_stage = project.status

    response = super().form_valid(form)

    # remove PAF submission task for staff group
    remove_tasks_for_user_group(
        code=PROJECT_SUBMIT_PAF,
        user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
        related_obj=self.object,
    )

    # remove PAF rejection task for staff if exists
    remove_tasks_for_user_group(
        code=PAF_REQUIRED_CHANGES,
        user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
        related_obj=self.object,
    )

    project_settings = ProjectSettings.for_request(self.request)

    paf_approvals = self.object.paf_approvals.filter(approved=False)

    if project_settings.paf_approval_sequential:
        if paf_approvals:
            user = paf_approvals.first().user
            if user:
                # notify only if first user/approver is updated
                messenger(
                    MESSAGES.SEND_FOR_APPROVAL,
                    request=self.request,
                    user=self.request.user,
                    source=self.object,
                )
                messenger(
                    MESSAGES.APPROVE_PAF,
                    request=self.request,
                    user=self.request.user,
                    source=self.object,
                    related=[paf_approvals.first()],
                )
                # add PAF waiting approval task for paf_approval user
                add_task_to_user(
                    code=PAF_WAITING_APPROVAL, user=user, related_obj=self.object
                )
            else:
                messenger(
                    MESSAGES.ASSIGN_PAF_APPROVER,
                    request=self.request,
                    user=self.request.user,
                    source=self.object,
                )
                # add PAF waiting assignee task for paf_approval reviewer_roles
                add_task_to_user_group(
                    code=PAF_WAITING_ASSIGNEE,
                    user_group=paf_approvals.first().paf_reviewer_role.user_roles.all(),
                    related_obj=self.object,
                )
    else:
        if paf_approvals.filter(user__isnull=False).exists():
            messenger(
                MESSAGES.SEND_FOR_APPROVAL,
                request=self.request,
                user=self.request.user,
                source=self.object,
            )
            messenger(
                MESSAGES.APPROVE_PAF,
                request=self.request,
                user=self.request.user,
                source=self.object,
                related=paf_approvals.filter(user__isnull=False),
            )
            # add PAF waiting approval task for paf_approvals users
            for paf_approval in paf_approvals.filter(user__isnull=False):
                add_task_to_user(
                    code=PAF_WAITING_APPROVAL,
                    user=paf_approval.user,
                    related_obj=self.object,
                )
        if paf_approvals.filter(user__isnull=True).exists():
            messenger(
                MESSAGES.ASSIGN_PAF_APPROVER,
                request=self.request,
                user=self.request.user,
                source=self.object,
            )
            # add PAF waiting assignee task for paf_approvals reviewer_roles
            for paf_approval in paf_approvals.filter(user__isnull=True):
                add_task_to_user_group(
                    code=PAF_WAITING_ASSIGNEE,
                    user_group=paf_approval.paf_reviewer_role.user_roles.all(),
                    related_obj=self.object,
                )

    project.status = INTERNAL_APPROVAL
    project.save(update_fields=["status"])

    messenger(
        MESSAGES.PROJECT_TRANSITION,
        request=self.request,
        user=self.request.user,
        source=project,
        related=old_stage,
    )

    messages.success(
        self.request,
        _("PAF has been submitted for approval"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return response

UploadDocumentView

Bases: DelegatedViewMixin, CreateView

context_name class-attribute instance-attribute

context_name = 'document_form'

form_class class-attribute instance-attribute

form_class = UploadDocumentForm

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    project = self.kwargs["object"]
    form.instance.project = project
    response = super().form_valid(form)

    messenger(
        MESSAGES.UPLOAD_DOCUMENT,
        request=self.request,
        user=self.request.user,
        source=project,
    )

    messages.success(
        self.request,
        _("Document has been uploaded"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )

    return response

RemoveDocumentView

Bases: DelegatedViewMixin, FormView

context_name class-attribute instance-attribute

context_name = 'remove_document_form'

form_class class-attribute instance-attribute

form_class = RemoveDocumentForm

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    document_id = form.cleaned_data["id"]
    project = self.kwargs["object"]

    try:
        project.packet_files.get(pk=document_id).delete()
    except PacketFile.DoesNotExist:
        pass

    messages.success(
        self.request,
        _("Document has been removed"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return redirect(project)

RemoveContractDocumentView

Bases: DelegatedViewMixin, FormView

context_name class-attribute instance-attribute

context_name = 'remove_contract_document_form'

form_class class-attribute instance-attribute

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    if not request.user.is_applicant or request.user != self.get_object().user:
        raise PermissionDenied
    return super().dispatch(request, *args, **kwargs)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    document_id = form.cleaned_data["id"]
    project = self.kwargs["object"]

    try:
        project.contract_packet_files.get(pk=document_id).delete()
    except ContractPacketFile.DoesNotExist:
        pass

    messages.success(
        self.request,
        _("Contracting document has been removed"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )

    return redirect(project)

SelectDocumentView

Bases: DelegatedViewMixin, CreateView

form_class class-attribute instance-attribute

form_class = SelectDocumentForm

context_name class-attribute instance-attribute

context_name = 'select_document_form'

model class-attribute instance-attribute

model = PacketFile

should_show property

should_show

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    self.project = get_object_or_404(Project, pk=self.kwargs["pk"])
    return super().dispatch(request, *args, **kwargs)

form_invalid

form_invalid(form)
Source code in hypha/apply/projects/views/project.py
def form_invalid(self, form):
    for error in form.errors:
        messages.error(self.request, error)

    return redirect(self.project)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    form.instance.project = self.project
    form.instance.name = form.instance.document.name

    response = super().form_valid(form)

    messenger(
        MESSAGES.UPLOAD_DOCUMENT,
        request=self.request,
        user=self.request.user,
        source=self.project,
    )

    return response

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/projects/views/project.py
def get_form_kwargs(self):
    kwargs = super().get_form_kwargs()
    kwargs.pop("user")
    kwargs.pop("instance")
    kwargs["existing_files"] = get_files(self.get_parent_object())
    return kwargs

UpdateLeadView

Bases: DelegatedViewMixin, UpdateView

model class-attribute instance-attribute

model = Project

form_class class-attribute instance-attribute

form_class = UpdateProjectLeadForm

context_name class-attribute instance-attribute

context_name = 'lead_form'

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    # Fetch the old lead from the database
    old_lead = copy(self.get_object().lead)

    response = super().form_valid(form)
    project = form.instance

    messenger(
        MESSAGES.UPDATE_PROJECT_LEAD,
        request=self.request,
        user=self.request.user,
        source=project,
        related=old_lead or "Unassigned",
    )

    messages.success(
        self.request,
        _("Lead has been updated"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return response

ContractsMixin

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/projects/views/project.py
def get_context_data(self, **kwargs):
    project = self.get_object()
    contracts = project.contracts.select_related(
        "approver",
    ).order_by("-created_at")

    latest_contract = contracts.first()
    contract_to_approve = None
    contract_to_sign = None
    if latest_contract:
        if not latest_contract.signed_by_applicant:
            contract_to_sign = latest_contract
        elif not latest_contract.approver:
            contract_to_approve = latest_contract

    context = super().get_context_data(**kwargs)
    context["contract_to_approve"] = contract_to_approve
    context["contract_to_sign"] = contract_to_sign
    context["contracts"] = contracts.approved()
    context["contract"] = latest_contract
    return context

ApproveContractView

Bases: DelegatedViewMixin, UpdateView

form_class class-attribute instance-attribute

form_class = ApproveContractForm

model class-attribute instance-attribute

model = Contract

context_name class-attribute instance-attribute

context_name = 'approve_contract_form'

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_object

get_object()
Source code in hypha/apply/projects/views/project.py
def get_object(self):
    project = self.get_parent_object()
    latest_contract = project.contracts.order_by("-created_at").first()
    if latest_contract and not latest_contract.approver:
        return latest_contract

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/projects/views/project.py
def get_form_kwargs(self):
    kwargs = super().get_form_kwargs()
    kwargs["instance"] = self.get_object()
    kwargs.pop("user")
    return kwargs

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    self.project = get_object_or_404(Project, pk=self.kwargs["pk"])
    return super().dispatch(request, *args, **kwargs)

form_invalid

form_invalid(form)
Source code in hypha/apply/projects/views/project.py
def form_invalid(self, form):
    messages.error(
        self.request,
        mark_safe(_("Sorry something went wrong") + form.errors.as_ul()),
    )
    return super().form_invalid(form)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    with transaction.atomic():
        form.instance.approver = self.request.user
        form.instance.approved_at = timezone.now()
        form.instance.project = self.project
        response = super().form_valid(form)

        old_stage = self.project.status

        messenger(
            MESSAGES.APPROVE_CONTRACT,
            request=self.request,
            user=self.request.user,
            source=self.project,
            related=self.object,
        )
        # remove Project waiting contract review task for staff
        remove_tasks_for_user_group(
            code=PROJECT_WAITING_CONTRACT_REVIEW,
            user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
            related_obj=self.project,
        )

        self.project.status = INVOICING_AND_REPORTING
        self.project.save(update_fields=["status"])

        messenger(
            MESSAGES.PROJECT_TRANSITION,
            request=self.request,
            user=self.request.user,
            source=self.project,
            related=old_stage,
        )
        # add Project waiting invoice task for applicant
        add_task_to_user(
            code=PROJECT_WAITING_INVOICE,
            user=self.project.user,
            related_obj=self.project,
        )

    messages.success(
        self.request,
        _(
            "Contractor documents have been approved."
            " You can receive invoices from vendor now."
        ),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return response

get_success_url

get_success_url()
Source code in hypha/apply/projects/views/project.py
def get_success_url(self):
    return self.project.get_absolute_url()

UploadContractView

Bases: DelegatedViewMixin, CreateView

context_name class-attribute instance-attribute

context_name = 'contract_form'

model class-attribute instance-attribute

model = Project

form_class class-attribute instance-attribute

form_class = UploadContractForm

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    project = self.kwargs["object"]
    permission, _ = has_permission("contract_upload", request.user, object=project)
    if permission:
        return super().dispatch(request, *args, **kwargs)

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/projects/views/project.py
def get_form_kwargs(self):
    kwargs = super().get_form_kwargs()
    kwargs.pop("instance")
    kwargs.pop("user")
    return kwargs

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    project = self.kwargs["object"]

    if project.contracts.exists():
        form.instance = project.contracts.order_by("created_at").first()

    form.instance.project = project

    if self.request.user == project.user:
        form.instance.signed_by_applicant = True
        form.instance.uploaded_by_applicant_at = timezone.now()
        messages.success(
            self.request,
            _("Countersigned contract uploaded"),
            extra_tags=PROJECT_ACTION_MESSAGE_TAG,
        )
    elif self.request.user.is_contracting:
        # :todo: update same date when staff uploads the contract(with STAFF_UPLOAD_CONTRACT setting)
        form.instance.uploaded_by_contractor_at = timezone.now()
        messages.success(
            self.request,
            _("Signed contract uploaded"),
            extra_tags=PROJECT_ACTION_MESSAGE_TAG,
        )

    response = super().form_valid(form)

    if self.request.user != project.user:
        messenger(
            MESSAGES.UPLOAD_CONTRACT,
            request=self.request,
            user=self.request.user,
            source=project,
            related=form.instance,
        )
        # remove Project waiting contract task for contracting/staff group
        if settings.STAFF_UPLOAD_CONTRACT:
            remove_tasks_for_user_group(
                code=PROJECT_WAITING_CONTRACT,
                user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
                related_obj=project,
            )
        else:
            remove_tasks_for_user_group(
                code=PROJECT_WAITING_CONTRACT,
                user_group=Group.objects.filter(name=CONTRACTING_GROUP_NAME),
                related_obj=project,
            )
        # add Project waiting contract document task for applicant
        add_task_to_user(
            code=PROJECT_WAITING_CONTRACT_DOCUMENT,
            user=project.user,
            related_obj=project,
        )

    return response

SubmitContractDocumentsView

Bases: DelegatedViewMixin, UpdateView

context_name class-attribute instance-attribute

context_name = 'submit_contract_documents_form'

model class-attribute instance-attribute

model = Project

form_class class-attribute instance-attribute

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    project = self.get_object()
    if ContractDocumentCategory.objects.filter(
        ~Q(contract_packet_files__project=project)
    ).exists():
        raise PermissionDenied
    contract = project.contracts.order_by("-created_at").first()
    permission, _ = has_permission(
        "submit_contract_documents",
        request.user,
        object=project,
        raise_exception=True,
        contract=contract,
    )
    return super().dispatch(request, *args, **kwargs)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    project = self.kwargs["object"]
    response = super().form_valid(form)

    project.submitted_contract_documents = True
    project.save(update_fields=["submitted_contract_documents"])

    messenger(
        MESSAGES.SUBMIT_CONTRACT_DOCUMENTS,
        request=self.request,
        user=self.request.user,
        source=project,
    )
    # remove project waiting contract documents task for applicant
    remove_tasks_for_user(
        code=PROJECT_WAITING_CONTRACT_DOCUMENT,
        user=project.user,
        related_obj=project,
    )
    # add project waiting contract review task for staff
    add_task_to_user_group(
        code=PROJECT_WAITING_CONTRACT_REVIEW,
        user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
        related_obj=project,
    )

    messages.success(
        self.request,
        _("Contract documents submitted"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return response

UploadContractDocumentView

Bases: DelegatedViewMixin, CreateView

form_class class-attribute instance-attribute

model class-attribute instance-attribute

model = Project

context_name class-attribute instance-attribute

context_name = 'contract_document_form'

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    if request.user != self.get_object().user or not request.user.is_applicant:
        raise PermissionDenied
    return super().dispatch(request, *args, **kwargs)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    project = self.kwargs["object"]
    form.instance.project = project
    response = super().form_valid(form)

    messages.success(
        self.request,
        _("Contracting document has been uploaded"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return response

ChangePAFStatusView

Bases: DelegatedViewMixin, UpdateView

form_class class-attribute instance-attribute

form_class = ChangePAFStatusForm

context_name class-attribute instance-attribute

context_name = 'change_paf_status'

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    self.object = self.get_object()
    permission, _ = has_permission(
        "paf_status_update",
        self.request.user,
        object=self.object,
        raise_exception=True,
        request=request,
    )
    return super().dispatch(request, *args, **kwargs)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    response = super().form_valid(form)
    project_settings = ProjectSettings.for_request(self.request)
    paf_approval = self.request.user.paf_approvals.filter(
        project=self.object, approved=False
    ).first()
    if not paf_approval:
        # get paf approval form for not-assigned case
        if project_settings.paf_approval_sequential:
            paf_approval = self.object.paf_approvals.filter(approved=False).first()
        else:
            for approval in self.object.paf_approvals.filter(approved=False):
                if self.request.user.id in [
                    role_user.id
                    for role_user in get_users_for_groups(
                        list(approval.paf_reviewer_role.user_roles.all()),
                        exact_match=True,
                    )
                ]:
                    paf_approval = approval
                    break
            else:
                # should never be the case but still to avoid 500.
                raise PermissionDenied("User don't have PAF approver roles")

    paf_status = form.cleaned_data.get("paf_status")
    comment = form.cleaned_data.get("comment", "")

    paf_status_update_message = _(
        "<p>{role} has updated PAF status to {paf_status}.</p>"
    ).format(
        role=paf_approval.paf_reviewer_role.label,
        paf_status=get_paf_status_display(paf_status).lower(),
    )
    Activity.objects.create(
        user=self.request.user,
        type=ACTION,
        source=self.object,
        timestamp=timezone.now(),
        message=paf_status_update_message,
        visibility=TEAM,
    )

    if paf_status == REQUEST_CHANGE:
        old_stage = self.object.status
        self.object.status = DRAFT
        self.object.save(update_fields=["status"])
        paf_approval.save()

        # remove PAF waiting assignee/approval task for paf approval user/reviewer roles.
        if project_settings.paf_approval_sequential:
            if paf_approval.user:
                remove_tasks_for_user(
                    code=PAF_WAITING_APPROVAL,
                    user=paf_approval.user,
                    related_obj=self.object,
                )
            else:
                remove_tasks_for_user_group(
                    code=PAF_WAITING_ASSIGNEE,
                    user_group=paf_approval.paf_reviewer_role.user_roles.all(),
                    related_obj=self.object,
                )
        else:
            for approval in self.object.paf_approvals.filter(approved=False):
                if approval.user:
                    remove_tasks_for_user(
                        code=PAF_WAITING_APPROVAL,
                        user=approval.user,
                        related_obj=self.object,
                    )
                else:
                    remove_tasks_for_user_group(
                        code=PAF_WAITING_ASSIGNEE,
                        user_group=approval.paf_reviewer_role.user_roles.all(),
                        related_obj=self.object,
                    )

        if not paf_approval.user:
            paf_approval.user = self.request.user
            paf_approval.save(update_fields=["user"])

        messenger(
            MESSAGES.REQUEST_PROJECT_CHANGE,
            request=self.request,
            user=self.request.user,
            source=self.object,
            comment=comment,
        )
        messenger(
            MESSAGES.PROJECT_TRANSITION,
            request=self.request,
            user=self.request.user,
            source=self.object,
            related=old_stage,
        )
        # add PAF required changes task to staff user group
        add_task_to_user_group(
            code=PAF_REQUIRED_CHANGES,
            user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
            related_obj=self.object,
        )

        messages.success(
            self.request,
            _("PAF status has been updated"),
            extra_tags=PROJECT_ACTION_MESSAGE_TAG,
        )
    elif paf_status == APPROVE:
        # remove task for paf approval user/user_group related to this paf_approval of project
        if paf_approval.user:
            remove_tasks_for_user(
                code=PAF_WAITING_APPROVAL,
                user=paf_approval.user,
                related_obj=self.object,
            )
        else:
            remove_tasks_for_user_group(
                code=PAF_WAITING_ASSIGNEE,
                user_group=paf_approval.paf_reviewer_role.user_roles.all(),
                related_obj=self.object,
            )
        paf_approval.approved = True
        paf_approval.approved_at = timezone.now()
        paf_approval.user = self.request.user
        paf_approval.save(update_fields=["approved", "approved_at", "user"])
        if project_settings.paf_approval_sequential:
            # notify next approver
            if self.object.paf_approvals.filter(approved=False).exists():
                next_paf_approval = self.object.paf_approvals.filter(
                    approved=False
                ).first()
                if next_paf_approval.user:
                    messenger(
                        MESSAGES.APPROVE_PAF,
                        request=self.request,
                        user=self.request.user,
                        source=self.object,
                        related=[next_paf_approval],
                    )
                    # add PAF waiting approval task for next paf approval user
                    add_task_to_user(
                        code=PAF_WAITING_APPROVAL,
                        user=next_paf_approval.user,
                        related_obj=self.object,
                    )
                else:
                    messenger(
                        MESSAGES.ASSIGN_PAF_APPROVER,
                        request=self.request,
                        user=self.request.user,
                        source=self.object,
                    )
                    # add PAF waiting assignee task for nex paf approval reviewer roles
                    add_task_to_user_group(
                        code=PAF_WAITING_ASSIGNEE,
                        user_group=next_paf_approval.paf_reviewer_role.user_roles.all(),
                        related_obj=self.object,
                    )
        messages.success(
            self.request,
            _("PAF has been approved"),
            extra_tags=PROJECT_ACTION_MESSAGE_TAG,
        )

    if form.cleaned_data["comment"]:
        comment = f"<p>\"{form.cleaned_data['comment']}.\"</p>"

        message = paf_status_update_message + comment

        Activity.objects.create(
            user=self.request.user,
            type=COMMENT,
            source=self.object,
            timestamp=timezone.now(),
            message=message,
            visibility=TEAM,
        )

    if self.object.is_approved_by_all_paf_reviewers:
        old_stage = self.object.status
        self.object.is_locked = True
        self.object.status = CONTRACTING
        self.object.save(update_fields=["is_locked", "status"])

        messenger(
            MESSAGES.PROJECT_TRANSITION,
            request=self.request,
            user=self.request.user,
            source=self.object,
            related=old_stage,
        )
        # add project waiting contract task to staff/contracting groups
        if settings.STAFF_UPLOAD_CONTRACT:
            add_task_to_user_group(
                code=PROJECT_WAITING_CONTRACT,
                user_group=Group.objects.filter(name=STAFF_GROUP_NAME),
                related_obj=self.object,
            )
        else:
            add_task_to_user_group(
                code=PROJECT_WAITING_CONTRACT,
                user_group=Group.objects.filter(name=CONTRACTING_GROUP_NAME),
                related_obj=self.object,
            )
    return response

ChangeProjectstatusView

Bases: DelegatedViewMixin, UpdateView

Project status can be updated manually only in 'IN PROGRESS, CLOSING and COMPLETE' state.

form_class class-attribute instance-attribute

context_name class-attribute instance-attribute

context_name = 'change_project_status'

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    self.project = get_object_or_404(Project, pk=self.kwargs["pk"])
    permission, _ = has_permission(
        "project_status_update", request.user, self.project, raise_exception=True
    )
    return super().dispatch(request, *args, **kwargs)

form_valid

form_valid(form)
Source code in hypha/apply/projects/views/project.py
def form_valid(self, form):
    old_stage = self.project.status

    response = super().form_valid(form)

    comment = form.cleaned_data.get("comment", "")

    if comment:
        Activity.objects.create(
            user=self.request.user,
            type=COMMENT,
            source=self.object,
            timestamp=timezone.now(),
            message=comment,
            visibility=ALL,
        )

    messenger(
        MESSAGES.PROJECT_TRANSITION,
        request=self.request,
        user=self.request.user,
        source=self.object,
        related=old_stage,
    )

    messages.success(
        self.request,
        _("Project status has been updated"),
        extra_tags=PROJECT_ACTION_MESSAGE_TAG,
    )
    return response

UpdateAssignApproversView

Bases: DelegatedViewMixin, UpdateView

context_name class-attribute instance-attribute

context_name = 'assign_approvers_form'

form_class class-attribute instance-attribute

form_class = AssignApproversForm

model class-attribute instance-attribute

model = Project

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_form_kwargs

get_form_kwargs()
Source code in hypha/apply/utils/views.py
def get_form_kwargs(self):
    form_kwargs = super().get_form_kwargs()
    form_kwargs["user"] = self.request.user
    form_kwargs.update(**self.get_parent_kwargs())
    return form_kwargs

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

get_success_url

get_success_url()
Source code in hypha/apply/utils/views.py
def get_success_url(self):
    query = self.request.GET.urlencode()
    if query:
        query = "?" + query
    return self.request.path + query

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/project.py
def dispatch(self, request, *args, **kwargs):
    self.project = get_object_or_404(Project, pk=self.kwargs["pk"])
    permission, _ = has_permission(
        "update_paf_assigned_approvers",
        request.user,
        self.project,
        raise_exception