Skip to content



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

Bases: StreamBaseForm, ModelForm

Source code in hypha/apply/projects/forms/
def __init__(self, *args, user=None, initial=None, **kwargs):
    if initial is None:
        initial = {}
    # Need to populate form_fields, right?
    # No: The form_fields got populated from the view which instantiated this Form.
    # Yes: they don't seem to be here.
    # No: this is not where the magic happens.
    # self.form_fields = kwargs.pop("form_fields", {})
    # Need to populate form_data, right? Yes. No. IDK. Appears no.
    # self.form_data = kwargs.pop("form_data", {})
    # OK, both yes and no. If there is an existing value it will come via "initial", so if present there, use them.
    # if initial["form_fields"] is not None:
    #     self.form_fields = initial["form_fields"]
    # if initial["form_data"] is not None:
    #     self.form_data = initial["form_data"]
    # But this should not be needed because super().__init__ will already take these initial values and use them.
    super().__init__(*args, initial=initial, **kwargs)
    self.user = user

user instance-attribute

user = user


model class-attribute instance-attribute
model = Report
fields class-attribute instance-attribute
fields = []


Source code in hypha/apply/stream_forms/
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


Source code in hypha/apply/stream_forms/
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]



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

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

    if not form_id:

    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)


Source code in hypha/apply/projects/forms/
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(commit=True, form_fields=dict)
Source code in hypha/apply/projects/forms/
def save(self, commit=True, form_fields=dict):
    is_draft = "save" in
    version = ReportVersion.objects.create(
        # Save a ReportVersion first then edit/update the form_data below.
    # We need to save the fields first, not attempt to save form_data on first save, then update the form_data next.
    # Otherwise, we don't get access to the generator method "question_field_ids" which we use to prevent temp file
    # fields from getting into the saved form_data.
    # Inspired by and but enhanced to support multi-answer fields.
    version.form_data = {
        field: self.cleaned_data["form_data"][field]
        for field in self.cleaned_data["form_data"]
        # Where do we get question_field_ids? On the version, but only when it exists, thus the create-then-update.
        # The split-on-underscore supports the use of multi-answer fields such as MultiInputCharFieldBlock.
        if field.split("_")[0] in version.question_field_ids

    # In case there are stream form file fields, process those here.
    # Because ReportVersion is a separate entity from Project, super().save will not save ReportVersion: save here.

    if is_draft:
        self.instance.draft = version
        # 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)
    return instance


ReportFrequencyForm(*args, **kwargs)

Bases: ModelForm

Source code in hypha/apply/projects/forms/
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)


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': ''}