1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

Merged trunk changes, and converted submit lines to use a template

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@741 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams 2005-09-30 13:39:24 +00:00
parent d0ba57ee90
commit eb07d93938
11 changed files with 99 additions and 50 deletions

View File

@ -18,10 +18,10 @@
#changelist {position:relative; width:100%;}
#changelist table {width:100%;}
.change-list .filtered table { border-right:1px solid #ddd; }
.change-list .filtered table { border-right:1px solid #ddd, width:100%; }
.change-list .filtered {min-height:400px; _height:400px;}
.change-list .filtered {background:white url(../img/admin/changelist-bg.gif) top right repeat-y !important;}
.change-list .filtered table, .filtered .paginator, .filtered #toolbar, .filtered div.xfull {margin-right:160px !important; width:auto !important; }
.change-list .filtered .paginator, .filtered #toolbar, .filtered div.xfull {margin-right:160px !important; width:auto !important; }
.change-list .filtered table tbody th {padding-right:10px;}
#changelist .toplinks {border-bottom:1px solid #ccc !important;}
#changelist .paginator { color:#666; border-top:1px solid #eee; border-bottom:1px solid #eee; background:white url(../img/admin/nav-bg.gif) 0 180% repeat-x; overflow:hidden;}

View File

@ -0,0 +1,7 @@
<div class="submit-row">
{% if show_delete_link %}<p class="float-left"><a href="delete/" class="deletelink">Delete</a></p>{% endif %}
{% if show_save_as_new %}<input type="submit" value="Save as new" name="_saveasnew" {{onclick_attrib}}/>{%endif%}
{% if show_save_and_add_another %}<input type="submit" value="Save and add another" name="_addanother" {{onclick_attrib}} />{% endif %}
{% if show_save_and_continue %}<input type="submit" value="Save and continue editing" name="_continue" {{onclick_attrib}}/>{% endif %}
{% if show_save %}<input type="submit" value="Save" class="default" {{onclick_attrib}}/>{% endif %}
</div>

View File

@ -98,6 +98,9 @@ class ForNode(template.Node):
# shortcuts for current loop iteration number
'counter0': i,
'counter': i+1,
# reverse counter iteration numbers
'revcounter': len_values - i,
'revcounter0': len_values - i - 1,
# boolean values designating first and last times through loop
'first': (i == 0),
'last': (i == len_values - 1),
@ -445,6 +448,10 @@ def do_for(parser, token):
========================== ================================================
``forloop.counter`` The current iteration of the loop (1-indexed)
``forloop.counter0`` The current iteration of the loop (0-indexed)
``forloop.revcounter`` The number of iterations from the end of the
loop (1-indexed)
``forloop.revcounter0`` The number of iterations from the end of the
loop (0-indexed)
``forloop.first`` True if this is the first time through the loop
``forloop.last`` True if this is the last time through the loop
``forloop.parentloop`` For nested loops, this is the loop "above" the

View File

@ -156,18 +156,23 @@ get_sql_reset.args = APP_ARGS
def get_sql_initial_data(mod):
"Returns a list of the initial INSERT SQL statements for the given module."
from django.core import db
output = []
app_label = mod._MODELS[0]._meta.app_label
output.append(_get_packages_insert(app_label))
app_dir = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), '../sql'))
for klass in mod._MODELS:
opts = klass._meta
# Add custom SQL, if it's available.
sql_file_name = os.path.join(app_dir, opts.module_name + '.sql')
if os.path.exists(sql_file_name):
fp = open(sql_file_name, 'r')
output.append(fp.read())
fp.close()
sql_files = [os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE + '.sql'),
os.path.join(app_dir, opts.module_name + '.sql')]
for sql_file in sql_files:
if os.path.exists(sql_file):
fp = open(sql_file)
output.append(fp.read())
fp.close()
# Content types.
output.append(_get_contenttype_insert(opts))
# Permissions.

View File

