Changeset 1286
- Timestamp:
- 11/18/05 16:06:17 (3 years ago)
- Files:
-
- django/branches/new-admin/django/contrib/admin/templates/admin/edit_inline_stacked.html (modified) (1 diff)
- django/branches/new-admin/django/contrib/admin/templates/admin/edit_inline_tabular.html (modified) (2 diffs)
- django/branches/new-admin/django/contrib/admin/templatetags/admin_modify.py (modified) (1 diff)
- django/branches/new-admin/django/contrib/admin/views/main.py (modified) (8 diffs)
- django/branches/new-admin/django/core/meta/__init__.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/new-admin/django/contrib/admin/templates/admin/edit_inline_stacked.html
r986 r1286 6 6 {% endif %}{% endif %} 7 7 {% for bound_field in fcw.bound_fields %} 8 {% if bound_field. not_in_table%}8 {% if bound_field.hidden %} 9 9 {% field_widget bound_field %} 10 10 {% else %} django/branches/new-admin/django/contrib/admin/templates/admin/edit_inline_tabular.html
r1028 r1286 21 21 <tr class="{% cycle row1,row2 %}"> 22 22 {% for bound_field in fcw.bound_fields %} 23 {% if not bound_field. not_in_table%}23 {% if not bound_field.hidden %} 24 24 <td {{bound_field.cell_class_attribute}}> 25 25 {% field_widget bound_field %} … … 36 36 {% for fcw in bound_related_object.form_field_collection_wrappers %} 37 37 {% for bound_field in fcw.bound_fields %} 38 {% if bound_field. not_in_table%}38 {% if bound_field.hidden %} 39 39 {% field_widget bound_field %} 40 40 {% endif %} django/branches/new-admin/django/contrib/admin/templatetags/admin_modify.py
r1175 r1286 127 127 def __init__(self, related_object, field_mapping, original): 128 128 super(TabularBoundRelatedObject, self).__init__(related_object, field_mapping, original) 129 self.field_wrapper_list = self.relation.editable_fields(FieldWrapper)129 self.field_wrapper_list = [FieldWrapper(field) for field in self.relation.editable_fields()] 130 130 131 131 fields = self.relation.editable_fields() django/branches/new-admin/django/contrib/admin/views/main.py
r1248 r1286 1 1 # Generic admin views. 2 2 from django.contrib.admin.views.decorators import staff_member_required 3 from django.contrib.admin.filterspecs import FilterSpec 3 4 from django.core import formfields, meta, template 4 5 from django.core.template import loader … … 7 8 from django.core.extensions import DjangoContext as Context 8 9 from django.core.extensions import get_object_or_404, render_to_response 10 from django.core.paginator import ObjectPaginator, InvalidPage 11 from django.conf.settings import ADMIN_MEDIA_PREFIX 9 12 from django.models.admin import log 10 13 from django.utils.html import strip_tags 11 14 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect 12 15 from django.utils.text import capfirst, get_text_list 13 from django.conf.settings import ADMIN_MEDIA_PREFIX14 from django.core.paginator import ObjectPaginator, InvalidPage15 16 from django.utils import dateformat 16 17 from django.utils.dates import MONTHS 17 18 from django.utils.html import escape 18 19 import operator 19 import datetime20 20 21 21 # The system will display a "Show all" link only if the total result count … … 54 54 pass 55 55 56 class FilterSpec(object):57 filter_specs = []58 def __init__(self, f, request, params):59 self.field = f60 self.params = params61 62 def register(cls, test, factory):63 cls.filter_specs.append( (test, factory) )64 register = classmethod(register)65 66 def create(cls, f, request, params):67 for test, factory in cls.filter_specs:68 if test(f):69 return factory(f, request, params)70 create = classmethod(create)71 72 def has_output(self):73 return True74 75 def choices(self, cl):76 raise NotImplementedException()77 78 def title(self):79 return self.field.verbose_name80 81 def output(self, cl):82 t = []83 if self.has_output():84 t.append(_('<h3>By %s:</h3>\n<ul>\n') % self.title())85 86 for choice in self.choices(cl):87 t.append('<li%s><a href="%s">%s</a></li>\n' % \88 ((choice['selected'] and ' class="selected"' or ''),89 choice['query_string'] ,90 choice['display']))91 t.append('</ul>\n\n')92 return "".join(t)93 94 class RelatedFilterSpec(FilterSpec):95 def __init__(self, f, request, params):96 super(RelatedFilterSpec, self).__init__(f, request, params)97 if isinstance(f, meta.ManyToManyField):98 self.lookup_title = f.rel.to.verbose_name99 else:100 self.lookup_title = f.verbose_name101 self.lookup_kwarg = '%s__%s__exact' % (f.name, f.rel.to.pk.name)102 self.lookup_val = request.GET.get(self.lookup_kwarg, None)103 self.lookup_choices = f.rel.to.get_model_module().get_list()104 105 def has_output(self):106 return len(self.lookup_choices) > 1107 108 def title(self):109 return self.lookup_title110 111 def choices(self, cl):112 yield {'selected': self.lookup_val is None,113 'query_string': cl.get_query_string({}, [self.lookup_kwarg]),114 'display': _('All') }115 for val in self.lookup_choices:116 pk_val = getattr(val, self.field.rel.to.pk.attname)117 yield { 'selected': self.lookup_val == str(pk_val),118 'query_string': cl.get_query_string( {self.lookup_kwarg: pk_val}),119 'display' : val }120 FilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec)121 122 class ChoicesFilterSpec(FilterSpec):123 def __init__(self, f, request, params):124 super(ChoicesFilterSpec, self).__init__(f, request, params)125 self.lookup_kwarg = '%s__exact' % f.name126 self.lookup_val = request.GET.get(self.lookup_kwarg, None)127 128 def choices(self, cl):129 yield {'selected' : self.lookup_val is None,130 'query_string': cl.get_query_string( {}, [self.lookup_kwarg]),131 'display': _('All') }132 for k, v in self.field.choices:133 yield {'selected': str(k) == self.lookup_val,134 'query_string' : cl.get_query_string( {self.lookup_kwarg: k}),135 'display' : v }136 FilterSpec.register(lambda f: bool(f.choices), ChoicesFilterSpec)137 138 class DateFieldFilterSpec(FilterSpec):139 140 def __init__(self, f, request, params):141 super(DateFieldFilterSpec, self).__init__(f, request, params)142 143 self.field_generic = '%s__' % self.field.name144 145 self.date_params = dict([(k, v) for k, v in params.items() if k.startswith(self.field_generic)])146 147 today = datetime.date.today()148 one_week_ago = today - datetime.timedelta(days=7)149 today_str = isinstance(self.field, meta.DateTimeField) and today.strftime('%Y-%m-%d 23:59:59') or today.strftime('%Y-%m-%d')150 151 self.links = (152 (_('Any date'), {}),153 (_('Today'), {'%s__year' % self.field.name: str(today.year),154 '%s__month' % self.field.name: str(today.month),155 '%s__day' % self.field.name: str(today.day)}),156 (_('Past 7 days'), {'%s__gte' % self.field.name: one_week_ago.strftime('%Y-%m-%d'),157 '%s__lte' % f.name: today_str}),158 (_('This month'), {'%s__year' % self.field.name: str(today.year),159 '%s__month' % f.name: str(today.month)}),160 (_('This year'), {'%s__year' % self.field.name: str(today.year)})161 )162 163 def title(self):164 return self.field.verbose_name165 166 def choices(self, cl):167 for title, param_dict in self.links:168 yield { 'selected' : self.date_params == param_dict,169 'query_string' : cl.get_query_string( param_dict, self.field_generic),170 'display' : title }171 172 FilterSpec.register(lambda f: isinstance(f, meta.DateField), DateFieldFilterSpec)173 174 class BooleanFieldFilterSpec(FilterSpec):175 def __init__(self, f, request, params):176 super(BooleanFieldFilterSpec, self).__init__(f, request, params)177 self.lookup_kwarg = '%s__exact' % f.name178 self.lookup_kwarg2 = '%s__isnull' % f.name179 self.lookup_val = request.GET.get(self.lookup_kwarg, None)180 self.lookup_val2 = request.GET.get(self.lookup_kwarg2, None)181 182 def title(self):183 return self.field.verbose_name184 185 def choices(self, cl):186 for k, v in ((_('All'), None), (_('Yes'), '1'), (_('No'), '0')):187 yield { 'selected' : self.lookup_val == v and not self.lookup_val2,188 'query_string' : cl.get_query_string( {self.lookup_kwarg: v}, [self.lookup_kwarg2]),189 'display': k190 }191 if isinstance(self.field, meta.NullBooleanField):192 yield { 'selected' : self.lookup_val2 == 'True',193 'query_string' : cl.get_query_string( {self.lookup_kwarg2: 'True'}, [self.lookup_kwarg]),194 'display': _('Unknown')195 }196 FilterSpec.register(lambda f: isinstance(f, meta.BooleanField) or197 isinstance(f, meta.NullBooleanField), BooleanFieldFilterSpec)198 56 199 57 class ChangeList(object): … … 251 109 else: 252 110 self.lookup_mod, self.lookup_opts = self.mod, self.opts 253 254 111 255 112 def get_search_parameters(self, request): … … 433 290 return js 434 291 292 435 293 class AdminBoundField(BoundField): 436 294 def __init__(self, field, field_mapping, original): … … 443 301 self.is_file_field = isinstance(field, meta.FileField) 444 302 self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin 445 self. not_in_table= isinstance(self.field, meta.AutoField)303 self.hidden = isinstance(self.field, meta.AutoField) 446 304 self.first = False 447 305 … … 494 352 super(AdminBoundFieldSet, self).__init__(field_set, field_mapping, original, AdminBoundFieldLine) 495 353 496 497 class AdminBoundManipulator(object): 354 class BoundManipulator(object): 498 355 def __init__(self, opts, manipulator, field_mapping): 499 self.inline_related_objects = opts.get_followed_related_objects() 500 501 field_sets = opts.admin.get_field_sets(opts) 356 self.inline_related_objects = opts.get_followed_related_objects(manipulator.follow) 502 357 self.original = hasattr(manipulator, 'original_object') and manipulator.original_object or None 503 358 self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet) 504 for field_set in field_sets] 505 359 for field_set in opts.admin.get_field_sets(opts)] 360 self.ordered_objects = opts.get_ordered_objects()[:] 361 362 class AdminBoundManipulator(BoundManipulator): 363 def __init__(self, opts, manipulator, field_mapping): 364 super(AdminBoundManipulator, self).__init__(opts, manipulator, field_mapping) 365 field_sets = opts.admin.get_field_sets(opts) 366 506 367 507 self.ordered_objects = opts.get_ordered_objects()[:]368 508 369 self.auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] 509 370 self.javascript_imports = get_javascript_imports(opts, self.auto_populated_fields, self.ordered_objects, field_sets); … … 514 375 'enctype="multipart/form-data" ' or '' 515 376 516 517 518 377 self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id(); 519 378 self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects] django/branches/new-admin/django/core/meta/__init__.py
r1282 r1286 214 214 215 215 216 def editable_fields(self, wrapping_func = lambda x: x): 217 """Get the fields in this class that should be edited inline. 218 Pass a callable, eg a class, as the second argument to wrap the fields. 219 This can be useful to add extra attributes for use in templates.""" 216 def editable_fields(self): 217 """Get the fields in this class that should be edited inline.""" 220 218 221 return [ wrapping_func(f)for f in self.opts.fields + self.opts.many_to_many if f.editable and f != self.field ]219 return [f for f in self.opts.fields + self.opts.many_to_many if f.editable and f != self.field ] 222 220 223 221 def get_follow(self, override=None):
