Пример #1
0
def get_poi_by_cat_id(request, cat_id, format=None):
    """
    Get all poi features for children and grandchildren of incomping parent cateogry id
    :param request:
    :param campus_id: id of campus as integer
    :param cat_id:
    :param format:
    :return:
    """
    if request.method == 'GET':

        poicat_qs = PoiCategory.objects.filter(enabled=True).get(pk=cat_id).get_descendants()
        # cat_children = PoiCategory.objects.add_related_count(poicat_qs,Poi,'category', 'cat_name')
        # poicat_qs = Poi.objects.filter(category__in=PoiCategory.objects.get(pk=cat_id) \
        #                        .get_descendants(include_self=True))

        poi_ids = []
        for x in poicat_qs:
            poi_ids.append(x.id)

        qs_objs = Poi.objects.filter(category_id__in=poi_ids).filter(enabled=True)

        if qs_objs:
            serializer = PoiSerializer(qs_objs, many=True)
            return Response(serializer.data)
        elif len(poi_ids)==0:
            qs = Poi.objects.filter(category_id = cat_id).filter(enabled=True)
            serializer = PoiSerializer(qs, many=True)
            return Response(serializer.data)
        else:
            return Response({'error': 'something booomed with category id : ' + cat_id})
Пример #2
0
def get_poi_by_cat_name(request, category_name, format=None):
    cats = PoiCategory.objects.filter(cat_name__exact=category_name).filter(enabled=True)
    # list = cats.get_descendants()


    # from itertools import chain
    # result_list = list(chain(page_list, article_list, post_list))

    if cats:
        if len(cats) > 1:
            cat_ids = []
            for cat in cats:

                cat_ids.append(cat.id)

            poi_qs = Poi.objects.filter(category__in=cat_ids).filter(enabled=True)

        else:
            poi_qs = Poi.objects.filter(category=cats[0].id).filter(enabled=True)
    else:
        # return Response({'error': 'No Poi found with the given category name: ' + category_name} )
        return Response({'error': 'no category found with the given category name: ' + category_name})

    if poi_qs:
        serializer = PoiSerializer(poi_qs, many=True)

        return Response(serializer.data)

    else:
        return Response({'error': 'sorry no poi entries found assigned to the category name : ' + category_name})
Пример #3
0
def get_poi_by_id(request, poi_id, format=None):
    try:
        poi_qs = Poi.objects.filter(id=poi_id).filter(enabled=True)
        serializer = PoiSerializer(poi_qs, many=True)
        return Response(serializer.data)

    except Exception as e:
        raise APIException(detail=e)
Пример #4
0
def poi_list(request, campus_id, format=None):
    try:
        poi_qs = Poi.objects.filter(enabled=True)
        serializer = PoiSerializer(poi_qs, many=True)
        return Response(serializer.data)

    except Exception as e:
        raise APIException(detail=e)
Пример #5
0
def get_poi_by_category(request, category_name, format=None):
    if request.method == 'GET':
        try:
            cats = PoiCategory.objects.filter(enabled=True).get(cat_name__contains=category_name)

            if cats:

                poi_qs = Poi.objects.filter(category=cats.id).filter(enabled=True)
                if poi_qs:
                    serializer = PoiSerializer(poi_qs, many=True)
                    return Response(serializer.data)
        except Exception as e:
            raise APIException(detail=e)
Пример #6
0
def get_poi_by_cat_id(request, campus_id, cat_id, format=None):
    if request.method == 'GET':

        poicat_qs = PoiCategory.objects.filter(enabled=True).get(pk=cat_id)
        cat_children = PoiCategory.objects.add_related_count(poicat_qs.get_children(),Poi,'fk_poi_category', 'cat_name')

        poi_ids = []

        for x in poicat_qs.get_children():
            poi_ids.append(x.id)

        qs_objs = Poi.objects.filter(fk_poi_category_id__in=poi_ids).filter(enabled=True)

        if cat_children:
            serializer = PoiSerializer(qs_objs, many=True)
            return Response(serializer.data)
        elif len(poi_ids)==0:
            qs = Poi.objects.filter(fk_poi_category_id = cat_id).filter(enabled=True)
            serializer = PoiSerializer(qs, many=True)
            return Response(serializer.data)
        else:
            return Response({'error': 'something booomed with category id : ' + cat_id})