mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
Fixes for attname & date hierarchy
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1159 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dbaf9c6f8d
commit
3865e76ee7
@ -1,3 +1,4 @@
|
|||||||
|
{% if show %}
|
||||||
<div class="xfull">
|
<div class="xfull">
|
||||||
<ul class="toplinks">
|
<ul class="toplinks">
|
||||||
{% if back %}<li class="date-back"><a href="{{back.link}}">‹ {{back.title}}</a></li>{% endif %}
|
{% if back %}<li class="date-back"><a href="{{back.link}}">‹ {{back.title}}</a></li>{% endif %}
|
||||||
@ -6,3 +7,4 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul><br class="clear" />
|
</ul><br class="clear" />
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
@ -147,7 +147,7 @@ def result_headers(cl):
|
|||||||
|
|
||||||
def items_for_result(cl, result):
|
def items_for_result(cl, result):
|
||||||
first = True
|
first = True
|
||||||
pk = cl.lookup_opts.pk.name
|
pk = cl.lookup_opts.pk.attname
|
||||||
for field_name in cl.lookup_opts.admin.list_display:
|
for field_name in cl.lookup_opts.admin.list_display:
|
||||||
row_class = ''
|
row_class = ''
|
||||||
try:
|
try:
|
||||||
@ -160,7 +160,7 @@ def items_for_result(cl, result):
|
|||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
result_repr = EMPTY_CHANGELIST_VALUE
|
result_repr = EMPTY_CHANGELIST_VALUE
|
||||||
else:
|
else:
|
||||||
field_val = getattr(result, f.column)
|
field_val = getattr(result, f.attname)
|
||||||
|
|
||||||
if isinstance(f.rel, meta.ManyToOne):
|
if isinstance(f.rel, meta.ManyToOne):
|
||||||
if field_val is not None:
|
if field_val is not None:
|
||||||
@ -246,7 +246,8 @@ def date_hierarchy(cl):
|
|||||||
|
|
||||||
if year_lookup and month_lookup and day_lookup:
|
if year_lookup and month_lookup and day_lookup:
|
||||||
month_name = MONTHS[int(month_lookup)]
|
month_name = MONTHS[int(month_lookup)]
|
||||||
return { 'back':
|
return { 'show': True,
|
||||||
|
'back':
|
||||||
{ 'link' : link({year_field: year_lookup, month_field: month_lookup}),
|
{ 'link' : link({year_field: year_lookup, month_field: month_lookup}),
|
||||||
'title': "%s %s" % ( month_name, year_lookup),
|
'title': "%s %s" % ( month_name, year_lookup),
|
||||||
},
|
},
|
||||||
@ -256,7 +257,8 @@ def date_hierarchy(cl):
|
|||||||
date_lookup_params = lookup_params.copy()
|
date_lookup_params = lookup_params.copy()
|
||||||
date_lookup_params.update({year_field: year_lookup, month_field: month_lookup})
|
date_lookup_params.update({year_field: year_lookup, month_field: month_lookup})
|
||||||
days = get_dates('day', date_lookup_params)
|
days = get_dates('day', date_lookup_params)
|
||||||
return { 'back':
|
return { 'show': True,
|
||||||
|
'back':
|
||||||
{ 'link' : link({year_field: year_lookup}),
|
{ 'link' : link({year_field: year_lookup}),
|
||||||
'title' : year_lookup
|
'title' : year_lookup
|
||||||
},
|
},
|
||||||
@ -268,7 +270,8 @@ def date_hierarchy(cl):
|
|||||||
date_lookup_params = lookup_params.copy()
|
date_lookup_params = lookup_params.copy()
|
||||||
date_lookup_params.update({year_field: year_lookup})
|
date_lookup_params.update({year_field: year_lookup})
|
||||||
months = get_dates('month', date_lookup_params)
|
months = get_dates('month', date_lookup_params)
|
||||||
return { 'back':
|
return { 'show' : True,
|
||||||
|
'back':
|
||||||
{ 'link' : link({}),
|
{ 'link' : link({}),
|
||||||
'title': _('All dates')
|
'title': _('All dates')
|
||||||
},
|
},
|
||||||
@ -278,7 +281,8 @@ def date_hierarchy(cl):
|
|||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
years = get_dates('year', lookup_params)
|
years = get_dates('year', lookup_params)
|
||||||
return { 'choices':
|
return { 'show': True,
|
||||||
|
'choices':
|
||||||
[ { 'link': link( {year_field: year.year}),
|
[ { 'link': link( {year_field: year.year}),
|
||||||
'title': year.year } for year in years ]
|
'title': year.year } for year in years ]
|
||||||
}
|
}
|
||||||
|
@ -59,20 +59,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
|
|||||||
return
|
return
|
||||||
raise validators.ValidationError, "%s with this %s already exists." % (capfirst(opts.verbose_name), f.verbose_name)
|
raise validators.ValidationError, "%s with this %s already exists." % (capfirst(opts.verbose_name), f.verbose_name)
|
||||||
|
|
||||||
# A guide to Field parameters:
|
|
||||||
#
|
|
||||||
# * name: The name of the field specifed in the model.
|
|
||||||
# * attname: The attribute to use on the model object. This is the same as
|
|
||||||
# "name", except in the case of ForeignKeys, where "_id" is
|
|
||||||
# appended.
|
|
||||||
# * db_column: The db_column specified in the model (or None).
|
|
||||||
# * column: The database column for this field. This is the same as
|
|
||||||
# "attname", except if db_column is specified.
|
|
||||||
#
|
|
||||||
# Code that introspects values, or does other dynamic things, should use
|
|
||||||
# attname. For example, this gets the primary key value of object "obj":
|
|
||||||
#
|
|
||||||
# getattr(obj, opts.pk.attname)
|
|
||||||
class BoundField(object):
|
class BoundField(object):
|
||||||
def __init__(self, field, field_mapping, original):
|
def __init__(self, field, field_mapping, original):
|
||||||
self.field = field
|
self.field = field
|
||||||
@ -92,6 +79,22 @@ class BoundField(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "BoundField:(%s, %s)" %( self.field.name, self.form_fields)
|
return "BoundField:(%s, %s)" %( self.field.name, self.form_fields)
|
||||||
|
|
||||||
|
|
||||||
|
# A guide to Field parameters:
|
||||||
|
#
|
||||||
|
# * name: The name of the field specifed in the model.
|
||||||
|
# * attname: The attribute to use on the model object. This is the same as
|
||||||
|
# "name", except in the case of ForeignKeys, where "_id" is
|
||||||
|
# appended.
|
||||||
|
# * db_column: The db_column specified in the model (or None).
|
||||||
|
# * column: The database column for this field. This is the same as
|
||||||
|
# "attname", except if db_column is specified.
|
||||||
|
#
|
||||||
|
# Code that introspects values, or does other dynamic things, should use
|
||||||
|
# attname. For example, this gets the primary key value of object "obj":
|
||||||
|
#
|
||||||
|
# getattr(obj, opts.pk.attname)
|
||||||
|
|
||||||
class Field(object):
|
class Field(object):
|
||||||
|
|
||||||
# Designates whether empty strings fundamentally are allowed at the
|
# Designates whether empty strings fundamentally are allowed at the
|
||||||
@ -224,7 +227,7 @@ class Field(object):
|
|||||||
if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.
|
if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.
|
||||||
params['maxlength'] = self.maxlength
|
params['maxlength'] = self.maxlength
|
||||||
if isinstance(self.rel, ManyToOne):
|
if isinstance(self.rel, ManyToOne):
|
||||||
params['member_name'] = name_prefix + self.get_db_column()
|
params['member_name'] = name_prefix + self.attname
|
||||||
if self.rel.raw_id_admin:
|
if self.rel.raw_id_admin:
|
||||||
field_objs = self.get_manipulator_field_objs()
|
field_objs = self.get_manipulator_field_objs()
|
||||||
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
|
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
|
||||||
@ -312,7 +315,8 @@ class Field(object):
|
|||||||
if self.choices:
|
if self.choices:
|
||||||
return first_choice + list(self.choices)
|
return first_choice + list(self.choices)
|
||||||
rel_obj = self.rel.to
|
rel_obj = self.rel.to
|
||||||
return first_choice + [(getattr(x, rel_obj.pk.attlist), str(x)) for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)]
|
return first_choice + [(getattr(x, rel_obj.pk.attname), str(x))
|
||||||
|
for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)]
|
||||||
|
|
||||||
def get_choices_default(self):
|
def get_choices_default(self):
|
||||||
if(self.radio_admin):
|
if(self.radio_admin):
|
||||||
@ -322,7 +326,7 @@ class Field(object):
|
|||||||
|
|
||||||
def _get_val_from_obj(self, obj):
|
def _get_val_from_obj(self, obj):
|
||||||
if obj:
|
if obj:
|
||||||
return getattr(obj, self.column)
|
return getattr(obj, self.attname)
|
||||||
else:
|
else:
|
||||||
return self.get_default()
|
return self.get_default()
|
||||||
|
|
||||||
@ -332,7 +336,7 @@ class Field(object):
|
|||||||
"flattened" string values for the admin view. Obj is the instance to extract the
|
"flattened" string values for the admin view. Obj is the instance to extract the
|
||||||
values from.
|
values from.
|
||||||
"""
|
"""
|
||||||
return { self.get_db_column(): self._get_val_from_obj(obj)}
|
return { self.attname : self._get_val_from_obj(obj)}
|
||||||
|
|
||||||
def get_follow(self, override=None):
|
def get_follow(self, override=None):
|
||||||
if override != None:
|
if override != None:
|
||||||
@ -716,7 +720,7 @@ class ForeignKey(Field):
|
|||||||
if not self.blank and not self.rel.raw_id_admin and self.choices:
|
if not self.blank and not self.rel.raw_id_admin and self.choices:
|
||||||
choice_list = self.get_choices_default()
|
choice_list = self.get_choices_default()
|
||||||
if len(choice_list) == 2:
|
if len(choice_list) == 2:
|
||||||
return { self.name : choice_list[1][0] }
|
return { self.attname : choice_list[1][0] }
|
||||||
return Field.flatten_data(self, follow, obj)
|
return Field.flatten_data(self, follow, obj)
|
||||||
|
|
||||||
class ManyToManyField(Field):
|
class ManyToManyField(Field):
|
||||||
@ -766,7 +770,7 @@ class ManyToManyField(Field):
|
|||||||
new_data = {}
|
new_data = {}
|
||||||
if obj:
|
if obj:
|
||||||
get_list_func = getattr(obj, 'get_%s_list' % self.rel.singular)
|
get_list_func = getattr(obj, 'get_%s_list' % self.rel.singular)
|
||||||
instance_ids = [getattr(instance, self.rel.to.pk.column) for instance in get_list_func()]
|
instance_ids = [getattr(instance, self.rel.to.pk.attname) for instance in get_list_func()]
|
||||||
if self.rel.raw_id_admin:
|
if self.rel.raw_id_admin:
|
||||||
new_data[self.name] = ",".join([str(id) for id in instance_ids])
|
new_data[self.name] = ",".join([str(id) for id in instance_ids])
|
||||||
else:
|
else:
|
||||||
|
@ -658,7 +658,6 @@ filter_raw_string = r"""
|
|||||||
}
|
}
|
||||||
|
|
||||||
filter_raw_string = filter_raw_string.replace("\n", "").replace(" ", "")
|
filter_raw_string = filter_raw_string.replace("\n", "").replace(" ", "")
|
||||||
|
|
||||||
filter_re = re.compile(filter_raw_string)
|
filter_re = re.compile(filter_raw_string)
|
||||||
|
|
||||||
class RegexFilterParser(object):
|
class RegexFilterParser(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user