Skip to content

Commit

Permalink
[#170] Fix CRUD for Admin Seating Position
Browse files Browse the repository at this point in the history
For Admin User:
In Views: Each CRUD Class accepts ssection_id as kwargs and sets the
value of section. Each returns to a dedicated 'office' url
	modified:   string_rota/views.py

Fix for Add Seating Position: conditional routing
	modified:   string_rota/templates/string_rota/add_sp.html
    modified:   string_rota/templates/string_rota/rota.html

Fix for Edit Seating position: conditional routing
	modified:   string_rota/templates/string_rota/edit_sp.html

Add dedicated office urls for each CRUD url
	modified:   string_rota/urls.py

Add testing for Fix CRUD for Admin Seating Position in README
	modified:   README.md
	new file:   readme_assets/images/testing-issue170-2.png
mikerae committed Oct 8, 2023
1 parent a5a770d commit 98d182f
Showing 7 changed files with 76 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Binary file added readme_assets/images/testing-issue170-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions string_rota/templates/string_rota/add_sp.html
Original file line number Diff line number Diff line change
@@ -32,8 +32,13 @@ <h1 class="card-title">Add Seating Position</h1>
<span class="col-md-4">{{player_project_form|crispy }}</span>
<div class="text-center">
<button type="submit" class="btn btn-success">Add Position</button>
{% if user.is_staff %}
<a href="{% url 'rota_office' project.slug section.id %}" class="btn btn-secondary">
Cancel</a>
{% else %}
<a href="{% url 'rota' project.slug %}" class="btn btn-secondary">
Cancel</a>
{% endif %}
</div>
</form>

8 changes: 8 additions & 0 deletions string_rota/templates/string_rota/edit_sp.html
Original file line number Diff line number Diff line change
@@ -36,10 +36,18 @@ <h1 class="card-title">Edit Seating Position for <strong>{{player}}</strong>
<span class="col-md-4">{{player_project_form | crispy }}</span>
<div class="text-center">
<button type="submit" class="btn btn-success">Edit Position</button>
{% if user.is_staff %}
<a href="{% url 'rota_office' project.slug section.id %}" class="btn btn-secondary">
Cancel</a>
<a class="btn btn-danger" href="{% url 'delete_sp_office' project.slug position.id section.id %}">
Delete</a>
{% else %}
<a href="{% url 'rota' project.slug %}" class="btn btn-secondary">
Cancel</a>
<a class="btn btn-danger" href="{% url 'delete_sp' project.slug position.id %}">
Delete</a>
{% endif %}

</div>
</form>
<!-- End Rota Form -->
9 changes: 8 additions & 1 deletion string_rota/templates/string_rota/rota.html
Original file line number Diff line number Diff line change
@@ -102,7 +102,14 @@ <h5 class="text-info">Please contact your Rota Manager</h5>

{% if rota_manager %}
<tr>
<td><a class="bi" href="{% url 'edit_sp' project.slug position.id %}">{{position.player}}</a></td>
{% if user.is_staff %}
<td><a class="bi"
href="{% url 'edit_sp_office' project.slug position.id section.id %}">{{position.player}}</a>
</td>
{% else %}
<td><a class="bi" href="{% url 'edit_sp' project.slug position.id %}">{{position.player}}</a>
</td>
{% endif %}
<td>{{position.position_number}}</td>
</tr>
{% else %}
10 changes: 10 additions & 0 deletions string_rota/urls.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,11 @@
views.EditSeatingPosition.as_view(),
name="edit_sp",
),
path(
"edit_sp/<slug:slug>/<seating_position_id>/<section_id>/",
views.EditSeatingPosition.as_view(),
name="edit_sp_office",
),
path(
"reserve/<slug:slug>/",
views.Reserve.as_view(),
@@ -34,6 +39,11 @@
views.DeleteSeatingPosition.as_view(),
name="delete_sp",
),
path(
"delete_sp/<slug:slug>/<position_id>/<section_id>/",
views.DeleteSeatingPosition.as_view(),
name="delete_sp_office",
),
path(
"toggle/<slug:slug>/<seating_plan_id>/",
views.ToggleSeatingPlanStatus.as_view(),
53 changes: 43 additions & 10 deletions string_rota/views.py
Original file line number Diff line number Diff line change
@@ -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]))


0 comments on commit 98d182f

Please sign in to comment.