mirror of
https://github.com/more-tech4-magnum-opus/backend.git
synced 2024-11-21 19:16:33 +03:00
Merge branch 'main' into blockchain-and-clans
This commit is contained in:
commit
a89a9d9614
3
app/.env.example
Normal file
3
app/.env.example
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
DJANGO_DEBUG=yes
|
||||||
|
DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/moretech
|
||||||
|
CELERY_BROKER_URL=redis://localhost:6379/0
|
|
@ -2,6 +2,7 @@ from django.urls import path, include
|
||||||
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
|
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
|
||||||
|
|
||||||
from marketplace.api.views import ListCreateProductApi, RetireUpdateDestroyProductApi
|
from marketplace.api.views import ListCreateProductApi, RetireUpdateDestroyProductApi
|
||||||
|
from users.api.views import ListCreateUserApi
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
|
@ -30,4 +31,12 @@ urlpatterns = [
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"users/",
|
||||||
|
include(
|
||||||
|
[
|
||||||
|
path("", ListCreateUserApi.as_view(), name="user_list_create"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -13,7 +13,7 @@ SECRET_KEY = env(
|
||||||
default="7IFkV9gOD8gP3RbPfBuFmcUE4rPVvlnTlVScHr8OBCmHQrA1OIl2la2TJqKIBkTu",
|
default="7IFkV9gOD8gP3RbPfBuFmcUE4rPVvlnTlVScHr8OBCmHQrA1OIl2la2TJqKIBkTu",
|
||||||
)
|
)
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
||||||
ALLOWED_HOSTS = ["*"]
|
ALLOWED_HOSTS = ["dev.akarpov.ru", "127.0.0.1"]
|
||||||
|
|
||||||
# CACHES
|
# CACHES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django.core.validators import MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
@ -12,7 +13,7 @@ class Product(models.Model):
|
||||||
image_cropped = models.ImageField(upload_to="cropped/", blank=True)
|
image_cropped = models.ImageField(upload_to="cropped/", blank=True)
|
||||||
nft = models.CharField(max_length=500, blank=True)
|
nft = models.CharField(max_length=500, blank=True)
|
||||||
|
|
||||||
price = models.IntegerField()
|
price = models.IntegerField(validators=[MinValueValidator(0)])
|
||||||
creator = models.ForeignKey(User, related_name="products", on_delete=models.CASCADE)
|
creator = models.ForeignKey(User, related_name="products", on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
0
app/users/api/__init__.py
Normal file
0
app/users/api/__init__.py
Normal file
28
app/users/api/serializers.py
Normal file
28
app/users/api/serializers.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
"about",
|
||||||
|
"name",
|
||||||
|
"type",
|
||||||
|
"telegram",
|
||||||
|
"password",
|
||||||
|
"salary",
|
||||||
|
"respect",
|
||||||
|
"wallet_public_key",
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"password": {"write_only": True},
|
||||||
|
"wallet_public_key": {"read_only": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
user = User.objects.create(
|
||||||
|
**validated_data, username=validated_data["telegram"]
|
||||||
|
)
|
||||||
|
return user
|
12
app/users/api/views.py
Normal file
12
app/users/api/views.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from rest_framework import generics
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
|
from common.permissions import IsAdmin
|
||||||
|
from users.api.serializers import UserSerializer
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class ListCreateUserApi(generics.ListCreateAPIView):
|
||||||
|
serializer_class = UserSerializer
|
||||||
|
permission_classes = [IsAuthenticated, IsAdmin]
|
||||||
|
queryset = User.objects.all()
|
|
@ -4,3 +4,6 @@ from django.apps import AppConfig
|
||||||
class UsersConfig(AppConfig):
|
class UsersConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "users"
|
name = "users"
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
import users.signals
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
from django.core.validators import MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
|
||||||
|
@ -25,19 +26,21 @@ class User(AbstractUser):
|
||||||
# image_cropped = models.ImageField(upload_to="cropped/", blank=True)
|
# image_cropped = models.ImageField(upload_to="cropped/", blank=True)
|
||||||
|
|
||||||
about = models.TextField(blank=True)
|
about = models.TextField(blank=True)
|
||||||
|
name = models.CharField(max_length=120)
|
||||||
type = models.CharField(
|
type = models.CharField(
|
||||||
max_length=6, choices=WorkerType.choices, default=WorkerType.WORKER
|
max_length=6, choices=WorkerType.choices, default=WorkerType.WORKER
|
||||||
)
|
)
|
||||||
salary = models.IntegerField(default=0)
|
salary = models.IntegerField(default=0)
|
||||||
clan = models.ForeignKey(Clan, on_delete=models.CASCADE, null=True)
|
clan = models.ForeignKey(Clan, on_delete=models.CASCADE, null=True)
|
||||||
|
salary = models.IntegerField(default=0, validators=[MinValueValidator(0)])
|
||||||
|
respect = models.IntegerField(default=0, validators=[MinValueValidator(0)])
|
||||||
|
wallet_private_key = models.CharField(max_length=96, unique=True)
|
||||||
|
wallet_public_key = models.CharField(max_length=96, unique=True)
|
||||||
|
telegram = models.CharField(max_length=100, unique=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.username
|
return self.username
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
self.set_password(self.password)
|
|
||||||
super(AbstractUser, self).save(*args, **kwargs)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_manager(self):
|
def is_manager(self):
|
||||||
return self.type in [self.WorkerType.HR, self.WorkerType.ADMIN]
|
return self.type in [self.WorkerType.HR, self.WorkerType.ADMIN]
|
||||||
|
|
19
app/users/signals.py
Normal file
19
app/users/signals.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from django.db.models.signals import pre_save, post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from users.models import User
|
||||||
|
from utils.blockchain import create_wallet
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=User)
|
||||||
|
def create_user(sender, instance, **kwargs):
|
||||||
|
wallet = create_wallet()
|
||||||
|
instance.wallet_public_key = wallet.publicKey
|
||||||
|
instance.wallet_private_key = wallet.privateKey
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=User)
|
||||||
|
def process_user(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
instance.set_password(instance.password)
|
||||||
|
instance.save()
|
6
app/users/tasks.py
Normal file
6
app/users/tasks.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from celery import shared_task
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def process_dir(path):
|
||||||
|
return path
|
|
@ -1,3 +0,0 @@
|
||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
# Create your views here.
|
|
Loading…
Reference in New Issue
Block a user