Linted wagtailcore

pull/3/head
Neal Todd 2014-02-06 11:33:32 +00:00
rodzic a2a580f0fe
commit 006145a196
14 zmienionych plików z 42 dodań i 11 usunięć

Wyświetl plik

@ -1,5 +1,4 @@
from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import GroupAdmin
@ -8,6 +7,7 @@ from wagtail.wagtailcore.models import Site, Page, GroupPagePermission
admin.site.register(Site)
admin.site.register(Page)
# Extend GroupAdmin to include page permissions as an inline
class GroupPagePermissionInline(admin.TabularInline):
model = GroupPagePermission
@ -15,6 +15,7 @@ class GroupPagePermissionInline(admin.TabularInline):
verbose_name = 'page permission'
verbose_name_plural = 'page permissions'
class GroupAdminWithPagePermissions(GroupAdmin):
inlines = GroupAdmin.inlines + [GroupPagePermissionInline]

Wyświetl plik

@ -4,6 +4,7 @@ from south.modelsinspector import add_introspection_rules
from wagtail.wagtailcore.rich_text import DbWhitelister, expand_db_html
class RichTextArea(Textarea):
def get_panel(self):
from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel

Wyświetl plik

@ -3,6 +3,7 @@ from django.core.exceptions import ObjectDoesNotExist
from wagtail.wagtailcore.models import Page
class Command(NoArgsCommand):
def handle_noargs(self, **options):
problems_found = False

Wyświetl plik

@ -1,4 +1,5 @@
from django.core.management.base import BaseCommand
from wagtail.wagtailcore.models import Page
@ -18,4 +19,4 @@ class Command(BaseCommand):
for page in pages:
page.move(to_page, pos='last-child')
print 'Done'
print 'Done'

Wyświetl plik

@ -1,5 +1,6 @@
from django.core.management.base import BaseCommand
from django.db import models
from wagtail.wagtailcore.models import PageRevision, get_page_types
@ -15,6 +16,7 @@ def replace_in_model(model, from_text, to_text):
if updated_fields:
model.save(update_fields=updated_fields)
class Command(BaseCommand):
def handle(self, from_text, to_text, **options):
for revision in PageRevision.objects.filter(content_json__contains=from_text):

Wyświetl plik

@ -2,6 +2,7 @@ from django.core.management.base import NoArgsCommand
from wagtail.wagtailcore.models import Page
class Command(NoArgsCommand):
def set_subtree(self, root, root_path):
root.url_path = root_path

Wyświetl plik

@ -1,5 +1,6 @@
from wagtail.wagtailcore.models import Site
class SiteMiddleware(object):
def process_request(self, request):
"""

Wyświetl plik

@ -1,17 +1,18 @@
from modelcluster.models import ClusterableModel
from treebeard.mp_tree import MP_Node
from django.db import models, connection, transaction
from django.db.models import get_model, Q
from django.http import Http404
from django.shortcuts import render
from django.core.cache import cache
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Group
from treebeard.mp_tree import MP_Node
from modelcluster.models import ClusterableModel
from wagtail.wagtailsearch import Indexed, Searcher
from wagtail.wagtailcore.util import camelcase_to_underscore
from wagtail.wagtailsearch import Indexed, Searcher
class SiteManager(models.Manager):
def get_by_natural_key(self, hostname):
@ -76,6 +77,8 @@ class Site(models.Model):
PAGE_MODEL_CLASSES = []
_PAGE_CONTENT_TYPES = []
def get_page_types():
global _PAGE_CONTENT_TYPES
if len(_PAGE_CONTENT_TYPES) != len(PAGE_MODEL_CLASSES):
@ -84,8 +87,11 @@ def get_page_types():
]
return _PAGE_CONTENT_TYPES
LEAF_PAGE_MODEL_CLASSES = []
_LEAF_PAGE_CONTENT_TYPE_IDS = []
def get_leaf_page_content_type_ids():
global _LEAF_PAGE_CONTENT_TYPE_IDS
if len(_LEAF_PAGE_CONTENT_TYPE_IDS) != len(LEAF_PAGE_MODEL_CLASSES):
@ -94,8 +100,11 @@ def get_leaf_page_content_type_ids():
]
return _LEAF_PAGE_CONTENT_TYPE_IDS
NAVIGABLE_PAGE_MODEL_CLASSES = []
_NAVIGABLE_PAGE_CONTENT_TYPE_IDS = []
def get_navigable_page_content_type_ids():
global _NAVIGABLE_PAGE_CONTENT_TYPE_IDS
if len(_NAVIGABLE_PAGE_CONTENT_TYPE_IDS) != len(NAVIGABLE_PAGE_MODEL_CLASSES):
@ -104,6 +113,7 @@ def get_navigable_page_content_type_ids():
]
return _NAVIGABLE_PAGE_CONTENT_TYPE_IDS
class PageBase(models.base.ModelBase):
"""Metaclass for Page"""
def __init__(cls, name, bases, dct):
@ -420,6 +430,7 @@ class Page(MP_Node, ClusterableModel, Indexed):
user_perms = UserPagePermissionsProxy(user)
return user_perms.for_page(self)
def get_navigation_menu_items():
# Get all pages that appear in the navigation menu: ones which have children,
# or are a non-leaf type (indicating that they *could* have children),
@ -487,6 +498,7 @@ class SubmittedRevisionsManager(models.Manager):
def get_query_set(self):
return super(SubmittedRevisionsManager, self).get_query_set().filter(submitted_for_moderation=True)
class PageRevision(models.Model):
page = models.ForeignKey('Page', related_name='revisions')
submitted_for_moderation = models.BooleanField(default=False)
@ -537,6 +549,7 @@ PAGE_PERMISSION_TYPE_CHOICES = [
('publish', 'Publish'),
]
class GroupPagePermission(models.Model):
group = models.ForeignKey(Group, related_name='page_permissions')
page = models.ForeignKey('Page', related_name='group_permissions')
@ -580,6 +593,7 @@ class UserPagePermissionsProxy(object):
permission to perform specific tasks on the given page"""
return PagePermissionTester(self, page)
class PagePermissionTester(object):
def __init__(self, user_perms, page):
self.user = user_perms.user

