Skip to content

Commit

Permalink
Merge branch 'develop' into i1707-feast-folio-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dchiller committed Dec 3, 2024
2 parents 751e162 + 093325d commit cc9d2c5
Show file tree
Hide file tree
Showing 19 changed files with 1,425 additions and 608 deletions.
31 changes: 31 additions & 0 deletions django/cantusdb_project/main_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
(False, "Partial inventory"),
)

# Define choices for Chant model's
# various proofreading fields: manuscript_full_text_std_proofread,
# manuscript_full_text_proofread, volpiano_proofread
PROOFREAD_CHOICES = [
(None, "Any"),
(True, "Yes"),
(False, "No"),
]


class NameModelChoiceField(forms.ModelChoiceField):
"""
Expand Down Expand Up @@ -520,6 +529,28 @@ class Meta:
)


class SourceBrowseChantsProofreadForm(forms.Form):
manuscript_full_text_std_proofread = forms.ChoiceField(
label="Full text as in Source (standardized spelling) proofread",
choices=PROOFREAD_CHOICES,
widget=forms.RadioSelect,
required=False,
)
manuscript_full_text_proofread = forms.ChoiceField(
label="Full text as in Source (source spelling) proofread",
choices=PROOFREAD_CHOICES,
widget=forms.RadioSelect,
required=False,
)

volpiano_proofread = forms.ChoiceField(
label="Volpiano proofread",
choices=PROOFREAD_CHOICES,
widget=forms.RadioSelect,
required=False,
)


class SequenceEditForm(forms.ModelForm):
class Meta:
model = Sequence
Expand Down
23 changes: 19 additions & 4 deletions django/cantusdb_project/main_app/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,29 @@ def user_can_proofread_chant(user: User, chant: Chant) -> bool:
if user.is_anonymous:
return False

source_id = chant.source.id
user_is_assigned_to_source = user.sources_user_can_edit.filter( # type: ignore[attr-defined]
source = chant.source
return user_can_proofread_source(user, source)


def user_can_proofread_source(user: User, source: Source) -> bool:
"""
Checks if the user can access the proofreading page of a given Source.
Used in SourceBrowseChantsView.
"""
if user.is_superuser:
return True

if user.is_anonymous:
return False

source_id = source.id
user_is_assigned_to_source: bool = user.sources_user_can_edit.filter( # type: ignore[attr-defined]
id=source_id
).exists()

user_groups = user.groups.all().values_list("name", flat=True)
user_is_pm = "project manager" in user_groups
user_is_editor = "editor" in user_groups
user_is_pm: bool = "project manager" in user_groups
user_is_editor: bool = "editor" in user_groups

return user_is_pm or (user_is_editor and user_is_assigned_to_source)

Expand Down
15 changes: 15 additions & 0 deletions django/cantusdb_project/main_app/templates/browse_chants.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ <h3>Browse Chants</h3>
</select>
</div>
</div>
{% if user_can_proofread_source %}
<fieldset>
{% for field in proofread_filter_form %}
<div class="filter-group">
<label class="small"><b>{{ field.label }}:</b></label>
{% for radio in field %}
<label for="{{ radio.id_for_label }}" style="margin-right: 10px;">
{{ radio.choice_label }}
<span class="radio">{{ radio.tag }}</span>
</label>
{% endfor %}
</div>
{% endfor %}
</fieldset>
{% endif %}

</form>
{% with exists_on_cantus_ultimus=source.exists_on_cantus_ultimus %}
Expand Down
Loading

0 comments on commit cc9d2c5

Please sign in to comment.