first commit
This commit is contained in:
commit
3e4574dcdd
163 files changed
+3559
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,10 @@
|
||||
from django.contrib import admin
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from .models import CUser
|
||||
# Register your models here.
|
||||
|
||||
|
||||
@admin.register(CUser)
|
||||
class CUserAdmin(ImportExportModelAdmin):
|
||||
list_filter = ['step', 'type']
|
||||
search_fields = ['username', 'mobile', 'name_family', 'name_family']
|
||||
@@ -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,40 @@
|
||||
# Generated by Django 4.2.1 on 2024-03-27 10:12
|
||||
|
||||
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)),
|
||||
('mobile', models.PositiveBigIntegerField(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)),
|
||||
('step', models.CharField(choices=[('1', '1-register'), ('2', '2-profileOk')], default='1')),
|
||||
('type', models.CharField(choices=[('MO', 'mojri'), ('OP', 'operator')], default='MO')),
|
||||
('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,18 @@
|
||||
# Generated by Django 4.2.1 on 2024-03-27 12:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='cuser',
|
||||
name='mobile',
|
||||
field=models.PositiveBigIntegerField(blank=True, null=True, unique=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.1 on 2024-04-20 11:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cuser', '0002_alter_cuser_mobile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='cuser',
|
||||
name='mojri_status',
|
||||
field=models.CharField(blank=True, choices=[('WT', 'waiting'), ('AP', 'approv'), ('RJ', 'reject')], default='WT', null=True),
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,63 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
|
||||
from utils.base_model import BaseModel
|
||||
import uuid
|
||||
# Create your models here.
|
||||
|
||||
|
||||
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):
|
||||
|
||||
STEP_CHOICES = [
|
||||
("1", "1-register"),
|
||||
("2", "2-profileOk")
|
||||
]
|
||||
|
||||
TYPE_CHOICES = [
|
||||
("MO", "mojri"),
|
||||
("OP", "operator")
|
||||
]
|
||||
|
||||
STATUS_CHOICES = [
|
||||
("WT", "waiting"),
|
||||
("AP", "approv"),
|
||||
("RJ", "reject"),
|
||||
]
|
||||
|
||||
username = models.CharField(max_length=50, null=False, blank=False, unique=True)
|
||||
mobile = models.PositiveBigIntegerField(null=True, blank=True, 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)
|
||||
step = models.CharField(default='1', null=False, blank=False, choices=STEP_CHOICES)
|
||||
type = models.CharField(default='MO', null=False, blank=False, choices=TYPE_CHOICES)
|
||||
mojri_status = models.CharField(default='WT', null=True, blank=True, choices=STATUS_CHOICES)
|
||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
|
||||
objects = CUserManager()
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name_family} - {self.username} - {self.mobile} - {self.type}'
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from apps.cuser.views import MojriInfoApiview
|
||||
|
||||
urlpatterns = [
|
||||
path('info/', MojriInfoApiview.as_view(), name='mojri-info'),
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,78 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from django.contrib.auth import get_user_model
|
||||
from apps.cuser.models import CUser as CUserModel
|
||||
from apps.project.models import Project as ProjectModel
|
||||
from rest_framework import serializers
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.generics import ListAPIView
|
||||
from utils.standard_pagination import StandardPagination
|
||||
from utils.tools.inline_serializer import inline_serializer
|
||||
from apps.emtiyazat.selector import get_emtiyaz_mojri
|
||||
#get user model
|
||||
|
||||
CUserModel2 = get_user_model()
|
||||
|
||||
|
||||
class MojriInfoApiview(APIView):
|
||||
permission_classes = (IsAuthenticated, )
|
||||
|
||||
def get(self, request):
|
||||
|
||||
user_project_count = ProjectModel.objects.filter(cuser=request.user).count()
|
||||
name_family = request.user.name_family
|
||||
step = request.user.step
|
||||
|
||||
if request.user.user_profile.ax_mojri:
|
||||
image = request.user.user_profile.ax_mojri.url
|
||||
else:
|
||||
image = '/media/media/app/usericon.jpg'
|
||||
|
||||
emtiyaz = get_emtiyaz_mojri(cuser=request.user)
|
||||
|
||||
output = {
|
||||
'project_count': user_project_count,
|
||||
'name_family': name_family,
|
||||
'emtiyaz': emtiyaz,
|
||||
'step': step,
|
||||
'image': image
|
||||
}
|
||||
|
||||
return Response(output, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ListMojrian(ListAPIView):
|
||||
|
||||
class OutputSerializer(serializers.ModelSerializer):
|
||||
|
||||
user_profile = inline_serializer(many=False, fields={
|
||||
'codemeli': serializers.IntegerField(),
|
||||
'city': inline_serializer(many=False, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
'ostan': inline_serializer(many=False, fields={
|
||||
'id': serializers.IntegerField(),
|
||||
'name': serializers.CharField(),
|
||||
})
|
||||
}),
|
||||
'address': serializers.CharField(),
|
||||
'codeposti': serializers.IntegerField(),
|
||||
'ax_mojri': serializers.CharField(),
|
||||
'ax_meli': serializers.CharField(),
|
||||
'ax_fani': serializers.CharField(),
|
||||
'ax_sayer': serializers.CharField(),
|
||||
|
||||
})
|
||||
|
||||
class Meta:
|
||||
model = CUserModel2
|
||||
fields = ('id', 'name_family', 'mobile', 'uuid', 'user_profile')
|
||||
|
||||
permission_classes = (IsAuthenticated,)
|
||||
serializer_class = OutputSerializer
|
||||
pagination_class = StandardPagination
|
||||
|
||||
def get_queryset(self):
|
||||
mojri_status = self.request.query_params.get('status', 'WT')
|
||||
return CUserModel2.objects.filter(type='MO', is_superuser=False, mojri_status=mojri_status)
|
||||
Reference in new issue
Block a user