Wyświetl plik

@ -1,17 +1,18 @@
from django.utils.html import escape
import re # parsing HTML with regexes LIKE A BOSS.
from django.utils.html import escape
from wagtail.wagtailcore.whitelist import Whitelister
from wagtail.wagtailcore.models import Page
from wagtail.wagtaildocs.models import Document
# FIXME: we don't really want to import wagtailimages within core.
# For that matter, we probably don't want core to be concerned about translating
# HTML for the benefit of the hallo.js editor...
from wagtail.wagtailimages.models import get_image_model
from wagtail.wagtailimages.formats import get_image_format
from wagtail.wagtaildocs.models import Document
# Define a set of 'embed handlers' and 'link handlers'. These handle the translation
# of 'special' HTML elements in rich text - ones which we do not want to include
@ -187,6 +188,7 @@ FIND_A_TAG = re.compile(r'<a(\b[^>]*)>')
FIND_EMBED_TAG = re.compile(r'<embed(\b[^>]*)/>')
FIND_ATTRS = re.compile(r'([\w-]+)\="([^"]*)"')
def extract_attrs(attr_string):
"""
helper method to extract tag attributes as a dict. Does not escape HTML entities!
@ -196,6 +198,7 @@ def extract_attrs(attr_string):
attributes[name] = val
return attributes
def expand_db_html(html, for_editor=False):
"""
Expand database-representation HTML into proper HTML usable in either

Wyświetl plik

@ -2,6 +2,7 @@ from django import template
register = template.Library()
@register.simple_tag(takes_context=True)
def pageurl(context, page):
"""

Wyświetl plik

@ -5,6 +5,7 @@ from wagtail.wagtailcore.rich_text import expand_db_html
register = template.Library()
@register.filter
def richtext(value):
return mark_safe(expand_db_html(value))

Wyświetl plik

@ -1,10 +1,11 @@
from django.conf.urls import patterns, url
urlpatterns = patterns('wagtail.wagtailcore.views',
urlpatterns = patterns(
'wagtail.wagtailcore.views',
# All front-end views are handled through Wagtail's core.views.serve mechanism.
# Here we match a (possibly empty) list of path segments, each followed by
# a '/'. If a trailing slash is not present, we leave CommonMiddleware to
# handle it as usual (i.e. redirect it to the trailing slash version if
# settings.APPEND_SLASH is True)
url(r'^((?:[\w\-]+/)*)$', 'serve' )
url(r'^((?:[\w\-]+/)*)$', 'serve')
)

Wyświetl plik

@ -1,5 +1,6 @@
import re
def camelcase_to_underscore(str):
# http://djangosnippets.org/snippets/585/
return re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', str).lower().strip('_')

Wyświetl plik

@ -8,6 +8,7 @@ from urlparse import urlparse
ALLOWED_URL_SCHEMES = ['', 'http', 'https', 'ftp', 'mailto', 'tel']
def check_url(url_string):
# TODO: more paranoid checks (urlparse doesn't catch "jav\tascript:alert('XSS')")
url = urlparse(url_string)
@ -46,6 +47,7 @@ def attribute_rule(allowed_attrs):
allow_without_attributes = attribute_rule({})
class Whitelister(object):
element_rules = {
'[document]': allow_without_attributes,