Skip to content

Commit

Permalink
Revert "Revert "Feature tickets" (#377)"
Browse files Browse the repository at this point in the history
This reverts commit 5d6d103.
  • Loading branch information
krestenlaust committed Oct 28, 2023
1 parent 0926c32 commit 7cab902
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 0 deletions.
Empty file added stregsystem.log
Empty file.
14 changes: 14 additions & 0 deletions stregsystem/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Room,
Sale,
MobilePayment,
Event,
NamedProduct,
)
from stregsystem.templatetags.stregsystem_extras import money
Expand Down Expand Up @@ -341,6 +342,18 @@ def has_delete_permission(self, request, obj=None):
return False


class EventEntryAdmin(admin.ModelAdmin):
search_fields = ('name', 'id')
list_display = (
'activated',
'id',
'name',
)

def activated(self, event):
return event.is_active()


admin.site.register(LogEntry, LogEntryAdmin)
admin.site.register(Sale, SaleAdmin)
admin.site.register(Member, MemberAdmin)
Expand All @@ -351,3 +364,4 @@ def has_delete_permission(self, request, obj=None):
admin.site.register(Category, CategoryAdmin)
admin.site.register(Room)
admin.site.register(MobilePayment, MobilePaymentAdmin)
admin.site.register(Event, EventEntryAdmin)
26 changes: 26 additions & 0 deletions stregsystem/migrations/0016_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.24 on 2022-04-12 17:47

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('stregsystem', '0015_product_caffeine_content_mg'),
]

operations = [
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=32)),
('active', models.BooleanField()),
('time', models.DateTimeField()),
('ticket_start_threshold', models.DateTimeField()),
('ticket_end_threshold', models.DateTimeField()),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stregsystem.Product')),
],
),
]
16 changes: 16 additions & 0 deletions stregsystem/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,22 @@ def __str__(self):
return self.product.name + ": " + money(self.price) + " (" + str(self.changed_on) + ")"


# A model to link certain products to events, to facilitate showing of active tickets
class Event(models.Model):
name = models.CharField(max_length=32)
active = models.BooleanField()
product = models.ForeignKey(Product, on_delete=models.CASCADE)
time = models.DateTimeField(null=False, blank=False)
ticket_start_threshold = models.DateTimeField(null=False, blank=False)
ticket_end_threshold = models.DateTimeField(null=False, blank=False)

def is_active(self):
is_after_start = self.ticket_start_threshold <= timezone.now()
is_before_end = self.ticket_end_threshold >= timezone.now()

return self.active and is_after_start and is_before_end


class Sale(models.Model):
member = models.ForeignKey(Member, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
Expand Down
3 changes: 3 additions & 0 deletions stregsystem/templates/stregsystem/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
</th>
<th>
<a href="/{{room.id}}/user/{{member.id}}/pay">Indsæt penge</a>
</th>
<th>
<a href="/{{room.id}}/user/{{member.id}}/tickets">Mine billetter</a>
</th>
<th>
<a href="/{{room.id}}/user/{{member.id}}/rank">Rangliste</a>
Expand Down
34 changes: 34 additions & 0 deletions stregsystem/templates/stregsystem/menu_ticketsview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "stregsystem/base.html" %}

{% load stregsystem_extras %}

{% block title %}Treoens stregsystem : Brugerinfo {% endblock %}

{% block content %}
<center><h3>{{member.firstname}} {{member.lastname}} ({{member.email}})</h3></center>

<center><h2><a href="/{{room.id}}/sale/{{member.id}}">Tilbage til produktmenu</a></h2></center>

<center>
<b>Aktive billeter</b>
<table border=1 width="60%">
<tr>
<th align=left>Event</th>
<th align=left>Produkt</th>
<th align=left>Pris</th>
<th align=left>Start Tidspunkt</th>
</tr>
{% autoescape off %}
{% for event in bought_events_list %}
<tr>
<td>{{event.name}}</td>
<td>{{event.product.name}}</td>
<td>{{event.product.price|money}}</td>
<td>{{event.time}}</td>
</tr>
{% endfor %}
{% endautoescape %}
</table>
</center>

{% endblock %}
1 change: 1 addition & 0 deletions stregsystem/templates/stregsystem/menu_userinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@
</tr>
</table>


{% endblock %}

94 changes: 94 additions & 0 deletions stregsystem/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,100 @@ def test_is_active_deactive_in_stock(self):
self.assertFalse(product.is_active())


class EventTests(TestCase):
def setUp(self):
self.jeff = Member.objects.create(
username="Jeff",
)

