def get_context(self, data, accepted_media_type, renderer_context):
     filters_on = False
     filter_fields = None
     context = super(BrowsableAPIRenderer,
                     self).get_context(data, accepted_media_type,
                                       renderer_context)
     request = renderer_context.get('request')
     r = request.GET
     try:
         model = context.get('view').get_queryset().model
         query = QueryParser(model, r.get('query'))
         if hasattr(model, 'filter_fields'):
             filter_fields = query.populate_filter_fields()
             for ff in filter_fields:
                 if hasattr(ff, 'value'):
                     filters_on = True
                     break
         context.update({
             'filter_fields': filter_fields,
             'sql': query.query_text,
             'object_type': model.model_name,
             'object_name_plural': model.model_name_plural,
             'has_filters': True,
             'filters_on': filters_on
         })
     except Exception:
         context.update({'filter_fields': ['No model detected']})
     return context
Esempio n. 2
0
def metadata(ret, view, request):
    from localground.apps.lib.helpers import QueryParser

    form = models.Form.objects.get(id=view.kwargs.get("form_id"))
    query = QueryParser(form.TableModel, request.GET.get("query"))
    ret["filters"] = query.to_dict_list()
    return ret
Esempio n. 3
0
 def filter_queryset(self, request, queryset, view):
     r = request.GET or request.POST
     if r.get('query'):
         query = QueryParser(queryset.model, r.get('query'))
         return query.extend_query(queryset)
     else:
         return queryset
Esempio n. 4
0
 def filter_queryset(self, request, queryset, view):
     r = request.GET or request.POST
     if r.get('query'):
         query = QueryParser(queryset.model, r.get('query'))
         return query.extend_query(queryset)
     else:
         return queryset
 def get_context(self, data, accepted_media_type, renderer_context):
     filters_on = False
     filter_fields = None
     context = super(BrowsableAPIRenderer, self).get_context(
         data, accepted_media_type, renderer_context
     )
     request = renderer_context.get('request')
     r = request.GET
     try:
         model = context.get('view').get_queryset().model
         query = QueryParser(model, r.get('query'))
         if hasattr(model, 'filter_fields'):
             filter_fields = query.populate_filter_fields()
             for ff in filter_fields:
                 if hasattr(ff, 'value'):
                     filters_on = True
                     break
         context.update({
             'filter_fields': filter_fields,
             'sql': query.query_text,
             'object_type': model.model_name,
             'object_name_plural': model.model_name_plural,
             'has_filters': True,
             'filters_on': filters_on
         })
     except Exception:
         context.update({
             'filter_fields': ['No model detected']
         })
     return context
Esempio n. 6
0
    def metadata(self, request):
        # extend the existing metadata method in the parent class by adding a
        # list of available filters
        from localground.apps.lib.helpers import QueryParser
        from django.utils.datastructures import SortedDict

        ret = super(QueryableListCreateAPIView, self).metadata(request)
        ret = SortedDict(ret)
        try:
            query = QueryParser(self.model, request.GET.get('query'))
            ret['filters'] = query.to_dict_list()
        except Exception:
            pass
        return ret
Esempio n. 7
0
    def metadata(self, request):
        # extend the existing metadata method in the parent class by adding a
        # list of available filters
        from localground.apps.lib.helpers import QueryParser
        from django.utils.datastructures import SortedDict

        ret = super(QueryableListCreateAPIView, self).metadata(request)
        ret = SortedDict(ret)
        try:
            query = QueryParser(self.model, request.GET.get('query'))
            ret['filters'] = query.to_dict_list()
        except Exception:
            pass
        return ret
Esempio n. 8
0
    def _apply_sql_filter(self, queryset, request, context):
        if context.get('has_filters') is not None:
            return queryset
        if request is None or request.GET.get('query') is None:
            return queryset

        from localground.apps.lib.helpers import QueryParser
        query = QueryParser(self.model, request.GET.get('query'))
        if query.error:
            context.update({'error_message': query.error_message})
            return queryset

        # Add some information to the request context
        context.update({
            'filter_fields': query.populate_filter_fields(),
            'sql': query.query_text,
            'has_filters': True
        })
        return query.extend_query(queryset)