From d54a385c6ad1d2b855533e11e8a5ac52ba2cdc38 Mon Sep 17 00:00:00 2001 From: Bojan Jovanovic Date: Sun, 3 Mar 2019 15:12:46 +0100 Subject: [PATCH 1/3] Better conf. switching --- pyconbalkan/conference/abstractions.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 pyconbalkan/conference/abstractions.py diff --git a/pyconbalkan/conference/abstractions.py b/pyconbalkan/conference/abstractions.py new file mode 100644 index 00000000..49fd789e --- /dev/null +++ b/pyconbalkan/conference/abstractions.py @@ -0,0 +1,9 @@ +from django.db import models +from pyconbalkan.conference.models import Conference + + +class AbstractConference(models.Model): + conference = models.ForeignKey(Conference, on_delete=models.CASCADE) + + class Meta: + abstract = True \ No newline at end of file From f7c4dec601d428c7351303dbc8b6a07f67679e02 Mon Sep 17 00:00:00 2001 From: Bojan Jovanovic Date: Sun, 3 Mar 2019 15:36:34 +0100 Subject: [PATCH 2/3] Make sponsor logo mandatory, added override of year by adding ?year={year} to the get param. --- .gitignore | 2 +- pyconbalkan/conference/middleware.py | 17 ++++++++++++++--- .../migrations/0009_auto_20190303_1426.py | 18 ++++++++++++++++++ pyconbalkan/sponsors/models.py | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 pyconbalkan/sponsors/migrations/0009_auto_20190303_1426.py diff --git a/.gitignore b/.gitignore index ead2c494..9146df13 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ *.sqlite3 *.py[cod] __pycache__ - +/core/static /staticfiles/ diff --git a/pyconbalkan/conference/middleware.py b/pyconbalkan/conference/middleware.py index 2b73802e..d372c4aa 100644 --- a/pyconbalkan/conference/middleware.py +++ b/pyconbalkan/conference/middleware.py @@ -10,6 +10,14 @@ class ConferenceSelectionMiddleware: def __init__(self, get_response): self.get_response = get_response + def _get_year_from_domain(self, request): + domain = request.META.get('HTTP_HOST', 'localhost') + try: + return int(domain.split('.')[0]) + except ValueError: + # Adding a non existing year, so it will never find this one, and will default to current. + return 9999 + def __call__(self, request): """ Code to be executed for each request before @@ -20,12 +28,15 @@ def __call__(self, request): `conference` is the conference.models.Conference object for the respective year fetched from it's domain. """ + if 'year' in request.GET.keys(): + domain_year = int(request.GET['year']) + else: + domain_year = self._get_year_from_domain(request) + - domain = request.META.get('HTTP_HOST', 'localhost') try: - domain_year = int(domain.split('.')[0]) request.conference = Conference.objects.get(year=domain_year) - except (Conference.DoesNotExist, ValueError): + except Conference.DoesNotExist: request.conference = Conference.objects.filter(active=True).first() if not request.conference: return self.get_response(request) diff --git a/pyconbalkan/sponsors/migrations/0009_auto_20190303_1426.py b/pyconbalkan/sponsors/migrations/0009_auto_20190303_1426.py new file mode 100644 index 00000000..ee488ef5 --- /dev/null +++ b/pyconbalkan/sponsors/migrations/0009_auto_20190303_1426.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-03-03 14:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sponsors', '0008_auto_20180811_1903'), + ] + + operations = [ + migrations.AlterField( + model_name='sponsor', + name='logo', + field=models.ImageField(upload_to='sponsors/logo'), + ), + ] diff --git a/pyconbalkan/sponsors/models.py b/pyconbalkan/sponsors/models.py index 7ef4035b..9521c4d7 100644 --- a/pyconbalkan/sponsors/models.py +++ b/pyconbalkan/sponsors/models.py @@ -29,7 +29,7 @@ class Sponsor(models.Model): name = models.CharField(max_length=256) description = MarkdownxField() level = models.CharField(max_length=16, choices=SponsorshipLevel.choices) - logo = models.ImageField(upload_to="sponsors/logo", blank=True, null=True) + logo = models.ImageField(upload_to="sponsors/logo") def __str__(self): return f'Sponsor [{ self.name }]' From c4c2617ff8c765cee1f72a4687e0a380e853a22f Mon Sep 17 00:00:00 2001 From: Bojan Jovanovic Date: Sun, 3 Mar 2019 17:47:57 +0100 Subject: [PATCH 3/3] Speakers + Sponsors editing enabled. Signed-off-by: Bojan Jovanovic --- .gitignore | 2 +- pyconbalkan/conference/abstractions.py | 44 ++++++++++++++++++- pyconbalkan/speaker/admin.py | 3 +- .../migrations/0011_speaker_conference.py | 21 +++++++++ pyconbalkan/speaker/models.py | 3 +- pyconbalkan/sponsors/admin.py | 5 ++- .../migrations/0010_sponsor_conference.py | 21 +++++++++ pyconbalkan/sponsors/models.py | 3 +- 8 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 pyconbalkan/speaker/migrations/0011_speaker_conference.py create mode 100644 pyconbalkan/sponsors/migrations/0010_sponsor_conference.py diff --git a/.gitignore b/.gitignore index 9146df13..ead2c494 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ *.sqlite3 *.py[cod] __pycache__ -/core/static + /staticfiles/ diff --git a/pyconbalkan/conference/abstractions.py b/pyconbalkan/conference/abstractions.py index 49fd789e..1a8ce61c 100644 --- a/pyconbalkan/conference/abstractions.py +++ b/pyconbalkan/conference/abstractions.py @@ -1,9 +1,49 @@ +from django.contrib import admin from django.db import models +from django.utils.translation import ugettext_lazy as _ + from pyconbalkan.conference.models import Conference +def _get_default_conference(): + return Conference.objects.first().id + + class AbstractConference(models.Model): - conference = models.ForeignKey(Conference, on_delete=models.CASCADE) + conference = models.ForeignKey( + Conference, on_delete=models.CASCADE, default=_get_default_conference + ) class Meta: - abstract = True \ No newline at end of file + abstract = True + + +class ConferenceFilter(admin.SimpleListFilter): + title = _('Conference year') + parameter_name = 'conference' + + def choices(self, changelist): + for lookup, title in self.lookup_choices: + yield { + 'selected': self.value() is lookup or self.value() == str(lookup), + 'query_string': changelist.get_query_string( + {self.parameter_name: lookup} + ), + 'display': title, + } + + def lookups(self, request, model_admin): + choices = [] + for _ in Conference.objects.all(): + if _ == request.conference: + choices.append((None, "{} Current".format(_))) + else: + choices.append((_.id, str(_))) + return choices + + def queryset(self, request, queryset): + return queryset.filter(conference=self.value() or request.conference.pk) + + +class ConferenceAbstractAdmin(admin.ModelAdmin): + list_filter = (ConferenceFilter,) diff --git a/pyconbalkan/speaker/admin.py b/pyconbalkan/speaker/admin.py index e3249618..3674d423 100644 --- a/pyconbalkan/speaker/admin.py +++ b/pyconbalkan/speaker/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from markdownx.admin import MarkdownxModelAdmin +from pyconbalkan.conference.abstractions import ConferenceAbstractAdmin from pyconbalkan.speaker.models import Speaker, SpeakerPhoto @@ -8,7 +9,7 @@ class SpeakerImageInline(admin.TabularInline): model = SpeakerPhoto -class SpeakerAdmin(MarkdownxModelAdmin): +class SpeakerAdmin(ConferenceAbstractAdmin, MarkdownxModelAdmin): inlines = [SpeakerImageInline] diff --git a/pyconbalkan/speaker/migrations/0011_speaker_conference.py b/pyconbalkan/speaker/migrations/0011_speaker_conference.py new file mode 100644 index 00000000..b3f238e0 --- /dev/null +++ b/pyconbalkan/speaker/migrations/0011_speaker_conference.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.7 on 2019-03-03 16:46 + +from django.db import migrations, models +import django.db.models.deletion +import pyconbalkan.conference.abstractions + + +class Migration(migrations.Migration): + + dependencies = [ + ('conference', '0007_auto_20190227_0738'), + ('speaker', '0010_speaker_country'), + ] + + operations = [ + migrations.AddField( + model_name='speaker', + name='conference', + field=models.ForeignKey(default=pyconbalkan.conference.abstractions._get_default_conference, on_delete=django.db.models.deletion.CASCADE, to='conference.Conference'), + ), + ] diff --git a/pyconbalkan/speaker/models.py b/pyconbalkan/speaker/models.py index 88dac64f..444da30b 100644 --- a/pyconbalkan/speaker/models.py +++ b/pyconbalkan/speaker/models.py @@ -1,10 +1,11 @@ from django.db import models from django.db.models import CASCADE +from pyconbalkan.conference.abstractions import AbstractConference from pyconbalkan.core.models import Person, ActiveModel -class Speaker(ActiveModel, Person): +class Speaker(AbstractConference, ActiveModel, Person): keynote = models.BooleanField(default=False) def __str__(self): diff --git a/pyconbalkan/sponsors/admin.py b/pyconbalkan/sponsors/admin.py index daefd501..63c87d33 100644 --- a/pyconbalkan/sponsors/admin.py +++ b/pyconbalkan/sponsors/admin.py @@ -1,7 +1,10 @@ from django.contrib import admin + +from pyconbalkan.conference.abstractions import ConferenceAbstractAdmin from pyconbalkan.sponsors.models import Package, PackageItem, Sponsor, Sponsoring -admin.site.register(Sponsor) + +admin.site.register(Sponsor, ConferenceAbstractAdmin) admin.site.register(Sponsoring) admin.site.register(Package) admin.site.register(PackageItem) diff --git a/pyconbalkan/sponsors/migrations/0010_sponsor_conference.py b/pyconbalkan/sponsors/migrations/0010_sponsor_conference.py new file mode 100644 index 00000000..89f28c4e --- /dev/null +++ b/pyconbalkan/sponsors/migrations/0010_sponsor_conference.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.7 on 2019-03-03 14:42 + +from django.db import migrations, models +import django.db.models.deletion +import pyconbalkan.conference.abstractions + + +class Migration(migrations.Migration): + + dependencies = [ + ('conference', '0007_auto_20190227_0738'), + ('sponsors', '0009_auto_20190303_1426'), + ] + + operations = [ + migrations.AddField( + model_name='sponsor', + name='conference', + field=models.ForeignKey(default=pyconbalkan.conference.abstractions._get_default_conference, on_delete=django.db.models.deletion.CASCADE, to='conference.Conference'), + ), + ] diff --git a/pyconbalkan/sponsors/models.py b/pyconbalkan/sponsors/models.py index 9521c4d7..de5ddb68 100644 --- a/pyconbalkan/sponsors/models.py +++ b/pyconbalkan/sponsors/models.py @@ -5,6 +5,7 @@ from markdownx.models import MarkdownxField from djmoney.models.fields import MoneyField +from pyconbalkan.conference.abstractions import AbstractConference from pyconbalkan.core.models import ActiveModel @@ -25,7 +26,7 @@ class SponsorshipLevel(DjangoChoices): } -class Sponsor(models.Model): +class Sponsor(AbstractConference): name = models.CharField(max_length=256) description = MarkdownxField() level = models.CharField(max_length=16, choices=SponsorshipLevel.choices)