There's no need to do imports this way, so move notification handling into a suitable module.
Signed-off-by: Stephen Finucane <stephenfinuc...@hotmail.com> --- patchwork/views/__init__.py | 34 ++++---------------------- patchwork/views/notifications.py | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 patchwork/views/notifications.py diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index 15695d6..e1e40a8 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -28,13 +28,14 @@ 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 Project from patchwork.paginator import Paginator @@ -403,29 +404,4 @@ def patch_to_mbox(patch): 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/notifications.py b/patchwork/views/notifications.py new file mode 100644 index 0000000..3000215 --- /dev/null +++ b/patchwork/views/notifications.py @@ -0,0 +1,53 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2008 Jeremy Kerr <j...@ozlabs.org> +# Copyright (C) 2016 Stephen Finucane <stephenfinuc...@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) -- 2.7.4 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork