Ticket #1375: main2.diff
File main2.diff, 2.7 KB (added by , 19 years ago) |
---|
-
contrib/admin/views/main.py
41 41 class IncorrectLookupParameters(Exception): 42 42 pass 43 43 44 def quote(s): 45 """ 46 Ensure that primary key values do not confuse the admin URLs by escaping 47 any '/', '_' and ':' characters. Similar to urllib.quote, except that the 48 quoting is slightly different so that it doesn't get autoamtically 49 unquoted by the web browser. 50 """ 51 if type(s) != type(''): 52 return s 53 res = list(s) 54 for i in range(len(res)): 55 c = res[i] 56 if c in ':/_': 57 res[i] = '_%02X' % ord(c) 58 return ''.join(res) 59 60 def unquote(s): 61 """ 62 Undo the effects of quote(). Based heavily on urllib.unquote(). 63 """ 64 mychr = chr 65 myatoi = int 66 list = s.split('_') 67 res = [list[0]] 68 myappend = res.append 69 del list[0] 70 for item in list: 71 if item[1:2]: 72 try: 73 myappend(mychr(myatoi(item[:2], 16)) 74 + item[2:]) 75 except ValueError: 76 myappend('_' + item) 77 else: 78 myappend('_' + item) 79 return "".join(res) 80 44 81 def get_javascript_imports(opts, auto_populated_fields, field_sets): 45 82 # Put in any necessary JavaScript imports. 46 83 js = ['js/core.js', 'js/admin/RelatedObjectLookups.js'] … … 250 287 251 288 def change_stage(request, app_label, model_name, object_id): 252 289 model = models.get_model(app_label, model_name) 290 object_id = unquote(object_id) 253 291 if model is None: 254 292 raise Http404, "App %r, model %r, not found" % (app_label, model_name) 255 293 opts = model._meta … … 433 471 def delete_stage(request, app_label, model_name, object_id): 434 472 import sets 435 473 model = models.get_model(app_label, model_name) 474 object_id = unquote(object_id) 436 475 if model is None: 437 476 raise Http404, "App %r, model %r, not found" % (app_label, model_name) 438 477 opts = model._meta … … 465 504 466 505 def history(request, app_label, model_name, object_id): 467 506 model = models.get_model(app_label, model_name) 507 object_id = unquote(object_id) 468 508 if model is None: 469 509 raise Http404, "App %r, model %r, not found" % (app_label, model_name) 470 510 action_list = LogEntry.objects.filter(object_id=object_id, … … 655 695 return qs 656 696 657 697 def url_for_result(self, result): 658 return "%s/" % getattr(result, self.pk_attname)698 return "%s/" % quote(getattr(result, self.pk_attname)) 659 699 660 700 def change_list(request, app_label, model_name): 661 701 model = models.get_model(app_label, model_name)