mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 23:17: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)
|
||||
|
||||
@@ -13,7 +13,7 @@ router = NinjaAPI(
|
||||
version="1",
|
||||
description="API docs for DataRush",
|
||||
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.errors import AuthenticationError
|
||||
|
||||
from api.v1.user.schemas import LoginSchema, RegisterSchema, TokenSchema, UserSchema
|
||||
from api.v1.auth import BearerAuth
|
||||
from api.v1.schemas import BadRequestError, ForbiddenError, NotFoundError
|
||||
from api.v1.user.schemas import (
|
||||
LoginSchema,
|
||||
RegisterSchema,
|
||||
TokenSchema,
|
||||
UserSchema,
|
||||
)
|
||||
from apps.user.models import User
|
||||
|
||||
router = Router(tags=["user"])
|
||||
@@ -56,5 +61,4 @@ def sign_in(request, data: LoginSchema):
|
||||
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.user.models import User
|
||||
|
||||
|
||||
class Competition(BaseModel):
|
||||
class CompetitionType(models.TextChoices):
|
||||
SOLO = "solo"
|
||||
|
||||
|
||||
class CompetitionParticipationType(models.TextChoices):
|
||||
EDU = "edu"
|
||||
COMPETITIVE = "competitive"
|
||||
|
||||
|
||||
title = models.CharField(max_length=100, verbose_name="Название")
|
||||
description = models.TextField(verbose_name="Описание")
|
||||
image_url = models.FileField(
|
||||
@@ -43,10 +42,10 @@ class Competition(BaseModel):
|
||||
|
||||
class State(BaseModel):
|
||||
class StateChoices(models.TextChoices):
|
||||
NOT_STARTED = 'not_started'
|
||||
STARTED = 'started'
|
||||
FINISHED = 'finished'
|
||||
NOT_STARTED = "not_started"
|
||||
STARTED = "started"
|
||||
FINISHED = "finished"
|
||||
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
|
||||
state = models.CharField(choices=StateChoices.choices, max_length=11)
|
||||
state = models.CharField(choices=StateChoices.choices, max_length=11)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import contextlib
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.core.cache import cache
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
|
||||
@@ -13,7 +13,9 @@ class User(BaseModel):
|
||||
username = models.SlugField(unique=True, 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):
|
||||
return self.username
|
||||
|
||||
Reference in New Issue
Block a user