Esempio n. 1
0
    def get(self, request, format=None):
        service_object_id = request.query_params.get('service_object_id', None)
        service_object_type = request.query_params.get('service_object_type', None)

        if service_object_id is not None and service_object_type is None:
            raise ValidationError(
                    "If service_object_id is included in the request, then service_object_type must be included.")

        queryset = get_feedbacks(
                service_request_ids=request.query_params.get('service_request_id', None),
                service_codes=request.query_params.get('service_code', None),
                start_date=request.query_params.get('start_date', None),
                end_date=request.query_params.get('end_date', None),
                statuses=request.query_params.get('status', None),
                service_object_type=service_object_type,
                service_object_id=service_object_id,
                lat=request.query_params.get('lat', None),
                lon=request.query_params.get('long', None),
                radius=request.query_params.get('radius', None),
                updated_after=request.query_params.get('updated_after', None),
                updated_before=request.query_params.get('updated_before', None),
                search=request.query_params.get('search', None),
                agency_responsible=request.query_params.get('agency_responsible', None),
                order_by=request.query_params.get('order_by', None),
                use_limit=True
        )

        serializer = FeedbackSerializer(queryset, many=True,
                                        context={'extensions': request.query_params.get('extensions', 'false')})
        return Response(serializer.data)
Esempio n. 2
0
    def get(self, request, service_request_id, format=None):
        queryset = get_feedbacks(
                service_request_ids=service_request_id,
                service_codes=request.query_params.get('service_code', None),
                start_date=request.query_params.get('start_date', None),
                end_date=request.query_params.get('end_date', None),
                statuses=request.query_params.get('status', None),
                lat=request.query_params.get('lat', None),
                lon=request.query_params.get('long', None),
                radius=request.query_params.get('radius', None),
                updated_after=request.query_params.get('updated_after', None),
                updated_before=request.query_params.get('updated_before', None),
                search=request.query_params.get('search', None),
                order_by=request.query_params.get('order_by', None)
        )

        serializer = FeedbackSerializer(queryset, many=True,
                                        context={'extensions': request.query_params.get('extensions', 'false')})
        return Response(serializer.data)
Esempio n. 3
0
def feedback_list(request):
    queries_without_page = request.GET.copy()
    if 'page' in queries_without_page:
        del queries_without_page['page']

    filter_start_date = request.GET.get("start_date")
    filter_end_date = request.GET.get("end_date")
    filter_order_by = request.GET.get("order_by")

    if filter_start_date:
        filter_start_date = datetime.datetime.strptime(filter_start_date, "%d.%m.%Y").isoformat()

    if filter_end_date:
        filter_end_date = datetime.datetime.strptime(filter_end_date, "%d.%m.%Y").isoformat()

    if not filter_order_by:
        filter_order_by = "-requested_datetime"
        queries_without_page["order_by"] = filter_order_by

    filter_params = {
        'start_date': filter_start_date,
        'end_date': filter_end_date,
        'statuses': request.GET.get("status"),
        'order_by': filter_order_by,
        'service_codes': request.GET.get("service_code"),
        'search': request.GET.get("search"),
        'lat': request.GET.get("lat"),
        'lon': request.GET.get("lon"),
        'agency_responsible': request.GET.get('agency_responsible')
    }

    feedbacks = get_feedbacks(**filter_params)

    page = request.GET.get("page")

    context = {
        'feedbacks': paginate_query_set(feedbacks, 20, page),
        'services': Service.objects.all(),
        'queries': queries_without_page
    }

    return render(request, "feedback_list.html", context)
Esempio n. 4
0
    def get_context_data(self, form, **kwargs):
        context = super().get_context_data(form=form, **kwargs)
        if self.steps.current == 'closest':
            closest = get_feedbacks(
                    statuses='Open',
                    lat=60.17067,
                    lon=24.94152,
                    radius=3000,
                    order_by='distance')[:10]
            form_id = uuid.uuid4().hex
            context.update({'closest': closest, "form_id": form_id})
        elif self.steps.current == 'category':
            categories = []
            data = Service.objects.all()

            GLYPHICONS = ["glyphicon-fire", "glyphicon-trash", "glyphicon-tint", "glyphicon-road",
                          "glyphicon-warning-sign",
                          "glyphicon-picture", "glyphicon-tree-conifer", "glyphicon-cloud", "glyphicon-tree-deciduous",
                          "glyphicon-wrench"]

            idx = 0
            for item in data:
                category = {}
                category["name"] = item.service_name
                category["description"] = item.description
                category["src"] = "https://placehold.it/150x150"
                category["alt"] = "Category image"
                category["glyphicon"] = GLYPHICONS[idx]
                category["service_code"] = item.service_code
                categories.append(category)
                context.update({'categories': categories})
                idx += 1
        elif self.steps.current == "basic_info":
            prev = self.storage.get_step_data("closest")
            form_id = prev.get("closest-form_id", '')
            context.update({'form_id': form_id})
        return context
Esempio n. 5
0
def get_closed_by_service_code(service_code):
    return get_feedbacks(service_codes=service_code, statuses="closed")