本文整理汇总了Python中django.contrib.admin.filterspecs.FilterSpec.register_front方法的典型用法代码示例。如果您正苦于以下问题:Python FilterSpec.register_front方法的具体用法?Python FilterSpec.register_front怎么用?Python FilterSpec.register_front使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.filterspecs.FilterSpec
的用法示例。
在下文中一共展示了FilterSpec.register_front方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: title
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import register_front [as 别名]
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = f.get_choices(include_blank=False)
def title(self):
return self.lookup_title
def choices(self, cl):
yield {'selected': self.lookup_val is None,
'query_string': cl.get_query_string({}, [self.lookup_kwarg]),
'display': _('All')}
for pk_val, val in self.lookup_choices:
yield {'selected': self.lookup_val == smart_unicode(pk_val),
'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}, [self.lookup_kwarg]),
'display': val}
FilterSpec.register_front(lambda f: bool(f.rel) and (not hasattr(f, 'null') or not f.null), RelatedFilterSpec)
#==============================================================================
class RelatedNullFilterSpec(FilterSpec):
def __init__(self, f, request, params, model, model_admin,
field_path=None):
super(RelatedNullFilterSpec, self).__init__(f, request, params, model, model_admin)
if isinstance(f, models.ManyToManyField):
self.lookup_title = f.rel.to._meta.verbose_name
else:
self.lookup_title = f.verbose_name
self.null_lookup_kwarg = '%s__isnull' % f.name
self.null_lookup_val = request.GET.get(self.null_lookup_kwarg, None)
rel_name = f.rel.get_related_field().name
self.lookup_kwarg = '%s__%s__exact' % (f.name, rel_name)
示例2: _register_front
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import register_front [as 别名]
yield {
'selected' : self.file_exists_lookup_val is not None,
'query_string' : cl.get_query_string({self.file_exists_lookup_kwarg : ""}, [self.file_not_exists_lookup_kwarg]),
'display' : 'PreGenCSV',
}
yield {
'selected' : self.file_not_exists_lookup_val is not None,
'query_string' : cl.get_query_string({self.file_not_exists_lookup_kwarg : ""}, [self.file_exists_lookup_kwarg]),
'display' : 'HUB-Core',
}
def _register_front(cls, test, factory):
cls.filter_specs.insert(0, (test, factory))
FilterSpec.register_front = classmethod(_register_front)
FilterSpec.register_front(lambda f: isinstance(f, FileNameField), IndicatorSourceListFilter)
# Actions available in Core
def batch_debug_indicators(modeladmin, request, queryset):
""" Run selected indicators, and store output and a "debug" csv
Each call to this view generates a view batch folder. The contents of the
folder:
- [indicator name].csv for each indicator selected
- [indicator name]_debug.csv for each indicator selected
- batch.log
The indicator generation is scheduled in celery, and output is directed to
batch.log.
"""