first
This commit is contained in:
commit
89a5d70512
284 files changed
+8364
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,30 @@
|
||||
from django.contrib import admin
|
||||
from apps.cuser.models import (
|
||||
CUser as CUserModel,
|
||||
CuserRole as CuserRoleModel,
|
||||
RoleType as RoleTypeModel,
|
||||
SmsOpt as SmsOptModel
|
||||
)
|
||||
# Register your models here.
|
||||
|
||||
|
||||
class CUserAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class CUserRoleAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class RoleTypeAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class SmsOptAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
admin.site.register(CUserModel, CUserAdmin)
|
||||
admin.site.register(CuserRoleModel, CUserRoleAdmin)
|
||||
admin.site.register(RoleTypeModel, RoleTypeAdmin)
|
||||
admin.site.register(SmsOptModel, SmsOptAdmin)
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CuserConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.cuser'
|
||||
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 4.2.1 on 2023-07-22 12:07
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CUser',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('username', models.CharField(max_length=50, unique=True)),
|
||||
('name_family', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('is_active', models.BooleanField(default=False)),
|
||||
('is_staff', models.BooleanField(default=False)),
|
||||
('is_superuser', models.BooleanField(default=False)),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,47 @@
|
||||
# Generated by Django 4.2.1 on 2023-07-23 05:20
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='RoleType',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('role_name', models.CharField(max_length=20)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CuserRole',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name_family', models.CharField(max_length=30)),
|
||||
('title', models.CharField(blank=True, max_length=30, null=True)),
|
||||
('mobile', models.PositiveBigIntegerField()),
|
||||
('mobile_verify', models.BooleanField(default=False)),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
('is_active', models.BooleanField(default=False)),
|
||||
('cuser', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cuser_role', to=settings.AUTH_USER_MODEL)),
|
||||
('role_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='role_type', to='cuser.roletype')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2023-08-08 08:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0002_roletype_cuserrole'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='roletype',
|
||||
name='role_name_en',
|
||||
field=models.CharField(default='', max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.1 on 2023-08-10 05:19
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0003_roletype_role_name_en'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='cuser',
|
||||
options={'permissions': [('user_is_workspace_owner', 'user is workspace owner'), ('user_is_workspace_admin', 'user is workspace admin'), ('user_is_workspace_operator', 'user is workspace operator'), ('user_is_workspace_customer', 'user is workspace customer')]},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 4.2.1 on 2023-08-20 08:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0004_alter_cuser_options'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SmsOpt',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('mobile', models.BigIntegerField()),
|
||||
('opt', models.IntegerField()),
|
||||
('expire', models.DateTimeField(blank=True, null=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2024-01-21 08:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0005_smsopt'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='cuser',
|
||||
name='mobile',
|
||||
field=models.PositiveBigIntegerField(default=411),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2024-01-21 08:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0006_cuser_mobile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='cuser',
|
||||
name='mobile',
|
||||
field=models.PositiveBigIntegerField(unique=True),
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,82 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
|
||||
from utils.base_model import BaseModel
|
||||
#from apps.workspace.models import Workspace as WorkspaceModel
|
||||
import uuid
|
||||
|
||||
# Create your models here.
|
||||
import random
|
||||
|
||||
class CUserManager(BaseUserManager):
|
||||
def create_user(self, username, password, **extra_fields):
|
||||
if not username:
|
||||
raise ValueError("Please Enter username")
|
||||
user = self.model(username=username, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def create_superuser(self, username, password, **extra_fields):
|
||||
extra_fields.setdefault('is_staff', True)
|
||||
extra_fields.setdefault('is_superuser', True)
|
||||
extra_fields.setdefault('is_active', True)
|
||||
|
||||
return self.create_user(username, password, **extra_fields)
|
||||
|
||||
|
||||
class CUser(BaseModel, AbstractBaseUser, PermissionsMixin):
|
||||
username = models.CharField(max_length=50, null=False, blank=False, unique=True)
|
||||
mobile = models.PositiveBigIntegerField(null=False, blank=False, unique=True)
|
||||
name_family = models.CharField(max_length=50, null=True, blank=True)
|
||||
is_active = models.BooleanField(default=False)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
is_superuser = models.BooleanField(default=False)
|
||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
|
||||
objects = CUserManager()
|
||||
|
||||
class Meta:
|
||||
permissions = [
|
||||
('user_is_workspace_owner', 'user is workspace owner'),
|
||||
('user_is_workspace_admin', 'user is workspace admin'),
|
||||
('user_is_workspace_operator', 'user is workspace operator'),
|
||||
('user_is_workspace_customer', 'user is workspace customer'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return str(self.username)
|
||||
|
||||
|
||||
class RoleType(BaseModel):
|
||||
role_name = models.CharField(max_length=20, null=False, blank=False)
|
||||
role_name_en = models.CharField(max_length=20, null=False, blank=False, default='')
|
||||
|
||||
def __str__(self):
|
||||
return str(self.role_name)
|
||||
|
||||
|
||||
class CuserRole(BaseModel):
|
||||
cuser = models.ForeignKey(CUser, on_delete=models.CASCADE, related_name='cuser_role')
|
||||
role_type = models.ForeignKey(RoleType, on_delete=models.CASCADE, related_name='role_type')
|
||||
name_family = models.CharField(max_length=30, null=False, blank=False)
|
||||
title = models.CharField(max_length=30, null=True, blank=True)
|
||||
mobile = models.PositiveBigIntegerField(null=False, blank=False)
|
||||
mobile_verify = models.BooleanField(default=False)
|
||||
#sys_ws = models.ForeignKey(WorkspaceModel, on_delete=models.CASCADE, null=True, blank=True, default=None)
|
||||
|
||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||
is_active = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f'{str(self.cuser) } - { str(self.id) }'
|
||||
|
||||
|
||||
class SmsOpt(BaseModel):
|
||||
mobile = models.BigIntegerField(null=False, blank=False)
|
||||
opt = models.IntegerField(null=False, blank=False)
|
||||
expire = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.mobile} {self.opt}'
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from apps.cuser.views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('info/', CUserGetInfo.as_view(), name='cuser_info'),
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
from rest_framework import views
|
||||
from apps.cuser.models import CuserRole as CuserRoleModel
|
||||
from utils.get_cuser_role import get_cuser_role_uuid
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
# Create your views here.
|
||||
|
||||
|
||||
class CUserGetInfo(views.APIView):
|
||||
def get(self, request):
|
||||
|
||||
cuser_role_uuid = get_cuser_role_uuid(request)
|
||||
cuser_obj = CuserRoleModel.objects.get(uuid=cuser_role_uuid)
|
||||
|
||||
return Response(data={"name_family": cuser_obj.name_family}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
Reference in new issue
Block a user