Skip to content

Commit

Permalink
[#170] Add Admin Allocate reserve
Browse files Browse the repository at this point in the history
Remove Register User from Admin login temporarily to ensure pull request
    is robust.
	modified:   templates/base.html

Add conditional rendering for login as Admin/Rota Manager in
    Reserve class
Add **kwargs to pass section.id into Reserve class
	modified:   string_rota/views.py

Add reserve_office url
	modified:   string_rota/urls.py

Add conditional Allocate Reserve button url
	modified:   string_rota/templates/string_rota/rota.html

Add conditional cancel button url
	modified:   string_rota/templates/string_rota/reserve.html

Add testing for Add Admin Allocate reserve to README
	modified:   README.md
	new file:   readme_assets/images/testing-issue170-4.png
  • Loading branch information
mikerae committed Oct 9, 2023
1 parent 4781bab commit f69296b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ The following manual tests were made:
- [see issue #170 here](https://github.com/mikerae/string-rota/issues/170)
- [Admin Toggle Draft/Published Rotas #170 Testing](/readme_assets/images/testing-issue170-3.png)
- [see issue #170 here](https://github.com/mikerae/string-rota/issues/170)
- [Admin Allocate Reserve Player #170 Testing](/readme_assets/images/testing-issue170-4.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.

Expand Down
Binary file added readme_assets/images/testing-issue170-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion string_rota/templates/string_rota/reserve.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<main id="main" class="main">

<div class="pagetitle">
<h1>Edit Player Info for {{section}} Section for the {{project.name}}</h1>
<h1>Edit Player Reserve Allocation for {{section}} Section for the {{project.name}}</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'home' %}">Home</a></li>
Expand Down Expand Up @@ -56,8 +56,13 @@ <h2 class="card-title">Project: {{ project }}: {{ section }} Section</h2>
{% csrf_token %}
<div class="text-center">
<button type="submit" class="btn btn-success">Change Reserve Player Status</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>
<!-- End Rota Form -->
Expand Down
7 changes: 3 additions & 4 deletions string_rota/templates/string_rota/rota.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ <h5 class="text-info">Please contact your Rota Manager</h5>
Player to Seating Plan</button></a></span>
<a href="{% url 'toggle_seating_plan_status_office' project.slug seating_plan.id section.id %}"><button
class="btn btn-success">Draft/Published</button></a>
<a href="{% url 'reserve' project.slug %}"><button class="btn btn-primary">Allocate
Reserved
<a href="{% url 'reserve_office' project.slug section.id %}"><button class="btn btn-primary">Allocate
Reserve
Player</button></a>
</div>
{% elif rota_manager %}
Expand All @@ -146,8 +146,7 @@ <h5 class="text-info">Please contact your Rota Manager</h5>
Player to Seating Plan</button></a></span>
<a href="{% url 'toggle_seating_plan_status' project.slug seating_plan.id %}"><button
class="btn btn-success">Draft/Published</button></a>
<a href="{% url 'reserve' project.slug %}"><button class="btn btn-primary">Allocate
Reserved
<a href="{% url 'reserve' project.slug %}"><button class="btn btn-primary">Allocate Reserve
Player</button></a>
</div>
{% endif %}
Expand Down
16 changes: 10 additions & 6 deletions string_rota/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
""" Urls for string-rota app """
from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
path("", views.Home.as_view(), name="home"),
path("<slug:slug>/", views.Rota.as_view(), name="rota"),
path(
"reserve/<slug:slug>/",
views.Reserve.as_view(),
name="reserve",
),
path(
"reserve/<slug:slug>/<section_id>/",
views.Reserve.as_view(),
name="reserve_office",
),
path(
"<slug:slug>/<section_id>/", views.Rota.as_view(), name="rota_office"
), # noqa E501
Expand All @@ -29,11 +38,6 @@
views.EditSeatingPosition.as_view(),
name="edit_sp_office",
),
path(
"reserve/<slug:slug>/",
views.Reserve.as_view(),
name="reserve",
),
path(
"delete_sp/<slug:slug>/<position_id>/",
views.DeleteSeatingPosition.as_view(),
Expand Down
44 changes: 32 additions & 12 deletions string_rota/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,31 @@ def post(self, request, slug, seating_position_id, **kwargs):
class Reserve(Rota):
"""Set the Reserve and Reduced status for a plyer iin a project"""

def get(self, request, slug):
def get(self, request, slug, **kwargs):
projects = Project.objects.all()
sections = Section.objects.all()
office = request.user.groups.filter(name="Office")
project = get_project(slug)

(
project,
section,
seating_plan,
not_playing_in_playerproject,
) = get_reserve_vars(request, slug)
if office:
section = get_object_or_404(Section, pk=kwargs["section_id"])
else:
player = get_player(request)
section = get_section(player)

seating_plan = get_seating_plan(project, section)
players = get_players(section)
not_playing_in_playerproject = get_not_playing_in_playerproject(
players, seating_plan, project
)

reserve_form = ReserveForm(section, seating_plan)

template = "string_rota/reserve.html"

context = {
"projects": projects,
"sections": sections,
"project": project,
"section": section,
"reserve_form": reserve_form,
Expand All @@ -430,13 +439,18 @@ def get(self, request, slug):

return render(request, template, context)

def post(self, request, slug):
def post(self, request, slug, **kwargs):
"""Saves reserve status for player in project"""

projects = Project.objects.all()
sections = Section.objects.all()
office = request.user.groups.filter(name="Office")
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)
players = get_players(section)
seating_plan = get_seating_plan(project, section)
not_playing_in_playerproject = get_not_playing_in_playerproject(
Expand All @@ -449,7 +463,6 @@ def post(self, request, slug):
data=request.POST,
)
if reserve_form.is_valid():
print("reserve form valid")
plpr_from_form = get_object_or_404(
PlayerProject,
project=project,
Expand Down Expand Up @@ -489,11 +502,11 @@ def post(self, request, slug):
plpr_from_form.save()

else:
print("reserve form not valid")
template = "string_rota/reserve.html"

context = {
"projects": projects,
"sections": sections,
"project": project,
"section": section,
"reserve_form": reserve_form,
Expand All @@ -503,6 +516,13 @@ def post(self, request, slug):

return render(request, template, context)

if office:
return HttpResponseRedirect(
reverse(
"rota_office",
args=[slug, section.id],
), # noqa E501
)
return HttpResponseRedirect(reverse("rota", args=[slug]))


Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ <h6>{{user.first_name}} {{user.last_name}}</h6>

<!-- Register Nav -->
{% if rota_manager %}
<li class="nav-item">
<li class="nav-item {% if user.is_superuser %}d-none{% endif %}">
<a class="nav-link collapsed" href="{% url 'register' %}">
<i class="bi bi-menu-button-wide"></i><span>Register a Player</span>
</a>
Expand Down

0 comments on commit f69296b

Please sign in to comment.