コード例 #1
0
ファイル: modelfilters.py プロジェクト: Alotor/intranet
 def render(self, context):
     filters = []
     request = context['request']
     app_name = self.app_name.resolve(context)
     model_name = self.model_name.resolve(context)
     field_name = self.field_name.resolve(context)
     if self.choices_queryset is not None:
         choices_queryset = self.choices_queryset.resolve(context)
     else:
         choices_queryset = None
     model = models.get_model(app_name, model_name)
     qsm = QueryStringManager(request)
     params = qsm.get_params()
     if params.get('page', None):
         del params['page']
     field = model._meta.get_field(field_name)
     if field.get_internal_type() == 'FileField':
         spec = FieldAvailabilityValueFilterSpec(field, request, params, model, None)
     elif self.multiselection and (field.rel is not None): # is a related field (ForeignKeyField)
         spec = MultipleRelatedFilterSpec(field, request, params, model, None, choices_queryset)
     else: # normal filter spec
         spec = FilterSpec.create(field, request, params, model, None)
     filter_context = {'title': spec.title(), 'choices' : list(spec.choices(qsm))}
     tpl = loader.get_template('admin/filter.html')
     return tpl.render(Context(dict(filter_context, autoescape=context.autoescape)))
コード例 #2
0
ファイル: main.py プロジェクト: ajaksu/Melange
 def get_filters(self, request):
     filter_specs = []
     if self.list_filter:
         filter_fields = [self.lookup_opts.get_field(field_name) for field_name in self.list_filter]
         for f in filter_fields:
             spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #3
0
 def get_filters(self, request):
     filter_specs = []
     if self.list_filter:
         filter_fields = [self.lookup_opts.get_field(field_name) for field_name in self.list_filter]
         for f in filter_fields:
             spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #4
0
ファイル: main.py プロジェクト: 9gix/RC-Tech
 def get_filters(self, request):
     filter_specs = []
     if self.list_filter:
         for filter_name in self.list_filter:
             field = get_fields_from_path(self.model, filter_name)[-1]
             spec = FilterSpec.create(field, request, self.params,
                                      self.model, self.model_admin,
                                      field_path=filter_name)
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #5
0
ファイル: main.py プロジェクト: buriy/django
 def get_filters(self, request):
     filter_specs = []
     if self.list_filter:
         lookup_opts = self.lookup_opts
         for filter_name in self.list_filter:
             if '__' in filter_name:
                 f = None
                 model = self.model
                 path = filter_name.split('__')
                 for field_name in path[:-1]:
                     f = model._meta.get_field(field_name)
                     model = f.rel.to
                     f = model._meta.get_field(path[-1])
                     spec = FilterSpec.create(f, request, self.params, model, self.model_admin, field_path=filter_name)
             else:
                 f = lookup_opts.get_field(filter_name)
                 spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #6
0
ファイル: main.py プロジェクト: HimanshuPoptani/django-1
 def get_filters(self, request):
     filter_specs = []
     if self.list_filter:
         for filter_name in self.list_filter:
             field = get_fields_from_path(self.model, filter_name)[-1]
             spec = FilterSpec.create(field, request, self.params,
                                      self.model, self.model_admin,
                                      field_path=filter_name)
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #7
0
ファイル: custom_filters.py プロジェクト: ildus/ch
 def get_filters(self, request):
     filter_specs = []
     if self.list_filter:
         filter_fields = []
         for field_name in self.list_filter:
             if '__' in field_name:
                 names = field_name.split('__')
                 field = FakeField(name = names[0], rel_fields = names)
             else:
                 field = self.lookup_opts.get_field(field_name)
             filter_fields.append(field)
             
         for f in filter_fields:
             spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #8
0
ファイル: rtgchangelist.py プロジェクト: salvapinyol/metricas
 def get_filters(self, request):
     # Esto lo modificamos para que en el filtro solo aparezcan opciones con 
     # datos (por ejemplo, en la vista dispositivos solo aparezcan en el 
     # filtro de localidad las localidades que tienen dispositivos
     filter_specs = []
     if self.list_filter:
         for filter_name in self.list_filter:
             field = get_fields_from_path(self.model, filter_name)[-1]
             spec = FilterSpec.create(field, request, self.params,
                                      self.model, self.model_admin,
                                      field_path=filter_name)
             #Salva:
             if isinstance(spec, RelatedFilterSpec) and not '__' in filter_name:
                 spec.lookup_choices = [(x._get_pk_val(),x.__unicode__()) for x in field.rel.to.objects.annotate(num_rel=Count(self.model._meta.verbose_name)).filter(num_rel__gt=0)] #IGNORE:W0212 
             #Fin Modificacion                
             if spec and spec.has_output():
                 filter_specs.append(spec)
     return filter_specs, bool(filter_specs)
コード例 #9
0
 def create(cls, field, request, params, model, model_admin, *arg,
            **kw):
     return FilterSpec.create(field, request, params, model,
                              model_admin)