Exemplo n.º 1
0
def method_test_title_description(
        request,
        param1: int = Query(..., title="param 1 title"),
        param2: str = Query("A Default", description="param 2 desc"),
        file: UploadedFile = File(..., description="file param desc"),
):
    return dict(i=param1, f=param2)
Exemplo n.º 2
0
def test_multi_query(
        request,
        i: int = Query(...),
        s: str = Query("a-str"),
        data: TestData4 = Query(...),
        nested_data: TestData = Query(..., alias="nested-data"),
):
    return dict(s=s, i=i, data=data, nested_data=nested_data)
Exemplo n.º 3
0
def query_params_mixed_schema(
        request,
        query1: int,
        query2: int = 5,
        filters: Filter = Query(...),
        data: Data = Query(...),
):
    return dict(query1=query1,
                query2=query2,
                filters=filters.dict(),
                data=data.dict())
Exemplo n.º 4
0
def get_datapoint_setpoint_latest(
        request,
        datapoint_filter_params: DatapointFilterParams = Query(...),
        setpoint_filter_params: SetpointFilterParams = Query(...),
):
    """
    Return the latest setpoints for datapoints targeted by the filter.
    """

    response = dp_setpoint_view.list_latest(
        request=request,
        datapoint_filter_params=datapoint_filter_params,
        related_filter_params=setpoint_filter_params,
    )
    return response
Exemplo n.º 5
0
def get_datapoint_value_latest(
        request,
        datapoint_filter_params: DatapointFilterParams = Query(...),
        value_filter_params: ValueMessageFilterParams = Query(...),
):
    """
    Return the latest values for datapoints targeted by the filter.
    """

    response = dp_value_view.list_latest(
        request=request,
        datapoint_filter_params=datapoint_filter_params,
        related_filter_params=value_filter_params,
    )
    return response
Exemplo n.º 6
0
def get_datapoint_schedule_history(
        request,
        datapoint_filter_params: DatapointFilterParams = Query(...),
        schedule_filter_params: ScheduleMessageFilterParams = Query(...),
):
    """
    Return one or more schedule messages for datapoints targeted by the filter.
    """

    response = dp_schedule_view.list_history(
        request=request,
        datapoint_filter_params=datapoint_filter_params,
        related_filter_params=schedule_filter_params,
    )
    return response
Exemplo n.º 7
0
def listview4(
        request,
        filters: Filters = Query(...),
):
    return {
        "filters": filters,
    }
Exemplo n.º 8
0
def get_datapoint_forecast_latest(
    request,
    product_run_filter_params: dp_forecast_view.PathParams = Path(...),
    datapoint_filter_params: DatapointFilterParams = Query(...),
    forecast_filter_params: dp_forecast_view.ForecastFilterParams = Query(...),
):
    """
    Return the latest setpoints for datapoints targeted by the filter.
    """

    response = dp_forecast_view.list_history(
        request=request,
        datapoint_filter_params=datapoint_filter_params,
        related_filter_params=forecast_filter_params,
        second_related_filter_params=product_run_filter_params,
    )
    return response
Exemplo n.º 9
0
def listview5(
        request,
        body: conlist(int, min_items=1),
        a_query: Data = Query(...),
):
    return {
        "query": a_query.data.query,
        "body": body,
    }
Exemplo n.º 10
0
def listview2(
        request,
        body: List[int],
        query: List[int] = Query(...),
):
    return {
        "query": query,
        "body": body,
    }
Exemplo n.º 11
0
def student_list(request,query_params: PageSizeQuerySchema = Query(...)):
    if any([request.auth['is_superuser'],request.auth['is_teacher']]):
        response, status = app.get(
            request, StudentSerializer, many=True, is_student=True
        )
    else:
        response = {"status":"failed","msg":"permission denied"}
        status = 403
    return JsonResponse(response, status=status)
Exemplo n.º 12
0
def listview1(
        request,
        query: List[int] = Query(...),
        form: List[int] = Form(...),
):
    return {
        "query": query,
        "form": form,
    }
