mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
Guests can pay with CB or coins, lot of other improvements
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from ..models import ActivityType, Activity, Guest, Entry
|
||||
from ..models import ActivityType, Activity, Guest, Entry, GuestTransaction
|
||||
|
||||
|
||||
class ActivityTypeSerializer(serializers.ModelSerializer):
|
||||
@ -48,3 +48,14 @@ class EntrySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Entry
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class GuestTransactionSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
REST API Serializer for Special transactions.
|
||||
The djangorestframework plugin will analyse the model `GuestTransaction` and parse all fields in the API.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = GuestTransaction
|
||||
fields = '__all__'
|
||||
|
@ -69,8 +69,6 @@ class Activity(models.Model):
|
||||
'note.Note',
|
||||
on_delete=models.PROTECT,
|
||||
related_name='+',
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name=_('note'),
|
||||
)
|
||||
|
||||
@ -152,7 +150,7 @@ class Entry(models.Model):
|
||||
GuestTransaction.objects.create(
|
||||
source=self.note,
|
||||
source_alias=self.note.user.username,
|
||||
destination=self.activity.organizer.note,
|
||||
destination=self.note,
|
||||
destination_alias=self.activity.organizer.name,
|
||||
quantity=1,
|
||||
amount=self.activity.activity_type.guest_entry_fee,
|
||||
|
@ -7,7 +7,7 @@ import django_tables2 as tables
|
||||
from django_tables2 import A
|
||||
from note.templatetags.pretty_money import pretty_money
|
||||
|
||||
from .models import Activity, Guest
|
||||
from .models import Activity, Guest, Entry
|
||||
|
||||
|
||||
class ActivityTable(tables.Table):
|
||||
@ -55,6 +55,22 @@ class GuestTable(tables.Table):
|
||||
return _("remove").capitalize()
|
||||
|
||||
|
||||
def get_row_class(record):
|
||||
c = "table-row"
|
||||
if isinstance(record, Guest):
|
||||
if record.has_entry:
|
||||
c += " table-success"
|
||||
else:
|
||||
c += " table-warning"
|
||||
else:
|
||||
qs = Entry.objects.filter(note=record.note, activity=record.activity, guest=None)
|
||||
if qs.exists():
|
||||
c += " table-success"
|
||||
elif record.note.balance < 0:
|
||||
c += " table-danger"
|
||||
return c
|
||||
|
||||
|
||||
class EntryTable(tables.Table):
|
||||
type = tables.Column(verbose_name=_("Type"))
|
||||
|
||||
@ -82,9 +98,11 @@ class EntryTable(tables.Table):
|
||||
}
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
row_attrs = {
|
||||
'class': 'table-row',
|
||||
'class': lambda record: get_row_class(record),
|
||||
'id': lambda record: "row-" + ("guest-" if isinstance(record, Guest) else "membership-") + str(record.pk),
|
||||
'data-type': lambda record: "guest" if isinstance(record, Guest) else "membership",
|
||||
'data-id': lambda record: record.pk,
|
||||
'data-id': lambda record: record.pk if isinstance(record, Guest) else record.note.pk,
|
||||
'data-inviter': lambda record: record.inviter.pk if isinstance(record, Guest) else "",
|
||||
'data-last-name': lambda record: record.last_name,
|
||||
'data-first-name': lambda record: record.first_name,
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from datetime import datetime
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
@ -8,11 +9,11 @@ from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView, DetailView, UpdateView, TemplateView
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_tables2.views import SingleTableView
|
||||
from note.models import NoteUser, Alias
|
||||
from note.models import NoteUser, Alias, NoteSpecial
|
||||
from permission.backends import PermissionBackend
|
||||
|
||||
from .forms import ActivityForm, GuestForm
|
||||
from .models import Activity, Guest
|
||||
from .models import Activity, Guest, Entry
|
||||
from .tables import ActivityTable, GuestTable, EntryTable
|
||||
|
||||
|
||||
@ -31,7 +32,10 @@ class ActivityListView(LoginRequiredMixin, SingleTableView):
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
ctx['title'] = _("Upcoming activities")
|
||||
ctx['title'] = _("Activities")
|
||||
|
||||
upcoming_activities = Activity.objects.filter(date_end__gt=datetime.now())
|
||||
ctx['upcoming'] = ActivityTable(data=upcoming_activities)
|
||||
|
||||
return ctx
|
||||
|
||||
@ -115,12 +119,16 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
||||
.distinct("username")[:20]
|
||||
for note in note_qs:
|
||||
note.type = "Adhérent"
|
||||
note.activity = activity
|
||||
matched.append(note)
|
||||
|
||||
table = EntryTable(data=matched)
|
||||
ctx["table"] = table
|
||||
|
||||
ctx["entries"] = Entry.objects.filter(activity=activity)
|
||||
|
||||
ctx["title"] = _('Entry for activity "{}"').format(activity.name)
|
||||
ctx["noteuser_ctype"] = ContentType.objects.get_for_model(NoteUser).pk
|
||||
ctx["notespecial_ctype"] = ContentType.objects.get_for_model(NoteSpecial).pk
|
||||
|
||||
return ctx
|
||||
|
@ -163,6 +163,7 @@ class SpecialTransactionSerializer(serializers.ModelSerializer):
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
class TransactionPolymorphicSerializer(PolymorphicSerializer):
|
||||
model_serializer_mapping = {
|
||||
Transaction: TransactionSerializer,
|
||||
@ -171,5 +172,12 @@ class TransactionPolymorphicSerializer(PolymorphicSerializer):
|
||||
SpecialTransaction: SpecialTransactionSerializer,
|
||||
}
|
||||
|
||||
try:
|
||||
from activity.models import GuestTransaction
|
||||
from activity.api.serializers import GuestTransactionSerializer
|
||||
model_serializer_mapping[GuestTransaction] = GuestTransactionSerializer
|
||||
except ImportError: # Activity app is not loaded
|
||||
pass
|
||||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
|
Reference in New Issue
Block a user