mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 03:57:09 +00:00
lint: linted
This commit is contained in:
@@ -13,16 +13,17 @@ class CompetitionOut(ModelSchema):
|
||||
model = Competition
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class StateOut(ModelSchema):
|
||||
class Meta:
|
||||
model = State
|
||||
fields = (
|
||||
"state",
|
||||
)
|
||||
fields = ("state",)
|
||||
|
||||
|
||||
class StateIn(Schema):
|
||||
state: Literal["started", "not_started", "finished"]
|
||||
|
||||
|
||||
class CompetitionListInstanceOut(ModelSchema):
|
||||
id: UUID
|
||||
is_participating: bool
|
||||
@@ -36,7 +37,9 @@ class CompetitionListInstanceOut(ModelSchema):
|
||||
@staticmethod
|
||||
def resolve_completed(self, context):
|
||||
user = context["request"].auth
|
||||
return State.objects.filter(competition=self, user=user, state="finished").exists()
|
||||
return State.objects.filter(
|
||||
competition=self, user=user, state="finished"
|
||||
).exists()
|
||||
|
||||
class Meta:
|
||||
model = Competition
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from http import HTTPStatus as status
|
||||
from typing import Literal
|
||||
from uuid import UUID
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.http import HttpRequest, Http404
|
||||
from ninja import Router
|
||||
|
||||
import api.v1.schemas as global_schemas
|
||||
from api.v1.auth import BearerAuth
|
||||
from api.v1.competition import schemas
|
||||
from apps.competition.models import Competition, State
|
||||
|
||||
@@ -46,13 +45,14 @@ def list_competitions(
|
||||
competitions = Competition.objects.exclude(participants=user)
|
||||
return status.OK, competitions
|
||||
|
||||
|
||||
@router.post(
|
||||
"competitions/{competition_id}/state",
|
||||
response={
|
||||
status.OK: schemas.StateOut,
|
||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||
}
|
||||
},
|
||||
)
|
||||
def change_competition_state(
|
||||
request: HttpRequest,
|
||||
@@ -63,8 +63,6 @@ def change_competition_state(
|
||||
competition = get_object_or_404(Competition, id=competition_id)
|
||||
|
||||
state_obj, _ = State.objects.update_or_create(
|
||||
user=user,
|
||||
competition=competition,
|
||||
state=state.state
|
||||
user=user, competition=competition, state=state.state
|
||||
)
|
||||
return status.OK, schemas.StateOut.from_orm(state_obj)
|
||||
|
||||
Reference in New Issue
Block a user