Esempio n. 1
0
  def get(self, request, set):
    top_s = request.query_params.get('top')
    top = None
    if top_s and top_s.isdigit():
      top = int(top_s) 

    date_range_s = request.query_params.get('date_range')
    date_range = None
    if date_range_s:
      date_range = parse_date_range(date_range_s)
      if not date_range:
        return Response(status=status.HTTP_400_BAD_REQUEST)
    else:
      date_range = date_start_end(request.user)
    
    qp = request.query_params
    category_set =  filter_category_set(set,qp.get('group'),qp.get('include'),qp.get('exclude'))
    if not category_set:
      return Response(status=status.HTTP_400_BAD_REQUEST)

    q = Transaction.category_total(
      request.user,
      category_set,
      date_range,
      top)
    serializer = CategoryTotalTransactionSerializer(q, many=True)
    return Response(serializer.data)
Esempio n. 2
0
 def resolve_period_total(self, info, period_len, set, group_name=None, include=None, exclude=None):
   if period_len not in PERIOD_LENGTHS:
     raise GraphQLError()
   category_set =  filter_category_set(set,group_name, include, exclude)
   if not category_set:
     raise GraphQLError()
   return Transaction.period_total(
     info.context.user,
     period_len,
     category_set)
Esempio n. 3
0
  def get(self, request, set, period_len):
    if period_len not in PERIOD_LENGTHS:
      return Response(status=status.HTTP_400_BAD_REQUEST)

    qp = request.query_params
    category_set =  filter_category_set(set,qp.get('group'),qp.get('include'),qp.get('exclude'))
    if not category_set:
      return Response(status=status.HTTP_400_BAD_REQUEST)

    q = Transaction.period_category_total(
      request.user,
      period_len,
      category_set)
    serializer = PeriodCategoryTotalTransactionSerializer(q, many=True)
    return Response(serializer.data)
Esempio n. 4
0
  def resolve_category_total(self, info, set, top=None, date_range=None, group_name=None, include=None, exclude=None):
    if date_range:
      date_range = parse_date_range(date_range)
      if not date_range:
        raise GraphQLError()
    else:
      date_range = date_start_end(info.context.user)

    category_set =  filter_category_set(set,group_name, include, exclude)
    if not category_set:
      raise GraphQLError()

    return Transaction.category_total(
      info.context.user,
      category_set,
      date_range,
      top)
Esempio n. 5
0
 def resolve_category_set_period_total(self, info, period_len):
     if period_len not in PERIOD_LENGTHS:
         raise GraphQLError()
     return Transaction.category_set_period_total(info.context.user,
                                                  period_len)