From e38ce75dd9603bbc8c6f85191f244b1951575dd3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 25 Nov 2021 10:21:49 +0100 Subject: [PATCH] trivial: apply pre-commit configuration --- panikweb_esperanzah/__init__.py | 3 +- .../commands/import_bonnes_ondes.py | 56 +++++++++++-------- panikweb_esperanzah/views.py | 36 +++++++----- setup.py | 2 +- 4 files changed, 57 insertions(+), 40 deletions(-) diff --git a/panikweb_esperanzah/__init__.py b/panikweb_esperanzah/__init__.py index d7614e9..01fe2ff 100644 --- a/panikweb_esperanzah/__init__.py +++ b/panikweb_esperanzah/__init__.py @@ -1,7 +1,7 @@ import django.apps -class Plugin(object): +class Plugin: def get_apps(self): return [__name__] @@ -12,6 +12,7 @@ class AppConfig(django.apps.AppConfig): def get_before_urls(self): from . import urls + return urls.urlpatterns diff --git a/panikweb_esperanzah/management/commands/import_bonnes_ondes.py b/panikweb_esperanzah/management/commands/import_bonnes_ondes.py index d637105..89d33ac 100644 --- a/panikweb_esperanzah/management/commands/import_bonnes_ondes.py +++ b/panikweb_esperanzah/management/commands/import_bonnes_ondes.py @@ -1,28 +1,30 @@ -# coding: utf-8 - import os -import yaml -import textile -from pytz import timezone +import textile +import yaml from django.core.files import File from django.core.management.base import BaseCommand, CommandError from django.utils.timezone import make_naive, utc +from emissions.models import Diffusion, Emission, Episode, SoundFile +from pytz import timezone -from emissions.models import Emission, Episode, SoundFile, Diffusion def construct_ruby_object(loader, suffix, node): return loader.construct_yaml_map(node) + def construct_ruby_sym(loader, node): return loader.construct_yaml_str(node) -yaml.add_multi_constructor(u"!ruby/object:", construct_ruby_object) -yaml.add_constructor(u"!ruby/sym", construct_ruby_sym) + +yaml.add_multi_constructor("!ruby/object:", construct_ruby_object) +yaml.add_constructor("!ruby/sym", construct_ruby_sym) + def get_as_html(text): return textile.textile(text) + class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--dirname', metavar='DIRNAME') @@ -31,11 +33,9 @@ class Command(BaseCommand): def handle(self, dirname, edition, *args, **kwargs): print(dirname, edition) emission, created = Emission.objects.get_or_create( - slug='edition-%s' % edition, - defaults={ - 'title': u'Édition %s' % edition, - 'text': u'

Une bien belle année.

' - }) + slug='edition-%s' % edition, + defaults={'title': 'Édition %s' % edition, 'text': '

Une bien belle année.

