diff --git a/README.md b/README.md index 15ea75f..1f2262c 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,8 @@ The following manual tests were made: - [see issue #156 here](https://github.com/mikerae/string-rota/issues/156) - [Admin Add Seating Position View Rotas #170 Testing](/readme_assets/images/testing-issue170-1.png) - [see issue #170 here](https://github.com/mikerae/string-rota/issues/170) +- [Admin Seating Position CRUD #170 Testing](/readme_assets/images/testing-issue170-2.png) + - [see issue #170 here](https://github.com/mikerae/string-rota/issues/170) #### Human Testing No human testing was done for this MVP, but once office manager functionality, and the hiding of draft rotas is implemented, user feedback will be sort. diff --git a/readme_assets/images/testing-issue170-2.png b/readme_assets/images/testing-issue170-2.png new file mode 100644 index 0000000..f4c2c49 Binary files /dev/null and b/readme_assets/images/testing-issue170-2.png differ diff --git a/string_rota/templates/string_rota/add_sp.html b/string_rota/templates/string_rota/add_sp.html index 9a7c6ef..dde725f 100644 --- a/string_rota/templates/string_rota/add_sp.html +++ b/string_rota/templates/string_rota/add_sp.html @@ -32,8 +32,13 @@

Add Seating Position

{{player_project_form|crispy }}
+ {% if user.is_staff %} + + Cancel + {% else %} Cancel + {% endif %}
diff --git a/string_rota/templates/string_rota/edit_sp.html b/string_rota/templates/string_rota/edit_sp.html index ab42a59..e7b8e3d 100644 --- a/string_rota/templates/string_rota/edit_sp.html +++ b/string_rota/templates/string_rota/edit_sp.html @@ -36,10 +36,18 @@

Edit Seating Position for {{player}} {{player_project_form | crispy }}
+ {% if user.is_staff %} + + Cancel + + Delete + {% else %} Cancel Delete + {% endif %} +
diff --git a/string_rota/templates/string_rota/rota.html b/string_rota/templates/string_rota/rota.html index e5e6ee9..9cbfc82 100644 --- a/string_rota/templates/string_rota/rota.html +++ b/string_rota/templates/string_rota/rota.html @@ -102,7 +102,14 @@

Please contact your Rota Manager
{% if rota_manager %} - {{position.player}} + {% if user.is_staff %} + {{position.player}} + + {% else %} + {{position.player}} + + {% endif %} {{position.position_number}} {% else %} diff --git a/string_rota/urls.py b/string_rota/urls.py index 022b050..b746196 100644 --- a/string_rota/urls.py +++ b/string_rota/urls.py @@ -24,6 +24,11 @@ views.EditSeatingPosition.as_view(), name="edit_sp", ), + path( + "edit_sp////", + views.EditSeatingPosition.as_view(), + name="edit_sp_office", + ), path( "reserve//", views.Reserve.as_view(), @@ -34,6 +39,11 @@ views.DeleteSeatingPosition.as_view(), name="delete_sp", ), + path( + "delete_sp////", + views.DeleteSeatingPosition.as_view(), + name="delete_sp_office", + ), path( "toggle///", views.ToggleSeatingPlanStatus.as_view(), diff --git a/string_rota/views.py b/string_rota/views.py index 3167b74..5baec44 100644 --- a/string_rota/views.py +++ b/string_rota/views.py @@ -124,7 +124,7 @@ def get(self, request, slug, **kwargs): messages.warning( request, f"There are no all_playerproject \ - records for the {project} project. Please contact a manager", + records for the {project} project. Please contact a manager", # noqa E501 ) return redirect(reverse("rota")) @@ -285,11 +285,18 @@ def post(self, request, slug, seating_plan_id, **kwargs): class EditSeatingPosition(Rota): """View and Edit the seating positions in a Seating Plan""" - def get(self, request, slug, seating_position_id): - projects = Project.objects.all() + def get(self, request, slug, seating_position_id, **kwargs): + """Show Edit Seating Position Form""" + office = request.user.groups.filter(name="Office") + sections = Section.objects.all() project = get_project(slug) - player = get_player(request) - section = get_section(player) + if office: + section = get_object_or_404(Section, pk=kwargs["section_id"]) + else: + player = get_player(request) + section = get_section(player) + projects = Project.objects.all() + seating_position = get_object_or_404( SeatingPosition, pk=seating_position_id ) # noqa E501 @@ -308,6 +315,7 @@ def get(self, request, slug, seating_position_id): context = { "player": sp_player, + "sections": sections, "projects": projects, "project": project, "section": section, @@ -318,13 +326,20 @@ def get(self, request, slug, seating_position_id): return render(request, template, context) - def post(self, request, slug, seating_position_id): + def post(self, request, slug, seating_position_id, **kwargs): """Edit a seating position in a seating Plan""" + office = request.user.groups.filter(name="Office") + sections = Section.objects.all() projects = Project.objects.all() + project = get_object_or_404(projects, slug=slug) - player = get_object_or_404(Player, users_django=request.user.id) - section = player.section + if office: + section = get_object_or_404(Section, pk=kwargs["section_id"]) + else: + player = get_object_or_404(Player, users_django=request.user.id) + section = player.section + projects = Project.objects.all() seating_position = get_object_or_404( SeatingPosition, pk=seating_position_id ) # noqa E501 @@ -348,6 +363,7 @@ def post(self, request, slug, seating_position_id): context = { "projects": projects, + "sections": sections, "project": project, "section": section, "position": seating_position, @@ -367,6 +383,7 @@ def post(self, request, slug, seating_position_id): context = { "projects": projects, + "sections": sections, "project": project, "section": section, "seating_position_form": seating_position_form, @@ -376,7 +393,13 @@ def post(self, request, slug, seating_position_id): return render(request, template, context) messages.success(request, "Your seating position is updated ") - + if office: + return HttpResponseRedirect( + reverse( + "rota_office", + args=[slug, section.id], + ), # noqa E501 + ) return HttpResponseRedirect(reverse("rota", args=[slug])) @@ -486,11 +509,14 @@ def post(self, request, slug): class DeleteSeatingPosition(View): """Delete a seating position in a project""" - def get(self, request, slug, position_id): + def get(self, request, slug, position_id, **kwargs): """Logic for deleting a seating position""" + office = request.user.groups.filter(name="Office") seating_position = get_object_or_404( SeatingPosition, id=position_id ) # noqa E501 + if office: + section = get_object_or_404(Section, pk=kwargs["section_id"]) player = seating_position.player project = seating_position.seating_plan.project player_project = get_object_or_404( @@ -508,6 +534,13 @@ def get(self, request, slug, position_id): messages.success( request, f"{player.first_name} has been removed from this rota." ) # noqa E501 + if office: + return HttpResponseRedirect( + reverse( + "rota_office", + args=[slug, section.id], + ), # noqa E501 + ) return HttpResponseRedirect(reverse("rota", args=[slug]))