Changeset 2418
- Timestamp:
- 02/27/06 15:36:52 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/contrib/admin/views/main.py
r2416 r2418 42 42 class IncorrectLookupParameters(Exception): 43 43 pass 44 45 def quote(s): 46 """ 47 Ensure that primary key values do not confuse the admin URLs by escaping 48 any '/', '_' and ':' characters. Similar to urllib.quote, except that the 49 quoting is slightly different so that it doesn't get autoamtically 50 unquoted by the web browser. 51 """ 52 if type(s) != type(''): 53 return s 54 res = list(s) 55 for i in range(len(res)): 56 c = res[i] 57 if c in ':/_': 58 res[i] = '_%02X' % ord(c) 59 return ''.join(res) 60 61 def unquote(s): 62 """ 63 Undo the effects of quote(). Based heavily on urllib.unquote(). 64 """ 65 mychr = chr 66 myatoi = int 67 list = s.split('_') 68 res = [list[0]] 69 myappend = res.append 70 del list[0] 71 for item in list: 72 if item[1:2]: 73 try: 74 myappend(mychr(myatoi(item[:2], 16)) 75 + item[2:]) 76 except ValueError: 77 myappend('_' + item) 78 else: 79 myappend('_' + item) 80 return "".join(res) 44 81 45 82 def get_javascript_imports(opts, auto_populated_fields, field_sets): … … 253 290 def change_stage(request, app_label, model_name, object_id): 254 291 model = models.get_model(app_label, model_name) 292 object_id = unquote(object_id) 255 293 if model is None: 256 294 raise Http404, "App %r, model %r, not found" % (app_label, model_name) … … 436 474 import sets 437 475 model = models.get_model(app_label, model_name) 476 object_id = unquote(object_id) 438 477 if model is None: 439 478 raise Http404, "App %r, model %r, not found" % (app_label, model_name) … … 471 510 def history(request, app_label, model_name, object_id): 472 511 model = models.get_model(app_label, model_name) 512 object_id = unquote(object_id) 473 513 if model is None: 474 514 raise Http404, "App %r, model %r, not found" % (app_label, model_name) … … 664 704 665 705 def url_for_result(self, result): 666 return "%s/" % getattr(result, self.pk_attname)706 return "%s/" % quote(getattr(result, self.pk_attname)) 667 707 668 708 def change_list(request, app_label, model_name):
