Ejemplo n.º 1
0
def get_agendaitem_by_tag(request, tag_name):
    '''
       Get agenda items for a specific tag name type. 
       Can ammend returns with offset and limit query parameters
    '''
    agenda_items = AgendaItem.objects.filter(
        tags__name=tag_name).select_related().all()
    limit = request.GET.get('limit')
    offset = request.GET.get('offset')
    total_length = len(agenda_items)
    num_returned = total_length
    if (offset is not None):
        try:
            offset = int(offset)
            end = None
            if (limit is not None):
                limit = int(limit)
                end = limit + offset
            if offset <= len(agenda_items):
                agenda_items = agenda_items[offset:end]
                num_returned = len(agenda_items)
            else:
                return Response(status=400)
        except ValueError:
            return Response(status=400)
    serialized_items = AgendaItemSerializer(agenda_items, many=True)
    data = {}
    data['tag'] = tag_name
    data['items'] = serialized_items.data
    data['limit'] = limit
    data['offset'] = offset
    data['total_items'] = total_length
    data['items_returned'] = num_returned
    return Response(data=data)
Ejemplo n.º 2
0
def get_agendaitem_by_tag(request, tag_name):
    agenda_items = AgendaItem.objects.filter(
        tags__name=tag_name).select_related().all()
    serialized_items = AgendaItemSerializer(agenda_items, many=True)
    data = {}
    data['tag'] = tag_name
    data['items'] = serialized_items.data
    return Response(data=data)
Ejemplo n.º 3
0
def get_agenda_item(request, agenda_item_id):
    '''
    Returns JSON serialized agenda item
    '''
    agenda_item = AgendaItem.objects.get(agenda_item_id=agenda_item_id)
    if agenda_item is None:
        return Response(data={"error": "No agenda item with id:" + str(agenda_item_id)}, status=404)
    data = AgendaItemSerializer(agenda_item, many=False).data
    return Response(data=data, status=200)