Fix flake8 warnings

This commit is contained in:
Ben Sturmfels 2024-07-22 17:13:34 +10:00
parent 1a5441ba75
commit c5289f39bb
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
9 changed files with 37 additions and 31 deletions

View file

@ -72,11 +72,11 @@ class Entry(models.Model, bsoup.SoupModelMixin):
# Ping Technorati # Ping Technorati
j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping') j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping')
reply = j.weblogUpdates.ping(blog_name, blog_url) j.weblogUpdates.ping(blog_name, blog_url)
# Ping Google Blog Search # Ping Google Blog Search
j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2') j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2')
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url) j.weblogUpdates.ping(blog_name, blog_url, post_url)
# Call any superclass's method # Call any superclass's method
super().save() super().save()

View file

@ -3,7 +3,6 @@ from functools import reduce
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.views.generic import ListView
from django.views.generic.dates import ( from django.views.generic.dates import (
DateDetailView, DateDetailView,
DayArchiveView, DayArchiveView,
@ -12,7 +11,7 @@ from django.views.generic.dates import (
) )
from ..staff.models import Person from ..staff.models import Person
from .models import Entry, EntryTag from .models import EntryTag
def OR_filter(field_name, objs): def OR_filter(field_name, objs):

View file

@ -46,10 +46,12 @@ def run(cmd, encoding=None, ok_exitcodes=frozenset([0]), **kwargs):
no_data = '' no_data = ''
with contextlib.ExitStack() as exit_stack: with contextlib.ExitStack() as exit_stack:
proc = exit_stack.enter_context(subprocess.Popen(cmd, **kwargs)) proc = exit_stack.enter_context(subprocess.Popen(cmd, **kwargs))
pipes = [exit_stack.enter_context(open( pipes = [
exit_stack.enter_context(open(
getattr(proc, name).fileno(), mode, encoding=encoding, closefd=False)) getattr(proc, name).fileno(), mode, encoding=encoding, closefd=False))
for name in ['stdout', 'stderr'] for name in ['stdout', 'stderr']
if kwargs.get(name) is subprocess.PIPE] if kwargs.get(name) is subprocess.PIPE
]
if pipes: if pipes:
yield (proc, *pipes) yield (proc, *pipes)
else: else:
@ -88,6 +90,7 @@ class GitPath:
def _cache(orig_func): def _cache(orig_func):
attr_name = '_cached_' + orig_func.__name__ attr_name = '_cached_' + orig_func.__name__
@functools.wraps(orig_func) @functools.wraps(orig_func)
def cache_wrapper(self): def cache_wrapper(self):
try: try:

View file

@ -13,9 +13,11 @@ from .news.models import PressRelease
class ConservancyFeedBase(Feed): class ConservancyFeedBase(Feed):
def copyright_holder(self): return "Software Freedom Conservancy" def copyright_holder(self):
return "Software Freedom Conservancy"
def license_no_html(self): return "Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License." def license_no_html(self):
return "Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License."
def item_copyright(self, item): def item_copyright(self, item):
year = 2008 year = 2008
@ -89,7 +91,8 @@ class OmnibusFeed(ConservancyFeedBase):
def item_description(self, item): def item_description(self, item):
return item.summary return item.summary
def item_enclosure_mime_type(self): return "audio/mpeg" def item_enclosure_mime_type(self):
return "audio/mpeg"
def item_enclosure_url(self, item): def item_enclosure_url(self, item):
if hasattr(item, 'mp3_path'): if hasattr(item, 'mp3_path'):
@ -98,9 +101,6 @@ class OmnibusFeed(ConservancyFeedBase):
if hasattr(item, 'mp3_path'): if hasattr(item, 'mp3_path'):
return item.mp3_length return item.mp3_length
def item_pubdate(self, item):
return item.pub_date
def item_author_name(self, item): def item_author_name(self, item):
if item.omnibus_type == "blog": if item.omnibus_type == "blog":
return item.author.formal_name return item.author.formal_name
@ -174,7 +174,8 @@ class BlogFeed(ConservancyFeedBase):
firstTime = True firstTime = True
done = {} done = {}
for tag in tags: for tag in tags:
if tag in done: continue if tag in done:
continue
if firstTime: if firstTime:
answer += " (" answer += " ("
firstTime = False firstTime = False
@ -192,8 +193,10 @@ class BlogFeed(ConservancyFeedBase):
GET = obj.GET GET = obj.GET
tags = [] tags = []
if 'author' in GET: tags = GET.getlist('author') if 'author' in GET:
if 'tag' in GET: tags += GET.getlist('tag') tags = GET.getlist('author')
if 'tag' in GET:
tags += GET.getlist('tag')
done = {} done = {}
if len(tags) == 1: if len(tags) == 1:
@ -201,7 +204,8 @@ class BlogFeed(ConservancyFeedBase):
elif len(tags) > 1: elif len(tags) > 1:
firstTime = True firstTime = True
for tag in tags: for tag in tags:
if tag in done: continue if tag in done:
continue
if firstTime: if firstTime:
answer += " tagged with " answer += " tagged with "
firstTime = False firstTime = False

View file

@ -34,8 +34,10 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
return self.headline return self.headline
def get_absolute_url(self): def get_absolute_url(self):
return "/news/{}/{}/".format(self.pub_date.strftime("%Y/%b/%d").lower(), return "/news/{}/{}/".format(
self.slug) self.pub_date.strftime("%Y/%b/%d").lower(),
self.slug,
)
def is_recent(self): def is_recent(self):
return self.pub_date > (datetime.now() - timedelta(days=5)) return self.pub_date > (datetime.now() - timedelta(days=5))
@ -60,11 +62,11 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
# Ping Technorati # Ping Technorati
j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping') j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping')
reply = j.weblogUpdates.ping(blog_name, blog_url) j.weblogUpdates.ping(blog_name, blog_url)
# Ping Google Blog Search # Ping Google Blog Search
j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2') j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2')
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url) j.weblogUpdates.ping(blog_name, blog_url, post_url)
# Call any superclass's method # Call any superclass's method
super().save() super().save()

