Commit 2a89b3dd authored by Florian Fuchs's avatar Florian Fuchs

* PEP8 conformity (LP: 1027496)

parents db943311 172c6e24
......@@ -16,5 +16,4 @@
# You should have received a copy of the GNU General Public License along with
# Postorius. If not, see <http://www.gnu.org/licenses/>.
__version__ = '1.0.0a1'
__version__ = '1.0.0a2'
# -*- coding: utf-8 -*-
# Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
# Copyright (C) 2012 by the Free Software Foundation, Inc.
#
# This file is part of Postorius.
#
......@@ -32,11 +32,9 @@ def postorius(request):
"""
# extend_template (no page header/footer when requested via AJAX)
if request.is_ajax():
extend_template = "postorius/base_ajax.html"
else:
extend_template = "postorius/base_ajax.html"
else:
extend_template = "postorius/base.html"
return {
'MAILMAN_THEME': settings.MAILMAN_THEME,
'extend_template': extend_template,
}
return {'MAILMAN_THEME': settings.MAILMAN_THEME,
'extend_template': extend_template}
......@@ -33,6 +33,7 @@ along with Postorius. If not, see <http://www.gnu.org/licenses/>.
* added list members view
* added developer documentation
* added test helper utils
* all code now conform to PEP8
1.0 alpha 1 -- "Space Farm"
......
......@@ -21,9 +21,11 @@ from django.utils import safestring
from django.forms.forms import BoundField
from django.forms.util import ErrorList
class FieldsetError(Exception):
pass
class FieldsetForm(Form):
"""
Extends a standard form and adds fieldsets and the possibililty
......@@ -41,14 +43,16 @@ class FieldsetForm(Form):
self.layout = self.Meta.layout
else:
self.layout = [["All"]]
self.layout[0][1:]=(self.fields.keys())
self.layout[0][1:] = (self.fields.keys())
def as_div(self):
"""Render the form as a set of <div>s."""
output = ""
#Adding Errors
try: output += str(self.errors["NON_FIELD_ERRORS"])
except: pass
try:
output += str(self.errors["NON_FIELD_ERRORS"])
except:
pass
#create the fieldsets
for index in range(len(self.layout)):
output += self.create_fieldset(self.layout[index])
......@@ -61,9 +65,10 @@ class FieldsetForm(Form):
it should include.
"""
# Create the divs in each fieldset by calling create_divs.
return u'<fieldset><legend>%s</legend>%s</fieldset>' % (field[0],
return u'<fieldset><legend>%s</legend>%s</fieldset>' % (
field[0],
self.create_divs(field[1:]))
def create_divs(self, fields):
"""Create a <div> for each field."""
output = ""
......@@ -73,17 +78,18 @@ class FieldsetForm(Form):
field_instance = self.fields[field]
except KeyError:
# could not create the instance so throw an exception
# msg on a separate line since the line got too long
# msg on a separate line since the line got too long
# otherwise
msg = "Could not resolve form field '%s'." % field
raise FieldsetError(msg)
# create a bound field containing all the necessary fields
# create a bound field containing all the necessary fields
# from the form
bound_field = BoundField(self, field_instance, field)
output += '<div class="field %(class)s">%(label)s%(help_text)s%(errors)s%(field)s</div>\n' % \
{'class': bound_field.name,
'label': bound_field.label,
'help_text': bound_field.help_text,
'errors': bound_field.errors,
'field': unicode(bound_field)}
output += '<div class="field %(class)s">%(label)s%(help_text)s%' \
'(errors)s%(field)s</div>\n' % \
{'class': bound_field.name,
'label': bound_field.label,
'help_text': bound_field.help_text,
'errors': bound_field.errors,
'field': unicode(bound_field)}
return output
This diff is collapsed.
......@@ -33,6 +33,7 @@ class MailmanApiError(Exception):
"""
pass
class Mailman404Error(Exception):
"""Proxy exception. Raised if the API returns 404."""
pass
......@@ -42,7 +43,7 @@ class MailmanRestManager(object):
"""Manager class to give a model class CRUD access to the API.
Returns objects (or lists of objects) retrived from the API.
"""
def __init__(self, resource_name, resource_name_plural, cls_name=None):
self.client = Client('%s/3.0' % settings.REST_SERVER,
settings.API_USER, settings.API_PASS)
......@@ -71,7 +72,6 @@ class MailmanRestManager(object):
except MailmanConnectionError, e:
raise MailmanApiError(e)
def get_or_404(self, **kwargs):
"""Similar to `self.get` but raises standard Django 404 error.
"""
......@@ -143,7 +143,7 @@ class MailmanRestModel(object):
self.kwargs = kwargs
def save(self):
"""Proxy function for `objects.create`.
"""Proxy function for `objects.create`.
(REST API uses `create`, while Django uses `save`.)
"""
self.objects.create(**self.kwargs)
......
......@@ -7,7 +7,7 @@
# 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
# 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.
......
......@@ -23,11 +23,13 @@ import tempfile
import subprocess
from django.conf import settings
class Testobject:
bindir = None
vardir = None
cfgfile = None
def setup_mm(testobject):
os.environ['MAILMAN_TEST_BINDIR'] = settings.MAILMAN_TEST_BINDIR
bindir = testobject.bindir = os.environ.get('MAILMAN_TEST_BINDIR')
......@@ -37,7 +39,7 @@ def setup_mm(testobject):
cfgfile = testobject.cfgfile = os.path.join(vardir, 'client_test.cfg')
with open(cfgfile, 'w') as fp:
print >> fp, """\
[mailman]
[mailman]
layout: tmpdir
[paths.tmpdir]
var_dir: {vardir}
......@@ -70,6 +72,7 @@ start: no
time.sleep(3)
return testobject
def teardown_mm(testobject):
bindir = testobject.bindir
cfgfile = testobject.cfgfile
......
......@@ -7,7 +7,7 @@
# 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
# 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.
......@@ -22,12 +22,11 @@ from mock import patch
class ListMembersViewTest(unittest.TestCase):
"""Tests for the ListMembersView."""
def setUp(self):
from django.test.client import RequestFactory
from postorius.tests.utils import create_mock_list, create_mock_member
self.request_factory = RequestFactory()
# create a mock list with members
list_name = '[email protected]'
self.mock_list = create_mock_list(dict(
......@@ -44,7 +43,6 @@ class ListMembersViewTest(unittest.TestCase):
def test_get_list(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:
......@@ -60,18 +58,23 @@ class ListMembersViewTest(unittest.TestCase):
with patch('mailman.client.Client.get_list') as mock:
mock.return_value = self.mock_list
request = self.request_factory.get(
'/lists/[email protected]/members/')
'/lists/[email protected]/members/')
# anonymous users should be redirected
request.user = AnonymousUser()
response = ListMembersView.as_view()(request, '[email protected]')
response = ListMembersView.as_view()(request,
'[email protected]')
self.assertEqual(response.status_code, 302)
# logged in users should be redirected
request.user = User.objects.create_user('les', '[email protected]', 'pwd')
response = ListMembersView.as_view()(request, '[email protected]')
request.user = User.objects.create_user('les', '[email protected]',
'pwd')
response = ListMembersView.as_view()(request,
'[email protected]')
self.assertEqual(response.status_code, 302)
# superusers should get the page
request.user = User.objects.create_superuser('su', '[email protected]', 'pwd')
response = ListMembersView.as_view()(request, '[email protected]')
request.user = User.objects.create_superuser('su', '[email protected]',
'pwd')
response = ListMembersView.as_view()(request,
'[email protected]')
self.assertEqual(response.status_code, 200)
def tearDown(self):
......
......@@ -7,7 +7,7 @@
# 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
# 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.
......
......@@ -7,7 +7,7 @@
# 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
# 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.
......@@ -17,15 +17,16 @@
from mock import patch, MagicMock
def create_mock_domain(properties=None):
"""Create and return a mocked Domain.
:param properties: A dictionary of the domain's properties.
:type properties: dict
:return: A MagicMock object with the properties set.
:rtype: MagicMock
"""
mock_object = MagicMock(name='Domain')
mock_object = MagicMock(name='Domain')
mock_object.base_url = ''
mock_object.contact_address = ''
mock_object.description = ''
......@@ -34,33 +35,35 @@ def create_mock_domain(properties=None):
mock_object.lists = []
if properties is not None:
for key in properties:
setattr(mock_object, key, properties[key])
setattr(mock_object, key, properties[key])
return mock_object
def create_mock_list(properties=None):
"""Create and return a mocked List.
:param properties: A dictionary of the list's properties.
:type properties: dict
:return: A MagicMock object with the properties set.
:rtype: MagicMock
"""
mock_object = MagicMock(name='List')
mock_object = MagicMock(name='List')
if properties is not None:
for key in properties:
setattr(mock_object, key, properties[key])
setattr(mock_object, key, properties[key])
return mock_object
def create_mock_member(properties=None):
"""Create and return a mocked Member.
:param properties: A dictionary of the member's properties.
:type properties: dict
:return: A MagicMock object with the properties set.
:rtype: MagicMock
"""
mock_object = MagicMock(name='Member')
mock_object = MagicMock(name='Member')
if properties is not None:
for key in properties:
setattr(mock_object, key, properties[key])
setattr(mock_object, key, properties[key])
return mock_object
......@@ -23,7 +23,8 @@ from django.conf.urls.static import static
from postorius.views import ListMembersView
urlpatterns = patterns('postorius.views',
urlpatterns = patterns(
'postorius.views',
(r'^$', 'list_index'),
# /account/
url(r'^accounts/login/$', 'user_login', name='user_login'),
......@@ -43,8 +44,8 @@ urlpatterns = patterns('postorius.views',
# /lists/
url(r'^lists/$', 'list_index', name='list_index'),
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>[^/]+)/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',
......@@ -57,27 +58,21 @@ urlpatterns = patterns('postorius.views',
'list_subscriptions', name='list_subscriptions'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/mass_subscribe/$',
'mass_subscribe', 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>[^/]+)/accept$',
'accept_held_message',
name='accept_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/discard$',
'discard_held_message',
name='discard_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/defer$',
'defer_held_message',
name='defer_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/reject$',
'reject_held_message',
name='reject_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/delete$',
'list_delete', name='list_delete'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/'
'accept$', 'accept_held_message', name='accept_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/'
'discard$', 'discard_held_message', name='discard_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/'
'defer$', 'defer_held_message', name='defer_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages/(?P<msg_id>[^/]+)/'
'reject$', 'reject_held_message', name='reject_held_message'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/held_messages$',
'list_held_messages',
name='list_held_messages'),
'list_held_messages', name='list_held_messages'),
url(r'^user_settings/$', 'user_settings', kwargs={"tab": "user"},
name='user_settings'),
url(r'^lists/(?P<fqdn_listname>[^/]+)/settings/(?P<visible_section>[^/]+)?(?:/(?P<visible_option>.*))?$',
'list_settings', name='list_settings'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
url(r'^lists/(?P<fqdn_listname>[^/]+)/settings/(?P<visible_section>[^/]+)?'
'(?:/(?P<visible_option>.*))?$', 'list_settings',
name='list_settings'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
......@@ -22,16 +22,17 @@ from django.template import RequestContext
def get_domain_name(request):
"""Extracts a domain name from the request object.
"""
"""
if "HTTP_HOST" in request.META.keys():
return request.META["HTTP_HOST"].split(":")[0]
return None
def render_api_error(request):
"""Renders an error template.
Use if MailmanApiError is catched.
"""
return render_to_response('postorius/errors/generic.html',
{'error': "REST API not found / Offline"},
context_instance=RequestContext(request))
return render_to_response(
'postorius/errors/generic.html',
{'error': "REST API not found / Offline"},
context_instance=RequestContext(request))
This diff is collapsed.
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