]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
views: Remove cyclic import
authorStephen Finucane <stephenfinucane@hotmail.com>
Mon, 19 Sep 2016 22:15:01 +0000 (23:15 +0100)
committerStephen Finucane <stephenfinucane@hotmail.com>
Sat, 24 Sep 2016 22:59:00 +0000 (23:59 +0100)
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>
patchwork/urls.py
patchwork/views/__init__.py
patchwork/views/notification.py [new file with mode: 0644]

index 39248ea5c99246750d2943f105d1bd6e8c9f2819..a58c1ee22123dc5cac4098b2ec6c844589ed568e 100644 (file)
@@ -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
index 15695d669137a21035afbafdf1f774a0b73cc733..a7b70610e700cb96b6acc9455b15781b8f4e597e 100644 (file)
@@ -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 (file)
index 0000000..3000215
--- /dev/null
@@ -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)