View file

@ -1,7 +1,6 @@
from datetime import datetime from datetime import datetime
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.views.generic import ListView from django.views.generic import ListView
from django.views.generic.dates import ( from django.views.generic.dates import (
@ -11,8 +10,7 @@ from django.views.generic.dates import (
YearArchiveView, YearArchiveView,
) )
from ..events.models import Event from .models import PressRelease
from .models import ExternalArticle, PressRelease
class NewsListView(ListView): class NewsListView(ListView):
@ -27,8 +25,9 @@ def listing(request, *args, **kwargs):
news_queryset = PressRelease.objects.all() news_queryset = PressRelease.objects.all()
# if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']: # if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']:
news_queryset = news_queryset.filter(**{'%s__lte' % kwargs['date_field']: news_queryset = news_queryset.filter(
datetime.now()}) **{'%s__lte' % kwargs['date_field']: datetime.now()}
)
date_list = news_queryset.dates(kwargs['date_field'], 'year') date_list = news_queryset.dates(kwargs['date_field'], 'year')

View file

@ -19,7 +19,6 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.db import models from django.db import models
from django.urls import reverse
class Podcast(models.Model): class Podcast(models.Model):

View file

@ -1,4 +1,4 @@
from .base import * from .base import * # NOQA
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']

View file

@ -2,7 +2,7 @@ import json
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from .base import * from .base import * # NOQA
DEBUG = False DEBUG = False
ALLOWED_HOSTS = ['www.sfconservancy.org', 'sfconservancy.org'] ALLOWED_HOSTS = ['www.sfconservancy.org', 'sfconservancy.org']
@ -25,7 +25,7 @@ DATABASES = {
# Apache/mod_wsgi doesn't make it straightforward to pass environment variables # Apache/mod_wsgi doesn't make it straightforward to pass environment variables
# to Django (can't use the Apache config). # to Django (can't use the Apache config).
with open(BASE_DIR.parent / 'secrets.json') as f: with open(BASE_DIR.parent / 'secrets.json') as f: # NOQA
secrets = json.load(f) secrets = json.load(f)
def get_secret(secrets, setting): def get_secret(secrets, setting):