1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +00:00

Fixed order_with_respect_to (finally), but still didn't add dom-drag.js because I don't know the licence.

Fixes for some filtering stuff. 

Other cleanups. 


git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1028 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams 2005-10-31 00:35:14 +00:00
parent 938b46d72f
commit ce8f990a0d
13 changed files with 61 additions and 45 deletions

View File

@ -6,6 +6,7 @@
####################
DEBUG = False
TEMPLATE_DEBUG = False
# Whether to use the "Etag" header. This saves bandwidth but slows down performance.
USE_ETAGS = False

View File

@ -1,6 +1,7 @@
# Django settings for {{ project_name }} project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@domain.com'),

View File

@ -60,11 +60,11 @@
{% if bound_manipulator.ordered_objects %}
{% if form.order_objects %}<ul id="orderthese">
{% for object in form.order_objects %}
<li id="p{% firstof bound_manipulator.ordered_object_names %}">
<span id="handlep{% firstof bound_manipulator.ordered_object_names %}">{{ object|truncatewords:"5" }}</span>
<li id="p{% object_pk bound_manipulator object %}">
<span id="handlep{% object_pk bound_manipulator object %}">{{ object|truncatewords:"5" }}</span>
</li>
{% endfor%}
{% endif %}
</ul>{% endif %}
{% endif %}
{% endif %}
</form></div>

View File

@ -6,7 +6,7 @@
{% block content %}
<div id="content-main">
{%if has_add_permission %}
<ul class="object-tools"><li><a href="add/{%if is_popup%}?_popup=1{%endif%}" class="addlink">Add {{cl.opts.verbose_name}}</a></li></ul>\n'
<ul class="object-tools"><li><a href="add/{%if is_popup%}?_popup=1{%endif%}" class="addlink">Add {{cl.opts.verbose_name}}</a></li></ul>
{% endif %}
<div class="module{%if cl.has_filters%} filtered{%endif%}" id="changelist">
{% search_form cl%}

View File

@ -33,7 +33,7 @@
{% endfor %} </table>
{% for fcw in bound_related_object.form_field_collection_wrapper_list %}
{% for fcw in bound_related_object.form_field_collection_wrappers %}
{% for bound_field in fcw.bound_fields %}
{% if bound_field.not_in_table %}
{% field_widget bound_field %}

View File

@ -4,7 +4,7 @@
<input type="text" size="40" name="{{search_var}}" value="{{cl.query|escape}}" id="searchbar" />
<input type="submit" value="Go" />
{%if show_result_count %}
<span class="small quiet">{{cl.result_count}}s result{{cl.result_count|pluralize}} (<a href="?">{{cl.full_result_count}} total</a>)</span>
<span class="small quiet">{{cl.result_count}} result{{cl.result_count|pluralize}} (<a href="?">{{cl.full_result_count}} total</a>)</span>
{%endif%}
{% for pair in cl.params.items %}
{%ifnotequal pair.0 search_var%}<input type="hidden" name="{{pair.0|escape}}" value="{{pair.1|escape}}"/>{%endifnotequal%}

View File

@ -9,7 +9,7 @@ from django.utils.html import strip_tags, escape
from django.core.exceptions import ObjectDoesNotExist
from django.conf.settings import ADMIN_MEDIA_PREFIX
from django.core import template
from django.utils import dateformat
DOT = '.'
class QueryStringNode(template.Node):

View File

