mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 21:27:10 +00:00
lint: linted
This commit is contained in:
@@ -13,16 +13,17 @@ class CompetitionOut(ModelSchema):
|
|||||||
model = Competition
|
model = Competition
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
class StateOut(ModelSchema):
|
class StateOut(ModelSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = State
|
model = State
|
||||||
fields = (
|
fields = ("state",)
|
||||||
"state",
|
|
||||||
)
|
|
||||||
|
|
||||||
class StateIn(Schema):
|
class StateIn(Schema):
|
||||||
state: Literal["started", "not_started", "finished"]
|
state: Literal["started", "not_started", "finished"]
|
||||||
|
|
||||||
|
|
||||||
class CompetitionListInstanceOut(ModelSchema):
|
class CompetitionListInstanceOut(ModelSchema):
|
||||||
id: UUID
|
id: UUID
|
||||||
is_participating: bool
|
is_participating: bool
|
||||||
@@ -36,7 +37,9 @@ class CompetitionListInstanceOut(ModelSchema):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_completed(self, context):
|
def resolve_completed(self, context):
|
||||||
user = context["request"].auth
|
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:
|
class Meta:
|
||||||
model = Competition
|
model = Competition
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
from http import HTTPStatus as status
|
from http import HTTPStatus as status
|
||||||
from typing import Literal
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
|
from django.http import HttpRequest
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.http import HttpRequest, Http404
|
|
||||||
from ninja import Router
|
from ninja import Router
|
||||||
|
|
||||||
import api.v1.schemas as global_schemas
|
import api.v1.schemas as global_schemas
|
||||||
from api.v1.auth import BearerAuth
|
|
||||||
from api.v1.competition import schemas
|
from api.v1.competition import schemas
|
||||||
from apps.competition.models import Competition, State
|
from apps.competition.models import Competition, State
|
||||||
|
|
||||||
@@ -46,13 +45,14 @@ def list_competitions(
|
|||||||
competitions = Competition.objects.exclude(participants=user)
|
competitions = Competition.objects.exclude(participants=user)
|
||||||
return status.OK, competitions
|
return status.OK, competitions
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
"competitions/{competition_id}/state",
|
"competitions/{competition_id}/state",
|
||||||
response={
|
response={
|
||||||
status.OK: schemas.StateOut,
|
status.OK: schemas.StateOut,
|
||||||
status.BAD_REQUEST: global_schemas.BadRequestError,
|
status.BAD_REQUEST: global_schemas.BadRequestError,
|
||||||
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
status.UNAUTHORIZED: global_schemas.UnauthorizedError,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
def change_competition_state(
|
def change_competition_state(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
@@ -63,8 +63,6 @@ def change_competition_state(
|
|||||||
competition = get_object_or_404(Competition, id=competition_id)
|
competition = get_object_or_404(Competition, id=competition_id)
|
||||||
|
|
||||||
state_obj, _ = State.objects.update_or_create(
|
state_obj, _ = State.objects.update_or_create(
|
||||||
user=user,
|
user=user, competition=competition, state=state.state
|
||||||
competition=competition,
|
|
||||||
state=state.state
|
|
||||||
)
|
)
|
||||||
return status.OK, schemas.StateOut.from_orm(state_obj)
|
return status.OK, schemas.StateOut.from_orm(state_obj)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ router = NinjaAPI(
|
|||||||
version="1",
|
version="1",
|
||||||
description="API docs for DataRush",
|
description="API docs for DataRush",
|
||||||
openapi_url="/docs/openapi.json",
|
openapi_url="/docs/openapi.json",
|
||||||
auth=BearerAuth()
|
auth=BearerAuth(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,14 @@ from http import HTTPStatus as status
|
|||||||
from ninja import Router
|
from ninja import Router
|
||||||
from ninja.errors import AuthenticationError
|
from ninja.errors import AuthenticationError
|
||||||
|
|
||||||
from api.v1.user.schemas import LoginSchema, RegisterSchema, TokenSchema, UserSchema
|
|
||||||
from api.v1.auth import BearerAuth
|
from api.v1.auth import BearerAuth
|
||||||
from api.v1.schemas import BadRequestError, ForbiddenError, NotFoundError
|
from api.v1.schemas import BadRequestError, ForbiddenError, NotFoundError
|
||||||
|
from api.v1.user.schemas import (
|
||||||
|
LoginSchema,
|
||||||
|
RegisterSchema,
|
||||||
|
TokenSchema,
|
||||||
|
UserSchema,
|
||||||
|
)
|
||||||
from apps.user.models import User
|
from apps.user.models import User
|
||||||
|
|
||||||
router = Router(tags=["user"])
|
router = Router(tags=["user"])
|
||||||
@@ -56,5 +61,4 @@ def sign_in(request, data: LoginSchema):
|
|||||||
status.NOT_FOUND: NotFoundError,
|
status.NOT_FOUND: NotFoundError,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def get_user(request, user_id: str):
|
def get_user(request, user_id: str): ...
|
||||||
...
|
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ from django.db import models
|
|||||||
from apps.core.models import BaseModel
|
from apps.core.models import BaseModel
|
||||||
from apps.user.models import User
|
from apps.user.models import User
|
||||||
|
|
||||||
|
|
||||||
class Competition(BaseModel):
|
class Competition(BaseModel):
|
||||||
class CompetitionType(models.TextChoices):
|
class CompetitionType(models.TextChoices):
|
||||||
SOLO = "solo"
|
SOLO = "solo"
|
||||||
|
|
||||||
|
|
||||||
class CompetitionParticipationType(models.TextChoices):
|
class CompetitionParticipationType(models.TextChoices):
|
||||||
EDU = "edu"
|
EDU = "edu"
|
||||||
COMPETITIVE = "competitive"
|
COMPETITIVE = "competitive"
|
||||||
|
|
||||||
|
|
||||||
title = models.CharField(max_length=100, verbose_name="Название")
|
title = models.CharField(max_length=100, verbose_name="Название")
|
||||||
description = models.TextField(verbose_name="Описание")
|
description = models.TextField(verbose_name="Описание")
|
||||||
image_url = models.FileField(
|
image_url = models.FileField(
|
||||||
@@ -43,9 +42,9 @@ class Competition(BaseModel):
|
|||||||
|
|
||||||
class State(BaseModel):
|
class State(BaseModel):
|
||||||
class StateChoices(models.TextChoices):
|
class StateChoices(models.TextChoices):
|
||||||
NOT_STARTED = 'not_started'
|
NOT_STARTED = "not_started"
|
||||||
STARTED = 'started'
|
STARTED = "started"
|
||||||
FINISHED = 'finished'
|
FINISHED = "finished"
|
||||||
|
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
|
competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import contextlib
|
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.core.cache import cache
|
|
||||||
|
|
||||||
|
|
||||||
class CoreConfig(AppConfig):
|
class CoreConfig(AppConfig):
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ class User(BaseModel):
|
|||||||
username = models.SlugField(unique=True, verbose_name="Юзернейм")
|
username = models.SlugField(unique=True, verbose_name="Юзернейм")
|
||||||
password = models.TextField(verbose_name="Пароль")
|
password = models.TextField(verbose_name="Пароль")
|
||||||
|
|
||||||
status = models.CharField(max_length=10, choices=UserRole, default="student")
|
status = models.CharField(
|
||||||
|
max_length=10, choices=UserRole, default="student"
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.username
|
return self.username
|
||||||
|
|||||||
Reference in New Issue
Block a user