+
diff --git a/lineups/views.py b/lineups/views.py
index 05860fc..5866d2b 100644
--- a/lineups/views.py
+++ b/lineups/views.py
@@ -1,11 +1,9 @@
from django.shortcuts import render, redirect, get_object_or_404
-from django.forms import formset_factory
from .models import Positioning
from .forms import PositioningFormSet
-from django.http import HttpResponse
-from django import forms
from events.models import Event
from players.models import Player
+from django.forms.models import model_to_dict
# Create your views here.
def edit(request, event_id):
@@ -31,7 +29,17 @@ def edit(request, event_id):
return render(request, 'success.html', {'call_back':'edit lineup','id':event_id}, status=200)
# return render(request, 'success.html', {'call_back':'schedule'})
event = Event.objects.get(id=event_id)
- players = Player.objects.all()
+ players = Player.objects.all().prefetch_related('availability_set', 'statline_set')
+ players = [
+ {
+ **model_to_dict(player),
+ 'availability':player.availability_set.get(event_id=event_id),
+ # 'available_value': player.availability_set.get(event_id=event_id).available,
+ 'statline': player.statline_set.get(player_id=player.id)
+ }
+ for player in players
+ ]
+ players.sort(key=lambda d: d['availability'].available, reverse = True)
qset = Positioning.objects.filter(event_id=event_id, order__isnull = False)
formset = PositioningFormSet(queryset=qset)
for form in formset:
diff --git a/players/fixtures/2021cmba.json b/players/fixtures/2021cmba.json
index b0d7c76..ba001a4 100644
--- a/players/fixtures/2021cmba.json
+++ b/players/fixtures/2021cmba.json
@@ -223,5 +223,255 @@
"jersey_number": 45,
"last_name": "Kelly"
}
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.417,
+ "onbase_pct": 0.488,
+ "player_id": 1,
+ "slugging_pct": 0.472
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.422,
+ "onbase_pct": 0.518,
+ "player_id": 2,
+ "slugging_pct": 0.667
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0,
+ "onbase_pct": 0.2,
+ "player_id": 3,
+ "slugging_pct": 0
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.061,
+ "onbase_pct": 0.233,
+ "player_id": 4,
+ "slugging_pct": 0.061
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.282,
+ "onbase_pct": 0.338,
+ "player_id": 5,
+ "slugging_pct": 0.296
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.267,
+ "onbase_pct": 0.333,
+ "player_id": 6,
+ "slugging_pct": 0.3
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.214,
+ "onbase_pct": 0.235,
+ "player_id": 7,
+ "slugging_pct": 0.357
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.219,
+ "onbase_pct": 0.324,
+ "player_id": 8,
+ "slugging_pct": 0.344
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.28,
+ "onbase_pct": 0.28,
+ "player_id": 9,
+ "slugging_pct": 0.32
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.333,
+ "onbase_pct": 0.424,
+ "player_id": 10,
+ "slugging_pct": 0.373
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0,
+ "onbase_pct": 0.25,
+ "player_id": 11,
+ "slugging_pct": 0
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0,
+ "onbase_pct": 0,
+ "player_id": 12,
+ "slugging_pct": 0
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.379,
+ "onbase_pct": 0.379,
+ "player_id": 13,
+ "slugging_pct": 0.552
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.095,
+ "onbase_pct": 0.174,
+ "player_id": 14,
+ "slugging_pct": 0.143
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.41,
+ "onbase_pct": 0.486,
+ "player_id": 15,
+ "slugging_pct": 0.525
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.357,
+ "onbase_pct": 0.406,
+ "player_id": 16,
+ "slugging_pct": 0.536
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.185,
+ "onbase_pct": 0.312,
+ "player_id": 17,
+ "slugging_pct": 0.259
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.299,
+ "onbase_pct": 0.378,
+ "player_id": 18,
+ "slugging_pct": 0.391
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.438,
+ "onbase_pct": 0.571,
+ "player_id": 19,
+ "slugging_pct": 0.781
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.333,
+ "onbase_pct": 0.417,
+ "player_id": 20,
+ "slugging_pct": 0.367
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.333,
+ "onbase_pct": 0.41,
+ "player_id": 22,
+ "slugging_pct": 0.522
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.062,
+ "onbase_pct": 0.211,
+ "player_id": 23,
+ "slugging_pct": 0.125
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.5,
+ "onbase_pct": 0.611,
+ "player_id": 24,
+ "slugging_pct": 0.5
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0.25,
+ "onbase_pct": 0.25,
+ "player_id": 25,
+ "slugging_pct": 0.5
+ }
+ },
+ {
+ "model": "players.statline",
+ "pk": null,
+ "fields": {
+ "batting_avg": 0,
+ "onbase_pct": 0,
+ "player_id": 21,
+ "slugging_pct": 0
+ }
}
]
\ No newline at end of file
diff --git a/players/models.py b/players/models.py
index d28cb9f..c769aa0 100644
--- a/players/models.py
+++ b/players/models.py
@@ -20,7 +20,7 @@ class StatLine(models.Model):
slugging_pct = models.DecimalField(max_digits=4, decimal_places=3, default=0)
def __str__(self):
- return f"{self.batting_avg}/{self.onbase_pct}/{self.slugging_pct}"
+ return f"{self.slash_line}"
@property
def slash_line(self):
diff --git a/players/urls.py b/players/urls.py
index 6618794..621b262 100644
--- a/players/urls.py
+++ b/players/urls.py
@@ -1,10 +1,12 @@
from django.urls import path, include
+from .views import PlayerListView, PlayerEditView
+
from . import views
urlpatterns = [
path('', views.root, name="root"),
- path('list', views.list, name="players list"),
- path('edit/
', views.edit, name="edit player"),
- path('edit', views.edit, name="edit player")
+ path('list', PlayerListView.as_view(), name='players list'),
+ path('edit/', PlayerEditView.as_view(), name="edit player"),
+ path('edit', PlayerEditView.as_view(), name="edit player")
]
\ No newline at end of file
diff --git a/players/views.py b/players/views.py
index 5ffb8d1..afc7a7d 100644
--- a/players/views.py
+++ b/players/views.py
@@ -1,48 +1,26 @@
from django.shortcuts import render, redirect, get_object_or_404
+from django.views.generic.list import ListView
from django.http import HttpResponse
from django.urls import reverse
from .models import Player
from .forms import PlayerForm
+from lib.views import BenchcoachListView, BenchcoachEditView
# Create your views here.
+
+class PlayerListView(BenchcoachListView):
+ Model = Player
+ edit_url = 'edit player'
+ list_url = 'players list'
+ page_title = "Players"
+ title_strf = "{first_name} {last_name}"
+ subtitle_strf = "#{jersey_number}"
+
def root(request):
return redirect('/players/list')
-def list(request):
- players = Player.objects.all()
- return render(request, 'list.html', {'title': "Players",
- 'items': [
- {'id':player.id,
- 'title':f"{player.first_name} {player.last_name}",
- 'subtitle':f"{player.jersey_number}"
- }
- for player in players],
- 'edit_url_name': 'edit player'})
-
-def edit(request, id=0):
- # if this is a POST request we need to process the form data
- if request.method == 'POST':
- # create a form instance and populate it with data from the request:
- if id:
- instance = get_object_or_404(Player, id=id)
- form = PlayerForm(request.POST or None, instance=instance)
- else:
- form = PlayerForm(request.POST or None)
- # check whether it's valid:
- if form.is_valid():
- # process the data in form.cleaned_data as required
- if id == 0: id = None
- new_player, did_create = Player.objects.update_or_create(pk=id, defaults=form.cleaned_data)
- return render(request, 'success.html', {'call_back':reverse('players list'),'id':new_player.id}, status=201 if did_create else 200)
- else:
- return HttpResponse(status=400)
-
- # if a GET (or any other method) we'll create a blank form
- else:
- if id:
- instance = get_object_or_404(Player, id=id)
- form = PlayerForm(request.POST or None, instance=instance)
- else:
- form = PlayerForm
-
- return render(request, 'edit.html', {'form': form, 'id': id, 'call_back':'edit player'})
\ No newline at end of file
+class PlayerEditView(BenchcoachEditView):
+ Form = PlayerForm
+ Model = Player
+ edit_url = 'edit player'
+ list_url = 'players list'
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..7c7317f
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,19 @@
+asgiref==3.4.1
+beautifulsoup4==4.9.3
+certifi==2021.5.30
+charset-normalizer==2.0.4
+Django==3.2.6
+idna==3.2
+importlib-metadata==3.10.1
+libsass==0.21.0
+Pillow==8.3.1
+PyYAML==6.0
+requests==2.26.0
+six==1.16.0
+soupsieve==2.2.1
+sqlparse==0.4.1
+urllib3==1.26.6
+zipp==3.5.0
+django-bootstrap-v5==1.0.7
+django-crispy-forms
+psycopg2
\ No newline at end of file
diff --git a/teams/urls.py b/teams/urls.py
index 16c4438..f0d37f9 100644
--- a/teams/urls.py
+++ b/teams/urls.py
@@ -6,7 +6,7 @@ from . import views
urlpatterns = [
path('', views.root, name="root"),
- path('list', views.list, name="teams list"),
- path('edit/', views.edit, name="edit team"),
- path('edit', views.edit, name="edit team")
+ path('list', views.TeamsListView.as_view(), name="teams list"),
+ path('edit/', views.TeamEditView.as_view(), name="edit team"),
+ path('edit', views.TeamEditView.as_view(), name="edit team")
]
\ No newline at end of file
diff --git a/teams/views.py b/teams/views.py
index f78fbf1..6a19dd4 100644
--- a/teams/views.py
+++ b/teams/views.py
@@ -3,43 +3,19 @@ from django.http import HttpResponse
from django.urls import reverse
from .forms import TeamForm
from .models import Team
+from lib.views import BenchcoachListView, BenchcoachEditView
def root(request):
- return redirect('/teams/list')
+ return redirect(reverse('teams list'))
-def list(request):
- teams = Team.objects.all()
- return render(request, 'list.html', {'title': "Players",
- 'items': [
- {'id':team.id,
- 'title':f"{team.name}"
- }
- for team in teams],
- 'edit_url_name': 'edit team'})
+class TeamsListView(BenchcoachListView):
+ Model = Team
+ edit_url = 'edit team'
+ list_url = 'teams list'
+ page_title = "Teams"
-def edit(request, id=0):
- # if this is a POST request we need to process the form data
- if request.method == 'POST':
- # create a form instance and populate it with data from the request:
- if id:
- instance = get_object_or_404(Team, id=id)
- form = TeamForm(request.POST or None, instance=instance)
- else:
- form = TeamForm(request.POST or None)
- # check whether it's valid:
- if form.is_valid():
- # process the data in form.cleaned_data as required
- # ...
- # redirect to a new URL:
- new_team, did_create = Team.objects.update_or_create(pk=id, defaults=form.cleaned_data)
- return render(request, 'success.html', {'call_back_url':reverse('teams list'), 'id':new_team.id},status=201 if did_create else 200)
-
- # if a GET (or any other method) we'll create a blank form
- else:
- if id:
- instance = get_object_or_404(Team, id=id)
- form = TeamForm(request.POST or None, instance=instance)
- else:
- form = TeamForm
-
- return render(request, 'edit.html', {'form': form, 'id': id, 'call_back':'edit team'})
\ No newline at end of file
+class TeamEditView(BenchcoachEditView):
+ Model = Team
+ edit_url = 'edit team'
+ list_url = 'teams list'
+ Form = TeamForm
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
index 8455c04..2d46b6c 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -8,19 +8,24 @@
{% bootstrap_css %}
{% bootstrap_javascript %}
-
+
+
+
+
+
+
-