1 from django import oldforms, template
2 from django.conf import settings
3 from django.contrib.admin.filterspecs import FilterSpec
4 from django.contrib.admin.views.decorators import staff_member_required
5 from django.views.decorators.cache import never_cache
6 from django.contrib.contenttypes.models import ContentType
7 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
8 from django.core.paginator import QuerySetPaginator, InvalidPage
9 from django.shortcuts import get_object_or_404, render_to_response
10 from django.db import models
11 from django.db.models.query import handle_legacy_orderlist, QuerySet
12 from django.http import Http404, HttpResponse, HttpResponseRedirect
13 from django.utils.html import escape
14 from django.utils.text import capfirst, get_text_list
15 from django.utils.encoding import force_unicode, smart_str
16 from django.utils.translation import ugettext as _
17 from django.utils.safestring import mark_safe
18 import operator
19
20 try:
21 set
22 except NameError:
23 from sets import Set as set
24
25 from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
26 if not LogEntry._meta.installed:
27 raise ImproperlyConfigured, "You'll need to put 'django.contrib.admin' in your INSTALLED_APPS setting before you can use the admin application."
28
29 if 'django.core.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS:
30 raise ImproperlyConfigured, "You'll need to put 'django.core.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting before you can use the admin application."
31
32
33
34 MAX_SHOW_ALL_ALLOWED = 200
35
36
37 ALL_VAR = 'all'
38 ORDER_VAR = 'o'
39 ORDER_TYPE_VAR = 'ot'
40 PAGE_VAR = 'p'
41 SEARCH_VAR = 'q'
42 IS_POPUP_VAR = 'pop'
43 ERROR_FLAG = 'e'
44
45
46 EMPTY_CHANGELIST_VALUE = '(None)'
47
48 use_raw_id_admin = lambda field: isinstance(field.rel, (models.ManyToOneRel, models.ManyToManyRel)) and field.rel.raw_id_admin
49
52
54 """
55 Ensure that primary key values do not confuse the admin URLs by escaping
56 any '/', '_' and ':' characters. Similar to urllib.quote, except that the
57 quoting is slightly different so that it doesn't get automatically
58 unquoted by the Web browser.
59 """
60 if type(s) != type(''):
61 return s
62 res = list(s)
63 for i in range(len(res)):
64 c = res[i]
65 if c in ':/_':
66 res[i] = '_%02X' % ord(c)
67 return ''.join(res)
68
70 """
71 Undo the effects of quote(). Based heavily on urllib.unquote().
72 """
73 mychr = chr
74 myatoi = int
75 list = s.split('_')
76 res = [list[0]]
77 myappend = res.append
78 del list[0]
79 for item in list:
80 if item[1:2]:
81 try:
82 myappend(mychr(myatoi(item[:2], 16)) + item[2:])
83 except ValueError:
84 myappend('_' + item)
85 else:
86 myappend('_' + item)
87 return "".join(res)
88
90
91 js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
92 if auto_populated_fields:
93 js.append('js/urlify.js')
94 if opts.has_field_type(models.DateTimeField) or opts.has_field_type(models.TimeField) or opts.has_field_type(models.DateField):
95 js.extend(['js/calendar.js', 'js/admin/DateTimeShortcuts.js'])
96 if opts.get_ordered_objects():
97 js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js'])
98 if opts.admin.js:
99 js.extend(opts.admin.js)
100 seen_collapse = False
101 for field_set in field_sets:
102 if not seen_collapse and 'collapse' in field_set.classes:
103 seen_collapse = True
104 js.append('js/admin/CollapsedFieldsets.js')
105
106 for field_line in field_set:
107 try:
108 for f in field_line:
109 if f.rel and isinstance(f, models.ManyToManyField) and f.rel.filter_interface:
110 js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
111 raise StopIteration
112 except StopIteration:
113 break
114 return js
115
117 - def __init__(self, field, field_mapping, original):
143
145 if self.original:
146 return self.original.__dict__[self.field.attname]
147
157
159 return repr(self.__dict__)
160
163
165 if self.is_file_field and self.original and self.field.attname:
166 url_method = getattr(self.original, 'get_%s_url' % self.field.attname)
167 if callable(url_method):
168 return url_method()
169 return ''
170
172 - def __init__(self, field_line, field_mapping, original):
173 self.bound_fields = [field.bind(field_mapping, original, AdminBoundField) for field in field_line]
174 for bound_field in self:
175 bound_field.first = True
176 break
177
179 for bound_field in self.bound_fields:
180 yield bound_field
181
183 return len(self.bound_fields)
184
186 - def __init__(self, field_set, field_mapping, original):
191
193 for bound_field_line in self.bound_field_lines:
194 yield bound_field_line
195
197 return len(self.bound_field_lines)
198