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):
    # Get `submission_partner_list` kwarg and remove it before initializing parent.
    submission_partner_list = None
    if "submission_partner_list" in kwargs:
        submission_partner_list = kwargs.pop("submission_partner_list")

    super().__init__(*args, **kwargs)
    self.visibility_choices = self._meta.model.visibility_choices_for(
        user, submission_partner_list
    )
    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()
    if not user.is_apply_staff:
        self.fields["assign_to"].widget = forms.HiddenInput()

attachments class-attribute instance-attribute

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

assign_to class-attribute instance-attribute

assign_to = ModelChoiceField(queryset=filter(groups__name=STAFF_GROUP_NAME), required=False, empty_label=gettext_lazy('Select...'), label=gettext_lazy('Assign to'))

visibility_choices instance-attribute

visibility_choices = visibility_choices_for(user, submission_partner_list)

Meta

model class-attribute instance-attribute
model = Activity
fields class-attribute instance-attribute
fields = ('message', 'visibility', 'assign_to')
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"]
    assigned_user = self.cleaned_data["assign_to"]
    if assigned_user:
        # add task to assigned user
        add_task_to_user(
            code=COMMENT_TASK,
            user=assigned_user,
            related_obj=instance,
        )
    if added_files:
        ActivityAttachment.objects.bulk_create(
            ActivityAttachment(activity=instance, file=file) for file in added_files
        )
    return instance