コード例 #1
0
 def filter_queryset(self, request, queryset, view):
     if not hasattr(view, 'date_range_filter_fields'):
         return queryset
     try:
         fields = dict(view.date_range_filter_fields)
     except ValueError:
         msg = "View {} datetime_filter_fields set is error".format(
             view.name)
         logging.error(msg)
         return queryset
     kwargs = {}
     for attr, date_range_keyword in fields.items():
         if len(date_range_keyword) != 2:
             continue
         for i, v in enumerate(date_range_keyword):
             value = request.query_params.get(v)
             if not value:
                 continue
             try:
                 field = DateTimeField()
                 value = field.to_internal_value(value)
                 if i == 0:
                     lookup = "__gte"
                 else:
                     lookup = "__lte"
                 kwargs[attr + lookup] = value
             except ValidationError as e:
                 print(e)
                 continue
     if kwargs:
         queryset = queryset.filter(**kwargs)
     return queryset
コード例 #2
0
ファイル: filters.py プロジェクト: WaylonWang2020/JumpServer
    def filter_queryset(self, request, queryset, view):
        fields = self._get_date_range_filter_fields(view)

        kwargs = {}
        for attr, date_range_keyword in fields.items():
            if len(date_range_keyword) != 2:
                continue
            for i, v in enumerate(date_range_keyword):
                value = request.query_params.get(v)
                if not value:
                    continue
                try:
                    field = DateTimeField()
                    value = field.to_internal_value(value)
                    if i == 0:
                        lookup = "__gte"
                    else:
                        lookup = "__lte"
                    kwargs[attr + lookup] = value
                except ValidationError as e:
                    print(e)
                    continue
        if kwargs:
            queryset = queryset.filter(**kwargs)
        return queryset
コード例 #3
0
ファイル: views.py プロジェクト: yfix/alco
    def log_model(self):
        start_ts = self.request.GET.get('start_ts') or ''
        try:
            f = DateTimeField()
            distr = f.to_internal_value(start_ts).strftime('%Y%m%d')
        except Exception:
            distr = None

        return create_index_model(self.index, distr=distr)
コード例 #4
0
ファイル: views.py プロジェクト: rutube/alco
    def log_model(self):
        start_ts = self.request.GET.get("start_ts") or ""
        try:
            f = DateTimeField()
            distr = f.to_internal_value(start_ts).strftime("%Y%m%d")
        except Exception:
            distr = None

        return create_index_model(self.index, distr=distr)
コード例 #5
0
def django_time_format(dtstr):
    """Convert a datetime to string according to the API settings"""
    from rest_framework.fields import DateTimeField

    field = DateTimeField()
    return field.to_internal_value(dtstr)
コード例 #6
0
ファイル: __init__.py プロジェクト: hds-lab/coding-ml
def django_time_format(dtstr):
    """Convert a datetime to string according to the API settings"""
    from rest_framework.fields import DateTimeField

    field = DateTimeField()
    return field.to_internal_value(dtstr)