aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfinucane@hotmail.com>2016-09-19 23:15:01 +0100
committerStephen Finucane <stephenfinucane@hotmail.com>2016-09-24 23:59:00 +0100
commitb0ca6df4e1facd3b9144462579d355e8208904d7 (patch)
treeea49254f1ce84be47ff94b47199ce6e1d47efe92
parent4821efa06db780e30246040a70b62fcd0c5e562a (diff)
downloadpatchwork-b0ca6df4e1facd3b9144462579d355e8208904d7.tar
patchwork-b0ca6df4e1facd3b9144462579d355e8208904d7.tar.gz
views: Remove cyclic import
There's no need to do imports this way, so move notification handling into a suitable module. Signed-off-by: Stephen Finucane <stephenfinucane@hotmail.com> Reviewed-by: Daniel Axtens <dja@axtens.net>
-rw-r--r--patchwork/urls.py4
-rw-r--r--patchwork/views/__init__.py38
-rw-r--r--patchwork/views/notification.py53
3 files changed, 61 insertions, 34 deletions
diff --git a/patchwork/urls.py b/patchwork/urls.py
index 39248ea..a58c1ee 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -22,12 +22,12 @@ from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
-from patchwork import views
from patchwork.views import api as api_views
from patchwork.views import bundle as bundle_views
from patchwork.views import cover as cover_views
from patchwork.views import help as help_views
from patchwork.views import mail as mail_views
+from patchwork.views import notification as notification_views
from patchwork.views import patch as patch_views
from patchwork.views import project as project_views
from patchwork.views import pwclient as pwclient_views
@@ -111,7 +111,7 @@ urlpatterns = [
bundle_views.mbox,
name='bundle-mbox'),
- url(r'^confirm/(?P<key>[0-9a-f]+)/$', views.confirm,
+ url(r'^confirm/(?P<key>[0-9a-f]+)/$', notification_views.confirm,
name='confirm'),
# submitter autocomplete
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 15695d6..a7b7061 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -28,13 +28,15 @@ import email.utils
import re
from django.contrib import messages
-from django.http import Http404
-from django.shortcuts import render, get_object_or_404
+from django.shortcuts import get_object_or_404
from patchwork.filters import Filters
from patchwork.forms import MultiplePatchForm
-from patchwork.models import (Bundle, BundlePatch, Comment, Patch,
- EmailConfirmation, Project)
+from patchwork.models import Bundle
+from patchwork.models import BundlePatch
+from patchwork.models import Comment
+from patchwork.models import Patch
+from patchwork.models import Project
from patchwork.paginator import Paginator
@@ -401,31 +403,3 @@ def patch_to_mbox(patch):
mail['Date'] = email.utils.formatdate(utc_timestamp)
return mail
-
-
-def confirm(request, key):
- import patchwork.views.user
- import patchwork.views.mail
-
- views = {
- 'userperson': patchwork.views.user.link_confirm,
- 'registration': patchwork.views.user.register_confirm,
- 'optout': patchwork.views.mail.optout_confirm,
- 'optin': patchwork.views.mail.optin_confirm,
- }
-
- conf = get_object_or_404(EmailConfirmation, key=key)
- if conf.type not in views:
- raise Http404
-
- if conf.active and conf.is_valid():
- return views[conf.type](request, conf)
-
- context = {}
- context['conf'] = conf
- if not conf.active:
- context['error'] = 'inactive'
- elif not conf.is_valid():
- context['error'] = 'expired'
-
- return render(request, 'patchwork/confirm-error.html', context)
diff --git a/patchwork/views/notification.py b/patchwork/views/notification.py
new file mode 100644
index 0000000..3000215
--- /dev/null
+++ b/patchwork/views/notification.py
@@ -0,0 +1,53 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
+# Copyright (C) 2016 Stephen Finucane <stephenfinucane@hotmail.com>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from django.http import Http404
+from django.shortcuts import get_object_or_404
+from django.shortcuts import render
+
+from patchwork.models import EmailConfirmation
+from patchwork.views import mail
+from patchwork.views import user
+
+
+def confirm(request, key):
+
+ views = {
+ 'userperson': user.link_confirm,
+ 'registration': user.register_confirm,
+ 'optout': mail.optout_confirm,
+ 'optin': mail.optin_confirm,
+ }
+
+ conf = get_object_or_404(EmailConfirmation, key=key)
+ if conf.type not in views:
+ raise Http404
+
+ if conf.active and conf.is_valid():
+ return views[conf.type](request, conf)
+
+ context = {}
+ context['conf'] = conf
+ if not conf.active:
+ context['error'] = 'inactive'
+ elif not conf.is_valid():
+ context['error'] = 'expired'
+
+ return render(request, 'patchwork/confirm-error.html', context)