Skip to content

Forms

hypha.apply.activity.forms

CommentForm

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

Bases: FileFormMixin, ModelForm

Source code in hypha/apply/activity/forms.py
def __init__(self, *args, user=None, **kwargs):
    super().__init__(*args, **kwargs)
    self.visibility_choices = self._meta.model.visibility_choices_for(user)
    visibility = self.fields["visibility"]
    # Set default visibility to "Applicant" for staff and staff can view everything.
    visibility.initial = self.visibility_choices[0]
    if len(self.visibility_choices) > 1:
        visibility.choices = self.visibility_choices
    else:
        visibility.required = False
        visibility.choices = self.visibility_choices
        visibility.initial = visibility.initial[0]
        visibility.widget = forms.HiddenInput()

attachments class-attribute instance-attribute

attachments = MultiFileField(label=gettext_lazy('Attachments'), required=False)

visibility_choices instance-attribute

visibility_choices = visibility_choices_for(user)

Meta

model class-attribute instance-attribute
model = Activity
fields class-attribute instance-attribute
fields = ('message', 'visibility')
labels class-attribute instance-attribute
labels = {'visibility': 'Visible to', 'message': 'Message'}
help_texts class-attribute instance-attribute
help_texts = {'visibility': 'Select a relevant user role. Staff can view every comment.'}
widgets class-attribute instance-attribute
widgets = {'visibility': RadioSelect(), 'message': PagedownWidget()}

save

save(commit=True)
Source code in hypha/apply/activity/forms.py
@transaction.atomic
def save(self, commit=True):
    instance = super().save(commit=True)
    added_files = self.cleaned_data["attachments"]
    if added_files:
        ActivityAttachment.objects.bulk_create(
            ActivityAttachment(activity=instance, file=file) for file in added_files
        )

    return instance