Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
(some) code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Feb 12, 2013
1 parent 87c3261 commit b178b59
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
20 changes: 13 additions & 7 deletions apps/wiki/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ def _massage_diff_content(content):
def bugize_text(content):
content = jinja2.escape(content)
content = re.sub(r'bug\s+#?(\d+)',
jinja2.Markup('<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=\\1" target="_blank">bug \\1</a>'),
jinja2.Markup('<a href="https://bugzilla.mozilla.org/'
'show_bug.cgi?id=\\1" '
'target="_blank">bug \\1</a>'),
content)
return content


@register.function
def format_comment(rev):
""" Massages revision comment content after the fact """
Expand All @@ -147,7 +150,10 @@ def format_comment(rev):

# If a page move, say so
if prev_rev and prev_rev.slug != rev.slug:
comment += jinja2.Markup('<span class="slug-change">Moved From <strong>%s</strong> to <strong>%s</strong></span>') % (prev_rev.slug, rev.slug)
comment += jinja2.Markup('<span class="slug-change">'
'Moved From <strong>%s</strong> '
'to <strong>%s</strong></span>') % (
prev_rev.slug, rev.slug)

return comment

Expand All @@ -162,11 +168,11 @@ def diff_table(content_from, content_to, prev_id, curr_id):
to_lines = tidy_to.splitlines()
try:
diff = html_diff.make_table(from_lines, to_lines,
_("Revision %s") % prev_id,
_("Revision %s") % curr_id,
context=True,
numlines=constance.config.DIFF_CONTEXT_LINES
)
_("Revision %s") % prev_id,
_("Revision %s") % curr_id,
context=True,
numlines=constance.config.DIFF_CONTEXT_LINES
)
except RuntimeError:
# some diffs hit a max recursion error
message = _(u'There was an error generating the content.')
Expand Down
28 changes: 24 additions & 4 deletions apps/wiki/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class GetSEODescriptionTests(TestCase):

