gold eggs backend
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s

This commit is contained in:
2026-04-15 08:59:36 +02:00
commit ab73d05ecc
359 changed files with 14415 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from .another import * # noqa
from .base import * # noqa
from .user import * # noqa

View File

@@ -0,0 +1,47 @@
from django.db import models
from polymorphic import models as polymorphic
from django.utils.translation import gettext as _
class Tags(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Meta:
verbose_name = _("Tag")
verbose_name_plural = _("Tags")
class Comment(models.Model):
text = models.CharField(max_length=255)
def __str__(self) -> str:
return self.text
class BaseComment(polymorphic.PolymorphicModel):
comments = models.ManyToManyField(Comment)
class Post(BaseComment):
title = models.CharField(max_length=255)
desc = models.TextField()
image = models.ImageField(upload_to="posts/", blank=True)
tags = models.ManyToManyField(Tags)
def __str__(self):
return self.title
class FrontendTranslation(BaseComment):
key = models.CharField(max_length=255, unique=True)
value = models.TextField()
def __str__(self):
return self.key
class Meta:
verbose_name = _("Frontend Translation")
verbose_name_plural = _("Frontend Translations")

9
core/http/models/base.py Normal file
View File

@@ -0,0 +1,9 @@
from django.db import models
class AbstractBaseModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True

110
core/http/models/user.py Normal file
View File

@@ -0,0 +1,110 @@
import math
from datetime import datetime, timedelta
from django.contrib.auth import models as auth_models
from django.db import models
from django.utils.translation import gettext_lazy as _
from core.http import managers
class User(auth_models.AbstractUser):
ROLE_CHOICES = (
("admin", _("Admin")),
("market", _("Market")),
("courier", _("Courier")),
("sklad", _("Sklad")),
)
phone = models.CharField(max_length=255, unique=True)
username = models.CharField(max_length=255, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
validated_at = models.DateTimeField(null=True, blank=True)
USERNAME_FIELD = "phone"
objects = managers.UserManager()
avatar = models.ImageField(
upload_to="avatars/",
null=True,
blank=True,
default="avatars/golden_eggs.png",
)
role = models.CharField(
max_length=10,
choices=ROLE_CHOICES,
default="admin",
)
fcm_token = models.CharField(max_length=255, null=True, blank=True)
def __str__(self):
return f"{self.phone} | {self.id}"
class SmsConfirm(models.Model):
SMS_EXPIRY_SECONDS = 120
RESEND_BLOCK_MINUTES = 10
TRY_BLOCK_MINUTES = 2
RESEND_COUNT = 5
TRY_COUNT = 10
code = models.IntegerField()
try_count = models.IntegerField(default=0)
resend_count = models.IntegerField(default=0)
phone = models.CharField(max_length=20)
expire_time = models.DateTimeField(null=True, blank=True)
unlock_time = models.DateTimeField(null=True, blank=True)
resend_unlock_time = models.DateTimeField(null=True, blank=True)
def sync_limits(self):
if self.resend_count >= self.RESEND_COUNT:
self.try_count = 0
self.resend_count = 0
self.resend_unlock_time = datetime.now() + timedelta(
minutes=self.RESEND_BLOCK_MINUTES
)
elif self.try_count >= self.TRY_COUNT:
self.try_count = 0
self.unlock_time = datetime.now() + timedelta(
minutes=self.TRY_BLOCK_MINUTES
)
if (
self.resend_unlock_time is not None
and self.resend_unlock_time.timestamp()
< datetime.now().timestamp()
):
self.resend_unlock_time = None
if (
self.unlock_time is not None
and self.unlock_time.timestamp() < datetime.now().timestamp()
):
self.unlock_time = None
self.save()
def is_expired(self):
return (
self.expire_time.timestamp() < datetime.now().timestamp()
if hasattr(self.expire_time, "timestamp")
else None
)
def is_block(self):
return self.unlock_time is not None
def reset_limits(self):
self.try_count = 0
self.resend_count = 0
self.unlock_time = None
def interval(self, time):
expire = time.timestamp() - datetime.now().timestamp()
minutes = math.floor(expire / 60)
expire -= minutes * 60
expire = math.floor(expire)
return f"{minutes:02d}:{expire:02d}"
def __str__(self) -> str:
return f"{self.phone} | {self.code}"