From 9dda7670df99e62e307962731e705903fb72f6a0 Mon Sep 17 00:00:00 2001 From: Halfdan Mouritzen Date: Sun, 14 Jan 2024 11:10:55 +0000 Subject: [PATCH 1/3] Minimal CSS for tables (#26) Reviewed-on: https://git.data.coop/data.coop/membersystem/pulls/26 Co-authored-by: Halfdan Mouritzen Co-committed-by: Halfdan Mouritzen --- src/project/static/css/style.css | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/project/static/css/style.css b/src/project/static/css/style.css index 7a6f045..49bb56e 100644 --- a/src/project/static/css/style.css +++ b/src/project/static/css/style.css @@ -28,6 +28,7 @@ p, h1, h2, h3, h4, h5, h6 { --light : #fff; --light-dust : #f6f6f6; --dust : #f1f1f1; + --medium-dust : #dadada; --dark-dust : #bfbfbf; --fade : #878787; --twilight : #4a4a4a; @@ -61,6 +62,8 @@ h1, h2, h3, h4, h5, h6 { a { font-weight : 500; + color : var(--splash); + text-decoration : none; } body { @@ -249,6 +252,25 @@ button:hover { opacity : 1.0; } +article table { + width : 100%; + border-spacing : 0; + margin : var(--space) 0; +} + +article table thead th { + text-align : left; +} + +article table tbody tr:nth-child(odd) { + background : var(--medium-dust); +} + +article table thead th, +article table tbody td { + padding : var(--half-space); +} + form > div { margin : 0 0 var(--double-space); } From b8a970d5fe09bc1e16532be75d53351d07646580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 14 Jan 2024 12:14:51 +0100 Subject: [PATCH 2/3] Add missing migration --- ...rency_alter_order_vat_currency_and_more.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/accounting/migrations/0002_alter_order_price_currency_alter_order_vat_currency_and_more.py diff --git a/src/accounting/migrations/0002_alter_order_price_currency_alter_order_vat_currency_and_more.py b/src/accounting/migrations/0002_alter_order_price_currency_alter_order_vat_currency_and_more.py new file mode 100644 index 0000000..7dcbdb1 --- /dev/null +++ b/src/accounting/migrations/0002_alter_order_price_currency_alter_order_vat_currency_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 5.0.1 on 2024-01-14 11:14 + +import djmoney.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("accounting", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="order", + name="price_currency", + field=djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], default=None, editable=False, max_length=3 + ), + ), + migrations.AlterField( + model_name="order", + name="vat_currency", + field=djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], default=None, editable=False, max_length=3 + ), + ), + migrations.AlterField( + model_name="payment", + name="amount_currency", + field=djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], default=None, editable=False, max_length=3 + ), + ), + migrations.AlterField( + model_name="transaction", + name="amount_currency", + field=djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], default=None, editable=False, max_length=3 + ), + ), + ] From f31cd623516124d8bd2870f1004ea1dec19f3c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 14 Jan 2024 12:27:36 +0100 Subject: [PATCH 3/3] Implement django-view-decorator --- pyproject.toml | 1 + requirements/base.txt | 3 +++ src/membership/views.py | 38 +++++++++++++++++++++++++-------- src/project/settings.py | 1 + src/project/templates/base.html | 2 +- src/project/urls.py | 18 ++-------------- src/project/views.py | 12 +++++++++++ 7 files changed, 49 insertions(+), 26 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e571243..2ff5219 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ dependencies = [ "whitenoise==6.6.0", "django-zen-queries==2.1.0", "django-registries==0.0.3", + "django-view-decorator==0.0.4", ] dynamic = ["version"] diff --git a/requirements/base.txt b/requirements/base.txt index 7213dee..4d4f8f1 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -30,6 +30,7 @@ django==5.0.1 # django-allauth # django-money # django-registries + # django-view-decorator # django-zen-queries # membersystem (pyproject.toml) django-allauth==0.60.0 @@ -40,6 +41,8 @@ django-money==3.4.1 # via membersystem (pyproject.toml) django-registries==0.0.3 # via membersystem (pyproject.toml) +django-view-decorator==0.0.4 + # via membersystem (pyproject.toml) django-zen-queries==2.1.0 # via membersystem (pyproject.toml) environs[django]==10.0.0 diff --git a/src/membership/views.py b/src/membership/views.py index a325e29..7655d12 100644 --- a/src/membership/views.py +++ b/src/membership/views.py @@ -1,6 +1,5 @@ -from django.contrib.auth.decorators import login_required -from django.contrib.auth.decorators import permission_required from django.utils.translation import gettext_lazy as _ +from django_view_decorator import namespaced_decorator_factory from .permissions import ADMINISTRATE_MEMBERS from .selectors import get_member @@ -12,7 +11,14 @@ from utils.view_utils import render_list from utils.view_utils import RowAction -@login_required +member_view = namespaced_decorator_factory(namespace="member", base_path="membership") + + +@member_view( + paths="", + name="membership-overview", + login_required=True, +) def membership_overview(request): memberships = get_memberships(member=request.user) current_membership = memberships.current() @@ -33,8 +39,18 @@ def membership_overview(request): ) -@login_required -@permission_required(ADMINISTRATE_MEMBERS.path) +admin_members_view = namespaced_decorator_factory( + namespace="admin-members", + base_path="admin", +) + + +@admin_members_view( + paths="members/", + name="list", + login_required=True, + permissions=[ADMINISTRATE_MEMBERS.path], +) def members_admin(request): users = get_members() @@ -54,15 +70,19 @@ def members_admin(request): row_actions=[ RowAction( label=_("View"), - url_name="admin-members-detail", + url_name="admin-members:detail", url_kwargs={"member_id": "id"}, ), ], ) -@login_required -@permission_required(ADMINISTRATE_MEMBERS.path) +@admin_members_view( + paths="/", + name="detail", + login_required=True, + permissions=[ADMINISTRATE_MEMBERS.path], +) def members_admin_detail(request, member_id): member = get_member(member_id=member_id) subscription_periods = get_subscription_periods(member=member) @@ -70,7 +90,7 @@ def members_admin_detail(request, member_id): context = { "member": member, "subscription_periods": subscription_periods, - "base_path": "admin-members", + "base_path": "admin-members:list", } return render( diff --git a/src/project/settings.py b/src/project/settings.py index 349ee9e..e16582b 100644 --- a/src/project/settings.py +++ b/src/project/settings.py @@ -40,6 +40,7 @@ DJANGO_APPS = [ THIRD_PARTY_APPS = [ "allauth", "allauth.account", + "django_view_decorator", ] LOCAL_APPS = [ diff --git a/src/project/templates/base.html b/src/project/templates/base.html index a822ae6..5e41e54 100644 --- a/src/project/templates/base.html +++ b/src/project/templates/base.html @@ -66,7 +66,7 @@ {% if perms.membership.administrate_memberships %}
  • - + Admin
  • diff --git a/src/project/urls.py b/src/project/urls.py index ecc691b..17e788b 100644 --- a/src/project/urls.py +++ b/src/project/urls.py @@ -1,26 +1,12 @@ """URLs for the membersystem""" from django.conf import settings from django.contrib import admin -from django.contrib.auth.decorators import login_required from django.urls import include from django.urls import path - -from .views import index -from .views import services_overview -from membership.views import members_admin -from membership.views import members_admin_detail -from membership.views import membership_overview +from django_view_decorator import include_view_urls urlpatterns = [ - path("", login_required(index), name="index"), - path("services/", login_required(services_overview), name="services"), - path("membership/", membership_overview, name="membership-overview"), - path("admin/members/", members_admin, name="admin-members"), - path( - "admin/members//", - members_admin_detail, - name="admin-members-detail", - ), + path("", include_view_urls(extra_modules=["project.views"])), path("accounts/", include("allauth.urls")), path("_admin/", admin.site.urls), ] diff --git a/src/project/views.py b/src/project/views.py index 26db680..7882b02 100644 --- a/src/project/views.py +++ b/src/project/views.py @@ -1,9 +1,21 @@ +from django_view_decorator import view + from utils.view_utils import render +@view( + paths="", + name="index", + login_required=True, +) def index(request): return render(request, "index.html") +@view( + paths="services/", + name="services", + login_required=True, +) def services_overview(request): return render(request, "services_overview.html")