@ -43,9 +43,7 @@ def submit_row(context):
'show_save_and_continue': not is_popup,
'show_save': True
}
srdec = inclusion_tag('admin/submit_line', takes_context=True)
submit_row = srdec(submit_row)
submit_row = inclusion_tag('admin/submit_line', takes_context=True)(submit_row)
#@simple_tag
def field_label(bound_field):
@ -123,17 +121,22 @@ class FieldWrapper(object):
and self.field.rel.raw_id_admin
class FormFieldCollectionWrapper(object):
def __init__(self, field_mapping, fields):
self.field_mapping = field_mapping
self.fields = fields
self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mapping['original']) for field in self.fields ]
self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mapping['original'])
for field in self.fields ]
class TabularBoundRelatedObject(BoundRelatedObject):
def __init__(self, related_object, field_mapping, original):
super(TabularBoundRelatedObject, self).__init__(related_object, field_mapping, original)
self.field_wrapper_list = self.relation.editable_fields(FieldWrapper)
fields = self.relation.editable_fields()
self.form_field_collection_wrappers = [FormFieldCollectionWrapper(field_mapping ,fields)
for field_mapping in self.field_mappings]
self.original_row_needed = max([fw.use_raw_id_admin() for fw in self.field_wrapper_list])
@ -200,8 +203,10 @@ def auto_populated_field_script(auto_pop_fields, change = False):
add_values = ' + " " + '.join(['document.getElementById("id_%s").value' % g for g in field.prepopulate_from])
for f in field.prepopulate_from:
t.append('document.getElementById("id_%s").onkeyup = function() { var e = document.getElementById("id_%s"); if(!e._changed) { e.value = URLify(%s, %s);} } ' % (f, field.name, add_values, field.maxlength) )
t.append('document.getElementById("id_%s").onkeyup = function() {' \
' var e = document.getElementById("id_%s");' \
' if(!e._changed) { e.value = URLify(%s, %s);} } ' % (
f, field.name, add_values, field.maxlength) )
return ''.join(t)
auto_populated_field_script = simple_tag(auto_populated_field_script)
@ -209,7 +214,9 @@ auto_populated_field_script = simple_tag(auto_populated_field_script)
def filter_interface_script_maybe(bound_field):
f = bound_field.field
if f.rel and isinstance(f.rel, meta.ManyToMany) and f.rel.filter_interface:
return '<script type="text/javascript">addEvent(window, "load", function(e) { SelectFilter.init("id_%s", "%s", %s, %r); });</script>\n' % (f.name, f.verbose_name, f.rel.filter_interface-1, ADMIN_MEDIA_PREFIX)
return '<script type="text/javascript">addEvent(window, "load", function(e) {' \
' SelectFilter.init("id_%s", "%s", %s, %r); });</script>\n' % (
f.name, f.verbose_name, f.rel.filter_interface-1, ADMIN_MEDIA_PREFIX)
else:
return ''
filter_interface_script_maybe = simple_tag(filter_interface_script_maybe)
@ -262,9 +269,10 @@ def admin_field_line(context, argument_val):
'bound_fields' : bound_fields,
'class_names' : " ".join(class_names)
}
admin_field_line = inclusion_tag('admin/field_line', takes_context=True)(admin_field_line)
#@simple_tag
def object_pk(bound_manip, ordered_obj):
return bound_manip.get_ordered_object_pk(ordered_obj)
afbdec = inclusion_tag('admin/field_line', takes_context=True)
admin_field_line = afbdec(admin_field_line)
object_pk = simple_tag(object_pk)

View File