def test_html_elements_spaces(self):
# No spaces with html tags
content = (u'<p><span class="seoSummary">The <strong>Document Object Model'
content = (u'<p><span class="seoSummary">The <strong>Document Object '
'Model'
'</strong> (<strong>DOM</strong>) is an API for '
'<a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a> and '
'<a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> '
Expand All @@ -18,13 +19,32 @@ def test_html_elements_spaces(self):
'<a href="/en-US/docs/JavaScript" '
'title="https://developer.mozilla.org/en-US/docs/JavaScript">'
'JavaScript</a>.</span></p>')
expected = ('The Document Object Model (DOM) is an API for HTML and XML'
expected = ('The Document Object Model (DOM) is an API for HTML and '
'XML'
' documents. It provides a structural representation of the'
' document, enabling you to modify its content and visual'
' presentation by using a scripting language such as'
' JavaScript.')
eq_(expected, get_seo_description(content, 'en-US'))

content = (u'<p><span class="seoSummary"><strong>Cascading Style Sheets</strong>, most of the time abbreviated in <strong>CSS</strong>, is a <a href="/en-US/docs/DOM/stylesheet">stylesheet</a> language used to describe the presentation of a document written in <a href="/en-US/docs/HTML" title="The HyperText Mark-up Language">HTML</a></span> or <a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> (including various XML languages like <a href="/en-US/docs/SVG" title="en-US/docs/SVG">SVG</a> or <a href="/en-US/docs/XHTML" title="en-US/docs/XHTML">XHTML</a>)<span class="seoSummary">. CSS describes how the structured element must be rendered on screen, on paper, in speech, or on other media.</span></p>')
expected = ('Cascading Style Sheets, most of the time abbreviated in CSS, is a stylesheet language used to describe the presentation of a document written in HTML. CSS describes how the structured element must be rendered on screen, on paper, in speech, or on other media.')
content = (u'<p><span class="seoSummary"><strong>Cascading Style '
'Sheets</strong>, most of the time abbreviated in '
'<strong>CSS</strong>, is a '
'<a href="/en-US/docs/DOM/stylesheet">stylesheet</a> '
'language used to describe the presentation of a document '
'written in <a href="/en-US/docs/HTML" title="The '
'HyperText Mark-up Language">HTML</a></span> or <a '
'href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> '
'(including various XML languages like <a '
'href="/en-US/docs/SVG" title="en-US/docs/SVG">SVG</a> or '
'<a href="/en-US/docs/XHTML" '
'title="en-US/docs/XHTML">XHTML</a>)<span '
'class="seoSummary">. CSS describes how the structured '
'element must be rendered on screen, on paper, in speech, '
'or on other media.</span></p>')
expected = ('Cascading Style Sheets, most of the time abbreviated in '
'CSS, is a stylesheet language used to describe the '
'presentation of a document written in HTML. CSS '
'describes how the structured element must be rendered on '
'screen, on paper, in speech, or on other media.')
eq_(expected, get_seo_description(content, 'en-US'))
19 changes: 14 additions & 5 deletions apps/wiki/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,19 +1329,28 @@ def test_invalid_slug_translate(inv_slug, url, data):
def _run_translate_edit_tests(edit_slug, edit_data, edit_doc):

# Hit the initial URL
response = client.get(reverse('wiki.edit_document', args=[edit_doc.slug], locale=foreign_locale))
response = client.get(reverse('wiki.edit_document',
args=[edit_doc.slug],
locale=foreign_locale))
eq_(200, response.status_code)
page = pq(response.content)
eq_(edit_data['slug'], page.find('input[name=slug]')[0].value)

# Attempt an invalid edit of the root, ensure the slug stays the same (i.e. no parent prepending)
# Attempt an invalid edit of the root, ensure the slug stays
# the same (i.e. no parent prepending)
edit_data['slug'] = invalid_slug
edit_data['form'] = 'both'
response = client.post(reverse('wiki.edit_document', args=[edit_doc.slug], locale=foreign_locale), edit_data)
response = client.post(reverse('wiki.edit_document',
args=[edit_doc.slug],
locale=foreign_locale),
edit_data)
eq_(200, response.status_code) # 200 = bad, invalid data
page = pq(response.content)
eq_(invalid_slug, page.find('input[name=slug]')[0].value) # Slug doesn't add parent
self.assertContains(response, page.find('ul.errorlist li a[href="#id_slug"]').text())
# Slug doesn't add parent
eq_(invalid_slug, page.find('input[name=slug]')[0].value)
self.assertContains(response, page.find('ul.errorlist li'
' a[href="#id_slug"]').
text())
eq_(0, len(Document.objects.filter(title=edit_data['title'] + ' Redirect 1', locale=foreign_locale))) # Ensure no redirect

# Push a valid edit, without changing the slug
Expand Down
21 changes: 4 additions & 17 deletions apps/wiki/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# coding=utf-8

from datetime import datetime
import time
import json
from collections import defaultdict
import base64
import httplib
import hashlib
import logging
from urllib import urlencode
Expand All @@ -16,11 +12,6 @@
except:
from StringIO import StringIO

import requests
import bleach

from taggit.utils import parse_tags, edit_string_for_tags

try:
from functools import wraps
except ImportError:
Expand All @@ -44,7 +35,6 @@
import constance.config

from waffle.decorators import waffle_flag
from waffle import flag_is_active

import jingo
from tower import ugettext_lazy as _lazy
Expand All @@ -57,9 +47,9 @@

from access.decorators import permission_required, login_required
from sumo.helpers import urlparams
from sumo.urlresolvers import Prefixer, reverse
from sumo.urlresolvers import reverse
from sumo.utils import paginate, smart_int
from wiki import (DOCUMENTS_PER_PAGE, TEMPLATE_TITLE_PREFIX, ReadOnlyException)
from wiki import (DOCUMENTS_PER_PAGE, TEMPLATE_TITLE_PREFIX)
from wiki.decorators import check_readonly
from wiki.events import (EditDocumentEvent, ReviewableRevisionInLocaleEvent,
ApproveRevisionInLocaleEvent)
Expand All @@ -68,24 +58,21 @@
TreeMoveForm)
from wiki.models import (Document, Revision, HelpfulVote, EditorToolbar,
DocumentTag, ReviewTag, Attachment,
DocumentRenderingInProgress,
DocumentRenderedContentNotAvailable,
CATEGORIES,
OPERATING_SYSTEMS, GROUPED_OPERATING_SYSTEMS,
FIREFOX_VERSIONS, GROUPED_FIREFOX_VERSIONS,
REVIEW_FLAG_TAGS_DEFAULT, ALLOWED_ATTRIBUTES,
ALLOWED_TAGS, ALLOWED_STYLES,
REVIEW_FLAG_TAGS_DEFAULT,
DOCUMENT_LAST_MODIFIED_CACHE_KEY_TMPL,
get_current_or_latest_revision)
from wiki.tasks import send_reviewed_notification, schedule_rebuild_kb
from wiki.tasks import send_reviewed_notification
from wiki.helpers import format_comment, get_seo_description
import wiki.content
from wiki import kumascript

from pyquery import PyQuery as pq
from django.utils.safestring import mark_safe

import logging

log = logging.getLogger('k.wiki')

Expand Down

0 comments on commit b178b59

Please sign in to comment.