Django 1.8+ compatibility

Update odsreg so that it runs with Django 1.8:
- Move base files under an odsreg module, update .gitignore
- Update module paths
- Update manage.py to Django 1.8 version
- Update instructions in README.rst
- Remove 'null has no effect on ManyToManyField' warning

Update odsreg so that it runs with Django 1.9:
- Update management command arg handling
- Use url instead of patterns in urls.py
- Move from TEMPLATE_* variables to TEMPLATES

Co-Authored-By: Tom Fifield <tom@openstack.org>
Change-Id: Ic18bddd29053ca0187889bb8a371048b2ad3fdb9
This commit is contained in:
Thierry Carrez 2016-12-19 10:32:40 +01:00
parent e03524ba65
commit 6b962fa3e2
19 changed files with 101 additions and 99 deletions

4
.gitignore vendored
View File

@ -4,5 +4,7 @@
*.sqlite
*.db
*~
local_settings.py
.venv
odsreg/local_settings.py
event.json
slots.json

View File

@ -18,14 +18,14 @@ Prerequisites
-------------
You'll need the following Python modules installed:
- django (1.4+)
- django (1.8+)
- python-django-auth-openid
OR
If you are using pip with or without a venv,
you can use the following commands instead:
- pip install django==1.4
- pip install django
- pip install python-openid
- pip install django-openid-auth
@ -33,11 +33,14 @@ you can use the following commands instead:
Configuration and Usage
-----------------------
Copy local_settings.py.sample to local_settings.py and change
settings there.
Copy odsreg/local_settings.py.sample to odsreg/local_settings.py and change
settings there. In particular you should set DEBUG=True or ALLOWED_HOSTS.
Create empty database:
./manage.py syncdb
./manage.py migrate
Create a superuser:
./manage.py createsuperuser
Copy event.json.sample to event.json and edit the file to match
the event and topics you want to have. Then run:

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from odsreg.cfp.models import Topic, Proposal, Event, Comment
from cfp.models import Topic, Proposal, Event, Comment
from django.contrib import admin

View File

@ -15,7 +15,7 @@
from django.forms import ModelForm, CharField, Textarea
from odsreg.cfp.models import Comment, Proposal
from cfp.models import Comment, Proposal
class CommentForm(ModelForm):

View File

@ -16,20 +16,22 @@
import json
from django.core.management.base import BaseCommand, CommandError
from odsreg.cfp.models import Event, Topic
from cfp.models import Event, Topic
class Command(BaseCommand):
args = '<description.json>'
help = 'Create topics from JSON description'
def handle(self, *args, **options):
def add_arguments(self, parser):
parser.add_argument('descriptive_json')
if len(args) != 1:
def handle(self, *args, **options):
if 'descriptive_json' not in options.keys():
raise CommandError('Incorrect arguments')
try:
with open(args[0]) as f:
with open(options['descriptive_json']) as f:
data = json.load(f)
except ValueError as exc:
raise CommandError("Malformed JSON: %s" % exc.message)

View File

@ -15,7 +15,7 @@
from django.shortcuts import render
from odsreg.cfp.models import Event
from cfp.models import Event
class EventMiddleware():

View File

@ -16,7 +16,7 @@
from django.db import models
from django.contrib.auth.models import User
from odsreg.cfp.utils import validate_bp
from cfp.utils import validate_bp
class Event(models.Model):

View File

@ -13,16 +13,18 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls.defaults import *
from django.conf.urls import url
from cfp import views
urlpatterns = patterns('odsreg.cfp.views',
(r'^details/(\d+)$', 'details'),
(r'^edit/(\d+)$', 'edit'),
(r'^create$', 'create'),
(r'^review/(\d+)$', 'review'),
(r'^switch/(\d+)$', 'switch'),
(r'^delete/(\d+)$', 'delete'),
(r'^topic/(\d+)$', 'topiclist'),
(r'^topicstatus$', 'topicstatus'),
)
urlpatterns = [
url(r'^details/(\d+)$', views.details),
url(r'^edit/(\d+)$', views.edit),
url(r'^create$', views.create),
url(r'^review/(\d+)$', views.review),
url(r'^switch/(\d+)$', views.switch),
url(r'^delete/(\d+)$', views.delete),
url(r'^topic/(\d+)$', views.topiclist),
url(r'^topicstatus$', views.topicstatus),
]

View File

@ -22,10 +22,10 @@ from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.template.response import TemplateResponse
from django.utils.encoding import smart_str
from odsreg.cfp.models import Proposal, Topic, Comment
from odsreg.cfp.forms import ProposalForm, ProposalEditForm, CommentForm
from odsreg.cfp.forms import ProposalReviewForm, ProposalSwitchForm
from odsreg.cfp.utils import linkify, is_editable, topiclead
from cfp.models import Proposal, Topic, Comment
from cfp.forms import ProposalForm, ProposalEditForm, CommentForm
from cfp.forms import ProposalReviewForm, ProposalSwitchForm
from cfp.utils import linkify, is_editable, topiclead
@login_required

