Move utility functions to utils.

master
Tom Hacohen 4 years ago
parent 629a84f432
commit 13d4121fc2

@ -1,4 +1,3 @@
import dataclasses
import typing as t
from asgiref.sync import sync_to_async
@ -8,7 +7,7 @@ from django.core.files.base import ContentFile
from django.db import transaction
from django.db.models import Q
from django.db.models import QuerySet
from fastapi import APIRouter, Depends, status, Query, Request
from fastapi import APIRouter, Depends, status, Request
from pydantic import BaseModel
from django_etebase import models
@ -16,7 +15,7 @@ from .authentication import get_authenticated_user
from .exceptions import ValidationError, transform_validation_error
from .msgpack import MsgpackRoute, MsgpackResponse
from .stoken_handler import filter_by_stoken_and_limit, filter_by_stoken, get_stoken_obj, get_queryset_stoken
from .utils import get_object_or_404
from .utils import get_object_or_404, Context, Prefetch, PrefetchQuery
User = get_user_model()
collection_router = APIRouter(route_class=MsgpackRoute)
@ -24,16 +23,6 @@ default_queryset: QuerySet = models.Collection.objects.all()
default_item_queryset: QuerySet = models.CollectionItem.objects.all()
Prefetch = t.Literal["auto", "medium"]
PrefetchQuery = Query(default="auto")
@dataclasses.dataclass
class Context:
user: t.Optional[User]
prefetch: t.Optional[Prefetch]
class ListMulti(BaseModel):
collectionTypes: t.List[bytes]

@ -1,10 +1,25 @@
from fastapi import status
import dataclasses
import typing as t
from fastapi import status, Query
from django.db.models import QuerySet
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import get_user_model
from .exceptions import ValidationError
User = get_user_model()
Prefetch = t.Literal["auto", "medium"]
PrefetchQuery = Query(default="auto")
@dataclasses.dataclass
class Context:
user: t.Optional[User]
prefetch: t.Optional[Prefetch]
def get_object_or_404(queryset: QuerySet, **kwargs):
try:

Loading…
Cancel
Save