Merge branch 'master' of https://e.coding.net/ctcdevteam/examtest
This commit is contained in:
commit
4a539505c2
|
@ -15,9 +15,8 @@ import load from "./dynamicLoadScript";
|
|||
import { upUrl, upHeaders } from "@/api/file";
|
||||
import { getToken } from "@/utils/auth";
|
||||
// why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
|
||||
const tinymceCDN =
|
||||
"https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js";
|
||||
|
||||
const tinymceCDN ="http://lib.baomitu.com/tinymce/4.9.3/tinymce.min.js";
|
||||
// "https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/tinymce/4.9.3/tinymce.min.js";
|
||||
export default {
|
||||
name: "Tinymce",
|
||||
props: {
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
# Generated by Django 3.2.12 on 2024-09-14 03:03
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0014_auto_20231207_2146'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CompanyInfo',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
|
||||
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
|
||||
('is_delete', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
|
||||
('company_name', models.CharField(max_length=50, verbose_name='父公司名称')),
|
||||
('edu_points', models.FloatField(blank=True, null=True, verbose_name='教育积分')),
|
||||
('co_sponsor_points', models.FloatField(blank=True, null=True, verbose_name='协办大赛积分')),
|
||||
('sum_points', models.FloatField(blank=True, null=True, verbose_name='总积分')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ChildrenCompany',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
|
||||
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
|
||||
('is_delete', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
|
||||
('child_company_name', models.CharField(max_length=50, verbose_name='子公司名称')),
|
||||
('child_edu_points', models.FloatField(blank=True, null=True, verbose_name='教育积分')),
|
||||
('child_co_sponsor_points', models.FloatField(blank=True, null=True, verbose_name='协办大赛积分')),
|
||||
('parent_compnay', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cms.companyinfo', verbose_name='父公司')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-09-14 06:03
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0015_auto_20240914_1103'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='childrencompany',
|
||||
old_name='parent_compnay',
|
||||
new_name='parent_comany',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-09-14 06:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0016_auto_20240914_1403'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='childrencompany',
|
||||
old_name='parent_comany',
|
||||
new_name='parent_company',
|
||||
)
|
||||
]
|
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.2.12 on 2024-09-18 03:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cms', '0017_auto_20240914_1405'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='childrencompany',
|
||||
name='child_company_name',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='article',
|
||||
name='type',
|
||||
field=models.IntegerField(default=0, verbose_name='类型'),
|
||||
),
|
||||
]
|
|
@ -11,6 +11,7 @@ class Article(CommonModel):
|
|||
content = models.TextField(verbose_name='内容', blank=True)
|
||||
ifrom = models.CharField(max_length=60, verbose_name='来源')
|
||||
is_top = models.BooleanField('置顶', default=False)
|
||||
type = models.IntegerField('类型', default=0)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '文章'
|
||||
|
@ -63,5 +64,26 @@ class Threshold(CommonModel):
|
|||
cas = models.CharField('cas号', max_length=20)
|
||||
|
||||
|
||||
class CompanyInfo(CommonModel):
|
||||
company_name = models.CharField('父公司名称', max_length=50)
|
||||
edu_points = models.FloatField('教育积分', null=True, blank=True)
|
||||
co_sponsor_points = models.FloatField('协办大赛积分', null=True, blank=True)
|
||||
sum_points = models.FloatField('总积分', null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.company_name
|
||||
|
||||
|
||||
class ChildrenCompany(CommonModel):
|
||||
child_edu_points = models.FloatField('教育积分', null=True, blank=True)
|
||||
child_co_sponsor_points = models.FloatField('协办大赛积分', null=True, blank=True)
|
||||
parent_company = models.ForeignKey(CompanyInfo, verbose_name='父公司', on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.child_company_name
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Article, Material, Source, Threshold
|
||||
from .models import Article, Material, Source, Threshold, CompanyInfo, ChildrenCompany
|
||||
from utils.constants import EXCLUDE_FIELDS_BASE
|
||||
|
||||
|
||||
|
@ -47,4 +47,65 @@ class ThresholdSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class PathSerializer(serializers.Serializer):
|
||||
path = serializers.CharField(label='文件地址')
|
||||
path = serializers.CharField(label='文件地址')
|
||||
|
||||
|
||||
|
||||
class CompanyInfoSerializer(serializers.ModelSerializer):
|
||||
# children_companies = serializers.SerializerMethodField()
|
||||
class Meta:
|
||||
model = CompanyInfo
|
||||
fields = '__all__'
|
||||
|
||||
# def get_children_companies(self, obj):
|
||||
# children = ChildrenCompany.objects.filter(parent_company=obj)
|
||||
# return ChildrenCompanySerializer(children, many=True).data
|
||||
|
||||
def create(self, validated_data):
|
||||
instance = super().create(validated_data)
|
||||
instance.sum_points = validated_data["edu_points"] + validated_data["co_sponsor_points"]
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
|
||||
class ChildrenCompanySerializer(serializers.ModelSerializer):
|
||||
parent_company_name = serializers.StringRelatedField(source='parent_company.company_name', read_only=True)
|
||||
class Meta:
|
||||
model = ChildrenCompany
|
||||
fields = '__all__'
|
||||
|
||||
def create(self, validated_data):
|
||||
instance = super().create(validated_data)
|
||||
parent_company = instance.parent_company
|
||||
children = ChildrenCompany.objects.filter(parent_company=parent_company)
|
||||
|
||||
total_edu = sum(c.child_edu_points or 0 for c in children)
|
||||
total_sponsor = sum(c.child_co_sponsor_points or 0 for c in children)
|
||||
# 加上未保存的分数
|
||||
parent_company.edu_points = total_edu
|
||||
parent_company.co_sponsor_points = total_sponsor
|
||||
parent_company.sum_points = parent_company.edu_points + parent_company.co_sponsor_points
|
||||
parent_company.save()
|
||||
return instance
|
||||
|
||||
|
||||
# # # 定义信号处理器
|
||||
# from django.db.models.signals import pre_save
|
||||
# from django.dispatch import receiver
|
||||
# from .models import ChildrenCompany, CompanyInfo
|
||||
|
||||
|
||||
# @receiver(pre_save, sender=ChildrenCompany)
|
||||
# def update_parent_sum_points(sender, instance, **kwargs):
|
||||
# parent_company = instance.parent_company
|
||||
# child_companies = ChildrenCompany.objects.filter(parent_company=parent_company)
|
||||
# # 计算子公司的积分
|
||||
# child_edu_sum = sum(c.child_edu_points or 0 for c in child_companies)
|
||||
# child_co_sponsor_sum = sum(c.child_co_sponsor_points or 0 for c in child_companies)
|
||||
|
||||
# # 更新父公司的总积分
|
||||
# parent_company.edu_points = child_edu_sum
|
||||
# parent_company.co_sponsor_points = child_co_sponsor_sum
|
||||
# parent_company.sum_points = child_edu_sum + child_co_sponsor_sum
|
||||
# parent_company.save()
|
|
@ -1,5 +1,5 @@
|
|||
from django.urls import path,include
|
||||
from .views import ArticleViewSet, MaterialViewSet, SourceViewSet, ThresholdViewSet
|
||||
from .views import ArticleViewSet, MaterialViewSet, SourceViewSet, ThresholdViewSet, ConpamyInfoViewSet, ChildrenCompanyViewSet
|
||||
from rest_framework import routers
|
||||
|
||||
|
||||
|
@ -8,6 +8,8 @@ router.register('article', ArticleViewSet, basename="article")
|
|||
router.register('material', MaterialViewSet, basename="material")
|
||||
router.register('source', SourceViewSet, basename='source')
|
||||
router.register('threshold', ThresholdViewSet, basename='threshold')
|
||||
router.register('company', ConpamyInfoViewSet, basename='company')
|
||||
router.register('childcomany', ChildrenCompanyViewSet, basename='child_company')
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
|
|
@ -11,8 +11,8 @@ from openpyxl import load_workbook, Workbook
|
|||
from django.db import transaction
|
||||
# Create your views here.
|
||||
|
||||
from .models import Article, Material, Source, Threshold
|
||||
from .serializers import ArticelSerializer, ArticelListSerializer, MaterialSerializer, SourceSerializer, ThresholdSerializer, PathSerializer
|
||||
from .models import Article, Material, Source, Threshold, CompanyInfo, ChildrenCompany
|
||||
from .serializers import ArticelSerializer, ArticelListSerializer, MaterialSerializer, SourceSerializer, ThresholdSerializer, PathSerializer, CompanyInfoSerializer, ChildrenCompanySerializer
|
||||
from utils.custom import CommonPagination
|
||||
class ArticleViewSet(ModelViewSet):
|
||||
"""
|
||||
|
@ -25,9 +25,10 @@ class ArticleViewSet(ModelViewSet):
|
|||
serializer_class = ArticelSerializer
|
||||
pagination_class = CommonPagination
|
||||
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||
search_fields = ['title','content']
|
||||
search_fields = ['title','content', 'types']
|
||||
ordering_fields = ['title','update_time']
|
||||
ordering = ['-is_top', '-update_time']
|
||||
filterset_fields = ['type']
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action=='list':
|
||||
|
@ -45,6 +46,38 @@ class ArticleViewSet(ModelViewSet):
|
|||
instance.save()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ConpamyInfoViewSet(ModelViewSet):
|
||||
"""
|
||||
父公司:增删改查
|
||||
"""
|
||||
perms_map = [
|
||||
{'get': '*'}, {'post': 'article_create'},
|
||||
{'put': 'article_update'}, {'delete': 'article_delete'}]
|
||||
queryset = CompanyInfo.objects.filter(is_delete=0).all()
|
||||
serializer_class = CompanyInfoSerializer
|
||||
pagination_class = CommonPagination
|
||||
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||
search_fields = ['company_name']
|
||||
ordering_fields = ['update_time']
|
||||
ordering = ['-sum_points']
|
||||
|
||||
|
||||
class ChildrenCompanyViewSet(ModelViewSet):
|
||||
"""
|
||||
子公司:增删改查
|
||||
"""
|
||||
perms_map = [
|
||||
{'get': '*'}, {'post': 'article_create'},
|
||||
{'put': 'article_update'}, {'delete': 'article_delete'}]
|
||||
queryset = ChildrenCompany.objects.filter(is_delete=0).all()
|
||||
serializer_class = ChildrenCompanySerializer
|
||||
pagination_class = CommonPagination
|
||||
filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
|
||||
filterset_fields = ['parent_company']
|
||||
ordering_fields = ['update_time']
|
||||
ordering = ['-update_time']
|
||||
|
||||
class MaterialViewSet(ModelViewSet):
|
||||
"""
|
||||
资料:增删改查
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.12 on 2024-09-19 08:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('crm', '0046_auto_20230407_1012'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='candidate',
|
||||
name='gender',
|
||||
field=models.CharField(blank=True, max_length=10, null=True, verbose_name='性别'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='candidate',
|
||||
name='opllevel',
|
||||
field=models.CharField(blank=True, max_length=60, null=True, verbose_name='职业等级'),
|
||||
),
|
||||
]
|
|
@ -129,6 +129,8 @@ class Candidate(CommonModel):
|
|||
train_start_date = models.DateField('培训开始日期', null=True)
|
||||
train_end_date = models.DateField('培训结束日期', null=True)
|
||||
create_admin = models.ForeignKey(UserProfile, verbose_name="创建管理员", null=True, blank=True, on_delete=models.SET_NULL)
|
||||
gender = models.CharField('性别', max_length=10, null=True, blank=True)
|
||||
opllevel = models.CharField('职业等级',max_length=60, null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '证书'
|
||||
|
|
|
@ -5,6 +5,8 @@ from rest_framework.permissions import IsAuthenticated
|
|||
from django.core.cache import cache
|
||||
from django.utils import timezone
|
||||
from datetime import datetime, timedelta
|
||||
from django.core.cache import cache
|
||||
from rbac.permission import get_permission_list
|
||||
# 学员接口列表
|
||||
ConsumerPerms = [
|
||||
'paper_view',
|
||||
|
@ -53,11 +55,13 @@ class MyPermission(RbacPermission):
|
|||
:return:
|
||||
"""
|
||||
perms = []
|
||||
# if 'perms' in request.session:
|
||||
# perms = request.session['perms']
|
||||
if isinstance(request.user, UserProfile): # 如果是管理员表
|
||||
# perms = get_permission_list(request.user)
|
||||
return True
|
||||
if request.user.is_superuser:
|
||||
return True
|
||||
perms = cache.get(f'{request.user.id}_perms', None)
|
||||
if perms is None:
|
||||
perms = get_permission_list(request.user)
|
||||
perms.extend(ConsumerPerms)
|
||||
elif isinstance(request.user, Consumer): # 如果是客户
|
||||
perms = cache.get('cperms_'+str(request.user.id), None)
|
||||
if not perms:
|
||||
|
|
|
@ -29,7 +29,7 @@ class SubjectViewSet(ModelViewSet):
|
|||
学科分类:增删改查
|
||||
"""
|
||||
perms_map = (
|
||||
{'get': 'subject_view'}, {'post': 'subject_create'},
|
||||
{'get': '*'}, {'post': 'subject_create'},
|
||||
{'put': 'subject_update'}, {'delete': 'subject_delete'})
|
||||
queryset = Questioncat.objects.filter(is_subject=True,is_delete=0).all().order_by("id")
|
||||
serializer_class = SubjectSerializer
|
||||
|
@ -44,7 +44,7 @@ class QuestioncatViewSet(ModelViewSet):
|
|||
题库分类:增删改查
|
||||
"""
|
||||
perms_map = (
|
||||
{'get': 'questioncat_view'}, {'post': 'questioncat_create'},
|
||||
{'get': '*'}, {'post': 'questioncat_create'},
|
||||
{'put': 'questioncat_update'}, {'delete': 'questioncat_delete'})
|
||||
queryset = Questioncat.objects.filter(is_delete=0,is_subject=False).all()
|
||||
serializer_class = QuestioncatSerializerDefault
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from rest_framework.permissions import BasePermission
|
||||
from .models import Menu
|
||||
from django.core.cache import cache
|
||||
|
||||
|
||||
def get_all_menu_queryset(user):
|
||||
|
@ -19,11 +20,13 @@ def get_permission_list(user):
|
|||
menus = get_all_menu_queryset(user)
|
||||
perms_list = menus.values_list('method',flat=True)
|
||||
perms_list = list(perms_list)
|
||||
if user.is_superuser:
|
||||
perms_list.append('admin')
|
||||
perms_l = []
|
||||
if perms_list:
|
||||
return list(perms_list)
|
||||
return ['basic']
|
||||
perms_l = perms_list
|
||||
else:
|
||||
perms_l = ['basic']
|
||||
cache.set(f'{user.id}_perms', perms_l, timeout=None)
|
||||
return perms_l
|
||||
|
||||
class RbacPermission(BasePermission):
|
||||
"""
|
||||
|
@ -38,14 +41,11 @@ class RbacPermission(BasePermission):
|
|||
:return:
|
||||
"""
|
||||
perms = []
|
||||
if 'perms' in request.session:
|
||||
perms = request.session['perms']
|
||||
else:
|
||||
perms = cache.get(f'{request.user.id}_perms', None)
|
||||
if perms is None:
|
||||
perms = get_permission_list(request.user)
|
||||
if perms:
|
||||
if 'admin' in perms:
|
||||
return True
|
||||
elif request.user.is_superuser:
|
||||
if request.user.is_superuser:
|
||||
return True
|
||||
elif not hasattr(view, 'perms_map'):
|
||||
return True
|
||||
|
|
|
@ -30,6 +30,7 @@ from ..serializers.user_serializer import (UserCreateSerializer,
|
|||
from server.conf import *
|
||||
from rest_framework_jwt.serializers import jwt_encode_handler
|
||||
from crm.views import my_payload_handler
|
||||
from django.core.cache import cache
|
||||
|
||||
class UserLogoutView(APIView):
|
||||
authentication_classes = ()
|
||||
|
@ -46,7 +47,6 @@ class UserInfoView(APIView):
|
|||
if request.user.id is not None:
|
||||
user = request.user
|
||||
perms = get_permission_list(user)
|
||||
request.session['perms'] = perms # 存到session表中
|
||||
data = {
|
||||
'id': user.id,
|
||||
'username': user.username,
|
||||
|
@ -73,7 +73,7 @@ class UserViewSet(PageOrNot, ModelViewSet):
|
|||
"""
|
||||
用户管理:增删改查
|
||||
"""
|
||||
perms_map = ({'get': 'user_list'}, {'post': 'user_create'}, {'put': 'user_update'},
|
||||
perms_map = ({'get': 'user_view'}, {'post': 'user_create'}, {'put': 'user_update'},
|
||||
{'delete': 'user_delete'})
|
||||
queryset = UserProfile.objects.filter(is_delete=0).all()
|
||||
serializer_class = UserListSerializer
|
||||
|
|
|
@ -143,9 +143,9 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'dist/static')
|
|||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'crm.authentication.MyTokenAuthentication',
|
||||
'rest_framework.authentication.BasicAuthentication',
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
'crm.authentication.MyTokenAuthentication'
|
||||
],
|
||||
'DEFAULT_PERMISSION_CLASSES':[
|
||||
'crm.permission.MyPermission'
|
||||
|
|
Loading…
Reference in New Issue