mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
new-admin: Negligible formatting changes to admin.templatetgas.admin_modify and template.decorators
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
95564bb882
commit
03d9d060c9
@ -1,14 +1,12 @@
|
|||||||
from django.core import template, template_loader, meta
|
from django.core import template, template_loader, meta
|
||||||
from django.core.template_loader import render_to_string
|
|
||||||
from django.conf.settings import ADMIN_MEDIA_PREFIX
|
|
||||||
from django.utils.text import capfirst
|
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
from django.utils.text import capfirst
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
from django.core.template.decorators import simple_tag, inclusion_tag
|
from django.core.template.decorators import simple_tag, inclusion_tag
|
||||||
from django.contrib.admin.views.main import AdminBoundField
|
from django.contrib.admin.views.main import AdminBoundField
|
||||||
from django.core.meta.fields import BoundField, Field
|
from django.core.meta.fields import BoundField, Field
|
||||||
from django.core.meta import BoundRelatedObject, TABULAR, STACKED
|
from django.core.meta import BoundRelatedObject, TABULAR, STACKED
|
||||||
|
from django.conf.settings import ADMIN_MEDIA_PREFIX
|
||||||
import re
|
import re
|
||||||
|
|
||||||
word_re = re.compile('[A-Z][a-z]+')
|
word_re = re.compile('[A-Z][a-z]+')
|
||||||
@ -18,11 +16,9 @@ def class_name_to_underscored(name):
|
|||||||
|
|
||||||
#@simple_tag
|
#@simple_tag
|
||||||
def include_admin_script(script_path):
|
def include_admin_script(script_path):
|
||||||
return '<script type="text/javascript" src="%s%s"></script>' % \
|
return '<script type="text/javascript" src="%s%s"></script>' % (ADMIN_MEDIA_PREFIX, script_path)
|
||||||
(ADMIN_MEDIA_PREFIX, script_path)
|
|
||||||
include_admin_script = simple_tag(include_admin_script)
|
include_admin_script = simple_tag(include_admin_script)
|
||||||
|
|
||||||
|
|
||||||
#@inclusion_tag('admin/submit_line', takes_context=True)
|
#@inclusion_tag('admin/submit_line', takes_context=True)
|
||||||
def submit_row(context, bound_manipulator):
|
def submit_row(context, bound_manipulator):
|
||||||
change = context['change']
|
change = context['change']
|
||||||
@ -54,14 +50,11 @@ def field_label(bound_field):
|
|||||||
if not bound_field.first:
|
if not bound_field.first:
|
||||||
class_names.append('inline')
|
class_names.append('inline')
|
||||||
colon = ":"
|
colon = ":"
|
||||||
|
|
||||||
class_str = class_names and ' class="%s"' % ' '.join(class_names) or ''
|
class_str = class_names and ' class="%s"' % ' '.join(class_names) or ''
|
||||||
return '<label for="%s"%s>%s%s</label> ' % \
|
return '<label for="%s"%s>%s%s</label> ' % (bound_field.element_id, class_str, \
|
||||||
(bound_field.element_id, class_str,
|
|
||||||
capfirst(bound_field.field.verbose_name), colon)
|
capfirst(bound_field.field.verbose_name), colon)
|
||||||
field_label = simple_tag(field_label)
|
field_label = simple_tag(field_label)
|
||||||
|
|
||||||
|
|
||||||
class FieldWidgetNode(template.Node):
|
class FieldWidgetNode(template.Node):
|
||||||
nodelists = {}
|
nodelists = {}
|
||||||
default = None
|
default = None
|
||||||
@ -92,7 +85,6 @@ class FieldWidgetNode(template.Node):
|
|||||||
get_nodelist = classmethod(get_nodelist)
|
get_nodelist = classmethod(get_nodelist)
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
|
|
||||||
bound_field = template.resolve_variable(self.bound_field_var, context)
|
bound_field = template.resolve_variable(self.bound_field_var, context)
|
||||||
|
|
||||||
context.push()
|
context.push()
|
||||||
@ -151,7 +143,7 @@ class StackedBoundRelatedObject(BoundRelatedObject):
|
|||||||
|
|
||||||
bound_related_object_overrides = {
|
bound_related_object_overrides = {
|
||||||
TABULAR: TabularBoundRelatedObject,
|
TABULAR: TabularBoundRelatedObject,
|
||||||
STACKED : StackedBoundRelatedObject
|
STACKED: StackedBoundRelatedObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
class EditInlineNode(template.Node):
|
class EditInlineNode(template.Node):
|
||||||
@ -178,13 +170,11 @@ class EditInlineNode(template.Node):
|
|||||||
context.pop()
|
context.pop()
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
#@simple_tag
|
#@simple_tag
|
||||||
def output_all(form_fields):
|
def output_all(form_fields):
|
||||||
return ''.join([str(f) for f in form_fields])
|
return ''.join([str(f) for f in form_fields])
|
||||||
output_all = simple_tag(output_all)
|
output_all = simple_tag(output_all)
|
||||||
|
|
||||||
|
|
||||||
#@simple_tag
|
#@simple_tag
|
||||||
def auto_populated_field_script(auto_pop_fields, change = False):
|
def auto_populated_field_script(auto_pop_fields, change = False):
|
||||||
for field in auto_pop_fields:
|
for field in auto_pop_fields:
|
||||||
@ -220,22 +210,19 @@ def do_one_arg_tag(node_factory, parser,token):
|
|||||||
raise template.TemplateSyntaxError("%s takes 1 argument" % tokens[0])
|
raise template.TemplateSyntaxError("%s takes 1 argument" % tokens[0])
|
||||||
return node_factory(tokens[1])
|
return node_factory(tokens[1])
|
||||||
|
|
||||||
|
|
||||||
one_arg_tag_nodes = [
|
|
||||||
FieldWidgetNode,
|
|
||||||
EditInlineNode,
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def register_one_arg_tag(node):
|
def register_one_arg_tag(node):
|
||||||
tag_name = class_name_to_underscored(node.__name__)
|
tag_name = class_name_to_underscored(node.__name__)
|
||||||
parse_func = curry(do_one_arg_tag, node)
|
parse_func = curry(do_one_arg_tag, node)
|
||||||
template.register_tag(tag_name, parse_func)
|
template.register_tag(tag_name, parse_func)
|
||||||
|
|
||||||
|
one_arg_tag_nodes = (
|
||||||
|
FieldWidgetNode,
|
||||||
|
EditInlineNode,
|
||||||
|
)
|
||||||
|
|
||||||
for node in one_arg_tag_nodes:
|
for node in one_arg_tag_nodes:
|
||||||
register_one_arg_tag(node)
|
register_one_arg_tag(node)
|
||||||
|
|
||||||
|
|
||||||
#@inclusion_tag('admin/field_line', takes_context=True)
|
#@inclusion_tag('admin/field_line', takes_context=True)
|
||||||
def admin_field_line(context, argument_val):
|
def admin_field_line(context, argument_val):
|
||||||
if (isinstance(argument_val, BoundField)):
|
if (isinstance(argument_val, BoundField)):
|
||||||
@ -260,7 +247,7 @@ def admin_field_line(context, argument_val):
|
|||||||
'add': context['add'],
|
'add': context['add'],
|
||||||
'change': context['change'],
|
'change': context['change'],
|
||||||
'bound_fields': bound_fields,
|
'bound_fields': bound_fields,
|
||||||
'class_names' : " ".join(class_names)
|
'class_names': " ".join(class_names),
|
||||||
}
|
}
|
||||||
admin_field_line = inclusion_tag('admin/field_line', takes_context=True)(admin_field_line)
|
admin_field_line = inclusion_tag('admin/field_line', takes_context=True)(admin_field_line)
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from inspect import getargspec
|
|
||||||
from django.core.template import Context, Node, TemplateSyntaxError, register_tag, resolve_variable
|
from django.core.template import Context, Node, TemplateSyntaxError, register_tag, resolve_variable
|
||||||
from django.core.template_loader import render_to_string, get_template
|
from django.core.template_loader import get_template
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
|
from inspect import getargspec
|
||||||
|
|
||||||
def gen_compile_func(params, defaults, name, node_class, parser, token):
|
def generic_tag_compiler(params, defaults, name, node_class, parser, token):
|
||||||
#look in tags for
|
"Returns a template.Node subclass."
|
||||||
bits = token.contents.split()[1:]
|
bits = token.contents.split()[1:]
|
||||||
bmax = len(params)
|
bmax = len(params)
|
||||||
def_len = defaults and len(defaults) or 0
|
def_len = defaults and len(defaults) or 0
|
||||||
@ -14,42 +14,40 @@ def gen_compile_func(params, defaults, name, node_class, parser, token):
|
|||||||
message = "%s takes %s arguments" % (name, bmin)
|
message = "%s takes %s arguments" % (name, bmin)
|
||||||
else:
|
else:
|
||||||
message = "%s takes between %s and %s arguments" % (name, bmin, bmax)
|
message = "%s takes between %s and %s arguments" % (name, bmin, bmax)
|
||||||
raise TemplateSyntaxError(message)
|
raise TemplateSyntaxError, message
|
||||||
return node_class(bits)
|
return node_class(bits)
|
||||||
|
|
||||||
|
|
||||||
def simple_tag(func):
|
def simple_tag(func):
|
||||||
(params,_, _, defaults) = getargspec(func)
|
(params, xx, xxx, defaults) = getargspec(func)
|
||||||
|
|
||||||
class SimpleNode(Node):
|
class SimpleNode(Node):
|
||||||
def __init__(self, vars_to_resolve):
|
def __init__(self, vars_to_resolve):
|
||||||
#get the vars to resolve
|
|
||||||
self.vars_to_resolve = vars_to_resolve
|
self.vars_to_resolve = vars_to_resolve
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
resolved_vars = [resolve_variable(var, context)
|
resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve]
|
||||||
for var in self.vars_to_resolve]
|
|
||||||
return func(*resolved_vars)
|
return func(*resolved_vars)
|
||||||
compile_func = curry(gen_compile_func, params, defaults, func.__name__, SimpleNode)
|
|
||||||
|
compile_func = curry(generic_tag_compiler, params, defaults, func.__name__, SimpleNode)
|
||||||
compile_func.__doc__ = func.__doc__
|
compile_func.__doc__ = func.__doc__
|
||||||
register_tag(func.__name__, compile_func)
|
register_tag(func.__name__, compile_func)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
def inclusion_tag(file_name, context_class=Context, takes_context=False):
|
def inclusion_tag(file_name, context_class=Context, takes_context=False):
|
||||||
def dec(func):
|
def dec(func):
|
||||||
(params,_, _, defaults) = getargspec(func)
|
(params, xx, xxx, defaults) = getargspec(func)
|
||||||
if takes_context:
|
if takes_context:
|
||||||
if params[0] == 'context':
|
if params[0] == 'context':
|
||||||
params = params[1:]
|
params = params[1:]
|
||||||
else:
|
else:
|
||||||
raise TemplateSyntaxError("Any tag function decorated with takes_context=True must have a first argument of 'context'" )
|
raise TemplateSyntaxError, "Any tag function decorated with takes_context=True must have a first argument of 'context'"
|
||||||
|
|
||||||
class InclusionNode(Node):
|
class InclusionNode(Node):
|
||||||
def __init__(self, vars_to_resolve):
|
def __init__(self, vars_to_resolve):
|
||||||
self.vars_to_resolve = vars_to_resolve
|
self.vars_to_resolve = vars_to_resolve
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
resolved_vars = [resolve_variable(var, context)
|
resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve]
|
||||||
for var in self.vars_to_resolve]
|
|
||||||
if takes_context:
|
if takes_context:
|
||||||
args = [context] + resolved_vars
|
args = [context] + resolved_vars
|
||||||
else:
|
else:
|
||||||
@ -62,9 +60,8 @@ def inclusion_tag(file_name, context_class=Context, takes_context=False):
|
|||||||
self.nodelist = t.nodelist
|
self.nodelist = t.nodelist
|
||||||
return self.nodelist.render(context_class(dict))
|
return self.nodelist.render(context_class(dict))
|
||||||
|
|
||||||
compile_func = curry(gen_compile_func, params, defaults, func.__name__, InclusionNode)
|
compile_func = curry(generic_tag_compiler, params, defaults, func.__name__, InclusionNode)
|
||||||
compile_func.__doc__ = func.__doc__
|
compile_func.__doc__ = func.__doc__
|
||||||
register_tag(func.__name__, compile_func)
|
register_tag(func.__name__, compile_func)
|
||||||
return func
|
return func
|
||||||
return dec
|
return dec
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user