Simplified lists creation in three places.

This commit is contained in:
Dmitry Dygalo 2015-11-08 17:05:45 +01:00 committed by Tim Graham
parent 02d974ceb5
commit 92eced62cd
3 changed files with 19 additions and 12 deletions

View File

@ -45,12 +45,15 @@ class FilteredSelectMultiple(forms.SelectMultiple):
attrs['class'] = 'selectfilter' attrs['class'] = 'selectfilter'
if self.is_stacked: if self.is_stacked:
attrs['class'] += 'stacked' attrs['class'] += 'stacked'
output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)] output = [
output.append('<script type="text/javascript">addEvent(window, "load", function(e) {') super(FilteredSelectMultiple, self).render(name, value, attrs, choices),
# TODO: "id_" is hard-coded here. This should instead use the correct '<script type="text/javascript">addEvent(window, "load", function(e) {',
# API to determine the ID dynamically. # TODO: "id_" is hard-coded here. This should instead use the
output.append('SelectFilter.init("id_%s", "%s", %s); });</script>\n' # correct API to determine the ID dynamically.
% (name, escapejs(self.verbose_name), int(self.is_stacked))) 'SelectFilter.init("id_%s", "%s", %s); });</script>\n' % (
name, escapejs(self.verbose_name), int(self.is_stacked),
),
]
return mark_safe(''.join(output)) return mark_safe(''.join(output))

View File

@ -61,8 +61,11 @@ class Command(BaseCommand):
index_output = [] index_output = []
qn = connection.ops.quote_name qn = connection.ops.quote_name
for f in fields: for f in fields:
field_output = [qn(f.name), f.db_type(connection=connection)] field_output = [
field_output.append("%sNULL" % ("NOT " if not f.null else "")) qn(f.name),
f.db_type(connection=connection),
'%sNULL' % ('NOT ' if not f.null else ''),
]
if f.primary_key: if f.primary_key:
field_output.append("PRIMARY KEY") field_output.append("PRIMARY KEY")
elif f.unique: elif f.unique:

View File

@ -1082,10 +1082,7 @@ class SQLUpdateCompiler(SQLCompiler):
self.pre_sql_setup() self.pre_sql_setup()
if not self.query.values: if not self.query.values:
return '', () return '', ()
table = self.query.tables[0]
qn = self.quote_name_unless_alias qn = self.quote_name_unless_alias
result = ['UPDATE %s' % qn(table)]
result.append('SET')
values, update_params = [], [] values, update_params = [], []
for field, model, val in self.query.values: for field, model, val in self.query.values:
if hasattr(val, 'resolve_expression'): if hasattr(val, 'resolve_expression'):
@ -1124,7 +1121,11 @@ class SQLUpdateCompiler(SQLCompiler):
values.append('%s = NULL' % qn(name)) values.append('%s = NULL' % qn(name))
if not values: if not values:
return '', () return '', ()
result.append(', '.join(values)) table = self.query.tables[0]
result = [
'UPDATE %s SET' % qn(table),
', '.join(values),
]
where, params = self.compile(self.query.where) where, params = self.compile(self.query.where)
if where: if where:
result.append('WHERE %s' % where) result.append('WHERE %s' % where)