2022-10-08 13:52:49 +03:00
|
|
|
from rest_framework import serializers
|
2022-10-08 20:13:21 +03:00
|
|
|
from ..services import create_season
|
2022-10-09 02:24:31 +03:00
|
|
|
from users.models import User, Department, Stream, Command, Clan
|
2022-10-08 13:52:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = [
|
|
|
|
"about",
|
|
|
|
"name",
|
|
|
|
"type",
|
|
|
|
"telegram",
|
|
|
|
"password",
|
|
|
|
"salary",
|
|
|
|
"respect",
|
|
|
|
"wallet_public_key",
|
2022-10-08 16:02:57 +03:00
|
|
|
"command",
|
|
|
|
"department",
|
2022-10-09 00:42:30 +03:00
|
|
|
"clan_name",
|
2022-10-09 02:24:31 +03:00
|
|
|
"money",
|
2022-10-08 13:52:49 +03:00
|
|
|
]
|
|
|
|
extra_kwargs = {
|
|
|
|
"password": {"write_only": True},
|
|
|
|
"wallet_public_key": {"read_only": True},
|
2022-10-09 00:42:30 +03:00
|
|
|
"clan_name": {"read_only": True},
|
2022-10-08 16:02:57 +03:00
|
|
|
"department": {"read_only": True},
|
2022-10-09 02:24:31 +03:00
|
|
|
"money": {"read_only": True},
|
2022-10-08 13:52:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
def create(self, validated_data):
|
|
|
|
user = User.objects.create(
|
|
|
|
**validated_data, username=validated_data["telegram"]
|
|
|
|
)
|
|
|
|
return user
|
2022-10-08 17:14:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CreateSeasonSerializer(serializers.Serializer):
|
|
|
|
created = serializers.BooleanField(read_only=True)
|
2022-10-09 00:42:30 +03:00
|
|
|
|
2022-10-08 17:14:19 +03:00
|
|
|
def create(self, *args, **kwargs):
|
|
|
|
create_season()
|
2022-10-09 00:42:30 +03:00
|
|
|
return {"created": True}
|
2022-10-08 17:16:16 +03:00
|
|
|
|
2022-10-09 02:24:31 +03:00
|
|
|
def update(self, instance, validated_data):
|
|
|
|
pass
|
|
|
|
|
2022-10-08 17:16:16 +03:00
|
|
|
|
2022-10-08 16:02:57 +03:00
|
|
|
class CommandSerializer(serializers.ModelSerializer):
|
|
|
|
workers = UserSerializer(many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Command
|
|
|
|
fields = ["id", "name", "stream", "workers"]
|
|
|
|
extra_kwargs = {
|
|
|
|
"id": {"read_only": True},
|
|
|
|
"stream": {"write_only": True},
|
|
|
|
"workers": {"read_only": True},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class StreamSerializer(serializers.ModelSerializer):
|
|
|
|
commands = CommandSerializer(many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Stream
|
|
|
|
fields = ["id", "name", "department", "commands"]
|
|
|
|
extra_kwargs = {
|
|
|
|
"id": {"read_only": True},
|
|
|
|
"department": {"write_only": True},
|
|
|
|
"commands": {"read_only": True},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DepartmentSerializer(serializers.ModelSerializer):
|
|
|
|
streams = StreamSerializer(many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Department
|
|
|
|
fields = ["id", "name", "streams"]
|
|
|
|
extra_kwargs = {
|
|
|
|
"id": {"read_only": True},
|
|
|
|
"streams": {"read_only": True},
|
|
|
|
}
|
2022-10-09 00:42:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ClanSerializer(serializers.ModelSerializer):
|
|
|
|
users = UserSerializer(many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Clan
|
|
|
|
fields = ["name", "users"]
|