@ -1,4 +1,5 @@
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
@ -8,42 +9,54 @@ from django.views.admin.main import AdminBoundField
import re
class IncludeAdminScriptNode(template.Node):
def __init__(self, var):
self.var = var
def __init__(self, var):
self.var = var
def render(self, context):
def render(self, context):
resolved = template.resolve_variable(self.var, context)
return '<script type="text/javascript" src="%s%s"></script>' % \
(ADMIN_MEDIA_PREFIX, resolved)
return '<script type="text/javascript" src="%s%s"></script>' % \
(ADMIN_MEDIA_PREFIX, resolved)
class SubmitRowNode(template.Node):
def __init__(self):
pass
def __init__(self):
pass
def render(self, context):
change = context['change']
add = context['add']
show_delete = context['show_delete']
ordered_objects = context['ordered_objects']
save_as = context['save_as']
has_delete_permission = context['has_delete_permission']
is_popup = context['is_popup']
def render(self, context):
change = context['change']
add = context['add']
show_delete = context['show_delete']
ordered_objects = context['ordered_objects']
save_as = context['save_as']
has_delete_permission = context['has_delete_permission']
is_popup = context['is_popup']
t = ['<div class="submit-row">']
onclick_attrib = ordered_objects and change and 'onclick="submitOrderForm();"' or ''
if not is_popup:
if has_delete_permission and (change or show_delete):
t.append('<p class="float-left"><a href="delete/" class="deletelink">Delete</a></p>')
if change and save_as:
t.append('<input type="submit" value="Save as new" name="_saveasnew" %s/>' % onclick_attrib)
if (not save_as or add):
t.append('<input type="submit" value="Save and add another" name="_addanother" %s/>' % onclick_attrib)
t.append('<input type="submit" value="Save and continue editing" name="_continue" %s/>' % onclick_attrib )
t.append('<input type="submit" value="Save" class="default" %s/>' % onclick_attrib)
t.append('</div>\n')
output = render_to_string('admin_submit_line', {
'onclick_attrib' : (ordered_objects and change
and 'onclick="submitOrderForm();"' or ''),
'show_delete_link' : (not is_popup and has_delete_permission
and (change or show_delete)),
'show_save_as_new' : not is_popup and change and save_as,
'show_save_and_add_another': not is_popup and (not save_as or add),
'show_save_and_continue': not is_popup,
'show_save': True
}, context);
context.pop()
return output;
# t = ['<div class="submit-row">']
return ''.join(t)
# if not is_popup:
# if has_delete_permission and (change or show_delete):
# t.append('<p class="float-left"><a href="delete/" class="deletelink">Delete</a></p>')
# if change and save_as:
# t.append('<input type="submit" value="Save as new" name="_saveasnew" %s/>' % onclick_attrib)
# if (not save_as or add):
# t.append('<input type="submit" value="Save and add another" name="_addanother" %s/>' % onclick_attrib)
# t.append('<input type="submit" value="Save and continue editing" name="_continue" %s/>' % onclick_attrib )
# t.append('<input type="submit" value="Save" class="default" %s/>' % onclick_attrib)
# t.append('</div>\n')
# return ''.join(t)

View File