def test_is_active_active_not_expired(self):
product = Product.objects.create(
active=True,
price=100,
)
event = Event.objects.create(
name="testEvent",
active=True,
product=product,
time=timezone.now() + datetime.timedelta(hours=1),
ticket_start_threshold=timezone.now() - datetime.timedelta(hours=1),
ticket_end_threshold=timezone.now() + datetime.timedelta(hours=1),
)

self.assertTrue(event.is_active())

def test_is_active_active_expired_after(self):
product = Product.objects.create(
active=True,
price=100,
)
event = Event.objects.create(
name="testEvent",
active=True,
product=product,
time=timezone.now() + datetime.timedelta(hours=1),
ticket_start_threshold=timezone.now() - datetime.timedelta(hours=10),
ticket_end_threshold=timezone.now() - datetime.timedelta(hours=1),
)

self.assertFalse(event.is_active())

def test_is_active_active_before_active(self):
product = Product.objects.create(
active=True,
price=100,
)
event = Event.objects.create(
name="testEvent",
active=True,
product=product,
time=timezone.now() + datetime.timedelta(hours=1),
ticket_start_threshold=timezone.now() + datetime.timedelta(hours=2),
ticket_end_threshold=timezone.now() + datetime.timedelta(hours=5),
)

self.assertFalse(event.is_active())

def test_is_active_inactive(self):
product = Product.objects.create(
active=True,
price=100,
)
event = Event.objects.create(
name="testEvent",
active=False,
product=product,
time=timezone.now() + datetime.timedelta(hours=1),
ticket_start_threshold=timezone.now() - datetime.timedelta(hours=10),
ticket_end_threshold=timezone.now() - datetime.timedelta(hours=1),
)

self.assertFalse(event.is_active())

def test_is_active_inactive_expired(self):
product = Product.objects.create(
active=False, price=100, deactivate_date=(timezone.now() - datetime.timedelta(hours=1))
)

self.assertFalse(product.is_active())

def test_is_active_deactive_out_of_stock(self):
product = Product.objects.create(
active=False, price=100, quantity=1, start_date=datetime.date(year=2017, month=12, day=1)
)
product.sale_set.create(price=100, member=self.jeff)

self.assertFalse(product.is_active())

def test_is_active_deactive_in_stock(self):
product = Product.objects.create(
active=False, price=100, quantity=2, start_date=datetime.date(year=2017, month=12, day=1)
)
product.sale_set.create(price=100, member=self.jeff)

self.assertFalse(product.is_active())


class SaleTests(TestCase):
def setUp(self):
self.member = Member.objects.create(username="jon", balance=100)
Expand Down
1 change: 1 addition & 0 deletions stregsystem/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
re_path(r'^(?P<room_id>\d+)/sale/\d+/\d+/$', lambda request, room_id: redirect('menu_index', room_id=room_id), name="menu_sale"),
re_path(r'^(?P<room_id>\d+)/user/(?P<member_id>\d+)/$', views.menu_userinfo, name="userinfo"),
re_path(r'^(?P<room_id>\d+)/user/(?P<member_id>\d+)/pay$', views.menu_userpay, name="userpay"),
re_path(r'^(?P<room_id>\d+)/user/(?P<member_id>\d+)/tickets$', views.menu_ticketsview, name="usertickets"),
re_path(r'^(?P<room_id>\d+)/user/(?P<member_id>\d+)/rank$', views.menu_userrank, name="userrank"),
re_path(r'^api/member/payment/qr$', views.qr_payment, name="payment_qr"),
re_path(r'^api/member/active$', views.check_user_active, name="active_member"),
Expand Down
10 changes: 10 additions & 0 deletions stregsystem/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Product,
Room,
Sale,
Event,
StregForbudError,
MobilePayment,
Category,
Expand Down Expand Up @@ -242,6 +243,15 @@ def menu_userinfo(request, room_id, member_id):
return render(request, 'stregsystem/menu_userinfo.html', locals())


# Used to see active tickets
def menu_ticketsview(request, room_id, member_id):
room = Room.objects.get(pk=room_id)
member = Member.objects.get(pk=member_id, active=True)
bought_events_list = Event.objects.filter(product__in=member.sale_set.values('product'))

return render(request, 'stregsystem/menu_ticketsview.html', locals())


def menu_userpay(request, room_id, member_id):
room = Room.objects.get(pk=room_id)
member = Member.objects.get(pk=member_id, active=True)
Expand Down

0 comments on commit 7cab902

Please sign in to comment.