Skip to content

Commit 1fcc69e

Browse files
authored
Add and use 'year' property for camp model. (#2033)
Before we had to do 'camp.camp.lower.year' to get the year, now we can do 'camp.year'
1 parent ed47b98 commit 1fcc69e

File tree

7 files changed

+106
-123
lines changed

7 files changed

+106
-123
lines changed

src/camps/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ def teardown_days(self):
322322

323323
# convenience properties to access Camp-related stuff easily from the Camp object
324324

325+
@property
326+
def year(self) -> int:
327+
"""Return the year of this camp."""
328+
return self.camp.lower.year
329+
325330
@property
326331
def event_types(self):
327332
"""Return all event types with at least one event in this camp."""

src/camps/tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,10 @@ def test_participant_count(self) -> None:
213213
child_one_day.save()
214214

215215
assert self.camp.participant_count == 4
216+
217+
def test_year_of_camp(self) -> None:
218+
"""Test the property `year` return current year of camp."""
219+
expected = self.camp.camp.lower.year
220+
221+
assert self.camp.year == expected
222+

src/program/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ def get(self, *args, **kwargs):
10851085
E.version("BornHack Frab XML Generator v2.0"),
10861086
E.conference(
10871087
E.title(self.camp.title),
1088-
E.acronym(str(self.camp.camp.lower.year)),
1088+
E.acronym(str(self.camp.year)),
10891089
E.start(self.camp.camp.lower.date().isoformat()),
10901090
E.end(self.camp.camp.upper.date().isoformat()),
10911091
E.days(len(self.camp.get_days("camp"))),

src/shop/management/commands/copy_tickets_from_camp_to_camp.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import logging
44

5-
from django.core.management import call_command
65
from django.core.management.base import BaseCommand
76
from django.utils import timezone
87
from datetime import timedelta
98

109
from camps.models import Camp
1110
from tickets.models import TicketType
12-
from shop.models import Product, SubProductRelation
11+
from shop.models import Product
12+
from shop.models import SubProductRelation
1313

1414
logger = logging.getLogger(f"bornhack.{__name__}")
1515

@@ -56,16 +56,16 @@ def handle(self, *args, **options) -> None:
5656
print(f"Created new TicketType {newtt}")
5757
for product in tt.product_set.filter(sub_products__isnull=True):
5858
newprod, created = Product.objects.get_or_create(
59-
name=product.name.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
59+
name=product.name.replace(str(fromcamp.year), str(tocamp.year)),
6060
ticket_type=newtt,
61-
slug=product.slug.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
61+
slug=product.slug.replace(str(fromcamp.year), str(tocamp.year)),
6262
defaults={
6363
"price": product.price,
6464
"category": product.category,
65-
"description": product.description.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
65+
"description": product.description.replace(str(fromcamp.year), str(tocamp.year)),
6666
"available_in": (timezone.now(), tocamp.camp.upper + timedelta(days=30)),
6767
"cost": product.cost,
68-
"comment": product.comment.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
68+
"comment": product.comment.replace(str(fromcamp.year), str(tocamp.year)),
6969
}
7070
)
7171
if created:
@@ -77,15 +77,15 @@ def handle(self, *args, **options) -> None:
7777
print(product)
7878
# create bundle product
7979
newprod, created = Product.objects.get_or_create(
80-
name=product.name.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
81-
slug=product.slug.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
80+
name=product.name.replace(str(fromcamp.year), str(tocamp.year)),
81+
slug=product.slug.replace(str(fromcamp.year), str(tocamp.year)),
8282
defaults={
8383
"price": product.price,
8484
"category": product.category,
85-
"description": product.description.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
85+
"description": product.description.replace(str(fromcamp.year), str(tocamp.year)),
8686
"available_in": (timezone.now(), tocamp.camp.upper + timedelta(days=30)),
8787
"cost": product.cost,
88-
"comment": product.comment.replace(str(fromcamp.camp.lower.year), str(tocamp.camp.lower.year)),
88+
"comment": product.comment.replace(str(fromcamp.year), str(tocamp.year)),
8989
}
9090
)
9191
for spr in product.sub_product_relations.all():

src/tickets/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def get(self, request, *args, **kwargs):
6565
ticket = self.get_object(*args, **kwargs)
6666
response = HttpResponse(content_type="application/pdf")
6767
response["Content-Disposition"] = (
68-
f'attachment; filename="BornHack_{ticket.ticket_type.camp.camp.lower.year}_{ticket.shortname}_ticket_{ticket.pk}.pdf"'
68+
f'attachment; filename="BornHack_{ticket.ticket_type.camp.year}_{ticket.shortname}_ticket_{ticket.pk}.pdf"'
6969
)
7070
response.write(ticket.generate_pdf().getvalue())
7171
return response

src/tokens/templates/token_dashboard.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ <h3 class="mb-4">How to play?</h3>
6565
<p>Token examples:</p>
6666
<p>
6767
<ul>
68-
<li><code>BornHack{{ camp.camp.lower.year }}</code></li>
68+
<li><code>BornHack{{ camp.year }}</code></li>
6969
<li><code>cm9sbGllczIwMjR5b3V3aW4K</code></li>
7070
<li><code>Ly5caCRLKRHrpiF6SQwe9geUKAxSsLQE</code></li>
7171
</ul>
7272
</p>
7373
<p>Tokens are hidden or in plain sight physically or virtually on the BornHack venue, online and offline.</p>
74-
<p class="mb-0">Submit the tokens you find in the field below. You can start with this one: <b>HelloTokenHunters{{ camp.camp.lower.year }}</b></p>
74+
<p class="mb-0">Submit the tokens you find in the field below. You can start with this one: <b>HelloTokenHunters{{ camp.year }}</b></p>
7575
</div>
7676
<div class="col-12 my-4">
7777
<form action="{% url 'tokens:submit' camp_slug=camp.slug %}" method="post">

0 commit comments

Comments
 (0)