Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature tickets v2 #378

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}

225 changes: 208 additions & 17 deletions stregsystem/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
PayTransaction,
Product,
Room,
Event,
Sale,
StregForbudError,
active_str,
Expand Down Expand Up @@ -694,44 +695,234 @@ def test_is_active_active(self):
self.assertTrue(product.is_active())

def test_is_active_active_not_expired(self):
product = Product.objects.create(
active=True, price=100, deactivate_date=(timezone.now() + datetime.timedelta(hours=1))
)
with freeze_time(timezone.datetime(2018, 1, 1)) as frozen_time:
product = Product.objects.create(
active=True, price=100, deactivate_date=(timezone.now() + datetime.timedelta(hours=1))
)

self.assertTrue(product.is_active())
self.assertTrue(product.is_active())

def test_is_active_active_expired(self):
with freeze_time(timezone.datetime(2018, 1, 1)) as frozen_time:
product = Product.objects.create(
active=True, price=100, deactivate_date=(timezone.now() - datetime.timedelta(hours=1))
)

self.assertFalse(product.is_active())

def test_is_active_active_out_of_stock(self):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
product = Product.objects.create(active=True, price=100, quantity=1, start_date=timezone.now())
product.sale_set.create(price=100, member=self.jeff)

self.assertFalse(product.is_active())

def test_is_active_active_in_stock(self):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
product = Product.objects.create(active=True, price=100, quantity=2, start_date=timezone.now())
product.sale_set.create(price=100, member=self.jeff)

self.assertTrue(product.is_active())

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

self.assertFalse(product.is_active())

def test_is_active_active_out_of_stock(self):
def test_is_active_deactive_expired(self):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
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):
with freeze_time(timezone.datetime(2017, 12, 1)) as frozen_time:
product = Product.objects.create(active=False, price=100, quantity=1, start_date=timezone.now())
product.sale_set.create(price=100, member=self.jeff)

self.assertFalse(product.is_active())

def test_is_active_deactive_in_stock(self):
with freeze_time(timezone.datetime(2017, 12, 1)) as frozen_time:
product = Product.objects.create(active=False, price=100, quantity=2, start_date=timezone.now())
product.sale_set.create(price=100, member=self.jeff)

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):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
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):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
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):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
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):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
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):
with freeze_time(timezone.datetime(2017, 1, 1)) as frozen_time:
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):
with freeze_time(timezone.datetime(2017, 12, 1)) as frozen_time:
product = Product.objects.create(active=False, price=100, quantity=1, start_date=timezone.now())
product.sale_set.create(price=100, member=self.jeff)

self.assertFalse(product.is_active())

def test_is_active_deactive_in_stock(self):
with freeze_time(timezone.datetime(2017, 12, 1)) as frozen_time:
product = Product.objects.create(active=False, price=100, quantity=2, start_date=timezone.now())
product.sale_set.create(price=100, member=self.jeff)

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, quantity=1, start_date=datetime.date(year=2017, month=1, day=1)
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),
)
product.sale_set.create(price=100, member=self.jeff)

self.assertFalse(product.is_active())
self.assertTrue(event.is_active())

def test_is_active_active_in_stock(self):
def test_is_active_active_expired_after(self):
product = Product.objects.create(
active=True, price=100, quantity=2, start_date=datetime.date(year=2017, month=1, day=1)
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),
)
product.sale_set.create(price=100, member=self.jeff)

self.assertTrue(product.is_active())
self.assertFalse(event.is_active())

def test_is_active_deactive(self):
def test_is_active_active_before_active(self):
product = Product.objects.create(
active=False,
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(product.is_active())
self.assertFalse(event.is_active())

def test_is_active_deactive_expired(self):
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))
)
Expand Down
Loading
Loading