@ -106,9 +106,9 @@ class RelatedFilterSpec(FilterSpec):
t.append('<h3>By %s:</h3>\n<ul>\n' % self.lookup_title)
t.append('<li%s><a href="%s">All</a></li>\n' % \
((self.lookup_val is None and ' class="selected"' or ''),
cl.get_query_string({}, [lookup_kwarg])))
for val in lookup_choices:
pk_val = getattr(val, f.rel.to.pk.column)
cl.get_query_string({}, [self.lookup_kwarg])))
for val in self.lookup_choices:
pk_val = getattr(val, self.field.rel.to.pk.column)
t.append('<li%s><a href="%s">%r</a></li>\n' % \
((self.lookup_val == str(pk_val) and ' class="selected"' or ''),
cl.get_query_string( {self.lookup_kwarg: pk_val}), val))
@ -121,7 +121,7 @@ class ChoicesFilterSpec(FilterSpec):
def __init__(self, f, request, params):
super(ChoicesFilterSpec, self).__init__(f, request, params)
self.lookup_kwarg = '%s__exact' % f.name
self.lookup_val = request.GET.get(lookup_kwarg, None)
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
def output(self, cl):
t = []
@ -129,10 +129,10 @@ class ChoicesFilterSpec(FilterSpec):
t.append('<li%s><a href="%s">All</a></li>\n' % \
((self.lookup_val is None and ' class="selected"' or ''),
cl.get_query_string( {}, [self.lookup_kwarg])))
for k, v in f.choices:
for k, v in self.field.choices:
t.append('<li%s><a href="%s">%s</a></li>' % \
((str(k) == self.lookup_val) and ' class="selected"' or '',
cl.get_query_string( {lookup_kwarg: k}), v))
cl.get_query_string( {self.lookup_kwarg: k}), v))
t.append('</ul>\n\n')
return "".join(t)
FilterSpec.register(lambda f: bool(f.choices), ChoicesFilterSpec)
@ -144,11 +144,11 @@ class DateFieldFilterSpec(FilterSpec):
self.field_generic = '%s__' % self.field.name
self.date_params = dict([(k, v) for k, v in params.items() if k.startswith(field_generic)])
self.date_params = dict([(k, v) for k, v in params.items() if k.startswith(self.field_generic)])
today = datetime.date.today()
one_week_ago = today - datetime.timedelta(days=7)
today_str = isinstance(self.f, meta.DateTimeField) and today.strftime('%Y-%m-%d 23:59:59') or today.strftime('%Y-%m-%d')
today_str = isinstance(self.field, meta.DateTimeField) and today.strftime('%Y-%m-%d 23:59:59') or today.strftime('%Y-%m-%d')
self.links = (
('Any date', {}),
@ -386,6 +386,7 @@ def change_list(request, app_label, module_name):
'is_popup': cl.is_popup,
'cl' : cl
})
c.update( { 'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}),
return render_to_response('admin/change_list',
context_instance = c)
change_list = staff_member_required(change_list)
@ -505,7 +506,7 @@ class AdminBoundManipulator(object):
self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();
self.ordered_object_names = ' '.join(['object.%s' % o.pk.name for o in self.ordered_objects])
self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects]
self.save_on_top = opts.admin.save_on_top
self.save_as = opts.admin.save_as
@ -515,6 +516,12 @@ class AdminBoundManipulator(object):
self.verbose_name = opts.verbose_name
self.object_name = opts.object_name
def get_ordered_object_pk(self, ordered_obj):
for name in self.ordered_object_pk_names:
if hasattr(ordered_obj, name):
return str(getattr(ordered_obj, name))
return ""
def render_change_form(opts, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''):
extra_context = {

View File

@ -55,7 +55,7 @@ times with multiple contexts)
'\n<html>\n\n</html>\n'
"""
import re
from django.conf.settings import DEFAULT_CHARSET, DEBUG
from django.conf.settings import DEFAULT_CHARSET, TEMPLATE_DEBUG
__all__ = ('Template','Context','compile_string')
@ -128,8 +128,9 @@ class StringOrigin(Origin):
class Template:
def __init__(self, template_string, origin=None):
"Compilation stage"
if origin == None:
if TEMPLATE_DEBUG and origin == None:
origin = StringOrigin(template_string)
#Could do some crazy stack frame stuff to record where this string came from...
self.nodelist = compile_string(template_string, origin)
def __iter__(self):
@ -143,7 +144,7 @@ class Template:
def compile_string(template_string, origin):
"Compiles template_string into NodeList ready for rendering"
if DEBUG:
if TEMPLATE_DEBUG:
lexer_factory = DebugLexer
parser_factory = DebugParser
else:

View File

@ -142,7 +142,6 @@ class IfEqualNode(Node):
def render(self, context):
val1 = resolve_variable(self.var1, context)
val2 = resolve_variable(self.var2, context)
if (self.negate and val1 != val2) or (not self.negate and val1 == val2):
return self.nodelist_true.render(context)
return self.nodelist_false.render(context)

View File

@ -21,7 +21,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.template import Origin, StringOrigin, Template, Context, Node, TemplateDoesNotExist, TemplateSyntaxError, resolve_variable_with_filters, register_tag
from django.conf.settings import TEMPLATE_LOADERS
from django.conf.settings import TEMPLATE_LOADERS, TEMPLATE_DEBUG
template_source_loaders = []
for path in TEMPLATE_LOADERS:
@ -30,7 +30,6 @@ for path in TEMPLATE_LOADERS:
try:
mod = __import__(module, globals(), locals(), [attr])
except ImportError, e:
raise e
raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e)
try:
func = getattr(mod, attr)
@ -44,19 +43,23 @@ for path in TEMPLATE_LOADERS:
class LoaderOrigin(Origin):
def __init__(self, display_name, loader, name, dirs):
def reload():
return loader(name, dirs)[0]
super(LoaderOrigin, self).__init__(display_name)
self._reload = reload
self.loader, self.name, self.dirs = loader, name, dirs
def reload(self):
return self._reload()
return self.loader(self.name, self.dirs)
def make_origin(display_name, loader, name, dirs):
if TEMPLATE_DEBUG:
LoaderOrigin(display_name, loader, name, dirs)
else:
return None
def find_template_source(name, dirs=None):
for loader in template_source_loaders:
try:
source, display_name = loader(name, dirs)
return (source, LoaderOrigin(display_name, loader, name, dirs))
return (source, make_origin(display_name, loader, name, dirs))
except TemplateDoesNotExist:
pass
raise TemplateDoesNotExist, name
@ -79,9 +82,6 @@ def get_template_from_string(source, origin=None ):
Returns a compiled Template object for the given template code,
handling template inheritance recursively.
"""
if origin==None:
#Could do some crazy stack frame stuff to record where this string came from.
origin = StringOrigin(source)
return Template(source, origin)
def render_to_string(template_name, dictionary=None, context_instance=None):
@ -241,7 +241,7 @@ def do_extends(parser, token):
if len(bits) != 2:
raise TemplateSyntaxError, "'%s' takes one argument" % bits[0]
parent_name, parent_name_var = None, None
if (bits[1].startswith('"') and bits[1].endswith('"')) or (bits[1].startswith("'") and bits[1].endswith("'")):
if bits[1][0] in ('"', "'") and bits[1][-1] == bits[1][0]:
parent_name = bits[1][1:-1]
else:
parent_name_var = bits[1]

View File

@ -24,7 +24,6 @@ for app in INSTALLED_APPS:
if os.path.isdir(template_dir):
app_template_dirs.append(template_dir)
# It won't change, so convert it to a tuple to save memory.
app_template_dirs = tuple(app_template_dirs)