Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Django 5 #266

Open
wants to merge 10 commits into
base: optimise-docker-build
Choose a base branch
from
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM golang:1.20.4 AS overmind-builder

RUN go install github.com/DarthSim/overmind/v2@latest

FROM ubuntu:16.04
FROM ubuntu:22.04

RUN apt-get update && \
apt-get install -yq \
Expand Down
3 changes: 2 additions & 1 deletion global/apps/homepage/middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.utils.deprecation import MiddlewareMixin
from backend.util import redis_connection

class RedisMiddleware(object):
class RedisMiddleware(MiddlewareMixin):
"""
Add a redis object to every request
"""
Expand Down
16 changes: 10 additions & 6 deletions global/apps/homepage/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.template import RequestContext
from django.views.decorators.cache import cache_control
from urllib.parse import quote
Expand Down Expand Up @@ -103,7 +103,8 @@ def homepage(request):
mission for mission in list(Mission.Query(request.redis_conn))
if mission.incomplete and mission.featured
]
return render_to_response(
return render(
request,
'homepage/homepage.html',
{
'missions': missions,
Expand Down Expand Up @@ -140,7 +141,7 @@ def _get_reading_list(country_code):

@cache_control(no_cache=True)
def about(request):
country_code = request.META.get('HTTP_CF_IPCOUNTRY')
country_code = request.headers.get('cf-ipcountry')
if country_code is None:
country_code = request.META.get(
'GEOIP_COUNTRY_CODE',
Expand Down Expand Up @@ -202,7 +203,8 @@ def _as_dict(contributor):

contributors = [ _as_dict(contributor) for contributor in contributors ]

return render_to_response(
return render(
request,
'pages/about.html',
{
'READING_LISTS': _get_reading_list(country_code),
Expand All @@ -213,7 +215,8 @@ def _as_dict(contributor):

@cache_control(no_cache=True)
def press(request):
return render_to_response(
return render(
request,
'pages/press.html',
{
'page': 'press',
Expand All @@ -223,7 +226,8 @@ def press(request):

@cache_control(no_cache=True)
def get_involved(request):
return render_to_response(
return render(
request,
'pages/get-involved.html',
{'page': 'get-involved'},
)
2 changes: 1 addition & 1 deletion global/apps/search/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import urllib.request, urllib.parse, urllib.error
from django.views.generic import TemplateView
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.conf import settings
from django.utils.safestring import mark_safe
import xappy
Expand Down
16 changes: 12 additions & 4 deletions global/configs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
Expand All @@ -76,8 +75,17 @@
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIGEST_FREE_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": 'whitenoise.storage.CompressedManifestStaticFilesStorage',
},
"digest_free_staticfiles": {
"BACKEND": 'whitenoise.storage.CompressedStaticFilesStorage',
},
}
STATICFILES_DIRS = [
os.path.join(SITE_ROOT, 'static'),
]
Expand Down Expand Up @@ -118,7 +126,7 @@
},
]

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.common.CommonMiddleware',
'homepage.middleware.RedisMiddleware',
Expand Down
12 changes: 6 additions & 6 deletions global/templates/_base/masthead.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ <h1>Spacelog</h1>

<nav>
<ul>
{% ifequal page "about" %}
{% if page == "about" %}
<li><span class="current">About</span></li>
{% else %}
<li><a href="/about/">About</a></li>
{% endifequal %}
{% ifequal page "press" %}
{% endif %}
{% if page == "press" %}
<li><span class="current">Press</span></li>
{% else %}
<li><a href="/press/">Press</a></li>
{% endifequal %}
{% ifequal page "get-involved" %}
{% endif %}
{% if page == "get-involved" %}
<li><span class="current">Get Involved</span></li>
{% else %}
<li><a href="/get-involved/">Get Involved</a></li>
{% endifequal %}
{% endif %}
</ul>
</nav>

Expand Down
2 changes: 1 addition & 1 deletion global/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}{% load missionstatic %}<!DOCTYPE html>
{% load static %}{% load missionstatic %}<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml"
Expand Down
2 changes: 1 addition & 1 deletion global/templates/holding.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}<!DOCTYPE html>
{% load static %}<!DOCTYPE html>
<html>
<head>
<title>We'll be back soon.</title>
Expand Down
2 changes: 1 addition & 1 deletion global/templates/pages/get-involved.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load static %}

{% block title %}Getting Involved with Spacelog{% endblock %}

Expand Down
10 changes: 5 additions & 5 deletions global/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.conf.urls import url
from django.urls import path
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
#from search.views import SearchView
from homepage import views as homepage_views

urlpatterns = [
url(r'^$', homepage_views.homepage, name="homepage"),
url(r'^about/$', homepage_views.about, name="about"),
url(r'^press/$', homepage_views.press, name="press"),
url(r'^get-involved/$', homepage_views.get_involved, name="get_involved"),
path('', homepage_views.homepage, name="homepage"),
path('about/', homepage_views.about, name="about"),
path('press/', homepage_views.press, name="press"),
path('get-involved/', homepage_views.get_involved, name="get_involved"),
# url(r'^search/$', SearchView.as_view(), name="search"),
]

Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
django~=1.11.0
django~=5.0
redis==2.10.6
boto==2.49.0
gunicorn==19.3.0
pyScss==1.3.4
eventlet~=0.20.1
whitenoise~=4.1.4
greenlet~=1.1.3
gunicorn~=21.2
pyScss~=1.4
eventlet~=0.36.1
whitenoise~=6.0
greenlet~=3.0
tzdata
2 changes: 1 addition & 1 deletion website/apps/search/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import urllib.request, urllib.parse, urllib.error
from django.views.generic import TemplateView
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.conf import settings
from django.utils.safestring import mark_safe
import xappy
Expand Down
7 changes: 3 additions & 4 deletions website/apps/transcripts/middleware.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import os
from django.shortcuts import render_to_response
from django.template import RequestContext
from backend.api import Mission
from backend.util import redis_connection
from transcripts.templatetags.missiontime import component_suppression
from django.utils.deprecation import MiddlewareMixin

class RedisMiddleware(object):
class RedisMiddleware(MiddlewareMixin):
"""
Add a redis object to every request
"""
def process_request(self, request):
request.redis_conn = redis_connection

class MissionMiddleware(object):
class MissionMiddleware(MiddlewareMixin):
"""
Adds a mission object into every request.
"""
Expand Down
2 changes: 1 addition & 1 deletion website/apps/transcripts/templatetags/characters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.template import Library
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.conf import settings
from django.utils.html import format_html
from .missionstatic import mission_static
Expand Down
2 changes: 1 addition & 1 deletion website/apps/transcripts/templatetags/linkify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from django.template import Library
from django.template.defaultfilters import slugify
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils.safestring import mark_safe
from backend.api import Glossary
from backend.util import timestamp_to_seconds
Expand Down
9 changes: 3 additions & 6 deletions website/apps/transcripts/templatetags/missionstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
from django import template
from django.conf import settings
from django.contrib.staticfiles.storage import (
get_storage_class, staticfiles_storage,
storages, staticfiles_storage,
)


staticfiles_digest_free_storage = get_storage_class(
settings.STATICFILES_DIGEST_FREE_STORAGE,
)()

staticfiles_digest_free_storage = storages["digest_free_staticfiles"]

def full_path(mission, *path):
"""
Expand All @@ -22,7 +19,7 @@ def full_path(mission, *path):

def digest_free_static(path):
"""
Uses STATICFILES_DIGEST_FREE_STORAGE instead of STATICFILES_STORAGE
Uses storages["digest_free_staticfiles"] instead of storages["staticfiles"]
to produce a URL that doesn't include the digest of the file's current
contents.

Expand Down
2 changes: 1 addition & 1 deletion website/apps/transcripts/templatetags/missiontime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.template import Library
from django.core.urlresolvers import reverse
from django.urls import reverse
from backend.util import timestamp_to_seconds

import threading
Expand Down
2 changes: 1 addition & 1 deletion website/apps/transcripts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.http import Http404, HttpResponseRedirect, HttpResponse
from django.views.generic import TemplateView
from django.views.decorators.http import condition
from django.core.urlresolvers import reverse
from django.urls import reverse
from website.apps.common.views import JsonTemplateView
from backend.api import LogLine, Act
from backend.util import timestamp_to_seconds
Expand Down
16 changes: 12 additions & 4 deletions website/configs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
Expand All @@ -76,8 +75,17 @@
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIGEST_FREE_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": 'whitenoise.storage.CompressedManifestStaticFilesStorage',
},
"digest_free_staticfiles": {
"BACKEND": 'whitenoise.storage.CompressedStaticFilesStorage',
},
}
STATICFILES_DIRS = [
os.path.join(SITE_ROOT, 'static'),
]
Expand Down Expand Up @@ -126,7 +134,7 @@
},
]

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.common.CommonMiddleware',
'transcripts.middleware.RedisMiddleware',
Expand Down
2 changes: 1 addition & 1 deletion website/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}{% load missionstatic %}<!DOCTYPE html>
{% load static %}{% load missionstatic %}<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml"
Expand Down
4 changes: 2 additions & 2 deletions website/templates/homepage/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ <h2>Jump into the story</h2>
<ol>
{% for number, act in acts %}
<li>
{% ifequal 1 number %}
{% if 1 == number %}
<a href='{% url "view_page" %}'>
{% else %}
<a href='{% timestamp_to_url act.start %}'>
{% endifequal %}
{% endif %}
{% if act.homepage %}
<img src="{% mission_static mission.name "images/homepage" act.homepage %}"
alt="" width="220" height="140"/>
Expand Down
6 changes: 3 additions & 3 deletions website/templates/homepage/memorial.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load static %}
{% load missionstatic %}
{% load missiontime %}
{% load linkify %}
Expand Down Expand Up @@ -38,11 +38,11 @@ <h1>{{ mission.upper_title }} <em>{{ mission.lower_title }}</em></h1>
{% for group in people %}
{% for person in group.members %}
{% cycle "<div class='group'>" "" "" %}
{% ifequal group.view "full" %}
{% if group.view == "full" %}
{% include "people/_person.html" %}
{% else %}
{% include "people/_simple_person.html" %}
{% endifequal %}
{% endif %}
{% cycle "" "" "</div>" %}
{% endfor %}
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions website/templates/people/people.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ <h1>People</h1>
<h2>{{ group.name }}</h2>
{% for person in group.members %}
{% cycle "<div class='group'>" "" "" %}
{% ifequal group.view "full" %}
{% if group.view == "full" %}
{% include "people/_person.html" %}
{% else %}
{% include "people/_simple_person.html" %}
{% endifequal %}
{% endif %}
{% cycle "" "" "</div>" %}
{% endfor %}
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion website/templates/transcripts/page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load static %}
{% load missionstatic %}
{% load missiontime %}
{% load linkify %}
Expand Down