View File

@ -1,29 +1,10 @@
#!/usr/bin/env python
# Copyright 2011 Thierry Carrez <thierry@openstack.org>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import os
import sys
sys.stderr.write("Error: Can't find the file 'settings.py'\n")
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "odsreg.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

View File

@ -28,8 +28,8 @@ DATABASES = {
SECRET_KEY = 'generateRandomOneHere'
# Run in production
ALLOWED_HOSTS = []
DEBUG = False
TEMPLATE_DEBUG = DEBUG
#OPENID_USE_AS_ADMIN_LOGIN = True
# Emails

View File

@ -21,7 +21,6 @@ import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SERVE_STATIC = True
@ -42,18 +41,28 @@ STATIC_URL = '/media/'
SECRET_KEY = 'changemeInLocalSettings'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
@ -61,7 +70,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'odsreg.cfp.middleware.EventMiddleware',
'cfp.middleware.EventMiddleware',
)
ROOT_URLCONF = 'odsreg.urls'
@ -74,8 +83,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django_openid_auth',
'django.contrib.admin',
'odsreg.cfp',
'odsreg.scheduling',
'cfp',
'scheduling',
]
AUTHENTICATION_BACKENDS = (
@ -86,6 +95,7 @@ AUTHENTICATION_BACKENDS = (
# Should users be created when new OpenIDs are used to log in?
OPENID_CREATE_USERS = True
OPENID_STRICT_USERNAMES = True
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
# Can we reuse existing users?
OPENID_REUSE_USERS = True

View File

@ -13,17 +13,18 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls.defaults import *
from django.conf.urls import include, url
from django.contrib import admin
from cfp import views
admin.autodiscover()
urlpatterns = patterns('',
(r'^openid/', include('django_openid_auth.urls')),
(r'^$', 'odsreg.cfp.views.list'),
(r'^cfp/', include('odsreg.cfp.urls')),
(r'^scheduling/', include('odsreg.scheduling.urls')),
urlpatterns = [
url(r'^openid/', include('django_openid_auth.urls')),
url(r'^$', views.list),
url(r'^cfp/', include('cfp.urls')),
url(r'^scheduling/', include('scheduling.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^logout$', 'odsreg.cfp.views.dologout'),
)
url(r'^logout$', views.dologout),
]

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from odsreg.scheduling.models import Slot, Room
from scheduling.models import Slot, Room
from django.contrib import admin

View File

@ -15,7 +15,7 @@
from django.forms import ModelForm
from odsreg.scheduling.models import Slot
from scheduling.models import Slot
class SlotForm(ModelForm):

View File

@ -15,7 +15,7 @@
from django.db import models
from odsreg.cfp.models import Proposal, Topic
from cfp.models import Proposal, Topic
class Room(models.Model):
@ -33,7 +33,7 @@ class Slot(models.Model):
start_time = models.CharField(max_length=16)
room = models.ForeignKey(Room)
topic = models.ForeignKey(Topic)
proposals = models.ManyToManyField(Proposal, blank=True, null=True)
proposals = models.ManyToManyField(Proposal, blank=True)
title = models.CharField(max_length=60, blank=True,
verbose_name="Override title with",
help_text="Default title is the title of the first proposal. You can"

View File

@ -13,13 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls.defaults import *
from django.conf.urls import url
from scheduling import views
urlpatterns = patterns('odsreg.scheduling.views',
(r'^(\d+)$', 'scheduling'),
(r'^edit/(\d+)$', 'edit'),
(r'^swap/(\d+)$', 'swap'),
(r'^publish/(\d+)$', 'publish'),
(r'^graph/(\d+)$', 'graph'),
)
urlpatterns = [
url(r'^(\d+)$', views.scheduling),
url(r'^edit/(\d+)$', views.edit),
url(r'^swap/(\d+)$', views.swap),
url(r'^publish/(\d+)$', views.publish),
url(r'^graph/(\d+)$', views.graph),
]

View File

@ -19,13 +19,13 @@ import urllib2
from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.template.response import TemplateResponse
from django.utils.encoding import smart_str
from odsreg.cfp.models import Proposal, Topic, Event
from odsreg.cfp.utils import topiclead
from odsreg.scheduling.forms import SlotForm
from odsreg.scheduling.models import Slot
from odsreg.scheduling.utils import combined_id, combined_title
from odsreg.scheduling.utils import combined_description, full_description
from odsreg.scheduling.utils import htmlize, end_time
from cfp.models import Proposal, Topic, Event
from cfp.utils import topiclead
from scheduling.forms import SlotForm
from scheduling.models import Slot
from scheduling.utils import combined_id, combined_title
from scheduling.utils import combined_description, full_description
from scheduling.utils import htmlize, end_time
def scheduling(request, topicid):