Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multiple comments per participation #1457

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions ephios/core/signup/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Field, Layout
from django import forms
from django.db import transaction
from django.utils.formats import date_format
from django.utils.timezone import localtime
from django.utils.translation import gettext_lazy as _
Expand All @@ -26,9 +27,6 @@ class BaseParticipationForm(forms.ModelForm):
comment_is_public = forms.BooleanField(
label=_("Make comment visible for other participants"), required=False
)
comment_visibility = forms.ChoiceField(
choices=ParticipationComment.Visibility, required=False, widget=forms.HiddenInput
)

def clean_individual_start_time(self):
if self.cleaned_data["individual_start_time"] == self.shift.start_time:
Expand Down Expand Up @@ -57,16 +55,17 @@ def clean(self):
self.add_error("individual_end_time", _("End time must not be before start time."))
return cleaned_data

def save(self, commit=True):
result = super().save(commit)
if comment := self.cleaned_data["comment"]:
ParticipationComment.objects.create(
participation=result,
text=comment,
authored_by_responsible=self.acting_user,
visibile_for=self.cleaned_data["comment_visibility"],
)
return result
def save(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm we can't remove the commit parameter here, as e.g. the named teams Participation Form calls save with the commit parameter. I actually ran into the exception while testing.

with transaction.atomic():
result = super().save()
if comment := self.cleaned_data["comment"]:
ParticipationComment.objects.create(
participation=result,
text=comment,
authored_by_responsible=self.acting_user,
visibile_for=self.get_comment_visibility(),
)
return result
Comment on lines +58 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use @transaction.atomic() as a decorator iirc


class Meta:
model = AbstractParticipation
Expand Down
19 changes: 8 additions & 11 deletions ephios/core/templates/core/disposition/fragment_participation.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,15 @@ <h6 class="d-inline">
{% if form.previous_comments %}
{{ form.previous_comments|as_crispy_field }}
{% endif %}
<div class="row">
<div class="form-group col">
{{ form.comment|as_crispy_field }}
<div class="mb-3">
<div class="form-label">
{{ form.comment.label_tag }}
<span class="float-end form-check">
<input type="checkbox" id="{{ form.comment_is_internal.auto_id }}" name="{{ form.comment_is_internal.html_name }}" class="form-check-input">
{{ form.comment_is_internal.label_tag }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does show a colon at the end, which I think doesn't fit here:
image

</span>
</div>
<div class="form-group col-md-2 pt-4">
<input type="checkbox" class="btn-check" id="{{ form.comment_is_internal.auto_id }}" name="{{ form.comment_is_internal.html_name }}" autocomplete="off">
<label class="btn btn-outline-primary" for="{{ form.comment_is_internal.auto_id }}"><span class="fa fa-eye-slash"></span></label>
</div>
{# <div class="form-group col">#}
{# <label class="form-label" for="flexSwitchCheckDefault">{{ form.comment_is_internal.label }}</label><br />#}
{# <input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault">#}
{# </div>#}
<input class="form-control" id="{{ form.comment.auto_id }}" name="{{ form.comment.html_name }}">
</div>
{% block participation_form %}
{% endblock %}
Expand Down
Loading