'}, + ) show = yaml.load(open(os.path.join(dirname, 'show.yaml'))) emission.title = show['attributes']['name'] emission.text = get_as_html(show['attributes']['description']) @@ -46,22 +46,29 @@ class Command(BaseCommand): episodes = yaml.load(open(os.path.join(dirname, 'episodes.yaml'))) images = {} for image_data in yaml.load(open(os.path.join(dirname, 'images.yaml'))): - images[image_data['attributes']['id']] = image_data['attributes']['content_uid'].encode('raw_unicode_escape').decode('utf-8') + images[image_data['attributes']['id']] = ( + image_data['attributes']['content_uid'].encode('raw_unicode_escape').decode('utf-8') + ) episode_ids = {} for episode_data in episodes: episode, created = Episode.objects.get_or_create( - slug=episode_data['attributes']['slug'], - emission=emission, - defaults={ - 'title': episode_data['attributes']['title'], - }) + slug=episode_data['attributes']['slug'], + emission=emission, + defaults={ + 'title': episode_data['attributes']['title'], + }, + ) episode.diffusions().delete() - broadcasted_at = utc.localize(episode_data['attributes']['broadcasted_at']).astimezone(europe_brussels) + broadcasted_at = utc.localize(episode_data['attributes']['broadcasted_at']).astimezone( + europe_brussels + ) Diffusion(episode=episode, datetime=make_naive(broadcasted_at)).save() episode.text = get_as_html(episode_data['attributes']['description']) if not episode.image and episode_data['attributes'].get('image_id'): - episode.image = File(open(os.path.join(dirname, 'images', images[episode_data['attributes']['image_id']]))) + episode.image = File( + open(os.path.join(dirname, 'images', images[episode_data['attributes']['image_id']])) + ) episode.save() episode_ids[episode_data['attributes']['id']] = episode.id @@ -79,9 +86,10 @@ class Command(BaseCommand): continue episode = episode_ids[soundfile_data['attributes']['episode_id']] soundfile, created = SoundFile.objects.get_or_create( - episode_id=episode, - title=soundfile_data['attributes']['name'], - fragment=not(soundfile_data['attributes']['principal'])) + episode_id=episode, + title=soundfile_data['attributes']['name'], + fragment=not (soundfile_data['attributes']['principal']), + ) soundfile.podcastable = True soundfile.file = File(open(filepath)) soundfile.save() diff --git a/panikweb_esperanzah/views.py b/panikweb_esperanzah/views.py index 5a06c20..a197228 100644 --- a/panikweb_esperanzah/views.py +++ b/panikweb_esperanzah/views.py @@ -1,11 +1,10 @@ import datetime +from combo.data.models import Page from django.http import HttpResponseRedirect from django.urls import reverse from django.views.generic.base import TemplateView - from emissions.models import Diffusion, Emission, Episode, NewsItem -from combo.data.models import Page import panikweb.views @@ -17,8 +16,11 @@ class Home(panikweb.views.Home): # force detour-vers-le-futur to go first detour = [x for x in context['emissions'] if x.slug == 'detour-vers-le-futur'] context['emissions'] = detour + [x for x in context['emissions'] if x.slug != 'detour-vers-le-futur'] - context['newsitems'] = NewsItem.objects.exclude(date__gt=datetime.date.today() - ).exclude(expiration_date__lt=datetime.date.today()).order_by('-date')[:3] + context['newsitems'] = ( + NewsItem.objects.exclude(date__gt=datetime.date.today()) + .exclude(expiration_date__lt=datetime.date.today()) + .order_by('-date')[:3] + ) context['extra_pages'] = Page.objects.filter(exclude_from_navigation=False) return context @@ -47,18 +49,24 @@ class EmissionDetailView(panikweb.views.EmissionDetailView): else: episodes_queryset = episodes_queryset.filter(emission=emission) - context['all_episodes'] = episodes_queryset.filter( - creation_timestamp__gt=current_year - ).extra(select={ - 'first_diffusion': 'emissions_diffusion.datetime', - }, - select_params=(False, True), - where=['''datetime = (SELECT MIN(datetime) + context['all_episodes'] = ( + episodes_queryset.filter(creation_timestamp__gt=current_year) + .extra( + select={ + 'first_diffusion': 'emissions_diffusion.datetime', + }, + select_params=(False, True), + where=[ + '''datetime = (SELECT MIN(datetime) FROM emissions_diffusion WHERE episode_id = emissions_episode.id - )'''], - tables=['emissions_diffusion'], - ).order_by('first_diffusion').distinct() + )''' + ], + tables=['emissions_diffusion'], + ) + .order_by('first_diffusion') + .distinct() + ) return context diff --git a/setup.py b/setup.py index 6a34121..b78347b 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ class sdist(_sdist): def get_version(): if os.path.exists('VERSION'): - with open('VERSION', 'r') as v: + with open('VERSION') as v: return v.read() if os.path.exists('.git'): p = subprocess.Popen( -- 2.39.2