From 2fd44c1f530167c16359dfb5537100c71c8e1132 Mon Sep 17 00:00:00 2001 From: Lukas Kucharczyk Date: Mon, 12 Aug 2024 21:52:26 +0200 Subject: [PATCH] separate views out 2/2 --- games/urls.py | 118 ++++++------------ games/views/__init__.py | 0 games/{deviceviews.py => views/device.py} | 2 +- games/{editionviews.py => views/edition.py} | 2 +- games/{gameviews.py => views/game.py} | 2 +- games/{views.py => views/general.py} | 9 +- games/{platformviews.py => views/platform.py} | 2 +- games/{purchaseviews.py => views/purchase.py} | 2 +- games/{sessionviews.py => views/session.py} | 2 +- timetracker/settings.py | 3 +- 10 files changed, 45 insertions(+), 97 deletions(-) create mode 100644 games/views/__init__.py rename games/{deviceviews.py => views/device.py} (98%) rename games/{editionviews.py => views/edition.py} (99%) rename games/{gameviews.py => views/game.py} (99%) rename games/{views.py => views/general.py} (98%) rename games/{platformviews.py => views/platform.py} (98%) rename games/{purchaseviews.py => views/purchase.py} (98%) rename games/{sessionviews.py => views/session.py} (99%) diff --git a/games/urls.py b/games/urls.py index 8a942c3..97565cd 100644 --- a/games/urls.py +++ b/games/urls.py @@ -1,154 +1,110 @@ from django.urls import path -from games import ( - deviceviews, - editionviews, - gameviews, - platformviews, - purchaseviews, - sessionviews, - views, -) +from games.views import device, edition, game, general, platform, purchase, session urlpatterns = [ - path("", views.index, name="index"), - path("device/add", deviceviews.add_device, name="add_device"), - path( - "device/delete/", deviceviews.delete_device, name="delete_device" - ), - path("device/edit/", deviceviews.edit_device, name="edit_device"), - path("device/list", deviceviews.list_devices, name="list_devices"), - path("edition/add", editionviews.add_edition, name="add_edition"), + path("", general.index, name="index"), + path("device/add", device.add_device, name="add_device"), + path("device/delete/", device.delete_device, name="delete_device"), + path("device/edit/", device.edit_device, name="edit_device"), + path("device/list", device.list_devices, name="list_devices"), + path("edition/add", edition.add_edition, name="add_edition"), path( "edition/add/for-game/", - editionviews.add_edition, + edition.add_edition, name="add_edition_for_game", ), - path( - "edition//edit", editionviews.edit_edition, name="edit_edition" - ), - path("edition/list", editionviews.list_editions, name="list_editions"), + path("edition//edit", edition.edit_edition, name="edit_edition"), + path("edition/list", edition.list_editions, name="list_editions"), path( "edition//delete", - editionviews.delete_edition, + edition.delete_edition, name="delete_edition", ), - path("game/add", gameviews.add_game, name="add_game"), - path("game//edit", gameviews.edit_game, name="edit_game"), - path("game//view", gameviews.view_game, name="view_game"), - path("game//delete", gameviews.delete_game, name="delete_game"), - path("game/list", gameviews.list_games, name="list_games"), - path("platform/add", platformviews.add_platform, name="add_platform"), + path("game/add", game.add_game, name="add_game"), + path("game//edit", game.edit_game, name="edit_game"), + path("game//view", game.view_game, name="view_game"), + path("game//delete", game.delete_game, name="delete_game"), + path("game/list", game.list_games, name="list_games"), + path("platform/add", platform.add_platform, name="add_platform"), path( "platform//edit", - platformviews.edit_platform, + platform.edit_platform, name="edit_platform", ), path( "platform//delete", - platformviews.delete_platform, + platform.delete_platform, name="delete_platform", ), - path("platform/list", platformviews.list_platforms, name="list_platforms"), - path("purchase/add", purchaseviews.add_purchase, name="add_purchase"), + path("platform/list", platform.list_platforms, name="list_platforms"), + path("purchase/add", purchase.add_purchase, name="add_purchase"), path( "purchase//edit", - purchaseviews.edit_purchase, + purchase.edit_purchase, name="edit_purchase", ), path( "purchase//delete", - purchaseviews.delete_purchase, + purchase.delete_purchase, name="delete_purchase", ), path( "purchase/list", - purchaseviews.list_purchases, + purchase.list_purchases, name="list_purchases", ), path( "purchase/related-purchase-by-edition", - purchaseviews.related_purchase_by_edition, + purchase.related_purchase_by_edition, name="related_purchase_by_edition", ), path( "purchase/add/for-edition/", - purchaseviews.add_purchase, + purchase.add_purchase, name="add_purchase_for_edition", ), - path("session/add", sessionviews.add_session, name="add_session"), + path("session/add", session.add_session, name="add_session"), path( "session/add/for-purchase/", - sessionviews.add_session, + session.add_session, name="add_session_for_purchase", ), path( "session/add/from-game/", - sessionviews.new_session_from_existing_session, + session.new_session_from_existing_session, {"template": "view_game.html#session-info"}, name="view_game_start_session_from_session", ), path( "session/add/from-list/", - sessionviews.new_session_from_existing_session, + session.new_session_from_existing_session, {"template": "list_sessions.html#session-row"}, name="list_sessions_start_session_from_session", ), - path( - "session//edit", sessionviews.edit_session, name="edit_session" - ), + path("session//edit", session.edit_session, name="edit_session"), path( "session//delete", - sessionviews.delete_session, + session.delete_session, name="delete_session", ), path( "session/end/from-game/", - sessionviews.end_session, + session.end_session, {"template": "view_game.html#session-info"}, name="view_game_end_session", ), path( "session/end/from-list/", - sessionviews.end_session, + session.end_session, {"template": "list_sessions.html#session-row"}, name="list_sessions_end_session", ), - path("session/list", sessionviews.list_sessions, name="list_sessions"), - path( - "session/list/by-purchase/", - sessionviews.list_sessions, - {"filter": "purchase"}, - name="list_sessions_by_purchase", - ), - path( - "session/list/by-platform/", - sessionviews.list_sessions, - {"filter": "platform"}, - name="list_sessions_by_platform", - ), - path( - "session/list/by-game/", - sessionviews.list_sessions, - {"filter": "game"}, - name="list_sessions_by_game", - ), - path( - "session/list/by-edition/", - sessionviews.list_sessions, - {"filter": "edition"}, - name="list_sessions_by_edition", - ), - path( - "session/list/by-ownership/", - sessionviews.list_sessions, - {"filter": "ownership_type"}, - name="list_sessions_by_ownership_type", - ), - path("stats/", views.stats_alltime, name="stats_alltime"), + path("session/list", session.list_sessions, name="list_sessions"), + path("stats/", general.stats_alltime, name="stats_alltime"), path( "stats/", - views.stats, + general.stats, name="stats_by_year", ), ] diff --git a/games/views/__init__.py b/games/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/games/deviceviews.py b/games/views/device.py similarity index 98% rename from games/deviceviews.py rename to games/views/device.py index db40913..0c4104e 100644 --- a/games/deviceviews.py +++ b/games/views/device.py @@ -9,7 +9,7 @@ from django.urls import reverse from games.forms import DeviceForm from games.models import Device -from games.views import dateformat +from games.views.general import dateformat @login_required diff --git a/games/editionviews.py b/games/views/edition.py similarity index 99% rename from games/editionviews.py rename to games/views/edition.py index d69be5a..4ec140d 100644 --- a/games/editionviews.py +++ b/games/views/edition.py @@ -10,7 +10,7 @@ from django.urls import reverse from common.utils import truncate_with_popover from games.forms import EditionForm from games.models import Edition, Game -from games.views import dateformat +from games.views.general import dateformat @login_required diff --git a/games/gameviews.py b/games/views/game.py similarity index 99% rename from games/gameviews.py rename to games/views/game.py index 03b590d..6cc80fb 100644 --- a/games/gameviews.py +++ b/games/views/game.py @@ -11,7 +11,7 @@ from common.time import format_duration from common.utils import safe_division, safe_getattr, truncate_with_popover from games.forms import GameForm from games.models import Game, Purchase, Session -from games.views import dateformat, use_custom_redirect +from games.views.general import dateformat, use_custom_redirect @login_required diff --git a/games/views.py b/games/views/general.py similarity index 98% rename from games/views.py rename to games/views/general.py index 3a567b2..dc0e641 100644 --- a/games/views.py +++ b/games/views/general.py @@ -7,12 +7,10 @@ from django.db.models.manager import BaseManager from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render from django.urls import reverse -from django.utils import timezone from common.time import format_duration from common.utils import safe_division - -from .models import Edition, Game, Platform, Purchase, Session +from games.models import Edition, Game, Platform, Purchase, Session dateformat: str = "%d/%m/%Y" datetimeformat: str = "%d/%m/%Y %H:%M" @@ -31,11 +29,6 @@ def model_counts(request: HttpRequest) -> dict[str, bool]: } -def stats_dropdown_year_range(request: HttpRequest) -> dict[str, range]: - result = {"stats_dropdown_year_range": range(timezone.now().year, 1999, -1)} - return result - - def use_custom_redirect( func: Callable[..., HttpResponse], ) -> Callable[..., HttpResponse]: diff --git a/games/platformviews.py b/games/views/platform.py similarity index 98% rename from games/platformviews.py rename to games/views/platform.py index 09a1287..556147a 100644 --- a/games/platformviews.py +++ b/games/views/platform.py @@ -9,7 +9,7 @@ from django.urls import reverse from games.forms import PlatformForm from games.models import Platform -from games.views import dateformat, use_custom_redirect +from games.views.general import dateformat, use_custom_redirect @login_required diff --git a/games/purchaseviews.py b/games/views/purchase.py similarity index 98% rename from games/purchaseviews.py rename to games/views/purchase.py index 555d61a..9b1d57f 100644 --- a/games/purchaseviews.py +++ b/games/views/purchase.py @@ -16,7 +16,7 @@ from django.utils import timezone from common.utils import truncate_with_popover from games.forms import PurchaseForm from games.models import Edition, Purchase -from games.views import dateformat, use_custom_redirect +from games.views.general import dateformat, use_custom_redirect @login_required diff --git a/games/sessionviews.py b/games/views/session.py similarity index 99% rename from games/sessionviews.py rename to games/views/session.py index 135d39f..18fc0f8 100644 --- a/games/sessionviews.py +++ b/games/views/session.py @@ -12,7 +12,7 @@ from common.time import format_duration from common.utils import truncate_with_popover from games.forms import SessionForm from games.models import Purchase, Session -from games.views import ( +from games.views.general import ( dateformat, datetimeformat, durationformat, diff --git a/timetracker/settings.py b/timetracker/settings.py index 5edd33b..eeb628a 100644 --- a/timetracker/settings.py +++ b/timetracker/settings.py @@ -83,8 +83,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", - "games.views.model_counts", - "games.views.stats_dropdown_year_range", + "games.views.general.model_counts", ], "builtins": [ "template_partials.templatetags.partials",