Skip to content

Commit

Permalink
Merge pull request #1563 from dchiller/split-views-files
Browse files Browse the repository at this point in the history
Put view classes in separate files
  • Loading branch information
dchiller authored Jul 25, 2024
2 parents 6995beb + c121369 commit c447fb1
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 465 deletions.
13 changes: 13 additions & 0 deletions django/cantusdb_project/main_app/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Sequence,
)
from users.models import User
from django.core.exceptions import PermissionDenied


def user_can_edit_chants_in_source(user: User, source: Optional[Source]) -> bool:
Expand Down Expand Up @@ -167,3 +168,15 @@ def user_can_manage_source_editors(user: User) -> bool:
or user.is_staff
or user.groups.filter(name="project manager").exists()
)


def user_is_project_manager(user: User) -> bool:
"""
A callback function that will be called by the user_passes_test decorator of content_overview.
Takes in a logged-in user as an argument.
Returns True if they are in a "project manager" group, raises PermissionDenied otherwise.
"""
if user.groups.filter(name="project manager").exists():
return True
raise PermissionDenied
96 changes: 62 additions & 34 deletions django/cantusdb_project/main_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,34 @@
PasswordResetConfirmView,
PasswordResetCompleteView,
)
from main_app.views import views
from main_app.views.api import (
ajax_melody_list,
ajax_melody_search,
ajax_search_bar,
json_cid_export,
json_nextchants,
json_sources_export,
notation_json_export,
json_node_export,
json_melody_export,
provenance_json_export,
csv_export,
articles_list_export,
flatpages_list_export,
)
from main_app.views.redirect import (
redirect_chants,
redirect_genre,
redirect_office,
redirect_source_inventory,
csv_export_redirect_from_old_path,
redirect_search,
redirect_node_url,
redirect_indexer,
redirect_documents,
)
from main_app.views.site_stats import items_count, content_overview
from main_app.views.contact import contact
from main_app.views.century import (
CenturyDetailView,
)
Expand Down Expand Up @@ -62,7 +89,7 @@
UserListView,
UserSourceListView,
)
from main_app.views.views import (
from main_app.views.autocomplete import (
CurrentEditorsAutocomplete,
AllUsersAutocomplete,
CenturyAutocomplete,
Expand All @@ -74,11 +101,12 @@
ProofreadByAutocomplete,
HoldingAutocomplete,
)
from main_app.views.auth import change_password

urlpatterns = [
path(
"contact/",
views.contact,
contact,
name="contact",
),
# login/logout/user
Expand Down Expand Up @@ -109,7 +137,7 @@
),
path(
"change-password/",
views.change_password,
change_password,
name="change-password",
),
# password reset views
Expand Down Expand Up @@ -190,7 +218,7 @@
),
path(
"chants/",
views.redirect_chants,
redirect_chants,
name="redirect-chants",
), # /chants/?source={source id}
# feast
Expand All @@ -217,7 +245,7 @@
),
path(
"genre/",
views.redirect_genre,
redirect_genre,
name="redirect-genre",
),
# indexer
Expand Down Expand Up @@ -245,7 +273,7 @@
),
path(
"office/",
views.redirect_office,
redirect_office,
name="redirect-office",
),
# provenance
Expand Down Expand Up @@ -293,7 +321,7 @@
),
path(
"index/",
views.redirect_source_inventory,
redirect_source_inventory,
name="redirect-source-inventory",
),
path(
Expand All @@ -319,49 +347,49 @@
),
path(
"ajax/melody/<str:cantus_id>",
views.ajax_melody_list,
ajax_melody_list,
name="ajax-melody",
),
path(
"ajax/melody-search/",
views.ajax_melody_search,
ajax_melody_search,
name="ajax-melody-search",
),
# json api
path(
"json-sources/",
views.json_sources_export,
json_sources_export,
name="json-sources-export",
),
path(
"json-nextchants/<str:cantus_id>",
views.json_nextchants,
json_nextchants,
name="json-nextchants",
),
path(
"json-melody/<str:cantus_id>",
views.json_melody_export,
json_melody_export,
name="json-melody-export",
),
path(
"json-cid/<str:cantus_id>",
views.json_cid_export,
json_cid_export,
name="json-cid-export",
),
# JSON APIs for returning data on individual objects in the database
path(
"json-node/<int:id>",
views.json_node_export,
json_node_export,
name="json-node-export",
),
path(
"notation/<int:id>/json",
views.notation_json_export,
notation_json_export,
name="notation-json-export",
),
path(
"provenance/<int:id>/json",
views.provenance_json_export,
provenance_json_export,
name="provenance-json-export",
),
# misc search
Expand All @@ -377,93 +405,93 @@
),
path(
"search/",
views.redirect_search,
redirect_search,
name="redirect-search",
),
path(
"ajax/search-bar/<str:search_term>",
views.ajax_search_bar,
ajax_search_bar,
name="ajax-search-bar",
),
# misc
path(
"content-statistics",
views.items_count,
items_count,
name="items-count",
),
path(
"source/<str:source_id>/csv/",
views.csv_export,
csv_export,
name="csv-export",
),
path(
"sites/default/files/csv/<str:source_id>.csv",
views.csv_export_redirect_from_old_path,
csv_export_redirect_from_old_path,
name="csv-export-old-path",
),
# content overview (for project managers)
path(
"content-overview/",
views.content_overview,
content_overview,
name="content-overview",
),
# /node/ url redirects
path(
"node/<int:pk>",
views.redirect_node_url,
redirect_node_url,
name="redirect-node-url",
),
# /indexer/ url redirects
path(
"indexer/<int:pk>",
views.redirect_indexer,
redirect_indexer,
name="redirect-indexer",
),
# links to APIs that list URLs of all pages that live in the database
path(
"articles-list/",
views.articles_list_export,
articles_list_export,
name="articles-list-export",
),
path(
"flatpages-list/",
views.flatpages_list_export,
flatpages_list_export,
name="flatpages-list-export",
),
# redirects for static files present on OldCantus
path(
"sites/default/files/documents/1. Quick Guide to Liturgy.pdf",
views.redirect_documents,
redirect_documents,
name="redirect-quick-guide-to-liturgy",
),
path(
"sites/default/files/documents/2. Volpiano Protocols.pdf",
views.redirect_documents,
redirect_documents,
name="redirect-volpiano-protocols",
),
path(
"sites/default/files/documents/3. Volpiano Neumes for Review.docx",
views.redirect_documents,
redirect_documents,
name="redirect-volpiano-neumes-for-review",
),
path(
"sites/default/files/documents/4. Volpiano Neume Protocols.pdf",
views.redirect_documents,
redirect_documents,
name="redirect-volpiano-neume-protocols",
),
path(
"sites/default/files/documents/5. Volpiano Editing Guidelines.pdf",
views.redirect_documents,
redirect_documents,
name="redirect-volpiano-editing-guidelines",
),
path(
"sites/default/files/documents/7. Guide to Graduals.pdf",
views.redirect_documents,
redirect_documents,
name="redirect-guide-to-graduals",
),
path(
"sites/default/files/HOW TO - manuscript descriptions-Nov6-20.pdf",
views.redirect_documents,
redirect_documents,
name="redirect-how-to-manuscript-descriptions",
),
path(
Expand Down
Loading

0 comments on commit c447fb1

Please sign in to comment.