diff -Naur django-trunk/django/contrib/admin/templatetags/admin_modify.py django-trunk-modified/django/contrib/admin/templatetags/admin_modify.py
|
old
|
new
|
|
| 180 | 180 | output_all = register.simple_tag(output_all) |
| 181 | 181 | |
| 182 | 182 | def auto_populated_field_script(auto_pop_fields, change = False): |
| | 183 | dependencies = [] |
| | 184 | dependencies_bodies = {} |
| | 185 | dependencies_scripts = {} |
| | 186 | for field in auto_pop_fields: |
| | 187 | for g in field.prepopulate_from: |
| | 188 | if g not in dependencies: |
| | 189 | dependencies.append(g) |
| | 190 | dependencies_bodies[g] = [] |
| | 191 | dependencies_scripts[g] = "" |
| | 192 | |
| 183 | 193 | t = [] |
| 184 | 194 | for field in auto_pop_fields: |
| | 195 | for g in field.prepopulate_from: |
| | 196 | if g not in dependencies: |
| | 197 | dependencies.append(g) |
| 185 | 198 | if change: |
| 186 | 199 | t.append(u'document.getElementById("id_%s")._changed = true;' % field.name) |
| 187 | 200 | else: |
| … |
… |
|
| 189 | 202 | |
| 190 | 203 | add_values = u' + " " + '.join([u'document.getElementById("id_%s").value' % g for g in field.prepopulate_from]) |
| 191 | 204 | for f in field.prepopulate_from: |
| 192 | | t.append(u'document.getElementById("id_%s").onkeyup = function() {' \ |
| 193 | | ' var e = document.getElementById("id_%s");' \ |
| 194 | | ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % ( |
| 195 | | f, field.name, add_values, field.max_length)) |
| | 205 | var_name = 'e_%s' % field.name |
| | 206 | f_script_body = u' var %s = document.getElementById("id_%s");' \ |
| | 207 | ' if(!%s._changed) { %s.value = URLify(%s, %s);}\n ' % ( |
| | 208 | var_name, field.name, var_name, var_name, add_values, field.max_length) |
| | 209 | dependencies_bodies[f].append(f_script_body) |
| | 210 | |
| | 211 | t = [] |
| | 212 | for field in auto_pop_fields: |
| | 213 | for f in field.prepopulate_from: |
| | 214 | if dependencies_scripts[f] == "": |
| | 215 | f_script_pre = u'document.getElementById("id_%s").onkeyup = function() {' % f |
| | 216 | f_script_post = '\n }; ' |
| | 217 | f_script = f_script_pre + u''.join(dependencies_bodies[f]) + f_script_post |
| | 218 | t.append(f_script) |
| | 219 | dependencies_scripts[f] = f_script |
| | 220 | |
| 196 | 221 | return u''.join(t) |
| 197 | 222 | auto_populated_field_script = register.simple_tag(auto_populated_field_script) |
| 198 | 223 | |