From 6ae4848c4561f7f493ec524c1a18a48357234df8 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 21 Dec 2015 11:52:36 +0100 Subject: [PATCH] Update for Django 1.8 * Move manage.py to parent directory, and update for new contents * Import a wsgi.py from 1.8 * Change transactions from commit_on_success to atomic * Add mandatory fields list to forms * Fully qualify name on imports * New module for django URL functions --- manage.py | 10 ++++++++++ pgmailmgr/mailmgr/forms.py | 2 ++ pgmailmgr/mailmgr/views.py | 4 ++-- pgmailmgr/manage.py | 14 -------------- pgmailmgr/settings.py | 8 +++++++- pgmailmgr/urls.py | 2 +- pgmailmgr/wsgi.py | 16 ++++++++++++++++ 7 files changed, 38 insertions(+), 18 deletions(-) create mode 100755 manage.py delete mode 100755 pgmailmgr/manage.py create mode 100644 pgmailmgr/wsgi.py diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..78c0b80 --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pgmailmgr.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/pgmailmgr/mailmgr/forms.py b/pgmailmgr/mailmgr/forms.py index 4bf44f5..0514ee8 100644 --- a/pgmailmgr/mailmgr/forms.py +++ b/pgmailmgr/mailmgr/forms.py @@ -7,6 +7,7 @@ from models import * class VirtualUserForm(forms.ModelForm): class Meta: model = VirtualUser + fields = ('local_domain', 'local_part', 'mail_quota', 'passwd', 'full_name') def __init__(self, data=None, instance=None, user=None): super(VirtualUserForm, self).__init__(data=data, instance=instance) @@ -74,6 +75,7 @@ class VirtualUserForm(forms.ModelForm): class ForwarderForm(forms.ModelForm): class Meta: model = Forwarder + fields = ('local_part', 'local_domain', 'remote_name') def __init__(self, data=None, instance=None, user=None): super(ForwarderForm, self).__init__(data=data, instance=instance) diff --git a/pgmailmgr/mailmgr/views.py b/pgmailmgr/mailmgr/views.py index 0389388..95d5cf5 100644 --- a/pgmailmgr/mailmgr/views.py +++ b/pgmailmgr/mailmgr/views.py @@ -25,7 +25,7 @@ def home(request): 'forwarders': forwards, }, RequestContext(request)) -@transaction.commit_on_success +@transaction.atomic @login_required def userform(request, userparam): if userparam == 'add': @@ -60,7 +60,7 @@ def userform(request, userparam): 'savebutton': (userparam == 'new') and "New" or "Save" }, RequestContext(request)) -@transaction.commit_on_success +@transaction.atomic @login_required def forwarderform(request, userparam): if userparam == 'add': diff --git a/pgmailmgr/manage.py b/pgmailmgr/manage.py deleted file mode 100755 index 3e4eedc..0000000 --- a/pgmailmgr/manage.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -from django.core.management import execute_manager -import imp -try: - imp.find_module('settings') # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) - sys.exit(1) - -import settings - -if __name__ == "__main__": - execute_manager(settings) diff --git a/pgmailmgr/settings.py b/pgmailmgr/settings.py index 54b6ff7..d90d342 100644 --- a/pgmailmgr/settings.py +++ b/pgmailmgr/settings.py @@ -1,5 +1,11 @@ # Django settings for pgmailmgr project. +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + ADMINS = ( ('PostgreSQL webmaster', 'webmaster@postgresql.org'), ) @@ -148,7 +154,7 @@ LOGGING = { } AUTHENTICATION_BACKENDS = ( - 'auth.AuthBackend', + 'pgmailmgr.auth.AuthBackend', ) SESSION_COOKIE_SECURE= True diff --git a/pgmailmgr/urls.py b/pgmailmgr/urls.py index bde17a8..8a40470 100644 --- a/pgmailmgr/urls.py +++ b/pgmailmgr/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import patterns, include, url +from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: from django.contrib import admin diff --git a/pgmailmgr/wsgi.py b/pgmailmgr/wsgi.py new file mode 100644 index 0000000..0bb348e --- /dev/null +++ b/pgmailmgr/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for pgmailmgr project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pgmailmgr.settings") + +application = get_wsgi_application() -- 2.39.5