Apply pyupgrade --py36-plus
(but skip f-strings as we're on Python 3.5)
This commit is contained in:
parent
5900f347c4
commit
9e39d7eadc
37 changed files with 56 additions and 107 deletions
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
import hashlib
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -8,7 +7,7 @@ from django.conf import settings
|
|||
from django.shortcuts import render as render_template_with_context
|
||||
|
||||
|
||||
class ParameterValidator(object):
|
||||
class ParameterValidator:
|
||||
def __init__(self, given_hash_or_params, params_hash_key=None):
|
||||
if params_hash_key is None:
|
||||
self.given_hash = given_hash_or_params
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2021-11-30 00:24
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2021-12-06 22:37
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2021-12-06 22:49
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2023-01-27 06:02
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import conservancy.apps.assignment.models
|
||||
from django.db import migrations, models
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import uuid
|
||||
|
||||
from django.core.validators import URLValidator, ValidationError
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import textwrap
|
||||
|
||||
TERMS = textwrap.dedent("""\
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from conservancy import bsoup
|
||||
|
@ -11,14 +10,14 @@ class EntryTag(models.Model):
|
|||
label = models.CharField(max_length=100)
|
||||
slug = models.SlugField()
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
db_table = 'techblog_entrytag' # legacy
|
||||
|
||||
def __str__(self):
|
||||
return self.label
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/blog/?tag=%s" % self.slug
|
||||
return "/blog/?tag=%s" % self.slug
|
||||
|
||||
class Entry(models.Model, bsoup.SoupModelMixin):
|
||||
"""Blog entry"""
|
||||
|
@ -34,7 +33,7 @@ class Entry(models.Model, bsoup.SoupModelMixin):
|
|||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
db_table = 'techblog_entries' # legacy
|
||||
verbose_name_plural = 'entries'
|
||||
ordering = ('-pub_date',)
|
||||
|
@ -46,7 +45,7 @@ class Entry(models.Model, bsoup.SoupModelMixin):
|
|||
return self.headline
|
||||
|
||||
def get_absolute_url(self):
|
||||
return (u"/blog/%s/%s/"
|
||||
return ("/blog/%s/%s/"
|
||||
% (self.pub_date.strftime("%Y/%b/%d").lower(),
|
||||
self.slug))
|
||||
|
||||
|
@ -58,7 +57,7 @@ class Entry(models.Model, bsoup.SoupModelMixin):
|
|||
# http://blog.foozia.com/blog/2007/apr/21/ping-technorati-your-django-blog-using-xml-rpc/
|
||||
def save(self):
|
||||
if settings.CONSERVANCY_DEVEL or True: # "or True" means it is disabled always
|
||||
super(Entry, self).save()
|
||||
super().save()
|
||||
return
|
||||
|
||||
blog_name = 'Software Freedom Conservancy Blog'
|
||||
|
@ -77,4 +76,4 @@ class Entry(models.Model, bsoup.SoupModelMixin):
|
|||
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
|
||||
|
||||
# Call any superclass's method
|
||||
super(Entry, self).save()
|
||||
super().save()
|
||||
|
|
|
@ -96,7 +96,7 @@ def query(request):
|
|||
|
||||
query_string = d.urlencode()
|
||||
|
||||
return relative_redirect(request, '%s%s%s' % (base_url, '?' if query_string else '', query_string))
|
||||
return relative_redirect(request, '{}{}{}'.format(base_url, '?' if query_string else '', query_string))
|
||||
|
||||
else:
|
||||
authors = sorted(Person.objects.filter(currently_employed=True,
|
||||
|
@ -113,7 +113,7 @@ def relative_redirect(request, path):
|
|||
if settings.FORCE_CANONICAL_HOSTNAME:
|
||||
host = settings.FORCE_CANONICAL_HOSTNAME
|
||||
|
||||
url = "%s://%s%s" % (request.is_secure() and 'https' or 'http', host, path)
|
||||
url = "{}://{}{}".format(request.is_secure() and 'https' or 'http', host, path)
|
||||
return http.HttpResponseRedirect(url)
|
||||
|
||||
class BlogYearArchiveView(YearArchiveView):
|
||||
|
@ -122,7 +122,7 @@ class BlogYearArchiveView(YearArchiveView):
|
|||
extra_context = {}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(BlogYearArchiveView, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(self.extra_context)
|
||||
return context
|
||||
|
||||
|
@ -131,7 +131,7 @@ class BlogMonthArchiveView(MonthArchiveView):
|
|||
extra_context = {}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(BlogMonthArchiveView, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(self.extra_context)
|
||||
return context
|
||||
|
||||
|
@ -140,7 +140,7 @@ class BlogDayArchiveView(DayArchiveView):
|
|||
extra_context = {}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(BlogDayArchiveView, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(self.extra_context)
|
||||
return context
|
||||
|
||||
|
@ -149,6 +149,6 @@ class BlogDateDetailView(DateDetailView):
|
|||
extra_context = {}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(BlogDateDetailView, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(self.extra_context)
|
||||
return context
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
|
||||
class ContactEntry(models.Model):
|
||||
|
@ -9,6 +8,6 @@ class ContactEntry(models.Model):
|
|||
email = models.EmailField() # should make it unique, but we really cannot
|
||||
subscribe_conservancy = models.BooleanField(default=False)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ('email',)
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.shortcuts import render
|
||||
from django import forms
|
||||
from conservancy.apps.contacts.models import ContactEntry
|
||||
|
@ -9,7 +8,7 @@ def subscribe(request):
|
|||
"""
|
||||
|
||||
class ContactEntryForm(ModelForm):
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
model = ContactEntry
|
||||
|
||||
ContactEntryForm.base_fields['subscribe_conservancy'].label = 'Receive Software Freedom Conservancy updates'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
from conservancy.apps.staff.models import Person
|
||||
from conservancy.apps.worldmap.models import EarthLocation
|
||||
|
@ -21,13 +20,13 @@ class PastEventManager(models.Manager):
|
|||
"""Returns all past events"""
|
||||
|
||||
def get_queryset(self):
|
||||
return super(PastEventManager, self).get_queryset().filter(date__lt=datetime.today())
|
||||
return super().get_queryset().filter(date__lt=datetime.today())
|
||||
|
||||
class FutureEventManager(models.Manager):
|
||||
"""Returns all future events"""
|
||||
|
||||
def get_queryset(self):
|
||||
return super(FutureEventManager, self).get_queryset().filter(date__gte=datetime.today())
|
||||
return super().get_queryset().filter(date__gte=datetime.today())
|
||||
|
||||
class Event(models.Model):
|
||||
"""Model for Conservancy staff member events (presentations, etc)"""
|
||||
|
@ -47,14 +46,14 @@ class Event(models.Model):
|
|||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ("-date",)
|
||||
|
||||
def __str__(self):
|
||||
return u"%s (%s)" % (self.title, self.date)
|
||||
return "{} ({})".format(self.title, self.date)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/events/%s/%s/" % (self.date.strftime("%Y"), self.slug)
|
||||
return "/events/{}/{}/".format(self.date.strftime("%Y"), self.slug)
|
||||
|
||||
def day_after(self):
|
||||
return self.date + timedelta(days=1)
|
||||
|
@ -87,9 +86,9 @@ class EventMedia(models.Model):
|
|||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
verbose_name_plural = 'event media'
|
||||
|
||||
def __str__(self):
|
||||
return u"%s media: %s" % (self.event, self.format)
|
||||
return "{} media: {}".format(self.event, self.format)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ def organize_media_by_event(eventmedia_queryset):
|
|||
media_by_event.setdefault(media.event.id, []).append(media)
|
||||
mbe = [{'event': x[0].event,
|
||||
'date': max(y.date_created for y in x),
|
||||
'media_list': ', '.join(set(y.get_format_display() for y in x))}
|
||||
'media_list': ', '.join({y.get_format_display() for y in x})}
|
||||
for x in list(media_by_event.values())]
|
||||
mbe.sort(key=(lambda x: x['date']), reverse=True) # sort by date
|
||||
return mbe
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2023-01-27 06:19
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2023-01-30 18:41
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-11-18 12:09
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-11-18 12:11
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2021-11-19 01:45
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import division
|
||||
from builtins import object
|
||||
import random
|
||||
|
||||
from django.db import models
|
||||
|
@ -21,7 +19,7 @@ class FundraisingGoal(models.Model):
|
|||
def percentage_there(self):
|
||||
return self.fundraiser_so_far_amount / self.fundraiser_goal_amount * 100
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ('fundraiser_code_name',)
|
||||
|
||||
def providers(self):
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from conservancy import bsoup
|
||||
|
@ -22,7 +21,7 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
|
|||
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ("-pub_date",)
|
||||
get_latest_by = "pub_date"
|
||||
|
||||
|
@ -32,7 +31,7 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
|
|||
return self.headline
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/news/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(),
|
||||
return "/news/{}/{}/".format(self.pub_date.strftime("%Y/%b/%d").lower(),
|
||||
self.slug)
|
||||
|
||||
def is_recent(self):
|
||||
|
@ -46,7 +45,7 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
|
|||
|
||||
def save(self):
|
||||
if settings.CONSERVANCY_DEVEL or True:
|
||||
super(PressRelease, self).save()
|
||||
super().save()
|
||||
return
|
||||
|
||||
blog_name = 'Software Freedom Conservancy News'
|
||||
|
@ -65,7 +64,7 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
|
|||
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
|
||||
|
||||
# Call any superclass's method
|
||||
super(PressRelease, self).save()
|
||||
super().save()
|
||||
|
||||
class ExternalArticleTag(models.Model):
|
||||
"""A way to tag external articles"""
|
||||
|
@ -79,7 +78,7 @@ class ExternalArticleTag(models.Model):
|
|||
|
||||
class PublicExternalArticleManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super(PublicExternalArticleManager, self).get_queryset().filter(visible=True)
|
||||
return super().get_queryset().filter(visible=True)
|
||||
|
||||
class ExternalArticle(models.Model):
|
||||
"""A system for displaying Conservancy news mentions on the site.
|
||||
|
@ -103,12 +102,12 @@ class ExternalArticle(models.Model):
|
|||
|
||||
date_created = models.DateField(auto_now_add=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ("-date_created",)
|
||||
get_latest_by = "date_created"
|
||||
|
||||
def __str__(self):
|
||||
return u"%s (%s)" % (self.title, self.publication)
|
||||
return "{} ({})".format(self.title, self.publication)
|
||||
|
||||
objects = models.Manager()
|
||||
public = PublicExternalArticleManager()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import zip
|
||||
import urllib.parse
|
||||
|
||||
from django import template
|
||||
|
|
|
@ -14,7 +14,7 @@ from django.http import HttpResponse
|
|||
class NewsListView(ListView):
|
||||
extra_context = {}
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(NewsListView, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
# context['key'] = 'value'
|
||||
context.update(self.extra_context)
|
||||
return context
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2021-11-28 21:12
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2021-11-28 21:12
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
|
||||
class Person(models.Model):
|
||||
|
@ -20,11 +19,11 @@ class Person(models.Model):
|
|||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
verbose_name_plural = 'people'
|
||||
|
||||
def __str__(self):
|
||||
return self.username
|
||||
|
||||
def biography_url(self):
|
||||
return u"/about/#%s" % self.username
|
||||
return "/about/#%s" % self.username
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
|
||||
class SummitRegistration(models.Model):
|
||||
|
@ -12,6 +11,6 @@ class SummitRegistration(models.Model):
|
|||
date_created = models.DateField(auto_now_add=True)
|
||||
cle_credit = models.BooleanField(default=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.shortcuts import render
|
||||
from django import forms
|
||||
from conervancy.apps.summit_registration.models import SummitRegistration
|
||||
|
@ -8,7 +7,7 @@ def register(request):
|
|||
"""
|
||||
|
||||
class SummitForm(ModelForm):
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
model = SummitRegistration
|
||||
|
||||
SummitForm.base_fields['email'].label = 'Email address'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
|
||||
class Supporter(models.Model):
|
||||
|
@ -13,5 +12,5 @@ class Supporter(models.Model):
|
|||
def __str__(self):
|
||||
return self.display_name
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
ordering = ('ledger_entity_id',)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import object
|
||||
from django.db import models
|
||||
|
||||
class EarthLocation(models.Model):
|
||||
|
@ -11,7 +10,7 @@ class EarthLocation(models.Model):
|
|||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
unique_together = (("latitude", "longitude"),)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
|
||||
from builtins import filter
|
||||
from builtins import object
|
||||
import io
|
||||
import itertools
|
||||
import re
|
||||
|
@ -27,7 +23,7 @@ class BeautifulSoup(bs4.BeautifulSoup):
|
|||
# for speed, but that doesn't work in our web application. On
|
||||
# Debian stretch, at least, using lxml causes the web server WSGI
|
||||
# application to go into an infinite loop.
|
||||
super(BeautifulSoup, self).__init__(src, parser)
|
||||
super().__init__(src, parser)
|
||||
|
||||
def _body_text(self, root):
|
||||
# "Body text" is all the strings under the root element, in order,
|
||||
|
@ -47,8 +43,7 @@ class BeautifulSoup(bs4.BeautifulSoup):
|
|||
if not started:
|
||||
break
|
||||
else:
|
||||
for s in self._body_text(child):
|
||||
yield s
|
||||
yield from self._body_text(child)
|
||||
# It's not worth it to use issubclass here, because elements that
|
||||
# don't have body text like Comments and CDATA are subclasses of
|
||||
# NavigableString.
|
||||
|
@ -107,7 +102,7 @@ class BeautifulSoup(bs4.BeautifulSoup):
|
|||
return self.find_all(self.is_video_source, src=True)
|
||||
|
||||
|
||||
class SoupModelMixin(object):
|
||||
class SoupModelMixin:
|
||||
"""Mixin for models to parse HTML with BeautifulSoup.
|
||||
|
||||
Classes that use this mixin must define `SOUP_ATTRS`, a list of strings
|
||||
|
@ -153,7 +148,7 @@ class SoupModelMixin(object):
|
|||
|
||||
def get_description(self):
|
||||
"""Return a string with a brief excerpt of body text from the HTML."""
|
||||
return u''.join(self._get_soup().some_body_text())
|
||||
return ''.join(self._get_soup().some_body_text())
|
||||
|
||||
def get_image_urls(self, *slice_args):
|
||||
"""Return an iterator of source URL strings of all images in the HTML.
|
||||
|
|
|
@ -53,7 +53,7 @@ class PressReleaseFeed(Feed):
|
|||
|
||||
class OmnibusFeedType(Rss201rev2Feed):
|
||||
def root_attributes(self):
|
||||
attrs = super(OmnibusFeedType, self).root_attributes()
|
||||
attrs = super().root_attributes()
|
||||
attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
|
||||
attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
|
||||
attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
|
||||
|
@ -61,10 +61,10 @@ class OmnibusFeedType(Rss201rev2Feed):
|
|||
return attrs
|
||||
|
||||
def add_root_elements(self, handler):
|
||||
super(OmnibusFeedType, self).add_root_elements(handler)
|
||||
super().add_root_elements(handler)
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
super(OmnibusFeedType, self).add_item_elements(handler, item)
|
||||
super().add_item_elements(handler, item)
|
||||
# Block things that don't have an enclosure from iTunes in
|
||||
# case someone uploads this feed there.
|
||||
handler.addQuickElement("itunes:block", 'Yes')
|
||||
|
@ -147,7 +147,7 @@ class OmnibusFeed(ConservancyFeedBase):
|
|||
|
||||
|
||||
def item_extra_kwargs(self, item):
|
||||
return super(OmnibusFeed, self).item_extra_kwargs(item)
|
||||
return super().item_extra_kwargs(item)
|
||||
|
||||
class BlogFeed(ConservancyFeedBase):
|
||||
link = "/blog/"
|
||||
|
@ -234,7 +234,7 @@ class BlogFeed(ConservancyFeedBase):
|
|||
def OR_filter(field_name, subfield_name, objs):
|
||||
from django.db.models import Q
|
||||
return reduce(lambda x, y: x | y,
|
||||
[Q(**{'%s__%s' % (field_name, subfield_name): x})
|
||||
[Q(**{'{}__{}'.format(field_name, subfield_name): x})
|
||||
for x in objs])
|
||||
|
||||
queryset = BlogEntry.objects.filter(pub_date__lte=datetime.now())
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from datetime import datetime as DateTime
|
||||
|
||||
import conservancy.settings
|
||||
|
@ -21,9 +19,9 @@ def sitefundraiser(request):
|
|||
}
|
||||
|
||||
if conservancy.settings.FORCE_CANONICAL_HOSTNAME:
|
||||
_HOST_URL_VAR = {'host_url': u'https://' + conservancy.settings.FORCE_CANONICAL_HOSTNAME}
|
||||
_HOST_URL_VAR = {'host_url': 'https://' + conservancy.settings.FORCE_CANONICAL_HOSTNAME}
|
||||
def host_url(request):
|
||||
return _HOST_URL_VAR
|
||||
else:
|
||||
def host_url(request):
|
||||
return {'host_url': request.build_absolute_uri(u'/').rstrip(u'/')}
|
||||
return {'host_url': request.build_absolute_uri('/').rstrip('/')}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from builtins import object
|
||||
from django import http
|
||||
from django.conf import settings
|
||||
from django.utils.cache import patch_response_headers
|
||||
|
||||
class ForceCanonicalHostnameMiddleware(object):
|
||||
class ForceCanonicalHostnameMiddleware:
|
||||
|
||||
def process_request(self, request):
|
||||
"""Modified common middleware for Conservancy site
|
||||
|
@ -28,7 +27,7 @@ class ForceCanonicalHostnameMiddleware(object):
|
|||
if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]):
|
||||
new_url[1] = new_url[1] + '/'
|
||||
if settings.DEBUG and request.method == 'POST':
|
||||
raise(RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1]))
|
||||
raise(RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to {}{} (note the trailing slash), or set APPEND_SLASH=False in your Django settings.".format(new_url[0], new_url[1]))
|
||||
# Strip trailing index.html
|
||||
if new_url[1].endswith('/index.html'):
|
||||
new_url[1] = new_url[1][:new_url[1].rfind('index.html')]
|
||||
|
@ -42,7 +41,7 @@ class ForceCanonicalHostnameMiddleware(object):
|
|||
new_url[0] = settings.FORCE_CANONICAL_HOSTNAME
|
||||
# Redirect
|
||||
if new_url[0]:
|
||||
newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], new_url[1])
|
||||
newurl = "{}://{}{}".format(request.is_secure() and 'https' or 'http', new_url[0], new_url[1])
|
||||
else:
|
||||
newurl = new_url[1]
|
||||
if request.GET:
|
||||
|
|
|
@ -26,7 +26,7 @@ ROOT_URLCONF = 'conservancy.urls'
|
|||
|
||||
FORCE_CANONICAL_HOSTNAME = False if DEBUG else 'sfconservancy.org'
|
||||
|
||||
ALLOWED_HOSTS = [ 'www.sfconservancy.org', 'aspen.sfconservancy.org', 'sfconservancy.org', u'104.130.70.210' ]
|
||||
ALLOWED_HOSTS = [ 'www.sfconservancy.org', 'aspen.sfconservancy.org', 'sfconservancy.org', '104.130.70.210' ]
|
||||
if DEBUG:
|
||||
ALLOWED_HOSTS.append('localhost')
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import str
|
||||
import mimetypes
|
||||
import os.path
|
||||
from django.http import HttpResponse
|
||||
|
@ -30,9 +29,9 @@ def handler500(request):
|
|||
return handler(request, 500)
|
||||
|
||||
def index(request, *args, **kwargs):
|
||||
path = request.path.lstrip(u'/')
|
||||
if path.endswith(u'/'):
|
||||
path += u'index.html'
|
||||
path = request.path.lstrip('/')
|
||||
if path.endswith('/'):
|
||||
path += 'index.html'
|
||||
fullpath = os.path.join(STATIC_ROOT, path)
|
||||
try:
|
||||
# Junk URLs in production (Python 3.5) are causing UnicodeEncodeErrors
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from builtins import str
|
||||
from mod_python import apache
|
||||
|
||||
# 404 should do NOTHING so apache can handle it. This view is referenced
|
||||
|
|
Loading…
Reference in a new issue