From ce8f990a0d811926e13751ef548d54c5b8b95574 Mon Sep 17 00:00:00 2001 From: Robert Wittams Date: Mon, 31 Oct 2005 00:35:14 +0000 Subject: [PATCH] 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 --- django/conf/global_settings.py | 1 + django/conf/project_template/settings.py | 1 + .../admin/templates/admin/change_form.html | 6 ++-- .../admin/templates/admin/change_list.html | 2 +- .../templates/admin/edit_inline_tabular.html | 4 +-- .../admin/templates/admin/search_form.html | 2 +- .../contrib/admin/templatetags/admin_list.py | 2 +- .../admin/templatetags/admin_modify.py | 30 ++++++++++++------- django/contrib/admin/views/main.py | 27 ++++++++++------- django/core/template/__init__.py | 7 +++-- django/core/template/defaulttags.py | 1 - django/core/template/loader.py | 22 +++++++------- .../core/template/loaders/app_directories.py | 1 - 13 files changed, 61 insertions(+), 45 deletions(-) diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 40e230b04c..7a238e3864 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -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 diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py index eaeeb56a53..5135508f0f 100644 --- a/django/conf/project_template/settings.py +++ b/django/conf/project_template/settings.py @@ -1,6 +1,7 @@ # Django settings for {{ project_name }} project. DEBUG = True +TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email@domain.com'), diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 84f1ea7b87..fa6b8ed9df 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -60,11 +60,11 @@ {% if bound_manipulator.ordered_objects %} {% if form.order_objects %}{% endif %} {% endif %} {% endif %} diff --git a/django/contrib/admin/templates/admin/change_list.html b/django/contrib/admin/templates/admin/change_list.html index 78b51a5916..3b0abe89a5 100644 --- a/django/contrib/admin/templates/admin/change_list.html +++ b/django/contrib/admin/templates/admin/change_list.html @@ -6,7 +6,7 @@ {% block content %}
{%if has_add_permission %} - \n' + {% endif %}
{% search_form cl%} diff --git a/django/contrib/admin/templates/admin/edit_inline_tabular.html b/django/contrib/admin/templates/admin/edit_inline_tabular.html index ddfe6f0ff2..d759d70e3f 100644 --- a/django/contrib/admin/templates/admin/edit_inline_tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline_tabular.html @@ -33,9 +33,9 @@ {% endfor %} - {% 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 %} + {% if bound_field.not_in_table %} {% field_widget bound_field %} {% endif %} {% endfor %} diff --git a/django/contrib/admin/templates/admin/search_form.html b/django/contrib/admin/templates/admin/search_form.html index d93c069a54..c80a00d00c 100644 --- a/django/contrib/admin/templates/admin/search_form.html +++ b/django/contrib/admin/templates/admin/search_form.html @@ -4,7 +4,7 @@ {%if show_result_count %} - {{cl.result_count}}s result{{cl.result_count|pluralize}} ({{cl.full_result_count}} total) + {{cl.result_count}} result{{cl.result_count|pluralize}} ({{cl.full_result_count}} total) {%endif%} {% for pair in cl.params.items %} {%ifnotequal pair.0 search_var%}{%endifnotequal%} diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index d03d27b036..3bc1034492 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -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): diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py index aed13c22c9..995b2844f5 100644 --- a/django/contrib/admin/templatetags/admin_modify.py +++ b/django/contrib/admin/templatetags/admin_modify.py @@ -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): @@ -122,18 +120,23 @@ class FieldWrapper(object): return isinstance(self.field.rel, (meta.ManyToOne, meta.ManyToMany)) \ 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 '\n' % (f.name, f.verbose_name, f.rel.filter_interface-1, ADMIN_MEDIA_PREFIX) + return '\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) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 3c8c150242..0b2f87dff5 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -106,9 +106,9 @@ class RelatedFilterSpec(FilterSpec): t.append('

By %s:

\n
    \n' % self.lookup_title) t.append('All\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('%r\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('All\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('%s' % \ ((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('
\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', {}), @@ -160,7 +160,7 @@ class DateFieldFilterSpec(FilterSpec): ('This month', {'%s__year' % self.field.name: str(today.year), '%s__month' % f.name: str(today.month)}), ('This year', {'%s__year' % self.field.name: str(today.year)}) - ) + ) def output(self, cl): t = [] @@ -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 = { diff --git a/django/core/template/__init__.py b/django/core/template/__init__.py index 4008958e91..1b4056b9ca 100644 --- a/django/core/template/__init__.py +++ b/django/core/template/__init__.py @@ -55,7 +55,7 @@ times with multiple contexts) '\n\n\n\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: diff --git a/django/core/template/defaulttags.py b/django/core/template/defaulttags.py index 7913c154ec..cc59dad388 100644 --- a/django/core/template/defaulttags.py +++ b/django/core/template/defaulttags.py @@ -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) diff --git a/django/core/template/loader.py b/django/core/template/loader.py index 81e6cbf30e..b3ccad89da 100644 --- a/django/core/template/loader.py +++ b/django/core/template/loader.py @@ -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] diff --git a/django/core/template/loaders/app_directories.py b/django/core/template/loaders/app_directories.py index 8753e16bd7..4e88728dae 100644 --- a/django/core/template/loaders/app_directories.py +++ b/django/core/template/loaders/app_directories.py @@ -23,7 +23,6 @@ for app in INSTALLED_APPS: template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') 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)