Exemplo n.º 13
0
def get_datapoint_metadata_latest(
        request,
        datapoint_filter_params: DatapointFilterParams = Query(...),
):
    """
    Return a queryset of datapoints matching the requested filter
    parameters.
    """

    response = dpm_view.list_latest(
        request=request, datapoint_filter_params=datapoint_filter_params)
    return response
Exemplo n.º 14
0
class PaginationBase(ABC):
    class Input(Schema):
        pass

    InputSource = Query(...)

    def __init__(self, **kwargs: DictStrAny) -> None:
        pass

    @abstractmethod
    def paginate_queryset(self, items: QuerySet, request: HttpRequest,
                          **params: DictStrAny) -> QuerySet:
        pass  # pragma: no cover
Exemplo n.º 15
0
def teacher_list(request, query_params: PageSizeQuerySchema = Query(...)):
    if request.auth['is_superuser']:
        response, status = app.get(
            request, TeacherSerializer, many=True, is_teacher=True
        )
    elif request.auth['is_teacher']:
        response, status = app.get(
        request, Person, TeacherSerializer, many=False, is_teacher=True, id=request.auth['id']
        )
    else:
        response = {"status":"failed","msg":"permission denied"}
        status = 403
    return JsonResponse(response,status=status)
Exemplo n.º 16
0
def get_plant_latest(
        request,
        filter_params: PlantFilterParams = Query(...),
):
    """
    Return the latest state of the Plant objects.

    Plants define the metadata necessary to compute optimized schedules or
    forecasts for a physical entities, e.g. represent PV plants or buildings.
    """

    response = plant_view.list_latest(request=request,
                                      filter_params=filter_params)
    return response
Exemplo n.º 17
0
def get_product_run_latest(
        request,
        filter_params: ProductRunFilterParams = Query(...),
):
    """
    Return the latest state of the `Product` objects.

    Each entry specifies the metadata necessary (alongside with `Plant`) to
    trigger requests to a defined product service, like e.g. a PV Forecast.
    """

    response = product_run_view.list_latest(request=request,
                                            filter_params=filter_params)
    return response
Exemplo n.º 18
0
class PaginationBase(ABC):
    class Input(Schema):
        pass

    InputSource = Query(...)

    class Output(Schema):
        items: List[Any]
        count: int

    items_attribute: str = "items"

    def __init__(self,
                 *,
                 pass_parameter: Optional[str] = None,
                 **kwargs: Any) -> None:
        self.pass_parameter = pass_parameter

    @abstractmethod
    def paginate_queryset(
        self,
        queryset: QuerySet,
        pagination: Any,
        **params: DictStrAny,
    ) -> Any:
        pass  # pragma: no cover

    def _items_count(self, queryset: QuerySet) -> int:
        """
        Since lists are mainly compatible with QuerySets and can be passed to paginator.
        We will first to try to use .count - and if not there will use a len
        """
        try:
            # forcing to find queryset.count instead of list.count:
            return queryset.all().count()
        except AttributeError:
            return len(queryset)
Exemplo n.º 19
0
def get_query_param_required_type(request, query: int = Query(...)):
    return f"foo bar {query}"
Exemplo n.º 20
0
def get_query_param_required(request, query=Query(...)):
    return f"foo bar {query}"
Exemplo n.º 21
0
def get_query_param(request, query=Query(None)):
    if query is None:
        return "foo bar"
    return f"foo bar {query}"
Exemplo n.º 22
0
def events(request, filters: Filters = Query(...)):
    return {"filters": filters.dict()}
Exemplo n.º 23
0
def view4query(request, q: OtherModel = Query(...)):
    assert isinstance(q, OtherModel)
    return q
Exemplo n.º 24
0
def query_params_schema(request, filters: Filter = Query(...)):
    return filters.dict()
Exemplo n.º 25
0
def get_query_aliased_name(request, query: AliasedSchema = Query(...)):
    return f"foo bar {query.query}"
Exemplo n.º 26
0
def listview6(
        request,
        object_id: List[int] = Query(None, alias="id"),
):
    return {"query": object_id}