Compare commits

...

2 commits

Author SHA1 Message Date
Benjamin Bach 17e5f969af
Merge branch 'main' of git.data.coop:data.coop/membersystem into payment-updates 2024-08-01 00:59:18 +02:00
Benjamin Bach 865bc6c7bd New WaitingListEntry (#33)
Sorted the pre-commit things... some were because of `src/static` being included, and some have been fixed in another PR 🎉

Reviewed-on: data.coop/membersystem#33
Reviewed-by: valberg <valberg@orn.li>
Co-authored-by: Benjamin Bach <benjamin@overtag.dk>
Co-committed-by: Benjamin Bach <benjamin@overtag.dk>
2024-07-31 22:49:46 +00:00
3 changed files with 18 additions and 30 deletions

View file

@ -1,4 +1,4 @@
.PHONY: run pre_commit_install pre_commit_run_all makemigrations migrate createsuperuser shell manage_command build requirements .PHONY: run makemigrations migrate createsuperuser shell manage_command build requirements
DOCKER_COMPOSE = COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose DOCKER_COMPOSE = COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose
DOCKER_RUN = ${DOCKER_COMPOSE} run -u `id -u` DOCKER_RUN = ${DOCKER_COMPOSE} run -u `id -u`
MANAGE_EXEC = python /app/src/manage.py MANAGE_EXEC = python /app/src/manage.py
@ -7,12 +7,6 @@ MANAGE_COMMAND = ${DOCKER_RUN} app ${MANAGE_EXEC}
run: run:
${DOCKER_COMPOSE} up ${DOCKER_COMPOSE} up
pre_commit_install:
venv/bin/pre-commit install
pre_commit_run_all:
venv/bin/pre-commit run --all-files
makemigrations: makemigrations:
${MANAGE_COMMAND} makemigrations ${ARGS} ${MANAGE_COMMAND} makemigrations ${ARGS}

View file

@ -98,13 +98,3 @@ hatch-pip-compile
# Update requirements/requirements-dev.txt: # Update requirements/requirements-dev.txt:
hatch-pip-compile dev hatch-pip-compile dev
``` ```
#### Updating requirements
If you want to update the requirements, you can run the following command:
```bash
hatch run requirements
```
This uses [hatch-pip-compile](https://juftin.com/hatch-pip-compile/) to update the requirements.

View file

@ -15,23 +15,27 @@ from django.db.models import QuerySet
from django.http import HttpRequest from django.http import HttpRequest
from django.http import HttpResponse from django.http import HttpResponse
from . import models from .models import Member
from .models import Membership
from .models import MembershipType
from .models import SubscriptionPeriod
from .models import WaitingListEntry
# Do not use existing user admin # Do not use existing user admin
admin.site.unregister(User) admin.site.unregister(User)
@admin.register(models.Membership) @admin.register(Membership)
class MembershipAdmin(admin.ModelAdmin): class MembershipAdmin(admin.ModelAdmin):
"""Admin for Membership model.""" """Admin for Membership model."""
@admin.register(models.MembershipType) @admin.register(MembershipType)
class MembershipTypeAdmin(admin.ModelAdmin): class MembershipTypeAdmin(admin.ModelAdmin):
"""Admin for MembershipType model.""" """Admin for MembershipType model."""
@admin.register(models.SubscriptionPeriod) @admin.register(SubscriptionPeriod)
class SubscriptionPeriodAdmin(admin.ModelAdmin): class SubscriptionPeriodAdmin(admin.ModelAdmin):
"""Admin for SubscriptionPeriod model.""" """Admin for SubscriptionPeriod model."""
@ -39,10 +43,10 @@ class SubscriptionPeriodAdmin(admin.ModelAdmin):
class MembershipInlineAdmin(admin.TabularInline): class MembershipInlineAdmin(admin.TabularInline):
"""Inline admin.""" """Inline admin."""
model = models.Membership model = Membership
def decorate_ensure_membership_type_exists(membership_type: models.MembershipType, label: str) -> Callable: def decorate_ensure_membership_type_exists(membership_type: MembershipType, label: str) -> Callable:
"""Generate an admin action for given membership type and label.""" """Generate an admin action for given membership type and label."""
@admin.action(description=label) @admin.action(description=label)
@ -56,7 +60,7 @@ def decorate_ensure_membership_type_exists(membership_type: models.MembershipTyp
def ensure_membership_type_exists( def ensure_membership_type_exists(
request: HttpRequest, request: HttpRequest,
queryset: QuerySet, queryset: QuerySet,
membership_type: models.MembershipType, membership_type: MembershipType,
) -> HttpResponse: ) -> HttpResponse:
"""Inner function that ensures that a membership exists for a given queryset of Member objects.""" """Inner function that ensures that a membership exists for a given queryset of Member objects."""
for member in queryset: for member in queryset:
@ -71,10 +75,10 @@ def ensure_membership_type_exists(
for product in membership_type.products.all(): for product in membership_type.products.all():
OrderProduct.objects.create(order=order, product=product, price=product.price, vat=product.vat) OrderProduct.objects.create(order=order, product=product, price=product.price, vat=product.vat)
# Create the Membership # Create the Membership
models.Membership.objects.create( Membership.objects.create(
membership_type=membership_type, membership_type=membership_type,
user=member, user=member,
period=models.SubscriptionPeriod.objects.current(), period=SubscriptionPeriod.objects.current(),
order=order, order=order,
) )
@ -82,7 +86,7 @@ def ensure_membership_type_exists(
messages.success(request, f"{member} has ordered a '{membership_type}' (unpaid)") messages.success(request, f"{member} has ordered a '{membership_type}' (unpaid)")
@admin.register(models.Member) @admin.register(Member)
class MemberAdmin(UserAdmin): class MemberAdmin(UserAdmin):
"""Member admin is actually an admin for User objects.""" """Member admin is actually an admin for User objects."""
@ -91,12 +95,12 @@ class MemberAdmin(UserAdmin):
def get_actions(self, request: HttpRequest) -> dict: def get_actions(self, request: HttpRequest) -> dict:
"""Populate actions with dynamic data (MembershipType).""" """Populate actions with dynamic data (MembershipType)."""
current_period = models.SubscriptionPeriod.objects.current() current_period = SubscriptionPeriod.objects.current()
super_dict = super().get_actions(request) super_dict = super().get_actions(request)
if current_period: if current_period:
for i, mtype in enumerate(models.MembershipType.objects.filter(active=True)): for i, mtype in enumerate(MembershipType.objects.filter(active=True)):
action_label = f"Ensure membership {mtype.name}, {current_period.period}, {mtype.total_including_vat}" action_label = f"Ensure membership {mtype.name}, {current_period.period}, {mtype.total_including_vat}"
action_func = decorate_ensure_membership_type_exists(mtype, action_label) action_func = decorate_ensure_membership_type_exists(mtype, action_label)
# Django ModelAdmin uses the non-unique __name__ property, so we need to suffix it to make it unique # Django ModelAdmin uses the non-unique __name__ property, so we need to suffix it to make it unique
@ -106,6 +110,6 @@ class MemberAdmin(UserAdmin):
return super_dict return super_dict
@admin.register(models.WaitingListEntry) @admin.register(WaitingListEntry)
class WaitingListEntryAdmin(admin.ModelAdmin): class WaitingListEntryAdmin(admin.ModelAdmin):
"""Admin for WaitingList model.""" """Admin for WaitingList model."""