Commit 2120543d authored by Florian Fuchs's avatar Florian Fuchs

* added generic MailingListView class for list-based views

* view code moved from views.py to views/views.py and views/generic.py
* refactored some view functions as subclasses of MailingListView
* added more detailed error messages to mass subscribe view
parent a566b33f
......@@ -48,10 +48,25 @@ class ListMembersViewTest(unittest.TestCase):
view = ListMembersView()
with patch('mailman.client.Client.get_list') as mock:
mock.return_value = self.mock_list
the_list = view.get_list('[email protected]')
the_list = view._get_list('[email protected]')
self.assertEqual(the_list.members[0].address, '[email protected]')
self.assertEqual(the_list.members[1].address, '[email protected]')
def test_dispatch(self):
"""Test if list members are retreived correctly."""
from postorius.views import ListMembersView
# test get_list
view = ListMembersView()
with patch('mailman.client.Client.get_list') as mock:
mock.return_value = self.mock_list
the_list = view._get_list('[email protected]')
request = self.request_factory.get(
'/lists/[email protected]/members/')
request.user = User.objects.create_superuser('sux', '[email protected]',
'pwd')
view.dispatch(request, fqdn_listname='[email protected]')
self.assertEqual(self.mock_list, view.mailing_list)
def test_return_code_by_user(self):
"""Test response status code by user status.
"""
......
......@@ -20,7 +20,8 @@ from django.conf.urls.defaults import *
from django.conf import settings
from django.conf.urls.static import static
from postorius.views import ListMembersView
from postorius.views import *
from postorius.views.generic import *
urlpatterns = patterns(
......@@ -46,18 +47,18 @@ urlpatterns = patterns(
url(r'^lists/new/$', 'list_new', name='list_new'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/members/$',
ListMembersView.as_view(), name='list_members'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/metrics$', 'list_metrics',
name='list_metrics'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/$', 'list_summary',
name='list_summary'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/metrics$',
ListMetricsView.as_view(), name='list_metrics'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/$',
ListSummaryView.as_view(), name='list_summary'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/subscribe$',
'list_subscribe', name='list_subscribe'),
ListSubsribeView.as_view(), name='list_subscribe'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/unsubscribe/(?P<email>[^/]+)$',
'list_unsubscribe', name='list_unsubscribe'),
ListUnsubscribeView.as_view(), name='list_unsubscribe'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/subscriptions$',
'list_subscriptions', name='list_subscriptions'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/mass_subscribe/$',
'mass_subscribe', name='mass_subscribe'),
ListMassSubsribeView.as_view(), name='mass_subscribe'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/delete$',
'list_delete', name='list_delete'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/'
......
# -*- coding: utf-8 -*-
# Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
#
# This file is part of Postorius.
#
# Postorius 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 3 of the License, or (at your option)
# any later version.
#
# Postorius 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
# Postorius. If not, see <http://www.gnu.org/licenses/>.
from postorius.views.views import *
# -*- coding: utf-8 -*-
# Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
#
# This file is part of Postorius.
#
# Postorius 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 3 of the License, or (at your option)
# any later version.
#
# Postorius 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
# Postorius. If not, see <http://www.gnu.org/licenses/>.
from django.shortcuts import render_to_response, redirect
from django.template import Context, loader, RequestContext
from django.views.generic import TemplateView
from postorius.models import (Domain, List, Member, MailmanUser,
MailmanApiError, Mailman404Error)
class MailingListView(TemplateView):
"""A generic view for everything based on a mailman.client
list object.
Sets self.mailing_list to list object if fqdn_listname in **kwargs.
"""
def _get_list(self, fqdn_listname):
return List.objects.get_or_404(fqdn_listname=fqdn_listname)
def dispatch(self, request, *args, **kwargs):
# get the list object.
if 'fqdn_listname' in kwargs:
try:
self.mailing_list = self._get_list(kwargs['fqdn_listname'])
except MailmanApiError:
return utils.render_api_error(request)
# set the template
if 'template' in kwargs:
self.template = kwargs['template']
return super(MailingListView, self).dispatch(request, *args, **kwargs)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment