Skip to content

Report

hypha.apply.projects.forms.report

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