mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
Cleanups of whitespace changes and errors after big merge
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@981 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b0ad6b878e
commit
5d74e282a4
@ -1,59 +0,0 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from django.conf.settings import INSTALLED_APPS
|
||||
|
||||
urlpatterns = (
|
||||
('^$', 'django.contrib.admin.views.main.index'),
|
||||
('^logout/$', 'django.views.auth.login.logout'),
|
||||
('^password_change/$', 'django.views.registration.passwords.password_change'),
|
||||
('^password_change/done/$', 'django.views.registration.passwords.password_change_done'),
|
||||
('^template_validator/$', 'django.contrib.admin.views.template.template_validator'),
|
||||
|
||||
# Documentation
|
||||
('^doc/$', 'django.contrib.admin.views.doc.doc_index'),
|
||||
('^doc/bookmarklets/$', 'django.contrib.admin.views.doc.bookmarklets'),
|
||||
('^doc/tags/$', 'django.contrib.admin.views.doc.template_tag_index'),
|
||||
('^doc/filters/$', 'django.contrib.admin.views.doc.template_filter_index'),
|
||||
('^doc/views/$', 'django.contrib.admin.views.doc.view_index'),
|
||||
('^doc/views/jump/$', 'django.contrib.admin.views.doc.jump_to_view'),
|
||||
('^doc/views/(?P<view>[^/]+)/$', 'django.contrib.admin.views.doc.view_detail'),
|
||||
('^doc/models/$', 'django.contrib.admin.views.doc.model_index'),
|
||||
('^doc/models/(?P<model>[^/]+)/$', 'django.contrib.admin.views.doc.model_detail'),
|
||||
# ('^doc/templates/$', 'django.views.admin.doc.template_index'),
|
||||
('^doc/templates/(?P<template>.*)/$', 'django.contrib.admin.views.doc.template_detail'),
|
||||
)
|
||||
|
||||
if 'ellington.events' in INSTALLED_APPS:
|
||||
urlpatterns += (
|
||||
("^events/usersubmittedevents/(?P<object_id>\d+)/$", 'ellington.events.views.admin.user_submitted_event_change_stage'),
|
||||
("^events/usersubmittedevents/(?P<object_id>\d+)/delete/$", 'ellington.events.views.admin.user_submitted_event_delete_stage'),
|
||||
)
|
||||
|
||||
if 'ellington.news' in INSTALLED_APPS:
|
||||
urlpatterns += (
|
||||
("^stories/preview/$", 'ellington.news.views.admin.story_preview'),
|
||||
("^stories/js/inlinecontrols/$", 'ellington.news.views.admin.inlinecontrols_js'),
|
||||
("^stories/js/inlinecontrols/(?P<label>[-\w]+)/$", 'ellington.news.views.admin.inlinecontrols_js_specific'),
|
||||
)
|
||||
|
||||
if 'ellington.alerts' in INSTALLED_APPS:
|
||||
urlpatterns += (
|
||||
("^alerts/send/$", 'ellington.alerts.views.admin.send_alert_form'),
|
||||
("^alerts/send/do/$", 'ellington.alerts.views.admin.send_alert_action'),
|
||||
)
|
||||
|
||||
if 'ellington.media' in INSTALLED_APPS:
|
||||
urlpatterns += (
|
||||
('^media/photos/caption/(?P<photo_id>\d+)/$', 'ellington.media.views.admin.get_exif_caption'),
|
||||
)
|
||||
|
||||
urlpatterns += (
|
||||
# Metasystem admin pages
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/add_old/$', 'django.contrib.admin.views.main.add_stage'),
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)_old/$', 'django.contrib.admin.views.main.change_stage'),
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/$', 'django.contrib.admin.views.main.change_list'),
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/add/$', 'django.contrib.admin.views.main.add_stage_new'),
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/history/$', 'django.contrib.admin.views.main.history'),
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'),
|
||||
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/$', 'django.contrib.admin.views.main.change_stage_new'),
|
||||
)
|
||||
urlpatterns = patterns('', *urlpatterns)
|
@ -927,7 +927,7 @@ def delete_stage(request, app_label, module_name, object_id):
|
||||
log.log_action(request.user.id, opts.get_content_type_id(), object_id, obj_repr, log.DELETION)
|
||||
request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr))
|
||||
return HttpResponseRedirect("../../")
|
||||
return render_to_response('admin/delete_confirmation_generic', {
|
||||
return render_to_response('admin/delete_confirmation', {
|
||||
"title": "Are you sure?",
|
||||
"object_name": opts.verbose_name,
|
||||
"object": obj,
|
||||
|
@ -23,7 +23,7 @@ def template_validator(request):
|
||||
errors = manipulator.get_validation_errors(new_data)
|
||||
if not errors:
|
||||
request.user.add_message('The template is valid.')
|
||||
return render_to_response('template_validator', {
|
||||
return render_to_response('admin/template_validator', {
|
||||
'title': 'Template validator',
|
||||
'form': formfields.FormWrapper(manipulator, new_data, errors),
|
||||
}, context_instance=DjangoContext(request))
|
||||
|
@ -244,7 +244,6 @@ class InlineObjectCollection:
|
||||
field = self.parent_manipulator[full_field_name]
|
||||
data = field.extract_data(self.data)
|
||||
errors = self.errors.get(full_field_name, [])
|
||||
# if(errors):raise full_field_name + " " + repr(errors)
|
||||
collection[field_name] = FormFieldWrapper(field, data, errors)
|
||||
wrapper.append(FormFieldCollection(collection))
|
||||
self._collections = wrapper
|
||||
@ -288,27 +287,24 @@ class FormField:
|
||||
return self.field_name
|
||||
|
||||
def extract_data(self, data_dict):
|
||||
if hasattr(self, 'requires_data_list') and hasattr(data_dict, 'getlist'):
|
||||
if hasattr(self, 'requires_data_list') and hasattr(data_dict, 'getlist'):
|
||||
data = data_dict.getlist(self.get_member_name())
|
||||
else:
|
||||
data = data_dict.get(self.get_member_name(), None)
|
||||
if data is None:
|
||||
data = ''
|
||||
self.data_dict = data_dict
|
||||
return data
|
||||
return data
|
||||
|
||||
def convert_post_data(self, new_data):
|
||||
name = self.get_member_name()
|
||||
name = self.get_member_name()
|
||||
if new_data.has_key(self.field_name):
|
||||
d = new_data.getlist(self.field_name)
|
||||
#del new_data[self.field_name]
|
||||
d = new_data.getlist(self.field_name)
|
||||
try:
|
||||
converted_data = [self.__class__.html2python(data)
|
||||
for data in d]
|
||||
except ValueError:
|
||||
converted_data = d
|
||||
new_data.setlist(name, converted_data)
|
||||
|
||||
else:
|
||||
try:
|
||||
# individual fields deal with None values themselves
|
||||
|
@ -633,7 +633,6 @@ def runserver(addr, port):
|
||||
sys.exit(0)
|
||||
from django.utils import autoreload
|
||||
autoreload.main(inner_run)
|
||||
#inner_run()
|
||||
runserver.args = '[optional port number, or ipaddr:port]'
|
||||
|
||||
def createcachetable(tablename):
|
||||
|
@ -924,8 +924,8 @@ def method_save(opts, self):
|
||||
# If it does already exist, do an UPDATE.
|
||||
if cursor.fetchone():
|
||||
db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), False)) for f in non_pks]
|
||||
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % (opts.db_table,
|
||||
','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column),
|
||||
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % (opts.db_table,
|
||||
','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column),
|
||||
db_values + [pk_val])
|
||||
else:
|
||||
record_exists = False
|
||||
@ -1580,7 +1580,6 @@ def manipulator_init(opts, add, change, self, obj_key=None, follow=None):
|
||||
|
||||
for f in opts.fields + opts.many_to_many:
|
||||
if self.follow.get(f.name, False):
|
||||
# if f.editable and not (f.primary_key and change) and (not f.rel or not f.rel.edit_inline):
|
||||
self.fields.extend(f.get_manipulator_fields(opts, self, change))
|
||||
|
||||
# Add fields for related objects.
|
||||
@ -1589,21 +1588,6 @@ def manipulator_init(opts, add, change, self, obj_key=None, follow=None):
|
||||
fol = self.follow[f.name]
|
||||
self.fields.extend(f.get_manipulator_fields(opts, self, change, fol))
|
||||
|
||||
# for obj in opts.get_inline_related_objects_wrapped():
|
||||
# if change:
|
||||
# count = getattr(self.original_object, 'get_%s_count' % opts.get_rel_object_method_name(obj.opts, obj.field))()
|
||||
# count += obj.field.rel.num_extra_on_change
|
||||
# if obj.field.rel.min_num_in_admin:
|
||||
# count = max(count, obj.field.rel.min_num_in_admin)
|
||||
# if obj.field.rel.max_num_in_admin:
|
||||
# count = min(count, obj.field.rel.max_num_in_admin)
|
||||
# else:
|
||||
# count = obj.field.rel.num_in_admin
|
||||
# for f in obj.opts.fields + obj.opts.many_to_many:
|
||||
# if f.editable and f != obj.field :
|
||||
# for i in range(count):
|
||||
# self.fields.extend(f.get_manipulator_fields(obj.opts, self, change, name_prefix='%s.%d.' % (obj.opts.object_name.lower(), i), rel=True))
|
||||
|
||||
# Add field for ordering.
|
||||
if change and opts.get_ordered_objects():
|
||||
self.fields.append(formfields.CommaSeparatedIntegerField(field_name="order_"))
|
||||
@ -1612,7 +1596,8 @@ def manipulator_save(opts, klass, add, change, self, new_data):
|
||||
# TODO: big cleanup when core fields go -> use recursive manipulators.
|
||||
from django.utils.datastructures import DotExpandedDict
|
||||
params = {}
|
||||
for f in opts.fields:
|
||||
for f in opts.fields:
|
||||
# Fields with auto_now_add should keep their original value in the change stage.
|
||||
auto_now_add = change and getattr(f, 'auto_now_add', False)
|
||||
if self.follow.get(f.name, None) and not auto_now_add:
|
||||
param = f.get_manipulator_new_data(new_data)
|
||||
@ -1623,12 +1608,6 @@ def manipulator_save(opts, klass, add, change, self, new_data):
|
||||
param = f.get_default()
|
||||
params[f.column] = param
|
||||
|
||||
# Fields with auto_now_add are another special case; they should keep
|
||||
# their original value in the change stage.
|
||||
#if change and getattr(f, 'auto_now_add', False):
|
||||
# params[f.column] = getattr(self.original_object, f.name)
|
||||
#else:
|
||||
# params[f.column] = f.get_manipulator_new_data(new_data)
|
||||
|
||||
if change:
|
||||
params[opts.pk.column] = self.obj_key
|
||||
|
@ -258,7 +258,6 @@ class Field(object):
|
||||
val = None
|
||||
return val
|
||||
|
||||
|
||||
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
|
||||
"Returns a list of tuples used as SelectField choices for this field."
|
||||
|
||||
@ -266,10 +265,7 @@ class Field(object):
|
||||
if self.choices:
|
||||
return first_choice + list(self.choices)
|
||||
rel_obj = self.rel.to
|
||||
choices = first_choice + [(getattr(x, rel_obj.pk.column), repr(x)) for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)]
|
||||
|
||||
return choices
|
||||
|
||||
return first_choice + [(getattr(x, rel_obj.pk.column), repr(x)) for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)]
|
||||
|
||||
def get_choices_default(self):
|
||||
if(self.radio_admin):
|
||||
@ -284,13 +280,12 @@ class Field(object):
|
||||
return self.get_default()
|
||||
|
||||
def flatten_data(self, follow, obj = None):
|
||||
"""
|
||||
Returns a dictionary mapping the field's manipulator field names to its
|
||||
"flattened" string values for the admin view. Obj is the instance to extract the
|
||||
values from.
|
||||
"""
|
||||
|
||||
return { self.get_db_column(): self._get_val_from_obj(obj)}
|
||||
"""
|
||||
Returns a dictionary mapping the field's manipulator field names to its
|
||||
"flattened" string values for the admin view. Obj is the instance to extract the
|
||||
values from.
|
||||
"""
|
||||
return { self.get_db_column(): self._get_val_from_obj(obj)}
|
||||
|
||||
def get_follow(self, override=None):
|
||||
if override != None:
|
||||
@ -306,7 +301,7 @@ class AutoField(Field):
|
||||
|
||||
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False):
|
||||
if not rel:
|
||||
return [] # Don't add a FormField unless it's in a related change context.
|
||||
return [] # Don't add a FormField unless it's in a related context.
|
||||
return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel)
|
||||
|
||||
def get_manipulator_field_objs(self):
|
||||
@ -398,8 +393,8 @@ class DateTimeField(DateField):
|
||||
def flatten_data(self,follow, obj = None):
|
||||
val = self._get_val_from_obj(obj)
|
||||
date_field, time_field = self.get_manipulator_field_names('')
|
||||
return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''),
|
||||
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''),
|
||||
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
|
||||
class EmailField(Field):
|
||||
def get_manipulator_field_objs(self):
|
||||
@ -594,7 +589,7 @@ class TimeField(Field):
|
||||
|
||||
def flatten_data(self,follow, obj = None):
|
||||
val = self._get_val_from_obj(obj)
|
||||
return {self.get_db_column(): (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
return {self.get_db_column(): (val is not None and val.strftime("%H:%M:%S") or '')}
|
||||
|
||||
class URLField(Field):
|
||||
def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
|
||||
@ -908,8 +903,6 @@ class Admin:
|
||||
returns a list of lists of name, dict
|
||||
the dict has attribs 'fields' and maybe 'classes'.
|
||||
fields is a list of subclasses of Field.
|
||||
|
||||
TODO:Return value needs to be encapsulated.
|
||||
"""
|
||||
if self.fields is None:
|
||||
field_struct = ((None, {'fields': [f.name for f in opts.fields + opts.many_to_many if f.editable and not isinstance(f, AutoField)]}),)
|
||||
|
@ -74,7 +74,7 @@ VARIABLE_TAG_END = '}}'
|
||||
|
||||
ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
|
||||
|
||||
#What to report as the origin of templates that come from non file sources (eg strings)
|
||||
#What to report as the origin of templates that come from non loader sources (ie strings)
|
||||
UNKNOWN_SOURCE="<unknown source>"
|
||||
|
||||
#match starts of lines
|
||||
@ -140,7 +140,6 @@ class Template:
|
||||
def render(self, context):
|
||||
"Display stage -- can be called many times"
|
||||
return self.nodelist.render(context)
|
||||
|
||||
|
||||
def compile_string(template_string, origin):
|
||||
"Compiles template_string into NodeList ready for rendering"
|
||||
@ -225,6 +224,7 @@ class Lexer(object):
|
||||
|
||||
def tokenize(self):
|
||||
"Return a list of tokens from a given template_string"
|
||||
# remove all empty strings, because the regex has a tendency to add them
|
||||
bits = filter(None, tag_re.split(self.template_string))
|
||||
return map(self.create_token, bits)
|
||||
|
||||
@ -276,7 +276,7 @@ class DebugLexer(Lexer):
|
||||
class Parser(object):
|
||||
def __init__(self, tokens):
|
||||
self.tokens = tokens
|
||||
|
||||
|
||||
def parse(self, parse_until=[]):
|
||||
nodelist = self.create_nodelist()
|
||||
while self.tokens:
|
||||
@ -296,26 +296,21 @@ class Parser(object):
|
||||
command = token.contents.split()[0]
|
||||
except IndexError:
|
||||
self.empty_block_tag(token)
|
||||
|
||||
# execute callback function for this tag and append resulting node
|
||||
self.enter_command(command, token);
|
||||
try:
|
||||
compile_func = registered_tags[command]
|
||||
except KeyError:
|
||||
self.invalid_block_tag(token, command)
|
||||
|
||||
self.invalid_block_tag(token, command)
|
||||
try:
|
||||
compiled_result = compile_func(self, token)
|
||||
except TemplateSyntaxError, e:
|
||||
if not self.compile_function_error(token, e):
|
||||
raise
|
||||
|
||||
self.extend_nodelist(nodelist, compiled_result, token)
|
||||
self.exit_command();
|
||||
|
||||
if parse_until:
|
||||
self.unclosed_block_tag(token, parse_until)
|
||||
|
||||
return nodelist
|
||||
|
||||
def create_nodelist(self):
|
||||
|
@ -227,7 +227,6 @@ class SsiNode(Node):
|
||||
return '' # Fail silently for invalid included templates.
|
||||
return output
|
||||
|
||||
|
||||
class LoadNode(Node):
|
||||
def __init__(self, taglib):
|
||||
self.taglib = taglib
|
||||
|
@ -41,30 +41,24 @@ for path in TEMPLATE_LOADERS:
|
||||
else:
|
||||
template_source_loaders.append(func)
|
||||
|
||||
|
||||
|
||||
|
||||
class LoaderOrigin(Origin):
|
||||
def __init__(self, name, loader):
|
||||
def __init__(self, name, loader, name, dirs):
|
||||
def reload():
|
||||
return loader(name, dirs)[0]
|
||||
super(LoaderOrigin, self).__init__(name)
|
||||
self.loader = loader
|
||||
self._reload = reload
|
||||
|
||||
def reload(self):
|
||||
if self.loader:
|
||||
return self.loader()
|
||||
else:
|
||||
raise NotImplementedException
|
||||
|
||||
return self._reload()
|
||||
|
||||
def find_template_source(name, dirs=None):
|
||||
for loader in template_source_loaders:
|
||||
try:
|
||||
source, display_name = loader(name, dirs)
|
||||
|
||||
def reload():
|
||||
return loader(name, dirs)[0]
|
||||
|
||||
return (source, LoaderOrigin(display_name, reload))
|
||||
|
||||
return (source, LoaderOrigin(display_name, loader, name, dirs))
|
||||
except TemplateDoesNotExist:
|
||||
pass
|
||||
raise TemplateDoesNotExist, name
|
||||
@ -216,7 +210,6 @@ class IncludeNode(Node):
|
||||
except Exception, e:
|
||||
return '' # Fail silently for invalid included templates.
|
||||
|
||||
|
||||
def do_block(parser, token):
|
||||
"""
|
||||
Define a block that can be overridden by child templates.
|
||||
|
@ -12,7 +12,7 @@ import re
|
||||
|
||||
_datere = r'\d{4}-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[12][0-9])|(?:3[0-1]))'
|
||||
_timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?'
|
||||
alnum_re = re.compile(r'^[\w-]+$')
|
||||
alnum_re = re.compile(r'^\w+$')
|
||||
alnumurl_re = re.compile(r'^[\w/]+$')
|
||||
ansi_date_re = re.compile('^%s$' % _datere)
|
||||
ansi_time_re = re.compile('^%s$' % _timere)
|
||||
@ -54,7 +54,7 @@ class CriticalValidationError(Exception):
|
||||
|
||||
def isAlphaNumeric(field_data, all_data):
|
||||
if not alnum_re.search(field_data):
|
||||
raise ValidationError, "This value must contain only letters, numbers, dashes and underscores."
|
||||
raise ValidationError, "This value must contain only letters, numbers and underscores."
|
||||
|
||||
def isAlphaNumericURL(field_data, all_data):
|
||||
if not alnumurl_re.search(field_data):
|
||||
|
@ -9,7 +9,7 @@ from django.core.exceptions import Http404, ObjectDoesNotExist, ImproperlyConfig
|
||||
|
||||
def create_object(request, app_label, module_name, template_name=None,
|
||||
template_loader=template_loader, extra_context={},
|
||||
post_save_redirect=None, login_required=False):
|
||||
post_save_redirect=None, login_required=False, follow=None):
|
||||
"""
|
||||
Generic object-creation function.
|
||||
|
||||
@ -22,17 +22,17 @@ def create_object(request, app_label, module_name, template_name=None,
|
||||
return redirect_to_login(request.path)
|
||||
|
||||
mod = models.get_module(app_label, module_name)
|
||||
manipulator = mod.AddManipulator()
|
||||
manipulator = mod.AddManipulator(follow=follow)
|
||||
if request.POST:
|
||||
# If data was POSTed, we're trying to create a new object
|
||||
new_data = request.POST.copy()
|
||||
|
||||
# Check for errors
|
||||
errors = manipulator.get_validation_errors(new_data)
|
||||
manipulator.do_html2python(new_data)
|
||||
|
||||
if not errors:
|
||||
# No errors -- this means we can save the data!
|
||||
manipulator.do_html2python(new_data)
|
||||
new_object = manipulator.save(new_data)
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
@ -48,7 +48,8 @@ def create_object(request, app_label, module_name, template_name=None,
|
||||
raise ImproperlyConfigured("No URL to redirect to from generic create view.")
|
||||
else:
|
||||
# No POST, so we want a brand new form without any data or errors
|
||||
errors = new_data = {}
|
||||
errors = {}
|
||||
new_data = manipulator.flatten_data()
|
||||
|
||||
# Create the FormWrapper, template, context, response
|
||||
form = formfields.FormWrapper(manipulator, new_data, errors)
|
||||
|
Loading…
x
Reference in New Issue
Block a user