瀏覽代碼

Necessary corrections have been made for correct operation with the sharix-open-user-model

TonyKurts 10 月之前
父節點
當前提交
0425c5e542

+ 1 - 0
.gitignore

@@ -17,6 +17,7 @@ conf/
 design_template/
 webservice_running/
 landing/
+user/
 
 # Django
 migrations/

+ 3 - 3
SharixAdmin/admin.py

@@ -2,7 +2,7 @@
 from django.contrib import admin
 from django.http import HttpResponseRedirect
 from django.shortcuts import render
-from SharixAdmin.models import *
+from django.contrib.auth import get_user_model
 from django import forms
 from xmpp import cli
 from django.contrib.auth.admin import UserAdmin
@@ -47,8 +47,8 @@ class PermissionsAdmin(admin.ModelAdmin):
         'codename',
     )
     
-@admin.register(SharixUser)
-class SharixUserAdmin(adm.UserAdmin):
+@admin.register(get_user_model())
+class ShariXUserAdmin(adm.UserAdmin):
     
     list_display = (
         'username',

+ 2 - 2
SharixAdmin/apiviews.py

@@ -3,7 +3,7 @@ from .serializer import *
 from rest_framework import viewsets, permissions, exceptions
 from rest_framework.authentication import TokenAuthentication
 from rest_framework.decorators import action
-from SharixAdmin.models import *
+from django.contrib.auth import get_user_model
 from rest_framework.views import APIView
 from rest_framework.response import Response
 from xmpp import cli
@@ -25,7 +25,7 @@ schema_view = get_schema_view(
 )
 
 class SharixUserMVS(viewsets.ModelViewSet):
-    queryset = SharixUser.objects.all()
+    queryset = get_user_model().objects.all()
     serializer_class = UserSerializer
     #permission_classes = [IsOwnerOrReadOnly]
     permission_classes = [permissions.IsAuthenticated]

+ 2 - 3
SharixAdmin/forms.py

@@ -1,10 +1,9 @@
 from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth import get_user_model
 
 from metaservicesynced.models import *
-from .models import SharixUser
 from django import forms
 from metaservicesynced.models import ServiceType, Service
-from .models import SharixUser
 from django import forms
 
 class LoginUserForm(AuthenticationForm):
@@ -16,7 +15,7 @@ class LoginUserForm(AuthenticationForm):
         widget=forms.TextInput(attrs={'class':'form-control'}))
 
     class Meta:
-        model = SharixUser
+        model = get_user_model()
         fields = ['username', 'password']
 
 

+ 1 - 26
SharixAdmin/models.py

@@ -1,26 +1 @@
-from django.db import models
-from django.contrib.auth.models import AbstractUser
-from django.urls import reverse
-
-
-class SharixUser(AbstractUser):
-    """
-    Пользователь - здесь находиться описание сущности!
-    """
-    #pk = models.BigAutoField(help_text="А здесь можно добавить описание поля")
-    phone_number = models.CharField(max_length=60, unique=True, blank=False, verbose_name='Номер телефона', help_text="А здесь можно добавить описание поля")
-
-    USERNAME_FIELD = 'phone_number'
-    REQUIRED_FIELDS = ['username']
-
-    @property
-    def full_name(self):
-        if self.first_name == "" or self.last_login  == "":
-            return self.username
-        else:
-            return f"{self.first_name} {self.last_name}"
-        
-    class Meta:
-        db_table = "auth_user"
-
-# Create your models here.
+from django.db import models

+ 2 - 2
SharixAdmin/serializer.py

@@ -1,14 +1,14 @@
 from rest_framework import serializers
 #from rest_framework.exceptions import ValidationError
 #from django.contrib.auth.models import User
-from .models import *
+from django.contrib.auth import get_user_model
 from django.contrib.auth.models import *
 
 class UserSerializer(serializers.ModelSerializer):
     full_name = serializers.ReadOnlyField()
     group_name = serializers.ReadOnlyField(source="groups.name")
     class Meta:
-        model = SharixUser
+        model = get_user_model()
         exclude = ['password', 'id']
         read_only_fields = ['username', 'phone_number']
         extra_kwargs = {

+ 3 - 2
SharixAdmin/tables.py

@@ -1,6 +1,7 @@
 import django_tables2 as tables
+from django.contrib.auth import get_user_model
+
 from metaservicesynced.models import *
-from .models import *
 from django.utils.html import format_html
 from metaservicesynced.models import *
 from django.utils.translation import gettext_lazy as _
@@ -166,7 +167,7 @@ class UserInfoTable(tables.Table):
     id = tables.Column(verbose_name=_('ID'), attrs={"td":{"width":"5%"}})
 
     class Meta:
-        model = SharixUser
+        model = get_user_model()
         attrs = {"class": "table table-layout-fixed"}
         exclude = ('password', 'phone_number', 
                    'last_login','is_staff', 'is_superuser',

+ 3 - 2
SharixAdmin/views/user_info.py

@@ -1,6 +1,7 @@
+from django.contrib.auth import get_user_model
+
 from django_tables2 import SingleTableView
 from SharixAdmin.tables import UserInfoTable
-from SharixAdmin.models import SharixUser
 from SharixAdmin.views.context import get_context
 from django.contrib.auth.mixins import UserPassesTestMixin
 from django.contrib.auth.models import Group
@@ -8,7 +9,7 @@ from django.utils.translation import gettext as _
 
 class UserListView(UserPassesTestMixin, SingleTableView):
     table_class = UserInfoTable
-    queryset = SharixUser.objects.all()
+    queryset = get_user_model().objects.all()
     template_name = 'SharixAdmin/user_information.html'
 
     def get_context_data(self, **kwargs):

+ 3 - 2
bin/install.sh

@@ -22,10 +22,11 @@ update_repository() {
 # Update repositories
 update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-tickets.git" "tickets" "master"
 update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-backend.git" "metaservicesynced" "metasynced_module"
-update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-settings.git" "conf" "master"
+update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-config.git" "conf" "master"
 update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-webapp-design-template.git" "design_template" "unstable"
 update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-webservice-running.git" "webservice_running" "unstable"
 update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-landing.git" "landing" "landing_module"
+update_repository "https://git.sharix-app.org/ShariX_Open/sharix-open-user-model.git" "user" "master"
 git pull
 
 # Create a Python virtual environment and activate it
@@ -45,7 +46,7 @@ else
 fi
 
 # Run Django migrations and other commands
-python manage.py makemigrations SharixAdmin metaservicesynced tickets webservice_running landing
+python manage.py makemigrations metaservicesynced tickets webservice_running landing user
 python manage.py migrate
 python manage.py collectstatic -l --no-input
 

+ 2 - 1
core/settings.py

@@ -36,6 +36,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'user.apps.UserConfig',
     'SharixAdmin.apps.SharixadminConfig',
     'tickets.apps.TicketsConfig',
     'metaservicesynced.apps.MetaservicesyncedConfig',
@@ -169,7 +170,7 @@ MESSAGE_TAGS = {message_constants.ERROR: "danger"}
 # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 
-AUTH_USER_MODEL = 'SharixAdmin.SharixUser'
+AUTH_USER_MODEL = 'user.ShariXUser'
 
 NAME_SYSTEM = sv.NAME_SYSTEM
 

+ 2 - 1
requirements.txt

@@ -56,4 +56,5 @@ uritemplate==4.1.1
 urllib3==1.26.14
 webencodings==0.5.1
 xmpppy==0.7.1
-django-ckeditor
+django-ckeditor
+pillow