Merge remote-tracking branch 'remotes/nyergler/pep8-ification'
Conflicts: mediagoblin/db/migrations.py mediagoblin/db/models.py mediagoblin/user_pages/views.py mediagoblin/util.py
This commit is contained in:
@@ -21,6 +21,7 @@ DISPLAY_IMAGE_FETCHING_ORDER = [u'medium', u'original', u'thumb']
|
||||
global TESTS_ENABLED
|
||||
TESTS_ENABLED = False
|
||||
|
||||
|
||||
def import_component(import_string):
|
||||
"""
|
||||
Import a module component defined by STRING. Probably a method,
|
||||
|
||||
@@ -24,7 +24,7 @@ from mediagoblin.tools import common
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
# We have two "test inboxes" here:
|
||||
#
|
||||
#
|
||||
# EMAIL_TEST_INBOX:
|
||||
# ----------------
|
||||
# If you're writing test views, you'll probably want to check this.
|
||||
@@ -44,11 +44,12 @@ from mediagoblin.tools import common
|
||||
# ***IMPORTANT!***
|
||||
# ----------------
|
||||
# Before running tests that call functions which send email, you should
|
||||
# always call _clear_test_inboxes() to "wipe" the inboxes clean.
|
||||
# always call _clear_test_inboxes() to "wipe" the inboxes clean.
|
||||
|
||||
EMAIL_TEST_INBOX = []
|
||||
EMAIL_TEST_MBOX_INBOX = []
|
||||
|
||||
|
||||
class FakeMhost(object):
|
||||
"""
|
||||
Just a fake mail host so we can capture and test messages
|
||||
@@ -63,12 +64,14 @@ class FakeMhost(object):
|
||||
'to': to_addrs,
|
||||
'message': message})
|
||||
|
||||
|
||||
def _clear_test_inboxes():
|
||||
global EMAIL_TEST_INBOX
|
||||
global EMAIL_TEST_MBOX_INBOX
|
||||
EMAIL_TEST_INBOX = []
|
||||
EMAIL_TEST_MBOX_INBOX = []
|
||||
|
||||
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
### </Special email test stuff>
|
||||
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -19,8 +19,10 @@ import copy
|
||||
from math import ceil, floor
|
||||
from itertools import izip, count
|
||||
|
||||
|
||||
PAGINATION_DEFAULT_PER_PAGE = 30
|
||||
|
||||
|
||||
class Pagination(object):
|
||||
"""
|
||||
Pagination class for mongodb queries.
|
||||
@@ -37,9 +39,9 @@ class Pagination(object):
|
||||
Args:
|
||||
- page: requested page
|
||||
- per_page: number of objects per page
|
||||
- cursor: db cursor
|
||||
- jump_to_id: ObjectId, sets the page to the page containing the object
|
||||
with _id == jump_to_id.
|
||||
- cursor: db cursor
|
||||
- jump_to_id: ObjectId, sets the page to the page containing the
|
||||
object with _id == jump_to_id.
|
||||
"""
|
||||
self.page = page
|
||||
self.per_page = per_page
|
||||
@@ -91,19 +93,19 @@ class Pagination(object):
|
||||
last = num
|
||||
|
||||
def get_page_url_explicit(self, base_url, get_params, page_no):
|
||||
"""
|
||||
"""
|
||||
Get a page url by adding a page= parameter to the base url
|
||||
"""
|
||||
"""
|
||||
new_get_params = copy.copy(get_params or {})
|
||||
new_get_params['page'] = page_no
|
||||
return "%s?%s" % (
|
||||
base_url, urllib.urlencode(new_get_params))
|
||||
|
||||
def get_page_url(self, request, page_no):
|
||||
"""
|
||||
"""
|
||||
Get a new page url based of the request, and the new page number.
|
||||
|
||||
This is a nice wrapper around get_page_url_explicit()
|
||||
"""
|
||||
"""
|
||||
return self.get_page_url_explicit(
|
||||
request.full_path, request.GET, page_no)
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
from webob import Response, exc
|
||||
from mediagoblin.tools.template import render_template
|
||||
|
||||
|
||||
def render_to_response(request, template, context, status=200):
|
||||
"""Much like Django's shortcut.render()"""
|
||||
return Response(
|
||||
render_template(request, template, context),
|
||||
status=status)
|
||||
|
||||
|
||||
def render_404(request):
|
||||
"""
|
||||
Render a 404.
|
||||
@@ -30,9 +32,10 @@ def render_404(request):
|
||||
return render_to_response(
|
||||
request, 'mediagoblin/404.html', {}, status=400)
|
||||
|
||||
|
||||
def redirect(request, *args, **kwargs):
|
||||
"""Returns a HTTPFound(), takes a request and then urlgen params"""
|
||||
|
||||
|
||||
querystring = None
|
||||
if kwargs.get('querystring'):
|
||||
querystring = kwargs.get('querystring')
|
||||
|
||||
@@ -17,18 +17,19 @@
|
||||
from math import ceil
|
||||
import jinja2
|
||||
from babel.localedata import exists
|
||||
from babel.support import LazyProxy
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin import messages
|
||||
from mediagoblin.tools import common
|
||||
from mediagoblin.tools.translate import setup_gettext
|
||||
from mediagoblin.middleware.csrf import render_csrf_form_token
|
||||
|
||||
|
||||
SETUP_JINJA_ENVS = {}
|
||||
|
||||
|
||||
def get_jinja_env(template_loader, locale):
|
||||
"""
|
||||
Set up the Jinja environment,
|
||||
Set up the Jinja environment,
|
||||
|
||||
(In the future we may have another system for providing theming;
|
||||
for now this is good enough.)
|
||||
@@ -60,6 +61,7 @@ def get_jinja_env(template_loader, locale):
|
||||
|
||||
return template_env
|
||||
|
||||
|
||||
# We'll store context information here when doing unit tests
|
||||
TEMPLATE_TEST_CONTEXT = {}
|
||||
|
||||
@@ -76,8 +78,8 @@ def render_template(request, template_path, context):
|
||||
context['request'] = request
|
||||
context['csrf_token'] = render_csrf_form_token(request)
|
||||
rendered = template.render(context)
|
||||
|
||||
if common.TESTS_ENABLED:
|
||||
|
||||
if common.TESTS_ENABLED:
|
||||
TEMPLATE_TEST_CONTEXT[template_path] = context
|
||||
|
||||
return rendered
|
||||
@@ -87,6 +89,7 @@ def clear_test_template_context():
|
||||
global TEMPLATE_TEST_CONTEXT
|
||||
TEMPLATE_TEST_CONTEXT = {}
|
||||
|
||||
|
||||
def gridify_list(this_list, num_cols=5):
|
||||
"""
|
||||
Generates a list of lists where each sub-list's length depends on
|
||||
|
||||
@@ -21,6 +21,7 @@ from lxml.html.clean import Cleaner
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.tools import url
|
||||
|
||||
|
||||
# A super strict version of the lxml.html cleaner class
|
||||
HTML_CLEANER = Cleaner(
|
||||
scripts=True,
|
||||
@@ -42,6 +43,7 @@ HTML_CLEANER = Cleaner(
|
||||
host_whitelist=(),
|
||||
whitelist_tags=set([]))
|
||||
|
||||
|
||||
def clean_html(html):
|
||||
# clean_html barfs on an empty string
|
||||
if not html:
|
||||
@@ -49,6 +51,7 @@ def clean_html(html):
|
||||
|
||||
return HTML_CLEANER.clean_html(html)
|
||||
|
||||
|
||||
def convert_to_tag_list_of_dicts(tag_string):
|
||||
"""
|
||||
Filter input from incoming string containing user tags,
|
||||
@@ -73,6 +76,7 @@ def convert_to_tag_list_of_dicts(tag_string):
|
||||
'slug': url.slugify(tag.strip())})
|
||||
return taglist
|
||||
|
||||
|
||||
def media_tags_as_string(media_entry_tags):
|
||||
"""
|
||||
Generate a string from a media item's tags, stored as a list of dicts
|
||||
@@ -85,9 +89,11 @@ def media_tags_as_string(media_entry_tags):
|
||||
[tag['name'] for tag in media_entry_tags])
|
||||
return media_tag_string
|
||||
|
||||
|
||||
TOO_LONG_TAG_WARNING = \
|
||||
u'Tags must be shorter than %s characters. Tags that are too long: %s'
|
||||
|
||||
|
||||
def tag_length_validator(form, field):
|
||||
"""
|
||||
Make sure tags do not exceed the maximum tag length.
|
||||
@@ -105,6 +111,7 @@ def tag_length_validator(form, field):
|
||||
|
||||
MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape')
|
||||
|
||||
|
||||
def cleaned_markdown_conversion(text):
|
||||
"""
|
||||
Take a block of text, run it through MarkDown, and clean its HTML.
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
import re
|
||||
import translitcodec
|
||||
|
||||
|
||||
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
|
||||
|
||||
|
||||
def slugify(text, delim=u'-'):
|
||||
"""
|
||||
Generates an ASCII-only slug. Taken from http://flask.pocoo.org/snippets/5/
|
||||
|
||||
Reference in New Issue
Block a user