Skip to content

Index

hypha.apply.projects.forms

ChangeInvoiceStatusForm

ChangeInvoiceStatusForm(instance, user, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/payment.py
def __init__(self, instance, user, *args, **kwargs):
    super().__init__(*args, **kwargs, instance=instance)
    self.initial["comment"] = ""
    status_field = self.fields["status"]
    user_choices = invoice_status_user_choices(user)
    possible_status_transitions_lut = {
        SUBMITTED: filter_request_choices(
            [CHANGES_REQUESTED_BY_STAFF, APPROVED_BY_STAFF, DECLINED], user_choices
        ),
        RESUBMITTED: filter_request_choices(
            [CHANGES_REQUESTED_BY_STAFF, APPROVED_BY_STAFF, DECLINED], user_choices
        ),
        CHANGES_REQUESTED_BY_STAFF: filter_request_choices(
            [DECLINED], user_choices
        ),
        APPROVED_BY_STAFF: filter_request_choices(
            [
                CHANGES_REQUESTED_BY_FINANCE,
                APPROVED_BY_FINANCE,
            ],
            user_choices,
        ),
        CHANGES_REQUESTED_BY_FINANCE: filter_request_choices(
            [CHANGES_REQUESTED_BY_STAFF, DECLINED], user_choices
        ),
        APPROVED_BY_FINANCE: filter_request_choices([PAID], user_choices),
        PAID: filter_request_choices([PAYMENT_FAILED], user_choices),
        PAYMENT_FAILED: filter_request_choices([PAID], user_choices),
    }
    if settings.INVOICE_EXTENDED_WORKFLOW:
        possible_status_transitions_lut.update(
            {
                CHANGES_REQUESTED_BY_FINANCE_2: filter_request_choices(
                    [
                        CHANGES_REQUESTED_BY_FINANCE,
                        APPROVED_BY_FINANCE,
                    ],
                    user_choices,
                ),
                APPROVED_BY_FINANCE: filter_request_choices(
                    [CHANGES_REQUESTED_BY_FINANCE_2, APPROVED_BY_FINANCE_2],
                    user_choices,
                ),
                APPROVED_BY_FINANCE_2: filter_request_choices([PAID], user_choices),
            }
        )
    status_field.choices = possible_status_transitions_lut.get(instance.status, [])

name_prefix class-attribute instance-attribute

name_prefix = 'change_invoice_status_form'

Meta

fields class-attribute instance-attribute
fields = ['status', 'comment']
model class-attribute instance-attribute
model = Invoice

CreateInvoiceForm

CreateInvoiceForm(user=None, *args, **kwargs)

Bases: FileFormMixin, InvoiceBaseForm

Source code in hypha/apply/projects/forms/payment.py
def __init__(self, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.initial["message_for_pm"] = ""

document class-attribute instance-attribute

document = SingleFileField(label='Invoice File', required=True, help_text=gettext_lazy('The invoice must be a PDF.'))

supporting_documents class-attribute instance-attribute

supporting_documents = MultiFileField(required=False, help_text=gettext_lazy('Files that are related to the invoice. They could be xls, microsoft office documents, open office documents, pdfs, txt files.'))

field_order class-attribute instance-attribute

field_order = ['invoice_number', 'invoice_amount', 'document', 'supporting_documents', 'message_for_pm']

Meta

fields class-attribute instance-attribute
fields = ['invoice_number', 'invoice_amount', 'document', 'message_for_pm']
model class-attribute instance-attribute
model = Invoice

save

save(commit=True)
Source code in hypha/apply/projects/forms/payment.py
def save(self, commit=True):
    invoice = super().save(commit=commit)

    supporting_documents = self.cleaned_data["supporting_documents"] or []

    SupportingDocument.objects.bulk_create(
        SupportingDocument(invoice=invoice, document=document)
        for document in supporting_documents
    )

    return invoice

EditInvoiceForm

EditInvoiceForm(user=None, *args, **kwargs)

Bases: FileFormMixin, InvoiceBaseForm

Source code in hypha/apply/projects/forms/payment.py
def __init__(self, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.initial["message_for_pm"] = ""

document class-attribute instance-attribute

document = SingleFileField(label=gettext_lazy('Invoice File'), required=True)

supporting_documents class-attribute instance-attribute

supporting_documents = MultiFileField(required=False)

field_order class-attribute instance-attribute

field_order = ['invoice_number', 'invoice_amount', 'document', 'supporting_documents', 'message_for_pm']

Meta

fields class-attribute instance-attribute
fields = ['invoice_number', 'invoice_amount', 'document', 'message_for_pm']
model class-attribute instance-attribute
model = Invoice

save

save(commit=True)
Source code in hypha/apply/projects/forms/payment.py
@transaction.atomic
def save(self, commit=True):
    invoice = super().save(commit=commit)
    not_deleted_original_filenames = [
        file["name"]
        for file in json.loads(self.cleaned_data["supporting_documents-uploads"])
    ]
    for f in invoice.supporting_documents.all():
        if f.document.name not in not_deleted_original_filenames:
            f.document.delete()
            f.delete()

    for f in self.cleaned_data["supporting_documents"]:
        if not isinstance(f, FieldFile):
            try:
                SupportingDocument.objects.create(invoice=invoice, document=f)
            finally:
                f.close()
    return invoice

SelectDocumentForm

SelectDocumentForm(existing_files, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/payment.py
def __init__(self, existing_files, *args, **kwargs):
    super().__init__(*args, **kwargs)

    self.files = existing_files

    choices = [(f.url, f.filename) for f in self.files]

    self.fields["document"].choices = choices

document class-attribute instance-attribute

document = ChoiceField(label='Document', widget=Select(attrs={'id': 'from_submission'}))

files instance-attribute

files = existing_files

Meta

model class-attribute instance-attribute
model = PacketFile
fields class-attribute instance-attribute
fields = ['category', 'document']

clean_document

clean_document()
Source code in hypha/apply/projects/forms/payment.py
def clean_document(self):
    file_url = self.cleaned_data["document"]
    for file in self.files:
        if file.url == file_url:
            new_file = ContentFile(file.read())
            new_file.name = file.filename
            return new_file
    raise forms.ValidationError(_("File not found on submission"))

save

save(*args, **kwargs)
Source code in hypha/apply/projects/forms/payment.py
@transaction.atomic()
def save(self, *args, **kwargs):
    return super().save(*args, **kwargs)

ApproveContractForm

ApproveContractForm(instance, *args, **kwargs)

Bases: Form

Source code in hypha/apply/projects/forms/project.py
def __init__(self, instance, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.instance = instance
    if instance:
        self.fields["id"].initial = instance.id

id class-attribute instance-attribute

id = IntegerField(widget=HiddenInput())

instance instance-attribute

instance = instance

clean_id

clean_id()
Source code in hypha/apply/projects/forms/project.py
def clean_id(self):
    if self.has_changed():
        raise forms.ValidationError(
            _("Something changed before your approval please re-review")
        )

clean

clean()
Source code in hypha/apply/projects/forms/project.py
def clean(self):
    if not self.instance:
        raise forms.ValidationError(
            _("The contract you were trying to approve has already been approved")
        )

    if not self.instance.signed_by_applicant:
        raise forms.ValidationError(_("You can only approve a signed contract"))

    super().clean()

save

save(*args, **kwargs)
Source code in hypha/apply/projects/forms/project.py
def save(self, *args, **kwargs):
    self.instance.save()
    return self.instance

ApproversForm

ApproversForm(user=None, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    from hypha.apply.activity.adapters.utils import get_users_for_groups

    super().__init__(*args, **kwargs)

    for paf_reviewer_role in PAFReviewersRole.objects.all():
        users = get_users_for_groups(
            list(paf_reviewer_role.user_roles.all()), exact_match=True
        )
        approval = PAFApprovals.objects.filter(
            project=self.instance, paf_reviewer_role=paf_reviewer_role
        )
        if approval:
            initial_user = approval.first().user
        self.fields[slugify(paf_reviewer_role.label)] = forms.ModelChoiceField(
            queryset=users,
            required=False,
            blank=True,
            label=paf_reviewer_role.label,
            initial=initial_user if approval else None,
            disabled=approval.first().approved if approval.first() else False,
            # using approval.first() as condition for existing projects
        )

Meta

fields class-attribute instance-attribute
fields = ['id']
model class-attribute instance-attribute
model = Project
widgets class-attribute instance-attribute
widgets = {'id': HiddenInput()}

save

save(commit=True)
Source code in hypha/apply/projects/forms/project.py
def save(self, commit=True):
    # add users as PAFApprovals
    for paf_reviewer_role in PAFReviewersRole.objects.all():
        assigned_user = self.cleaned_data[slugify(paf_reviewer_role.label)]
        paf_approvals = PAFApprovals.objects.filter(
            project=self.instance, paf_reviewer_role=paf_reviewer_role
        )
        if not paf_approvals.exists():
            PAFApprovals.objects.create(
                project=self.instance,
                paf_reviewer_role=paf_reviewer_role,
                user=assigned_user if assigned_user else None,
                approved=False,
            )
        elif not paf_approvals.first().approved:
            paf_approval = paf_approvals.first()
            paf_approval.user = assigned_user if assigned_user else None
            paf_approval.save()
    return super().save(commit=True)

AssignApproversForm

AssignApproversForm(user=None, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    from hypha.apply.activity.adapters.utils import get_users_for_groups

    super().__init__(*args, **kwargs)
    self.user = user

    paf_approval = get_latest_project_paf_approval_via_roles(
        project=self.instance, roles=user.groups.all()
    )

    if paf_approval:
        current_paf_reviewer_role = paf_approval.paf_reviewer_role

        users = get_users_for_groups(
            list(current_paf_reviewer_role.user_roles.all()), exact_match=True
        )

        self.fields[
            slugify(current_paf_reviewer_role.label)
        ] = forms.ModelChoiceField(
            queryset=users,
            required=False,
            blank=True,
            label=current_paf_reviewer_role.label,
            initial=paf_approval.user,
            disabled=paf_approval.approved,
        )

user instance-attribute

user = user

Meta

fields class-attribute instance-attribute
fields = ['id']
model class-attribute instance-attribute
model = Project
widgets class-attribute instance-attribute
widgets = {'id': HiddenInput()}

save

save(commit=True)
Source code in hypha/apply/projects/forms/project.py
def save(self, commit=True):
    paf_approval = get_latest_project_paf_approval_via_roles(
        project=self.instance, roles=self.user.groups.all()
    )

    current_paf_reviewer_role = paf_approval.paf_reviewer_role
    assigned_user = self.cleaned_data[slugify(current_paf_reviewer_role.label)]

    if not paf_approval.approved:
        paf_approval.user = assigned_user if assigned_user else None
        paf_approval.save()

    return super().save(commit=True)

ChangePAFStatusForm

ChangePAFStatusForm(instance, user, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, instance, user, *args, **kwargs):
    super().__init__(*args, **kwargs, instance=instance)
    self.fields["paf_status"].widget.attrs["class"] = "grid--status-update"

name_prefix class-attribute instance-attribute

name_prefix = 'change_paf_status_form'

paf_status class-attribute instance-attribute

paf_status = ChoiceField(label='PAF status', choices=PAF_STATUS_CHOICES, widget=RadioSelect())

comment class-attribute instance-attribute

comment = CharField(required=False, widget=Textarea)

Meta

fields class-attribute instance-attribute
fields = ['paf_status', 'comment']
model class-attribute instance-attribute
model = Project

ChangeProjectStatusForm

ChangeProjectStatusForm(instance, user, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, instance, user, *args, **kwargs):
    super().__init__(*args, **kwargs, instance=instance)
    status_field = self.fields["status"]
    possible_status_transitions = {
        INVOICING_AND_REPORTING: filter_request_choices([CLOSING, COMPLETE]),
        CLOSING: filter_request_choices([INVOICING_AND_REPORTING, COMPLETE]),
        COMPLETE: filter_request_choices([INVOICING_AND_REPORTING, CLOSING]),
    }
    status_field.choices = possible_status_transitions.get(instance.status, [])

name_prefix class-attribute instance-attribute

name_prefix = 'change_project_status_form'

comment class-attribute instance-attribute

comment = CharField(required=False, widget=Textarea)

Meta

fields class-attribute instance-attribute
fields = ['status', 'comment']
model class-attribute instance-attribute
model = Project

CreateProjectForm

CreateProjectForm(instance=None, user=None, *args, **kwargs)

Bases: Form

Source code in hypha/apply/projects/forms/project.py
def __init__(self, instance=None, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

    if instance:
        self.fields["submission"].initial = instance.id

    # Update lead field queryset
    lead_field = self.fields["project_lead"]
    qwargs = Q(groups__name=STAFF_GROUP_NAME) | Q(is_superuser=True)
    lead_field.queryset = lead_field.queryset.filter(qwargs).distinct()
    if instance:
        lead_field.initial = instance.lead

submission class-attribute instance-attribute

submission = ModelChoiceField(queryset=filter(project__isnull=True), widget=HiddenInput())

project_lead class-attribute instance-attribute

project_lead = ModelChoiceField(label=gettext_lazy('Select Project Lead'), queryset=all())

clean_project_lead

clean_project_lead()
Source code in hypha/apply/projects/forms/project.py
def clean_project_lead(self):
    project_lead = self.cleaned_data["project_lead"]
    if not project_lead:
        raise forms.ValidationError(_("Project lead is a required field"))
    return project_lead

save

save(*args, **kwargs)
Source code in hypha/apply/projects/forms/project.py
def save(self, *args, **kwargs):
    submission = self.cleaned_data["submission"]
    lead = self.cleaned_data["project_lead"]
    return Project.create_from_submission(submission, lead=lead)

ProjectApprovalForm

ProjectApprovalForm(*args, extra_fields=None, **kwargs)

Bases: StreamBaseForm, ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, *args, extra_fields=None, **kwargs):
    super().__init__(*args, **kwargs)

Meta

fields class-attribute instance-attribute
fields = ['title']
model class-attribute instance-attribute
model = Project
widgets class-attribute instance-attribute
widgets = {'title': HiddenInput()}

swap_fields_for_display

swap_fields_for_display(func)
Source code in hypha/apply/stream_forms/forms.py
def swap_fields_for_display(func):
    def wrapped(self, *args, **kwargs):
        # Replaces the form fields with the display fields
        # should only add new streamblocks and wont affect validation
        fields = self.fields.copy()
        self.fields = self.display
        yield from func(self, *args, **kwargs)
        self.fields = fields

    return wrapped

hidden_fields

hidden_fields()
Source code in hypha/apply/stream_forms/forms.py
def hidden_fields(self):
    # No hidden fields are returned by default because of MixedFieldMetaclass
    return [self[f] for f in self.fields.keys() if self[f].is_hidden]

delete_temporary_files

delete_temporary_files()

Overridden method of django_file_form's FileFormMixin, to handle multiple forms on the same page.

Source code in hypha/apply/stream_forms/forms.py
def delete_temporary_files(self):
    """
    Overridden method of django_file_form's FileFormMixin, to handle multiple forms on the same page.
    """
    form_id = self.data.getlist(self.add_prefix("form_id"))

    if not form_id:
        return

    form_id = form_id[0]
    for field_name, field in self.fields.items():
        if hasattr(field, "delete_file_data"):
            prefixed_field_name = self.add_prefix(field_name)
            field.delete_file_data(prefixed_field_name, form_id)

clean

clean()
Source code in hypha/apply/projects/forms/project.py
def clean(self):
    cleaned_data = super().clean()
    cleaned_data["form_data"] = {
        key: value
        for key, value in cleaned_data.items()
        if key not in self._meta.fields
    }
    return cleaned_data

save

save(*args, **kwargs)
Source code in hypha/apply/projects/forms/project.py
def save(self, *args, **kwargs):
    self.instance.form_fields = kwargs.pop("paf_form_fields", {})
    self.instance.form_data = {
        field: self.cleaned_data[field]
        for field in self.instance.question_field_ids
        if field in self.cleaned_data
    }
    self.instance.process_file_data(self.cleaned_data)
    self.instance.user_has_updated_details = True
    return super().save(*args, **kwargs)

ProjectSOWForm

ProjectSOWForm(*args, extra_fields=None, **kwargs)

Bases: StreamBaseForm, ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, *args, extra_fields=None, **kwargs):
    super().__init__(*args, **kwargs)

Meta

fields class-attribute instance-attribute
fields = ['project']
model class-attribute instance-attribute
model = ProjectSOW
widgets class-attribute instance-attribute
widgets = {'project': HiddenInput()}

swap_fields_for_display

swap_fields_for_display(func)
Source code in hypha/apply/stream_forms/forms.py
def swap_fields_for_display(func):
    def wrapped(self, *args, **kwargs):
        # Replaces the form fields with the display fields
        # should only add new streamblocks and wont affect validation
        fields = self.fields.copy()
        self.fields = self.display
        yield from func(self, *args, **kwargs)
        self.fields = fields

    return wrapped

hidden_fields

hidden_fields()
Source code in hypha/apply/stream_forms/forms.py
def hidden_fields(self):
    # No hidden fields are returned by default because of MixedFieldMetaclass
    return [self[f] for f in self.fields.keys() if self[f].is_hidden]

delete_temporary_files

delete_temporary_files()

Overridden method of django_file_form's FileFormMixin, to handle multiple forms on the same page.

Source code in hypha/apply/stream_forms/forms.py
def delete_temporary_files(self):
    """
    Overridden method of django_file_form's FileFormMixin, to handle multiple forms on the same page.
    """
    form_id = self.data.getlist(self.add_prefix("form_id"))

    if not form_id:
        return

    form_id = form_id[0]
    for field_name, field in self.fields.items():
        if hasattr(field, "delete_file_data"):
            prefixed_field_name = self.add_prefix(field_name)
            field.delete_file_data(prefixed_field_name, form_id)

clean

clean()
Source code in hypha/apply/projects/forms/project.py
def clean(self):
    cleaned_data = super().clean()
    cleaned_data["form_data"] = {
        key: value
        for key, value in cleaned_data.items()
        if key not in self._meta.fields
    }
    return cleaned_data

save

save(*args, **kwargs)
Source code in hypha/apply/projects/forms/project.py
def save(self, *args, **kwargs):
    self.instance, _ = self._meta.model.objects.get_or_create(
        project=kwargs.pop("project", None)
    )
    self.instance.form_fields = kwargs.pop("sow_form_fields", {})
    self.instance.form_data = {
        field: self.cleaned_data[field]
        for field in self.instance.question_field_ids
        if field in self.cleaned_data
    }
    self.instance.process_file_data(self.cleaned_data)
    return super().save(*args, **kwargs)

RemoveContractDocumentForm

RemoveContractDocumentForm(user=None, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

id class-attribute instance-attribute

id = IntegerField(widget=HiddenInput())

Meta

fields class-attribute instance-attribute
fields = ['id']
model class-attribute instance-attribute

RemoveDocumentForm

RemoveDocumentForm(user=None, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

id class-attribute instance-attribute

id = IntegerField(widget=HiddenInput())

Meta

fields class-attribute instance-attribute
fields = ['id']
model class-attribute instance-attribute
model = PacketFile

SetPendingForm

SetPendingForm(user=None, *args, **kwargs)

Bases: ApproversForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    from hypha.apply.activity.adapters.utils import get_users_for_groups

    super().__init__(*args, **kwargs)

    for paf_reviewer_role in PAFReviewersRole.objects.all():
        users = get_users_for_groups(
            list(paf_reviewer_role.user_roles.all()), exact_match=True
        )
        approval = PAFApprovals.objects.filter(
            project=self.instance, paf_reviewer_role=paf_reviewer_role
        )
        if approval:
            initial_user = approval.first().user
        self.fields[slugify(paf_reviewer_role.label)] = forms.ModelChoiceField(
            queryset=users,
            required=False,
            blank=True,
            label=paf_reviewer_role.label,
            initial=initial_user if approval else None,
            disabled=approval.first().approved if approval.first() else False,
            # using approval.first() as condition for existing projects
        )

Meta

fields class-attribute instance-attribute
fields = ['id']
model class-attribute instance-attribute
model = Project
widgets class-attribute instance-attribute
widgets = {'id': HiddenInput()}

save

save(commit=True)
Source code in hypha/apply/projects/forms/project.py
def save(self, commit=True):
    # add users as PAFApprovals
    for paf_reviewer_role in PAFReviewersRole.objects.all():
        assigned_user = self.cleaned_data[slugify(paf_reviewer_role.label)]
        paf_approvals = PAFApprovals.objects.filter(
            project=self.instance, paf_reviewer_role=paf_reviewer_role
        )
        if not paf_approvals.exists():
            PAFApprovals.objects.create(
                project=self.instance,
                paf_reviewer_role=paf_reviewer_role,
                user=assigned_user if assigned_user else None,
                approved=False,
            )
        elif not paf_approvals.first().approved:
            paf_approval = paf_approvals.first()
            paf_approval.user = assigned_user if assigned_user else None
            paf_approval.save()
    return super().save(commit=True)

clean

clean()
Source code in hypha/apply/projects/forms/project.py
def clean(self):
    if self.instance.status != DRAFT:
        raise forms.ValidationError(
            _("A Project can only be sent for Approval when Drafted.")
        )

    # :todo: we should have a check form contains enough data to create PAF Approvals
    cleaned_data = super().clean()
    return cleaned_data

StaffUploadContractForm

Bases: FileFormMixin, ModelForm

file class-attribute instance-attribute

file = SingleFileField(label=gettext_lazy('Contract'), required=True)

Meta

fields class-attribute instance-attribute
fields = ['file', 'signed_by_applicant']
model class-attribute instance-attribute
model = Contract

SubmitContractDocumentsForm

SubmitContractDocumentsForm(user=None, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

Meta

fields class-attribute instance-attribute
fields = ['id']
model class-attribute instance-attribute
model = Project
widgets class-attribute instance-attribute
widgets = {'id': HiddenInput()}

UpdateProjectLeadForm

UpdateProjectLeadForm(user=None, *args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

    lead_field = self.fields["lead"]
    lead_field.label = _("Update lead from {lead} to").format(
        lead=self.instance.lead
    )

    qwargs = Q(groups__name=STAFF_GROUP_NAME) | Q(is_superuser=True)
    lead_field.queryset = (
        lead_field.queryset.exclude(pk=self.instance.lead_id)
        .filter(qwargs)
        .distinct()
    )

Meta

fields class-attribute instance-attribute
fields = ['lead']
model class-attribute instance-attribute
model = Project

UploadContractDocumentForm

UploadContractDocumentForm(user=None, instance=None, *args, **kwargs)

Bases: FileFormMixin, ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, instance=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

document class-attribute instance-attribute

document = SingleFileField(label=gettext_lazy('Contract Document'), required=True)

Meta

fields class-attribute instance-attribute
fields = ['category', 'document']
model class-attribute instance-attribute

save

save(commit=True)
Source code in hypha/apply/projects/forms/project.py
def save(self, commit=True):
    self.instance.title = self.instance.document
    return super(UploadContractDocumentForm, self).save(commit=True)

UploadContractForm

Bases: FileFormMixin, ModelForm

file class-attribute instance-attribute

file = SingleFileField(label=gettext_lazy('Contract'), required=True)

Meta

fields class-attribute instance-attribute
fields = ['file']
model class-attribute instance-attribute
model = Contract

save

save(commit=True)
Source code in hypha/apply/projects/forms/project.py
def save(self, commit=True):
    self.instance.file = self.cleaned_data.get("file")
    return super().save(commit=True)

UploadDocumentForm

UploadDocumentForm(user=None, instance=None, *args, **kwargs)

Bases: FileFormMixin, ModelForm

Source code in hypha/apply/projects/forms/project.py
def __init__(self, user=None, instance=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

document class-attribute instance-attribute

document = SingleFileField(label=gettext_lazy('Document'), required=True)

Meta

fields class-attribute instance-attribute
fields = ['category', 'document']
model class-attribute instance-attribute
model = PacketFile

save

save(commit=True)
Source code in hypha/apply/projects/forms/project.py
def save(self, commit=True):
    self.instance.title = self.instance.document
    return super(UploadDocumentForm, self).save(commit=True)

ReportEditForm

ReportEditForm(*args, user=None, initial=None, **kwargs)

Bases: FileFormMixin, ModelForm

Source code in hypha/apply/projects/forms/report.py
def __init__(self, *args, user=None, initial=None, **kwargs):
    if initial is None:
        initial = {}
    self.report_files = initial.pop(
        "file_list",
        ReportPrivateFiles.objects.none(),
    )
    super().__init__(*args, initial=initial, **kwargs)
    self.fields["file_list"].queryset = self.report_files
    self.user = user

public_content class-attribute instance-attribute

public_content = RichTextField(help_text=gettext_lazy('This section of the report will be shared with the broader community.'))

private_content class-attribute instance-attribute

private_content = RichTextField(help_text=gettext_lazy('This section of the report will be shared with staff only.'))

file_list class-attribute instance-attribute

file_list = ModelMultipleChoiceField(widget=CheckboxSelectMultiple(attrs={'class': 'delete'}), queryset=all(), required=False, label='Files')

files class-attribute instance-attribute

files = MultiFileField(required=False, label='')

report_files instance-attribute

report_files = pop('file_list', none())

user instance-attribute

user = user

Meta

model class-attribute instance-attribute
model = Report
fields class-attribute instance-attribute
fields = ('public_content', 'private_content', 'file_list', 'files')

clean

clean()
Source code in hypha/apply/projects/forms/report.py
def clean(self):
    cleaned_data = super().clean()
    public = cleaned_data["public_content"]
    private = cleaned_data["private_content"]
    if not private and not public:
        missing_content = _(
            "Must include either public or private content when submitting a report."
        )
        self.add_error("public_content", missing_content)
        self.add_error("private_content", missing_content)
    return cleaned_data

save

save(commit=True)
Source code in hypha/apply/projects/forms/report.py
@transaction.atomic
def save(self, commit=True):
    is_draft = "save" in self.data

    version = ReportVersion.objects.create(
        report=self.instance,
        public_content=self.cleaned_data["public_content"],
        private_content=self.cleaned_data["private_content"],
        submitted=timezone.now(),
        draft=is_draft,
        author=self.user,
    )

    if is_draft:
        self.instance.draft = version
    else:
        # If this is the first submission of the report we track that as the
        # submitted date of the report
        if not self.instance.submitted:
            self.instance.submitted = version.submitted
        self.instance.current = version
        self.instance.draft = None

    instance = super().save(commit)

    removed_files = self.cleaned_data["file_list"]
    ReportPrivateFiles.objects.bulk_create(
        ReportPrivateFiles(report=version, document=file.document)
        for file in self.report_files
        if file not in removed_files
    )

    added_files = self.cleaned_data["files"]
    if added_files:
        ReportPrivateFiles.objects.bulk_create(
            ReportPrivateFiles(report=version, document=file)
            for file in added_files
        )

    return instance

ReportFrequencyForm

ReportFrequencyForm(*args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/report.py
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fields["occurrence"].required = False
    self.fields["frequency"].required = False

start class-attribute instance-attribute

start = DateField(label='Report on:', required=False)

Meta

model class-attribute instance-attribute
model = ReportConfig
fields class-attribute instance-attribute
fields = ('start', 'occurrence', 'frequency', 'does_not_repeat')
labels class-attribute instance-attribute
labels = {'occurrence': '', 'frequency': ''}

CreateVendorFormStep1

CreateVendorFormStep1(*args, **kwargs)

Bases: BaseVendorForm, Form

Source code in hypha/apply/projects/forms/vendor.py
def __init__(self, *args, **kwargs):
    super(CreateVendorFormStep1, self).__init__(*args, **kwargs)
    self.fields = self.apply_form_settings(self.fields)

form_settings instance-attribute

form_settings = for_site(site)

TYPE_CHOICES class-attribute instance-attribute

TYPE_CHOICES = [('organization', gettext_lazy('Yes, the account belongs to the organisation above')), ('personal', gettext_lazy('No, it is a personal bank account'))]

name class-attribute instance-attribute

name = CharField(required=True)

contractor_name class-attribute instance-attribute

contractor_name = CharField(required=True)

type class-attribute instance-attribute

type = ChoiceField(choices=TYPE_CHOICES, required=True, widget=RadioSelect)

fields instance-attribute

fields = apply_form_settings(fields)

apply_form_settings

apply_form_settings(fields)
Source code in hypha/apply/projects/forms/vendor.py
def apply_form_settings(self, fields):
    for field in fields:
        try:
            self.fields[field].label = getattr(self.form_settings, f"{field}_label")
        except AttributeError:
            pass
        try:
            self.fields[field].help_text = getattr(
                self.form_settings, f"{field}_help_text"
            )
        except AttributeError:
            pass
    return fields

CreateVendorFormStep2

CreateVendorFormStep2(*args, **kwargs)

Bases: BaseVendorForm, Form

Source code in hypha/apply/projects/forms/vendor.py
def __init__(self, *args, **kwargs):
    super(CreateVendorFormStep2, self).__init__(*args, **kwargs)
    self.fields = self.apply_form_settings(self.fields)

form_settings instance-attribute

form_settings = for_site(site)

required_to_pay_taxes class-attribute instance-attribute

required_to_pay_taxes = TypedChoiceField(choices=((False, 'No'), (True, 'Yes')), coerce=lambda : x == 'True', widget=RadioSelect, required=True)

fields instance-attribute

fields = apply_form_settings(fields)

apply_form_settings

apply_form_settings(fields)
Source code in hypha/apply/projects/forms/vendor.py
def apply_form_settings(self, fields):
    for field in fields:
        try:
            self.fields[field].label = getattr(self.form_settings, f"{field}_label")
        except AttributeError:
            pass
        try:
            self.fields[field].help_text = getattr(
                self.form_settings, f"{field}_help_text"
            )
        except AttributeError:
            pass
    return fields

CreateVendorFormStep3

CreateVendorFormStep3(*args, **kwargs)

Bases: FileFormMixin, BaseVendorForm, Form

Source code in hypha/apply/projects/forms/vendor.py
def __init__(self, *args, **kwargs):
    super(CreateVendorFormStep3, self).__init__(*args, **kwargs)
    self.fields = self.apply_form_settings(self.fields)

form_settings instance-attribute

form_settings = for_site(site)

due_diligence_documents class-attribute instance-attribute

due_diligence_documents = MultiFileField(required=True)

fields instance-attribute

fields = apply_form_settings(fields)

apply_form_settings

apply_form_settings(fields)
Source code in hypha/apply/projects/forms/vendor.py
def apply_form_settings(self, fields):
    for field in fields:
        try:
            self.fields[field].label = getattr(self.form_settings, f"{field}_label")
        except AttributeError:
            pass
        try:
            self.fields[field].help_text = getattr(
                self.form_settings, f"{field}_help_text"
            )
        except AttributeError:
            pass
    return fields

CreateVendorFormStep4

CreateVendorFormStep4(*args, **kwargs)

Bases: BaseVendorForm, Form

Source code in hypha/apply/projects/forms/vendor.py
def __init__(self, *args, **kwargs):
    super(CreateVendorFormStep4, self).__init__(*args, **kwargs)
    self.fields = self.apply_form_settings(self.fields)

form_settings instance-attribute

form_settings = for_site(site)

CURRENCY_CHOICES class-attribute instance-attribute

CURRENCY_CHOICES = [(currency, f'{get_currency_name(currency, locale=CURRENCY_LOCALE)} - {currency}') for currency in get_active_currencies()]

account_holder_name class-attribute instance-attribute

account_holder_name = CharField(required=True)

account_routing_number class-attribute instance-attribute

account_routing_number = CharField(required=True)

account_number class-attribute instance-attribute

account_number = CharField(required=True)

account_currency class-attribute instance-attribute

account_currency = ChoiceField(choices=sorted(CURRENCY_CHOICES, key=itemgetter(1)), required=True, initial='USD')

fields instance-attribute

fields = apply_form_settings(fields)

apply_form_settings

apply_form_settings(fields)
Source code in hypha/apply/projects/forms/vendor.py
def apply_form_settings(self, fields):
    for field in fields:
        try:
            self.fields[field].label = getattr(self.form_settings, f"{field}_label")
        except AttributeError:
            pass
        try:
            self.fields[field].help_text = getattr(
                self.form_settings, f"{field}_help_text"
            )
        except AttributeError:
            pass
    return fields

CreateVendorFormStep5

CreateVendorFormStep5(*args, **kwargs)

Bases: BaseVendorForm, Form

Source code in hypha/apply/projects/forms/vendor.py
def __init__(self, *args, **kwargs):
    super(CreateVendorFormStep5, self).__init__(*args, **kwargs)
    self.fields = self.apply_form_settings(self.fields)

form_settings instance-attribute

form_settings = for_site(site)

need_extra_info class-attribute instance-attribute

need_extra_info = TypedChoiceField(choices=((False, gettext_lazy('No')), (True, gettext_lazy('Yes'))), coerce=lambda : x == 'True', widget=RadioSelect, required=True)

fields instance-attribute

fields = apply_form_settings(fields)

apply_form_settings

apply_form_settings(fields)
Source code in hypha/apply/projects/forms/vendor.py
def apply_form_settings(self, fields):
    for field in fields:
        try:
            self.fields[field].label = getattr(self.form_settings, f"{field}_label")
        except AttributeError:
            pass
        try:
            self.fields[field].help_text = getattr(
                self.form_settings, f"{field}_help_text"
            )
        except AttributeError:
            pass
    return fields

CreateVendorFormStep6

CreateVendorFormStep6(*args, **kwargs)

Bases: BaseVendorForm, Form

Source code in hypha/apply/projects/forms/vendor.py
def __init__(self, *args, **kwargs):
    super(CreateVendorFormStep6, self).__init__(*args, **kwargs)
    self.fields = self.apply_form_settings(self.fields)

form_settings instance-attribute

form_settings = for_site(site)

CURRENCY_CHOICES class-attribute instance-attribute

CURRENCY_CHOICES = [(currency, f'{get_currency_name(currency, locale=CURRENCY_LOCALE)} - {currency}') for currency in get_active_currencies()]

branch_address class-attribute instance-attribute

branch_address = AddressField()

ib_account_routing_number class-attribute instance-attribute

ib_account_routing_number = CharField(required=False)

ib_account_number class-attribute instance-attribute

ib_account_number = CharField(required=False)

ib_account_currency class-attribute instance-attribute

ib_account_currency = ChoiceField(choices=sorted(CURRENCY_CHOICES, key=itemgetter(1)), required=False, initial='USD')

ib_branch_address class-attribute instance-attribute

ib_branch_address = AddressField()

nid_type class-attribute instance-attribute

nid_type = CharField(required=False)

nid_number class-attribute instance-attribute

nid_number = CharField(required=False)

other_info class-attribute instance-attribute

other_info = CharField(required=False, widget=Textarea)

fields instance-attribute

fields = apply_form_settings(fields)

apply_form_settings

apply_form_settings(fields)
Source code in hypha/apply/projects/forms/vendor.py
def apply_form_settings(self, fields):
    for field in fields:
        try:
            self.fields[field].label = getattr(self.form_settings, f"{field}_label")
        except AttributeError:
            pass
        try:
            self.fields[field].help_text = getattr(
                self.form_settings, f"{field}_help_text"
            )
        except AttributeError:
            pass
    return fields