Merge branch 'dev-denzel' into test
This commit is contained in:
commit
f13857cdf5
26 files changed
+1470
-677
No files matched your search
+2
-1
@@ -8,4 +8,5 @@ portal/settings.py
|
||||
/front/node_modules/
|
||||
*.sqlite3
|
||||
/media/
|
||||
/static/
|
||||
/static/
|
||||
*.env
|
||||
@@ -0,0 +1,6 @@
|
||||
ENGINE=django.db.backends.mysql
|
||||
DBNAME = accounting
|
||||
USER =
|
||||
PASSWORD=
|
||||
HOST=127.0.0.1
|
||||
PORT=3306
|
||||
@@ -1,8 +0,0 @@
|
||||
class Settings():
|
||||
def __init__(self) -> None:
|
||||
self.secret_key=''
|
||||
self.redis_hosts = []
|
||||
self.db = {
|
||||
}
|
||||
|
||||
pass
|
||||
@@ -0,0 +1,301 @@
|
||||
"""
|
||||
Django settings for portal project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.3.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
from .ds import Settings
|
||||
stngs = Settings()
|
||||
CORS_ORIGIN_ALLOW_ALL=True
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
LIST_PER_PAGE=25
|
||||
SECRET_KEY=stngs.secret_key
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
myDEBUG=True
|
||||
SWAGGER_SETTINGS = {
|
||||
'DEFAULT_INFO': 'import.path.to.urls.api_info',
|
||||
'SECURITY_DEFINITIONS': {
|
||||
'Basic': {
|
||||
'type': 'basic'
|
||||
},
|
||||
'Bearer': {
|
||||
'type': 'apiKey',
|
||||
'name': 'Authorization',
|
||||
'in': 'header'
|
||||
}
|
||||
}
|
||||
}
|
||||
ALLOWED_HOSTS = []
|
||||
CHANNEL_LAYERS = {
|
||||
"default": {
|
||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||
"CONFIG": {
|
||||
"hosts":stngs.redis_hosts,
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'daphne',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'djoser',
|
||||
'rest_framework_simplejwt',
|
||||
'navigation.apps.NavigationConfig',
|
||||
'drf_yasg',
|
||||
'accounts',
|
||||
'safety',
|
||||
|
||||
'vote.apps.VoteConfig',
|
||||
'commeteresp',
|
||||
# 'orgmanagment',
|
||||
'corsheaders',
|
||||
'watcher.apps.WatcherConfig',
|
||||
'userauth.apps.UserauthConfig',
|
||||
'feedback.apps.FeedbackConfig',
|
||||
'general_vacation.apps.GeneralVacationConfig',
|
||||
'about_inspection.apps.AboutInspectionConfig',
|
||||
'calendar_of_events.apps.CalendarOfEventsConfig',
|
||||
'tests.apps.TestsConfig',
|
||||
'ckeditor'
|
||||
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
# 'django.contrib.auth.middleware.RemoteUserMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
AUTHENTICATION_BACKENDS = [
|
||||
# 'django.contrib.auth.backends.RemoteUserBackend',
|
||||
'accounts.backends.CustomAuth',
|
||||
'django.contrib.auth.backends.ModelBackend'
|
||||
|
||||
|
||||
|
||||
]
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 10,
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
|
||||
),
|
||||
|
||||
}
|
||||
|
||||
ROOT_URLCONF = 'portal.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
# WSGI_APPLICATION = 'portal.wsgi.application'
|
||||
ASGI_APPLICATION = "portal.asgi.application"
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = stngs.db
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
AUTH_USER_MODEL = 'accounts.User'
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'ru'
|
||||
|
||||
# TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = 'Europe/Moscow'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
# STATICFILES_DIRS = (
|
||||
# BASE_DIR.joinpath('static'),
|
||||
# )
|
||||
STATIC_ROOT = BASE_DIR.joinpath('static')
|
||||
CKEDITOR_UPLOAD_PATH = "uploads/"
|
||||
# Media
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = BASE_DIR.joinpath('media')
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": stngs.access_token_lifetime,
|
||||
"REFRESH_TOKEN_LIFETIME": stngs.refresh_token_lifetime,
|
||||
"ROTATE_REFRESH_TOKENS": False,
|
||||
"BLACKLIST_AFTER_ROTATION": False,
|
||||
"UPDATE_LAST_LOGIN": False,
|
||||
|
||||
"ALGORITHM": "HS256",
|
||||
"SIGNING_KEY": SECRET_KEY,
|
||||
"VERIFYING_KEY": "",
|
||||
"AUDIENCE": None,
|
||||
"ISSUER": None,
|
||||
"JSON_ENCODER": None,
|
||||
"JWK_URL": None,
|
||||
"LEEWAY": 0,
|
||||
|
||||
"AUTH_HEADER_TYPES": ("Bearer",),
|
||||
"AUTH_HEADER_NAME": "HTTP_AUTHORIZATION",
|
||||
"USER_ID_FIELD": "id",
|
||||
"USER_ID_CLAIM": "user_id",
|
||||
"USER_AUTHENTICATION_RULE": "rest_framework_simplejwt.authentication.default_user_authentication_rule",
|
||||
|
||||
"AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
|
||||
"TOKEN_TYPE_CLAIM": "token_type",
|
||||
"TOKEN_USER_CLASS": "rest_framework_simplejwt.models.TokenUser",
|
||||
|
||||
"JTI_CLAIM": "jti",
|
||||
|
||||
"SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
|
||||
"SLIDING_TOKEN_LIFETIME": timedelta(minutes=5),
|
||||
"SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=1),
|
||||
|
||||
"TOKEN_OBTAIN_SERIALIZER": 'accounts.backends.MyTokenObtainPairSerializer',
|
||||
"TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSerializer",
|
||||
"TOKEN_VERIFY_SERIALIZER": "rest_framework_simplejwt.serializers.TokenVerifySerializer",
|
||||
"TOKEN_BLACKLIST_SERIALIZER": "rest_framework_simplejwt.serializers.TokenBlacklistSerializer",
|
||||
"SLIDING_TOKEN_OBTAIN_SERIALIZER": "rest_framework_simplejwt.serializers.TokenObtainSlidingSerializer",
|
||||
"SLIDING_TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSlidingSerializer",
|
||||
}
|
||||
|
||||
CKEDITOR_CONFIGS = {
|
||||
'default': {
|
||||
# 'skin': 'moono',
|
||||
# 'skin': 'office2013',
|
||||
'toolbar_Basic': [
|
||||
['Source', '-', 'Bold', 'Italic']
|
||||
],
|
||||
'toolbar_YourCustomToolbarConfig': [
|
||||
# {'name': 'document', 'items': ['Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates']},
|
||||
# {'name': 'clipboard', 'items': ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']},
|
||||
{'name': 'editing', 'items': ['Find',]},
|
||||
# {'name': 'forms',
|
||||
# 'items': ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
|
||||
# 'HiddenField']},
|
||||
# '/',
|
||||
{'name': 'basicstyles',
|
||||
'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']},
|
||||
|
||||
{'name': 'paragraph',
|
||||
'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-',
|
||||
'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-',
|
||||
# 'BidiLtr', 'BidiRtl',
|
||||
]},
|
||||
# '/',
|
||||
{'name': 'links', 'items': ['Link', 'Unlink', 'Anchor']},
|
||||
{'name': 'insert',
|
||||
'items': [ 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak']},
|
||||
# 'Image', 'Flash', 'Iframe']},
|
||||
'/',
|
||||
{'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize']},
|
||||
{'name': 'colors', 'items': ['TextColor', 'BGColor']},
|
||||
{'name': 'tools', 'items': ['Maximize', 'ShowBlocks']},
|
||||
# {'name': 'about', 'items': ['About']},
|
||||
# '/', # put this to force next toolbar on new line
|
||||
{'name': 'yourcustomtools', 'items': [
|
||||
# put the name of your editor.ui.addButton here
|
||||
'Preview',
|
||||
'Maximize',
|
||||
|
||||
]},
|
||||
],
|
||||
'toolbar': 'YourCustomToolbarConfig', # put selected toolbar config here
|
||||
# 'toolbarGroups': [{ 'name': 'document', 'groups': [ 'mode', 'document', 'doctools' ] }],
|
||||
# 'height': 291,
|
||||
# 'width': '100%',
|
||||
# 'filebrowserWindowHeight': 725,
|
||||
# 'filebrowserWindowWidth': 940,
|
||||
# 'toolbarCanCollapse': True,
|
||||
# 'mathJaxLib': '//cdn.mathjax.org/mathjax/2.2-latest/MathJax.js?config=TeX-AMS_HTML',
|
||||
'tabSpaces': 4,
|
||||
'extraPlugins': ','.join([
|
||||
'uploadimage', # the upload image feature
|
||||
# your extra plugins here
|
||||
'div',
|
||||
'autolink',
|
||||
'autoembed',
|
||||
'embedsemantic',
|
||||
'autogrow',
|
||||
# 'devtools',
|
||||
'widget',
|
||||
'lineutils',
|
||||
'clipboard',
|
||||
'dialog',
|
||||
'dialogui',
|
||||
'elementspath'
|
||||
]),
|
||||
}
|
||||
}
|
||||
Binary file not shown.
+1
-12
@@ -1,15 +1,4 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(ThanksVote)
|
||||
admin.site.register(BestVote)
|
||||
|
||||
|
||||
|
||||
class DictEmplyeeRAdmin(admin.ModelAdmin):
|
||||
list_display=('id_dict_employee', 'id_dict_department',)
|
||||
list_editable=('id_dict_department', )
|
||||
|
||||
|
||||
admin.site.register(DictEmplyeeR, DictEmplyeeRAdmin)
|
||||
admin.site.register(Vote)
|
||||
@@ -4,4 +4,5 @@ from django.apps import AppConfig
|
||||
class VoteConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'vote'
|
||||
verbose_name = 'Голосование'
|
||||
|
||||
+34
-32
@@ -1,43 +1,45 @@
|
||||
from django.db import models
|
||||
from userauth.models import *
|
||||
from accounts.models import User
|
||||
import datetime
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class ThanksVote(models.Model):
|
||||
voted_user = models.CharField(blank=False, max_length=255)
|
||||
department_user = models.CharField(
|
||||
blank=False, default=None, max_length=255)
|
||||
cand_name = models.CharField(blank=False, default=None, max_length=255)
|
||||
vote_thanks_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Голосование, хочу сказать спасибо!"
|
||||
verbose_name_plural = "Голосование, хочу сказать спасибо!"
|
||||
class Vote(models.Model):
|
||||
name = models.CharField(max_length=255,verbose_name='Название голосования')
|
||||
description = models.TextField(verbose_name='Описание')
|
||||
datestart = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время начала периода')
|
||||
dateend = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время окончания периода')
|
||||
settings = models.JSONField(default=dict, verbose_name='Json настроек голосования')
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Создатель голосования')
|
||||
|
||||
def __str__(self):
|
||||
return self.cand_name
|
||||
|
||||
|
||||
class BestVote(models.Model):
|
||||
voted_user = models.CharField(blank=False, max_length=255)
|
||||
department_user = models.CharField(
|
||||
blank=False, default=None, max_length=255)
|
||||
cand_name = models.CharField(blank=False, default=None, max_length=255)
|
||||
vote_best_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Голосование, мой коллега самый лучший"
|
||||
verbose_name_plural = "Голосование, мой коллега самый лучший"
|
||||
verbose_name = "Голосование"
|
||||
verbose_name_plural = "Голосования"
|
||||
|
||||
class Question(models.Model):
|
||||
question = models.CharField(max_length=255)
|
||||
vote = models.ForeignKey(Vote, related_name='questions', on_delete=models.CASCADE)
|
||||
file = models.ImageField(upload_to='question_images/', null=True, blank=True)
|
||||
numb = models.PositiveIntegerField()
|
||||
|
||||
def __str__(self):
|
||||
return self.cand_name
|
||||
return self.question
|
||||
|
||||
class Answer(models.Model):
|
||||
answer = models.CharField(max_length=255)
|
||||
file = models.FileField(upload_to='answer_files/', null=True, blank=True)
|
||||
question = models.ForeignKey(Question, related_name='answers', on_delete=models.CASCADE)
|
||||
|
||||
class DictEmplyeeR(models.Model):
|
||||
# id = models.IntegerField(primary_key=True)
|
||||
id_dict_employee = models.ForeignKey(DictEmployee, models.DO_NOTHING)
|
||||
id_dict_department = models.ForeignKey(DictDepartment, models.DO_NOTHING)
|
||||
class Meta:
|
||||
verbose_name = "Сотрудники(реальные отделы)"
|
||||
verbose_name_plural = "Сотрудники(реальные отделы)"
|
||||
def __str__(self):
|
||||
return str(self.id_dict_employee)
|
||||
return self.answer
|
||||
|
||||
class Result(models.Model):
|
||||
user = models.ForeignKey(DictEmployee, on_delete=models.CASCADE)
|
||||
answer = models.ForeignKey(Answer, on_delete=models.CASCADE)
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'Result by {self.user.username} for {self.answer.answer}'
|
||||
@@ -3,32 +3,26 @@ from .models import *
|
||||
from userauth.models import *
|
||||
|
||||
|
||||
class GetEmpSerializer(serializers.ModelSerializer):
|
||||
class VoteSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DictEmployee
|
||||
fields = ['id', 'id_dict_department',
|
||||
'fio', 'post', 'department']
|
||||
model = Vote
|
||||
fields = '__all__'
|
||||
|
||||
class GetEmpSerializerR(serializers.ModelSerializer):
|
||||
id = serializers.CharField(source="id_dict_employee.id")
|
||||
fio = serializers.CharField(source="id_dict_employee.fio")
|
||||
id_dict_department = serializers.CharField(source="id_dict_employee.id_dict_department")
|
||||
post = serializers.CharField(source="id_dict_employee.post")
|
||||
department = serializers.CharField(source="id_dict_employee.department")
|
||||
|
||||
class QuestionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DictEmplyeeR
|
||||
fields = ['id', 'id_dict_department',
|
||||
'fio', 'post', 'department']
|
||||
model = Question
|
||||
fields = '__all__'
|
||||
|
||||
class AnswerSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Answer
|
||||
fields = '__all__'
|
||||
|
||||
class ThanksVoteSerializer(serializers.ModelSerializer):
|
||||
class ResultSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ThanksVote
|
||||
fields = ('id', 'voted_user', 'cand_name', 'vote_thanks_date')
|
||||
model = Result
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class BestVoteSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = BestVote
|
||||
fields = ('id', 'voted_user', 'cand_name', 'vote_best_date')
|
||||
class VoteResultSerializer(serializers.Serializer):
|
||||
answer = serializers.CharField(source='answer__answer')
|
||||
count = serializers.IntegerField()
|
||||
@@ -4,12 +4,5 @@ from .views import *
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('get_for_thn/', GetForThn.as_view(),),
|
||||
path('get_for_bst/', GetForBst.as_view(),),
|
||||
path('setthanks/', SetThanks.as_view(), name=''),
|
||||
path('getthanks/', GetThanks.as_view(), name=''),
|
||||
path('setbest/', SetBest.as_view(), name=''),
|
||||
path('getbest/', GetBest.as_view(), name=''),
|
||||
path('getnotvotethn/', GetNotVoteThn.as_view()),
|
||||
path('getnotvotebst/', GetNotVoteBst.as_view()),
|
||||
path('getvotes/', GetVotes.as_view(),name='GetVotes'),
|
||||
]
|
||||
+49
-63
@@ -5,78 +5,64 @@ from django.db.models import Q
|
||||
from .models import *
|
||||
from userauth.models import *
|
||||
from .serializers import *
|
||||
import datetime
|
||||
|
||||
# Create your views here.
|
||||
class GetVotes(APIView):
|
||||
|
||||
|
||||
class GetForThn(APIView):
|
||||
def get(self, request):
|
||||
user_login = request.GET.get('login')
|
||||
all_emps = DictEmplyeeR.objects.exclude(id_dict_employee__login=user_login).exclude(id_dict_employee__department='Руководство').exclude(id_dict_employee__deleted=1).order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(all_emps, many=True).data)
|
||||
user = request.user
|
||||
# user = DictEmployee.objects.get(login='9966-00-125')
|
||||
now = datetime.datetime.now()
|
||||
status = request.query_params.get('status')
|
||||
print(status)
|
||||
votes = self.get_votes_by_status(status, now)
|
||||
serialized_votes = VoteSerializer(votes, many=True).data
|
||||
|
||||
for vote in serialized_votes:
|
||||
vote['is_passed'] = self.has_participated(user, vote['id'])
|
||||
|
||||
return Response(serialized_votes)
|
||||
|
||||
def get_votes_by_status(self, status, now):
|
||||
status_filters = {
|
||||
'active': Vote.objects.filter(dateend__gt=now),
|
||||
'completed': Vote.objects.filter(dateend__lt=now),
|
||||
}
|
||||
|
||||
return status_filters.get(status, Vote.objects.none()).order_by('dateend')
|
||||
|
||||
class GetForBst(APIView):
|
||||
def get(self, request):
|
||||
user_login = request.GET.get('login')
|
||||
dep_id = DictEmplyeeR.objects.get(id_dict_employee__login=user_login)
|
||||
emp_user = DictEmplyeeR.objects.filter(Q(id_dict_department=dep_id.id_dict_department), ~Q(id_dict_employee__login=user_login)).exclude(id_dict_employee__deleted=1).order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(emp_user, many=True).data)
|
||||
def has_participated(self, employee, vote):
|
||||
return Result.objects.filter(user=employee, answer__question__vote=vote).exists()
|
||||
|
||||
|
||||
class SetThanks(APIView):
|
||||
def post(self, request):
|
||||
voted_user = request.data['voted_user']
|
||||
department_user = request.data['department_user']
|
||||
cand_name = request.data['cand_name_id']
|
||||
ThanksVote.objects.create(
|
||||
voted_user=voted_user,
|
||||
department_user=department_user,
|
||||
cand_name=cand_name
|
||||
def create_vote(self, request):
|
||||
vote = Vote(
|
||||
name=request.data['name'],
|
||||
description=request.data['description'],
|
||||
datestart=request.data['datestart'],
|
||||
dateend=request.data['dateend'],
|
||||
settings=request.data.get('settings', {}),
|
||||
author=request.user,
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
vote.save()
|
||||
|
||||
def delete_vote(self,request):
|
||||
vote_id = request.data.get('vote_id')
|
||||
vote = Vote.objects.get(id=vote_id)
|
||||
questions = vote.questions.all()
|
||||
for question in questions:
|
||||
answers = question.answers.all()
|
||||
answers.delete()
|
||||
|
||||
class GetThanks(APIView):
|
||||
def get(self, request):
|
||||
# Группировка кандидатов по имени и подсчет каждого
|
||||
count_thanks = ThanksVote.objects.values('voted_user',
|
||||
'cand_name').annotate(total=Count('id')).order_by('cand_name')
|
||||
return Response(count_thanks)
|
||||
questions.delete()
|
||||
|
||||
results = Result.objects.filter(answer__question__vote=vote)
|
||||
results.delete()
|
||||
|
||||
class SetBest(APIView):
|
||||
def post(self, request):
|
||||
voted_user = request.data['voted_user']
|
||||
department_user = request.data['department_user']
|
||||
cand_name = request.data['cand_name_id']
|
||||
BestVote.objects.create(
|
||||
voted_user=voted_user,
|
||||
department_user=department_user,
|
||||
cand_name=cand_name
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
vote.delete()
|
||||
|
||||
|
||||
|
||||
class GetBest(APIView):
|
||||
def get(self, request):
|
||||
# Группировка кандидатов по имени и подсчет каждого
|
||||
count_bests = BestVote.objects.values('voted_user','department_user', 'cand_name').annotate(total=Count('id')).order_by('cand_name')
|
||||
return Response(count_bests)
|
||||
|
||||
|
||||
class GetNotVoteThn(APIView):
|
||||
def get(self, request):
|
||||
list_thn_users = ThanksVote.objects.values('voted_user')
|
||||
list_emp = DictEmplyeeR.objects.filter(
|
||||
id_dict_employee__deleted=0).exclude(id_dict_employee__login__in=list_thn_users).exclude(id_dict_employee__department='Руководство').order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(list_emp, many=True).data)
|
||||
|
||||
|
||||
class GetNotVoteBst(APIView):
|
||||
def get(self, request):
|
||||
list_bst_users = BestVote.objects.values('voted_user')
|
||||
list_emp_bst = DictEmplyeeR.objects.filter(
|
||||
id_dict_employee__deleted=0).exclude(id_dict_employee__login__in=list_bst_users).exclude(id_dict_employee__department='Руководство').order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(list_emp_bst, many=True).data)
|
||||
def get_vote_results(self, request):
|
||||
vote_id = request.data.get('vote_id')
|
||||
vote = Vote.objects.get(id=vote_id)
|
||||
results = Result.objects.filter(answer__question__vote=vote).values('answer__answer').annotate(count=Count('id'))
|
||||
serialized_results = VoteResultSerializer(results, many=True).data
|
||||
return Response(serialized_results)
|
||||
Reference in new issue
Block a user