{% trans %}You can add a card by asking at a counter or add it yourself here. If you want to manually add a student card yourself, you'll need a NFC reader. We store the UID of the card which is 14 characters long.{% endtrans %}
+
+{% if profile.customer.student_cards.exists() %}
+
+ {% for card in profile.customer.student_cards.all() %}
+
{% trans %}No student cards registered.{% endtrans %}
+{% endif %}
+{% endif %}
{% endblock %}
diff --git a/core/views/user.py b/core/views/user.py
index fb9e6455..019cda0a 100644
--- a/core/views/user.py
+++ b/core/views/user.py
@@ -64,6 +64,7 @@ from core.views.forms import (
)
from core.models import User, SithFile, Preferences, Gift
from subscription.models import Subscription
+from counter.views import StudentCardForm
from trombi.views import UserTrombiForm
@@ -741,6 +742,8 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
kwargs = super(UserPreferencesView, self).get_context_data(**kwargs)
if not hasattr(self.object, "trombi_user"):
kwargs["trombi_form"] = UserTrombiForm()
+ if self.object.customer:
+ kwargs["student_card_form"] = StudentCardForm()
return kwargs
diff --git a/counter/models.py b/counter/models.py
index 0d373d36..693b277b 100644
--- a/counter/models.py
+++ b/counter/models.py
@@ -91,22 +91,7 @@ class Customer(models.Model):
"""
Add a new student card on the customer account
"""
- # If you are comming from a counter, only your connection to the counter is checked, not your right on the user to avoid wierd conflicts
- if counter != None and (
- counter.type != "BAR"
- or not (
- "counter_token" in request.session.keys()
- and request.session["counter_token"] == counter.token
- )
- or len(counter.get_barmen_list()) < 1
- ):
- raise PermissionDenied
- # If you are not comming from a counter, your permissions are checked
- if not (
- request.user.id == self.user.id
- or request.user.is_board_member
- or request.user.is_root
- ):
+ if not StudentCard.check_creation_permission(request, self, counter):
raise PermissionDenied
StudentCard(customer=self, uid=uid).save()
@@ -769,6 +754,38 @@ class StudentCard(models.Model):
UID_SIZE = 14
+ @staticmethod
+ def is_valid(uid):
+ return len(uid) == StudentCard.UID_SIZE
+
+ @staticmethod
+ def __comming_from_right_counter(request, counter):
+ return (
+ counter.type == "BAR"
+ and "counter_token" in request.session.keys()
+ and request.session["counter_token"] == counter.token
+ and len(counter.get_barmen_list()) > 0
+ )
+
+ @staticmethod
+ def __user_has_rights(customer, user):
+ return user.pk == customer.user.pk or user.is_board_member or user.is_root
+
+ @staticmethod
+ def check_creation_permission(request, customer, counter=None):
+ """
+ If you are comming from a counter, only your connection to the counter is checked, not your right on the user to avoid wierd conflicts
+ If you are not comming from a counter, your permissions are checked
+ """
+ if counter:
+ return StudentCard.__comming_from_right_counter(request, counter)
+ return StudentCard.__user_has_rights(customer, request.user)
+
+ def can_edit(self, obj):
+ if isinstance(obj, User):
+ return StudentCard.__user_has_rights(self.customer, obj)
+ return False
+
uid = models.CharField(
_("uid"), max_length=14, unique=True, validators=[MinLengthValidator(4)]
)
diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja
index 521ec4c9..ed40e584 100644
--- a/counter/templates/counter/counter_click.jinja
+++ b/counter/templates/counter/counter_click.jinja
@@ -40,6 +40,16 @@
{% endif %}
+
{% trans %}Registered cards{% endtrans %}
+ {% if customer.student_cards.exists() %}
+
+ {% for card in customer.student_cards.all() %}
+