Skip to content

Commit f7c4dec

Browse files
author
Bojan Jovanovic
committed
Make sponsor logo mandatory, added override of year by adding ?year={year} to the get param.
1 parent d54a385 commit f7c4dec

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
*.sqlite3
88
*.py[cod]
99
__pycache__
10-
10+
/core/static
1111
/staticfiles/

pyconbalkan/conference/middleware.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ class ConferenceSelectionMiddleware:
1010
def __init__(self, get_response):
1111
self.get_response = get_response
1212

13+
def _get_year_from_domain(self, request):
14+
domain = request.META.get('HTTP_HOST', 'localhost')
15+
try:
16+
return int(domain.split('.')[0])
17+
except ValueError:
18+
# Adding a non existing year, so it will never find this one, and will default to current.
19+
return 9999
20+
1321
def __call__(self, request):
1422
"""
1523
Code to be executed for each request before
@@ -20,12 +28,15 @@ def __call__(self, request):
2028
`conference` is the conference.models.Conference object for the
2129
respective year fetched from it's domain.
2230
"""
31+
if 'year' in request.GET.keys():
32+
domain_year = int(request.GET['year'])
33+
else:
34+
domain_year = self._get_year_from_domain(request)
35+
2336

24-
domain = request.META.get('HTTP_HOST', 'localhost')
2537
try:
26-
domain_year = int(domain.split('.')[0])
2738
request.conference = Conference.objects.get(year=domain_year)
28-
except (Conference.DoesNotExist, ValueError):
39+
except Conference.DoesNotExist:
2940
request.conference = Conference.objects.filter(active=True).first()
3041
if not request.conference:
3142
return self.get_response(request)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.1.7 on 2019-03-03 14:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('sponsors', '0008_auto_20180811_1903'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='sponsor',
15+
name='logo',
16+
field=models.ImageField(upload_to='sponsors/logo'),
17+
),
18+
]

pyconbalkan/sponsors/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Sponsor(models.Model):
2929
name = models.CharField(max_length=256)
3030
description = MarkdownxField()
3131
level = models.CharField(max_length=16, choices=SponsorshipLevel.choices)
32-
logo = models.ImageField(upload_to="sponsors/logo", blank=True, null=True)
32+
logo = models.ImageField(upload_to="sponsors/logo")
3333

3434
def __str__(self):
3535
return f'Sponsor [{ self.name }]'

0 commit comments

Comments
 (0)