diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e6477b7..3095e5f 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -18,10 +18,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - uses: actions/cache@v4 with: path: ~/.cache/pip @@ -39,10 +39,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - uses: actions/cache@v4 with: path: ~/.cache/pip @@ -61,10 +61,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - uses: actions/cache@v4 with: path: ~/.cache/pip @@ -83,10 +83,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - uses: actions/cache@v4 with: path: ~/.cache/pip @@ -105,10 +105,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - uses: actions/cache@v4 with: path: ~/.cache/pip diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 504eec4..21fc7bc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,10 +16,10 @@ jobs: name: Tests steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - uses: actions/cache@v4 with: path: ~/.cache/pip diff --git a/MANIFEST.in b/MANIFEST.in index 24f1396..ed8c294 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,4 @@ recursive-include pretix_roomsharing/templates * recursive-include pretix_roomsharing/locale * include LICENSE exclude .gitlab-ci.yml +exclude renovate.json \ No newline at end of file diff --git a/pretix_roomsharing/__init__.py b/pretix_roomsharing/__init__.py index 3cb7d95..fb69db9 100644 --- a/pretix_roomsharing/__init__.py +++ b/pretix_roomsharing/__init__.py @@ -1 +1 @@ -__version__ = "0.1.13" +__version__ = "0.1.14" diff --git a/pretix_roomsharing/checkoutflow.py b/pretix_roomsharing/checkoutflow.py index 78d1d24..e884506 100644 --- a/pretix_roomsharing/checkoutflow.py +++ b/pretix_roomsharing/checkoutflow.py @@ -29,9 +29,9 @@ class RoomCreateForm(forms.Form): password = forms.CharField( max_length=190, label=_("Room password"), - min_length=3, + min_length=3, widget=forms.PasswordInput, - required=False + required=False, ) def __init__(self, *args, **kwargs): @@ -205,10 +205,12 @@ def create_form(self): prefix="create", initial=initial, current=current, - data=self.request.POST - if self.request.method == "POST" - and self.request.POST.get("room_mode") == "create" - else None, + data=( + self.request.POST + if self.request.method == "POST" + and self.request.POST.get("room_mode") == "create" + else None + ), ) @cached_property @@ -232,10 +234,12 @@ def join_form(self): event=self.event, prefix="join", initial=initial, - data=self.request.POST - if self.request.method == "POST" - and self.request.POST.get("room_mode") == "join" - else None, + data=( + self.request.POST + if self.request.method == "POST" + and self.request.POST.get("room_mode") == "join" + else None + ), ) @cached_property @@ -269,6 +273,64 @@ def is_completed(self, request, warn=False): room = Room.objects.get( event=self.event, pk=cart_session(request)["room_join"] ) + # Validation of max people + if self.request.event.settings.roomsharing__check_max_people: + max_people = None + for cartPosition in self.get_cart()["positions"]: + item_id = str(cartPosition.item.id) + max_people_setting_key = f"roomsharing__max_people_{item_id}" + if max_people_setting_key in self.request.event.settings: + max_people = self.request.event.settings[ + max_people_setting_key + ] + break + + if max_people is not None and len(room.orderrooms.all()) >= int( + max_people + ): + if warn: + messages.warning( + request, + _( + """ + The room you requested to join is already full. + Please choose a different room. + """ + ), + ) + return False + # Validation of ticket type + if self.request.event.settings.roomsharing__check_ticket_type: + room_ticket_types = set( + c["order__all_positions__item"] + for c in room.orderrooms.filter( + order__all_positions__canceled=False + ) + .values("order__all_positions__item") + .distinct() + ) + cart_ticket_types = set( + c["item"] for c in get_cart(request).values("item").distinct() + ) + if any(c not in room_ticket_types for c in cart_ticket_types): + if warn: + messages.warning( + request, + _( + """ + You requested to join a room that participates in "{room_ticket_type}", + while you chose to participate in "{cart_ticket_type}". + Please choose a different room. + """ + ).format( + room_ticket_type=room.name, + cart_ticket_type=SubEvent.objects.get( + pk=list(cart_ticket_types)[0] + ).name, + ), + ) + return False + room_subevents = set( c["order__all_positions__subevent"] for c in room.orderrooms.filter( @@ -277,8 +339,6 @@ def is_completed(self, request, warn=False): .values("order__all_positions__subevent") .distinct() ) - # TODO: Validation of same room type - # TODO: Validation of max room quantity? if room_subevents: cart_subevents = set( c["subevent"] diff --git a/pretix_roomsharing/signals.py b/pretix_roomsharing/signals.py index 8c2fe3d..9414a63 100644 --- a/pretix_roomsharing/signals.py +++ b/pretix_roomsharing/signals.py @@ -116,10 +116,7 @@ def order_info(sender: Event, order: Order, **kwargs): # Show link for user to change room order_has_room = False for orderPosition in order.positions.all(): - if ( - str(orderPosition.item.id) - in sender.settings.roomsharing__products - ): + if str(orderPosition.item.id) in sender.settings.roomsharing__products: order_has_room = True ctx["order_has_room"] = order_has_room @@ -237,4 +234,4 @@ def control_order_search(sender, request, **kwargs): except ImportError: pass -settings_hierarkey.add_default('roomsharing__products', None, list) \ No newline at end of file +settings_hierarkey.add_default("roomsharing__products", None, list) diff --git a/pretix_roomsharing/templates/pretix_roomsharing/settings.html b/pretix_roomsharing/templates/pretix_roomsharing/settings.html index 967ccc2..0ec7ec2 100644 --- a/pretix_roomsharing/templates/pretix_roomsharing/settings.html +++ b/pretix_roomsharing/templates/pretix_roomsharing/settings.html @@ -1,6 +1,7 @@ {% extends "pretixcontrol/event/settings_base.html" %} {% load i18n %} {% load bootstrap3 %} +{% load room_tags %} {% block title %} {% trans "Roomsharing Settings" %} {% endblock %} {% block inside %}
{% trans "Selecting a product here requires room shares to be the same product. You can get around this by using bundled products and selecting one of those here." %}
{% bootstrap_field form.roomsharing__products layout="control" %} - + {% for field in form %} + {% if field.name|startswith:"roomsharing__max_people_" %} + {% bootstrap_field field layout="control" %} + {% endif %} + {% endfor %} + {% bootstrap_field form.roomsharing__check_max_people layout="control" %} + {% bootstrap_field form.roomsharing__check_ticket_type layout="control" %} +