Permalink
Browse files

(some) pep8 cleanup

  • Loading branch information...
1 parent 581ca78 commit e63900511ac38ae51029e63d96227a2217a1d706 @groovecoder groovecoder committed Feb 7, 2013
Showing with 105 additions and 85 deletions.
  1. +18 −15 apps/wiki/models.py
  2. +24 −26 apps/wiki/tests/test_views.py
  3. +63 −44 apps/wiki/views.py
View
@@ -53,7 +53,8 @@
# Note: <iframe> is allowed, but src="" is pre-filtered before bleach
'iframe',
'table', 'tbody', 'thead', 'tfoot', 'tr', 'th', 'td', 'colgroup', 'col',
- 'section', 'header', 'footer', 'nav', 'article', 'aside', 'figure', 'figcaption',
+ 'section', 'header', 'footer', 'nav', 'article', 'aside', 'figure',
+ 'figcaption',
'dialog', 'hgroup', 'mark', 'time', 'meter', 'command', 'output',
'progress', 'audio', 'video', 'details', 'datagrid', 'datalist', 'table',
'address', 'font',
@@ -73,7 +74,8 @@
ALLOWED_ATTRIBUTES['p'] = ['style', 'class', 'id', 'align', 'lang', 'dir']
ALLOWED_ATTRIBUTES['span'] = ['style', 'class', 'id', 'title', 'lang', 'dir']
ALLOWED_ATTRIBUTES['img'] = ['src', 'id', 'align', 'alt', 'class', 'is',
- 'title', 'style', 'lang', 'dir', 'width', 'height']
+ 'title', 'style', 'lang', 'dir', 'width',
+ 'height']
ALLOWED_ATTRIBUTES['a'] = ['style', 'id', 'class', 'href', 'title',
'lang', 'name', 'dir', 'hreflang', 'rel']
ALLOWED_ATTRIBUTES['td'] = ['style', 'id', 'class', 'colspan', 'rowspan',
@@ -86,10 +88,12 @@
ALLOWED_ATTRIBUTES['select'] = ['name', 'dir']
ALLOWED_ATTRIBUTES['option'] = ['value', 'selected', 'dir']
ALLOWED_ATTRIBUTES['ol'] = ['style', 'class', 'id', 'lang', 'start', 'dir']
-ALLOWED_ATTRIBUTES.update(dict((x, ['style', 'class', 'id', 'name', 'lang', 'dir'])
+ALLOWED_ATTRIBUTES.update(dict((x, ['style', 'class', 'id', 'name', 'lang',
+ 'dir'])
for x in
('h1', 'h2', 'h3', 'h4', 'h5', 'h6')))
-ALLOWED_ATTRIBUTES.update(dict((x, ['style', 'class', 'id', 'lang', 'dir']) for x in (
+ALLOWED_ATTRIBUTES.update(dict((x, ['style', 'class', 'id', 'lang', 'dir'])
+ for x in (
'div', 'pre', 'ul', 'li', 'code', 'dl', 'dt', 'dd',
'section', 'header', 'footer', 'nav', 'article', 'aside', 'figure',
'dialog', 'hgroup', 'mark', 'time', 'meter', 'command', 'output',
@@ -357,7 +361,7 @@ def clean_content(self, content_in, use_constance_bleach_whitelists=False):
.parse(content_in)
.filterIframeHosts(allowed_hosts)
.serialize())
-
+
if use_constance_bleach_whitelists:
tags = constance.config.BLEACH_ALLOWED_TAGS
attributes = constance.config.BLEACH_ALLOWED_ATTRIBUTES
@@ -646,7 +650,6 @@ def calculate_etag(self, section_id=None):
.serialize())
return '"%s"' % hashlib.sha1(content.encode('utf8')).hexdigest()
-
@property
def is_rendering_scheduled(self):
"""Does this have a rendering scheduled?"""
@@ -763,7 +766,8 @@ def render(self, cache_control=None, base_url=None, timeout=None):
self.rendered_html, self.rendered_errors = self.html, []
else:
self.rendered_html, errors = kumascript.get(self, cache_control,
- base_url, timeout=timeout)
+ base_url,
+ timeout=timeout)
self.rendered_errors = errors and json.dumps(errors) or None
# Finally, note the end time of rendering and update the document.
@@ -949,7 +953,7 @@ def revise(self, user, data, section_id=None):
new_rev.save()
new_rev.review_tags.set(*parse_tags(review_tags))
return new_rev
-
+
def save(self, *args, **kwargs):
self.is_template = self.slug.startswith(TEMPLATE_TITLE_PREFIX)
self.is_redirect = 1 if self.redirect_url() else 0
@@ -1041,7 +1045,7 @@ def _tree_conflicts(self, new_slug):
child_title = child.slug.split('/')[-1]
try:
existing = Document.objects.get(locale=self.locale,
- slug='/'.join([new_slug, child_title]))
+ slug='/'.join([new_slug, child_title]))
if not existing.redirect_url():
conflicts.append(existing)
except Document.DoesNotExist:
@@ -1169,7 +1173,7 @@ def files_dict(self):
'description': rev.description,
'mime_type': rev.mime_type,
'html': attachment.get_embed_html(),
- 'url': attachment.get_file_url(),}
+ 'url': attachment.get_file_url()}
return files
@property
@@ -1388,9 +1392,8 @@ def other_translations(self):
if self.parent == None:
translations = list(self.translations.all().order_by('locale'))
else:
- translations = list(self.parent.translations.all().exclude(
- id=self.id).
- order_by('locale'))
+ translations = list(self.parent.translations.all().
+ exclude(id=self.id).order_by('locale'))
translations.insert(0, self.parent)
return translations
@@ -1796,7 +1799,7 @@ class DocumentAttachment(models.Model):
Intermediary between Documents and Attachments. Allows storing the
user who attached a file to a document, and a (unique for that
document) name for referring to the file from the document.
-
+
"""
file = models.ForeignKey('Attachment')
document = models.ForeignKey(Document)
@@ -1878,7 +1881,7 @@ def get_embed_html(self):
'wiki/attachments/%s.html' % rev.mime_type.split('/')[0],
'wiki/attachments/generic.html'])
return t.render({'attachment': rev})
-
+
class AttachmentRevision(models.Model):
"""
@@ -148,7 +148,8 @@ def test_toc_view(self):
slug = 'toc_test_doc'
html = '<h2>Head 2</h2><h3>Head 3</h3>'
- doc = document(title='blah', slug=slug, html=html, save=True, locale=settings.WIKI_DEFAULT_LANGUAGE)
+ doc = document(title='blah', slug=slug, html=html, save=True,
+ locale=settings.WIKI_DEFAULT_LANGUAGE)
doc.save()
rev = revision(document=doc, content=html, is_approved=True, save=True)
rev.save()
@@ -157,7 +158,9 @@ def test_toc_view(self):
locale=settings.WIKI_DEFAULT_LANGUAGE)
resp = self.client.get(url)
- eq_(resp.content, '<ol><li><a href="#Head_2" rel="internal">Head 2</a><ol><li><a href="#Head_3" rel="internal">Head 3</a></ol></li></ol>')
+ eq_(resp.content, '<ol><li><a href="#Head_2" rel="internal">Head 2</a>'
+ '<ol><li><a href="#Head_3" rel="internal">Head 3</a>'
+ '</ol></li></ol>')
def test_children_view(self):
def _make_doc(title, slug, parent=None):
@@ -189,8 +192,8 @@ def _make_doc(title, slug, parent=None):
# Depth parameter testing
def _depth_test(depth, aught):
- url = reverse('wiki.get_children', args=['Root'],
- locale=settings.WIKI_DEFAULT_LANGUAGE) + '?depth=' + str(depth)
+ url = reverse('wiki.get_children', args=['Root'],
+ locale=settings.WIKI_DEFAULT_LANGUAGE) + '?depth=' + str(depth)
resp = self.client.get(url)
json_obj = json.loads(resp.content)
eq_(len(json_obj['subpages'][0]['subpages'][1]['subpages']), aught)
@@ -201,8 +204,10 @@ def _depth_test(depth, aught):
# Sorting test
sort_root_doc = _make_doc('Sort Root', 'Sort_Root')
- sort_child_doc_1 = _make_doc('B Child', 'Sort_Root/B_Child', sort_root_doc)
- sort_child_doc_2 = _make_doc('A Child', 'Sort_Root/A_Child', sort_root_doc)
+ sort_child_doc_1 = _make_doc('B Child', 'Sort_Root/B_Child',
+ sort_root_doc)
+ sort_child_doc_2 = _make_doc('A Child', 'Sort_Root/A_Child',
+ sort_root_doc)
resp = self.client.get(reverse('wiki.get_children', args=['Sort_Root'],
locale=settings.WIKI_DEFAULT_LANGUAGE))
json_obj = json.loads(resp.content)
@@ -717,7 +722,7 @@ def test_noindex_post(self):
# Go to new document page to ensure no-index header works
response = client.get(reverse('wiki.new_document', args=[],
- locale=settings.WIKI_DEFAULT_LANGUAGE))
+ locale=settings.WIKI_DEFAULT_LANGUAGE))
eq_(response['X-Robots-Tag'], 'noindex')
def test_seo_title(self):
@@ -1027,7 +1032,7 @@ def test_invalid_slug(self):
response = client.post(reverse('wiki.new_document'), data)
self.assertRedirects(response,
reverse('wiki.document', args=[data['slug']],
- locale=settings.WIKI_DEFAULT_LANGUAGE))
+ locale=settings.WIKI_DEFAULT_LANGUAGE))
# Slashes should not be acceptable via form input
data['title'] = 'valid with slash'
@@ -1256,7 +1261,6 @@ def test_invalid_slug_edit(inv_slug, url, data):
locale=locale,
args=[edit_doc.slug]))
-
""" TRANSLATION DOCUMENT TESTING """
def _run_translate_tests(translate_slug, translate_data,
translate_doc):
@@ -1294,7 +1298,6 @@ def test_invalid_slug_translate(inv_slug, url, data):
' Redirect 1',
locale=foreign_locale)))
-
# Push a valid translation
translate_data['slug'] = translate_slug
translate_data['form'] = 'both'
@@ -1342,7 +1345,6 @@ def _run_translate_edit_tests(edit_slug, edit_data, edit_doc):
eq_(0, len(Document.objects.filter(title=edit_data['title'] + ' Redirect 1', locale=foreign_locale))) # Ensure no redirect
self.assertRedirects(response, reverse('wiki.document', locale=foreign_locale, args=[edit_doc.slug]))
-
""" TEST EDITING SLUGS AND TRANSLATIONS """
def _run_slug_edit_tests(edit_slug, edit_data, edit_doc, loc):
@@ -1354,7 +1356,6 @@ def _run_slug_edit_tests(edit_slug, edit_data, edit_doc, loc):
eq_(1, len(Document.objects.filter(title__contains=edit_data['title'] + ' Redir', locale=loc))) # Ensure *1* redirect
self.assertRedirects(response, reverse('wiki.document', locale=loc, args=[edit_doc.slug.replace(edit_slug, edit_data['slug'])]))
-
# Run all of the tests
_createAndRunTests("parent")
@@ -1460,15 +1461,14 @@ def test_clone(self):
content = '<p>Hello!</p>'
document = revision(save=True, title=title, slug=slug, content=content).document
-
+
response = self.client.get(reverse('wiki.new_document', args=[], locale=settings.WIKI_DEFAULT_LANGUAGE) + '?clone=' + str(document.id))
page = pq(response.content)
eq_(page.find('input[name=title]')[0].value, title)
eq_(page.find('input[name=slug]')[0].value, slug + '_clone')
eq_(page.find('textarea[name=content]')[0].value, content)
-
def test_localized_based_on(self):
"""Editing a localized article 'based on' an older revision of the
localization is OK."""
@@ -1646,7 +1646,7 @@ def test_review_tags(self, get_current):
# Post an edit that removes one of the tags.
data.update({
'form': 'rev',
- 'review_tags': ['editorial',],
+ 'review_tags': ['editorial',]
})
response = client.post(reverse('wiki.edit_document', args=[doc.full_path]), data)
@@ -2415,11 +2415,11 @@ def test_document_redirects(self):
def test_list_no_redirects(self):
invalidDocuments = (
- {'title': 'Something Redirect 8', 'slug': 'xx',
+ {'title': 'Something Redirect 8', 'slug': 'xx',
'html': 'REDIRECT <a class="redirect" href="http://davidwalsh.name">yo</a>'},
{'title': 'My Template', 'slug': 'Template:Something', 'html': 'blah'},
)
- validDocuments = ({ 'title': 'A Doc', 'slug': 'blah', 'html': 'Blah blah blah'},)
+ validDocuments = ({'title': 'A Doc', 'slug': 'blah', 'html': 'Blah blah blah'},)
allDocuments = invalidDocuments + validDocuments
for doc in allDocuments:
@@ -2629,7 +2629,7 @@ def test_raw_content_during_initial_render(self, mock_kumascript_get):
ok_(self.rendered_content not in txt)
ok_(self.raw_content in txt)
eq_(0, p.find('#doc-render-raw-fallback').length)
-
+
# Only for logged-in users, ensure that a warning is displayed about
# the fallback
self.client.login(username='testuser', password='testpass')
@@ -2686,7 +2686,7 @@ def test_alternate_bleach_whitelist(self, mock_requests_post, mock_kumascript_ge
<textarea name="foo"></textarea>
</p>
"""
-
+
# Expected result filtered through alternate whitelist
expected_content_new = """
<p id="foo">
@@ -2697,7 +2697,7 @@ def test_alternate_bleach_whitelist(self, mock_requests_post, mock_kumascript_ge
# Set up an alternate set of whitelists...
constance.config.BLEACH_ALLOWED_TAGS = json.dumps([
- "a","p"
+ "a", "p"
])
constance.config.BLEACH_ALLOWED_ATTRIBUTES = json.dumps({
"a": ['href', 'style'],
@@ -2744,7 +2744,7 @@ def test_alternate_bleach_whitelist(self, mock_requests_post, mock_kumascript_ge
resp = self.client.get(url, follow=True)
eq_(normalize_html(expected),
normalize_html(resp.content),
- "Should match? %s %s %s %s" %
+ "Should match? %s %s %s %s" %
(do_login, param, expected, resp.content))
@@ -3125,7 +3125,6 @@ def _post_new_attachment(self):
resp = self.client.post(reverse('wiki.new_attachment'), data=post_data)
return resp
-
def test_legacy_redirect(self):
self.client = Client() # file views don't need LocalizingClient
test_user = User.objects.get(username='testuser2')
@@ -3354,7 +3353,7 @@ def test_intermediate(self):
"""
Test that the intermediate DocumentAttachment gets created
correctly when adding an Attachment with a document_id.
-
+
"""
doc = document(locale='en', slug='attachment-test-intermediate')
doc.save()
@@ -3410,7 +3409,7 @@ def test_files_dict(self):
self.client.login(username='admin', password='testpass')
resp = self.client.post(add_url, data=post_data)
-
+
test_file_2 = make_test_file(
content='Another file for testing the files dict')
@@ -3420,7 +3419,7 @@ def test_files_dict(self):
'comment': 'Initial upload',
'file': test_file_2,
}
-
+
resp = self.client.post(add_url, data=post_data)
doc = Document.objects.get(pk=doc.id)
@@ -3597,7 +3596,6 @@ def test_move_top_level_docs(self):
page_child_doc.parent_topic = page_to_move_doc
page_child_doc.save()
-
# move page to new slug
new_title = page_to_move_title + ' Moved'
data = {'slug': page_moved_slug, 'title': new_title}
Oops, something went wrong.

0 comments on commit e639005

Please sign in to comment.