@ -506,7 +506,7 @@ def _get_submit_row_template(opts, app_label, add, change, show_delete, ordered_
if not opts.admin.save_as or add:
t.append('{%% if not is_popup %%}<input type="submit" value="Save and add another" name="_addanother" %s/>{%% endif %%}' % \
(ordered_objects and change and 'onclick="submitOrderForm();"' or ''))
t.append('<input type="submit" value="Save and continue editing" name="_continue" %s/>' % \
t.append('{%% if not is_popup %%}<input type="submit" value="Save and continue editing" name="_continue" %s/>{%% endif %%}' % \
(ordered_objects and change and 'onclick="submitOrderForm();"' or ''))
t.append('<input type="submit" value="Save" class="default" %s/>' % \
(ordered_objects and change and 'onclick="submitOrderForm();"' or ''))

View File

@ -8,7 +8,8 @@ from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
from django.core.exceptions import Http404, ObjectDoesNotExist, ImproperlyConfigured
def create_object(request, app_label, module_name, template_name=None,
extra_context={}, post_save_redirect=None, login_required=False):
template_loader=template_loader, extra_context={},
post_save_redirect=None, login_required=False):
"""
Generic object-creation function.
@ -65,8 +66,9 @@ def create_object(request, app_label, module_name, template_name=None,
return HttpResponse(t.render(c))
def update_object(request, app_label, module_name, object_id=None, slug=None,
slug_field=None, template_name=None, extra_lookup_kwargs={},
extra_context={}, post_save_redirect=None, login_required=False):
slug_field=None, template_name=None, template_loader=template_loader,
extra_lookup_kwargs={}, extra_context={}, post_save_redirect=None,
login_required=False):
"""
Generic object-update function.
@ -139,7 +141,8 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
def delete_object(request, app_label, module_name, post_delete_redirect,
object_id=None, slug=None, slug_field=None, template_name=None,
extra_lookup_kwargs={}, extra_context={}, login_required=False):
template_loader=template_loader, extra_lookup_kwargs={},
extra_context={}, login_required=False):
"""
Generic object-delete function.

View File

@ -7,7 +7,8 @@ from django.utils.httpwrappers import HttpResponse
import datetime, time
def archive_index(request, app_label, module_name, date_field, num_latest=15,
template_name=None, extra_lookup_kwargs={}, extra_context={}):
template_name=None, template_loader=template_loader,
extra_lookup_kwargs={}, extra_context={}):
"""
Generic top-level archive of date-based objects.
@ -49,7 +50,8 @@ def archive_index(request, app_label, module_name, date_field, num_latest=15,
return HttpResponse(t.render(c))
def archive_year(request, year, app_label, module_name, date_field,
template_name=None, extra_lookup_kwargs={}, extra_context={}):
template_name=None, template_loader=template_loader,
extra_lookup_kwargs={}, extra_context={}):
"""
Generic yearly archive view.
@ -85,8 +87,8 @@ def archive_year(request, year, app_label, module_name, date_field,
return HttpResponse(t.render(c))
def archive_month(request, year, month, app_label, module_name, date_field,
month_format='%b', template_name=None, extra_lookup_kwargs={},
extra_context={}):
month_format='%b', template_name=None, template_loader=template_loader,
extra_lookup_kwargs={}, extra_context={}):
"""
Generic monthly archive view.
@ -138,7 +140,8 @@ def archive_month(request, year, month, app_label, module_name, date_field,
def archive_day(request, year, month, day, app_label, module_name, date_field,
month_format='%b', day_format='%d', template_name=None,
extra_lookup_kwargs={}, extra_context={}, allow_empty=False):
template_loader=template_loader, extra_lookup_kwargs={},
extra_context={}, allow_empty=False):
"""
Generic daily archive view.
@ -201,7 +204,8 @@ def archive_today(request, **kwargs):
def object_detail(request, year, month, day, app_label, module_name, date_field,
month_format='%b', day_format='%d', object_id=None, slug=None,
slug_field=None, template_name=None, template_name_field=None,
extra_lookup_kwargs={}, extra_context={}):
template_loader=template_loader, extra_lookup_kwargs={},
extra_context={}):
"""
Generic detail view from year/month/day/slug or year/month/day/id structure.

View File

@ -7,7 +7,8 @@ from django.core.paginator import ObjectPaginator, InvalidPage
from django.core.exceptions import Http404, ObjectDoesNotExist
def object_list(request, app_label, module_name, paginate_by=None, allow_empty=False,
template_name=None, extra_lookup_kwargs={}, extra_context={}):
template_name=None, template_loader=template_loader,
extra_lookup_kwargs={}, extra_context={}):
"""
Generic list of objects.
@ -76,7 +77,8 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
def object_detail(request, app_label, module_name, object_id=None, slug=None,
slug_field=None, template_name=None, template_name_field=None,
extra_lookup_kwargs={}, extra_context={}):
template_loader=template_loader, extra_lookup_kwargs={},
extra_context={}):
"""
Generic list of objects.

View File

@ -376,6 +376,10 @@ Built-in tag reference
========================== ================================================
``forloop.counter`` The current iteration of the loop (1-indexed)
``forloop.counter0`` The current iteration of the loop (0-indexed)
``forloop.revcounter`` The number of iterations from the end of the
loop (1-indexed)
``forloop.revcounter0`` The number of iterations from the end of the
loop (0-indexed)
``forloop.first`` True if this is the first time through the loop
``forloop.last`` True if this is the last time through the loop
``forloop.parentloop`` For nested loops, this is the loop "above" the

View File

@ -107,6 +107,10 @@ TEMPLATE_TESTS = {
### FOR TAG ###############################################################
'for-tag01': ("{% for val in values %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "123"),
'for-tag02': ("{% for val in values reversed %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "321"),
'for-tag-vars01': ("{% for val in values %}{{ forloop.counter }}{% endfor %}", {"values": [6, 6, 6]}, "123"),
'for-tag-vars02': ("{% for val in values %}{{ forloop.counter0 }}{% endfor %}", {"values": [6, 6, 6]}, "012"),
'for-tag-vars03': ("{% for val in values %}{{ forloop.revcounter }}{% endfor %}", {"values": [6, 6, 6]}, "321"),
'for-tag-vars04': ("{% for val in values %}{{ forloop.revcounter0 }}{% endfor %}", {"values": [6, 6, 6]}, "210"),
### IFEQUAL TAG ###########################################################
'ifequal01': ("{% ifequal a b %}yes{% endifequal %}", {"a": 1, "b": 2}, ""),