Merge remote-tracking branch 'origin/сja' into Alex

This commit is contained in:
Alex committed 2025-01-31 14:44:46 +03:00
commit 579e54374a
6 files changed
+166 -56

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ SWAGGER_SETTINGS = {
} }
} }
} }
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ["*","portal-t",'portal9966']
CHANNEL_LAYERS = { CHANNEL_LAYERS = {
"default": { "default": {
"BACKEND": "channels_redis.core.RedisChannelLayer", "BACKEND": "channels_redis.core.RedisChannelLayer",
+17 -6
View File
@@ -132,11 +132,21 @@ class TestResultCreate(generics.ListCreateAPIView):
queryset = TestResult.objects.all() queryset = TestResult.objects.all()
serializer_class = TestResultSerializer serializer_class = TestResultSerializer
def get(self, request, *args, **kwargs):
user = request.user
# user = User.objects.get(username = "9966-00-125")
test_id = request.GET.get('id')
test = Testing.objects.filter(user=user, test__id=test_id).first().test
last_attempt = TestAttempt.objects.filter(user=user, test=test).order_by('-completion_date').first()
answer_ids = TestResult.objects.filter(attempt=last_attempt).values_list('answer__id', flat=True)
test_info = self.get_test_info(answer_ids)
return Response(data={'score': test_info['score'], 'answered_questions_total': test_info['answered_questions_total']})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
user = request.user user = request.user
# user = User.objects.get(username = "9966-00-125") # user = User.objects.get(username = "9966-00-125")
answer_ids = [item['answer'] for item in request.data]
test_info = self.get_test_info(request) test_info = self.get_test_info(answer_ids)
test_attempt = self.create_test_attempt(user, test_info) test_attempt = self.create_test_attempt(user, test_info)
serializer = self.get_serializer(data=request.data, many=True) serializer = self.get_serializer(data=request.data, many=True)
@@ -144,7 +154,7 @@ class TestResultCreate(generics.ListCreateAPIView):
serializer.save(attempt=test_attempt) serializer.save(attempt=test_attempt)
self.update_testing(user, test_info) self.update_testing(user, test_info)
return Response(test_info['is_passed']) return Response(data={'score': test_info['score'], 'answered_questions_total': test_info['answered_questions_total']})
def create_test_attempt(self, user, test_info): def create_test_attempt(self, user, test_info):
test = test_info['test'] test = test_info['test']
@@ -158,11 +168,11 @@ class TestResultCreate(generics.ListCreateAPIView):
test_passed = test_info['is_passed'] test_passed = test_info['is_passed']
Testing.objects.update_or_create(user=user, test=test, defaults = {"completion_date": test.dateend,"test_passed":test_passed}) Testing.objects.update_or_create(user=user, test=test, defaults = {"completion_date": test.dateend,"test_passed":test_passed})
def get_test_info(self, request): def get_test_info(self, answer_ids):
answer_ids = [item['answer'] for item in request.data]
test_answers = TestAnswer.objects.filter(id__in=answer_ids) test_answers = TestAnswer.objects.filter(id__in=answer_ids)
test = test_answers[0].question.test test = test_answers[0].question.test
answered_questions_total = test_answers.values('question').distinct().count()
correct_questions = sum( correct_questions = sum(
TestAnswer.objects.filter( TestAnswer.objects.filter(
@@ -179,7 +189,8 @@ class TestResultCreate(generics.ListCreateAPIView):
result = { result = {
"is_passed": correct_questions >= pass_perc, "is_passed": correct_questions >= pass_perc,
"score": correct_questions, "score": correct_questions,
"test": test "test": test,
"answered_questions_total": answered_questions_total,
} }
return result return result
+84 -36
View File
@@ -25,16 +25,8 @@ class GetVotes(APIView):
status = request.query_params.get('status') status = request.query_params.get('status')
votes = self.get_votes_by_status(status, now) votes = self.get_votes_by_status(status, now)
serialized_votes = VotesSerializer(votes, many=True).data serialized_votes = VotesSerializer(votes, many=True).data
questions = Question.objects.filter(vote__in=votes) questions_by_vote_id = self.get_questions_by_vote_id(votes)
self.enrich_votes(serialized_votes, questions_by_vote_id, user)
questions_by_vote_id = defaultdict(list)
for question in questions:
questions_by_vote_id[question.vote.id].append(question)
for vote in serialized_votes:
vote['is_passed'] = self.has_participated(user, vote['id'])
related_questions = questions_by_vote_id[vote['id']]
vote['files'] = [question.file.url for question in related_questions if question.file]
return Response(serialized_votes) return Response(serialized_votes)
@@ -50,6 +42,20 @@ class GetVotes(APIView):
return status_filters.get(status, Vote.objects.none()).order_by('dateend') return status_filters.get(status, Vote.objects.none()).order_by('dateend')
def get_questions_by_vote_id(self, votes):
questions = Question.objects.filter(vote__in=votes)
questions_by_vote_id = defaultdict(list)
for question in questions:
questions_by_vote_id[question.vote.id].append(question)
return questions_by_vote_id
def enrich_votes(self, serialized_votes, questions_by_vote_id, user):
for vote in serialized_votes:
vote['is_passed'] = self.has_participated(user, vote['id'])
related_questions = questions_by_vote_id[vote['id']]
vote['files'] = [question.file.url for question in related_questions if question.file]
def has_participated(self, employee, vote): def has_participated(self, employee, vote):
return Result.objects.filter(user=employee, answer__question__vote=vote).exists() return Result.objects.filter(user=employee, answer__question__vote=vote).exists()
@@ -60,36 +66,56 @@ class VoteDetail(generics.RetrieveUpdateDestroyAPIView):
lookup_field = 'id' lookup_field = 'id'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
results = Result.objects.filter(answer__question__vote=kwargs['id'], user=request.user)
if results: # if self.check_user_vote(kwargs['id'], User.objects.get(username='9966-00-125')):
if self.check_user_vote(kwargs['id'], request.user):
return Response({'status': 'error', 'message': 'voted'}, status=400) return Response({'status': 'error', 'message': 'voted'}, status=400)
vote = self.get_vote(kwargs['id'])
if isinstance(vote, Response):
return vote
answers_employee = self.get_employee_answers(vote)
answers_names = [item['name'] for item in answers_employee]
employee_dict = self.serialize_employees(answers_names)
serialized_data = self.retrieve(request, *args, **kwargs).data
self.add_employee_info(serialized_data, answers_employee, answers_names, employee_dict)
return Response(serialized_data)
def check_user_vote(self, vote_id, user):
results = Result.objects.filter(answer__question__vote=vote_id, user=user)
return results.exists()
def get_vote(self, vote_id):
try: try:
vote = Vote.objects.get(id=kwargs['id']) vote = Vote.objects.get(id=vote_id)
if vote.dateend < datetime.now(timezone.utc): if vote.dateend < datetime.now(timezone.utc):
return Response({'status': 'error', 'message': 'Voting is over'}, status=400) return Response({'status': 'error', 'message': 'Voting is over'}, status=400)
return vote
except Exception as e: except Exception as e:
return Response({'status': 'error', 'message': str(e)}, status=400) return Response({'status': 'error', 'message': str(e)}, status=400)
answers_employee = Answer.objects.filter(question__vote=vote).filter(question__settings__choice="employee").values('name', 'question') def get_employee_answers(self, vote):
return Answer.objects.filter(question__vote=vote).filter(question__settings__choice="employee").values('name', 'question')
def serialize_employees(self, answers_names):
employees_serializer = get_employees_serializer(answers_names)
return {employee['id']: employee for employee in employees_serializer}
def add_employee_info(self, serialized_data, answers_employee, answers_names, employee_dict):
answers_names = [item['name'] for item in answers_employee]
question_ids = [item['question'] for item in answers_employee] question_ids = [item['question'] for item in answers_employee]
if answers_employee:
employees_serializer = get_employees_serializer(answers_names)
employee_dict = {employee['id']: employee for employee in employees_serializer}
serialized_data = self.retrieve(request, *args, **kwargs).data
for question in serialized_data['questions']: for question in serialized_data['questions']:
for answer in question['answers']: for answer in question['answers']:
if question['id'] in question_ids: if question['id'] in question_ids:
if answer['name'] in answers_names: if answer['name'] in answers_names:
answer['employee'] = employee_dict.get(int(answer['name'])) answer['employee'] = employee_dict.get(int(answer['name']))
return Response(serialized_data)
class VoteCreate(APIView): class VoteCreate(APIView):
def post(self, request): def post(self, request):
try: try:
@@ -166,31 +192,54 @@ class GetResults(APIView):
def get(self, request): def get(self, request):
vote_id = request.GET.get('id') vote_id = request.GET.get('id')
vote = self.get_vote(vote_id)
if isinstance(vote, Response):
return vote
serialized_data = VoteSerializer(vote).data
answers_employee = self.get_employee_answers(vote)
answers_names = [item['name'] for item in answers_employee]
employee_dict = self.create_employee_dict(answers_names)
result_dict = self.get_answer_counts(vote)
self.add_employee_info(serialized_data, answers_employee, answers_names, employee_dict, result_dict)
serialized_data['nonvoting'] = self.get_non_voting_employees(vote)
return Response(serialized_data)
def get_vote(self, vote_id):
try: try:
vote = Vote.objects.get(id=vote_id) vote = Vote.objects.get(id=vote_id)
return vote
except Vote.DoesNotExist: except Vote.DoesNotExist:
return Response({'status': 'error', 'message': 'Vote not found'}, status=404) return Response({'status': 'error', 'message': 'Vote not found'}, status=404)
serialized_data = VoteSerializer(vote).data def get_employee_answers(self, vote):
answers_employee = Answer.objects.filter( answers_employee = Answer.objects.filter(
question__vote=vote, question__vote=vote,
question__settings__choice="employee" question__settings__choice="employee"
).values('name', 'question') ).values('name', 'question')
answers_names = [item['name'] for item in answers_employee] return answers_employee
question_ids = [item['question'] for item in answers_employee]
employee_dict = {} def create_employee_dict(self, answers_names):
if answers_employee: if not answers_names:
employees_serializer = get_employees_serializer(answers_names) return {}
employee_dict = {employee['id']: employee for employee in employees_serializer}
employees_serializer = get_employees_serializer(answers_names)
return {employee['id']: employee for employee in employees_serializer}
def get_answer_counts(self, vote):
results = Result.objects.filter( results = Result.objects.filter(
answer__question__vote=vote answer__question__vote=vote
).values('answer_id').annotate(count=Count('id')) ).values('answer_id').annotate(count=Count('id'))
result_dict = {int(result['answer_id']): result['count'] for result in results} return {int(result['answer_id']): result['count'] for result in results}
def add_employee_info(self, serialized_data, answers_employee, answers_names, employee_dict, result_dict):
question_ids = [item['question'] for item in answers_employee]
for question in serialized_data['questions']: for question in serialized_data['questions']:
for answer in question['answers']: for answer in question['answers']:
answer['count'] = result_dict.get(int(answer['id']), 0) answer['count'] = result_dict.get(int(answer['id']), 0)
@@ -198,12 +247,11 @@ class GetResults(APIView):
if answer['name'] in answers_names: if answer['name'] in answers_names:
answer['employee'] = employee_dict.get(int(answer['name'])) answer['employee'] = employee_dict.get(int(answer['name']))
def get_non_voting_employees(self, vote):
users = Result.objects.filter(answer__question__vote=vote).values('user_id') users = Result.objects.filter(answer__question__vote=vote).values('user_id')
users = User.objects.filter(created_at__lt=vote.dateend).exclude(id__in=users) non_voting_users = User.objects.filter(created_at__lt=vote.dateend).exclude(id__in=users)
employee_ids = users.values_list('user_id', flat=True) employee_ids = non_voting_users.values_list('user_id', flat=True)
serialized_data['nonvoting'] = get_employees_serializer(employee_ids) return get_employees_serializer(employee_ids)
return Response(serialized_data)
class VoteResultCreate(generics.ListCreateAPIView): class VoteResultCreate(generics.ListCreateAPIView):
queryset = Result.objects.all() queryset = Result.objects.all()
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "front", "name": "front",
"version": "0.0.83", "version": "0.0.84",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "front", "name": "front",
"version": "0.0.83", "version": "0.0.84",
"dependencies": { "dependencies": {
"@ckeditor/ckeditor5-build-classic": "^44.1.0", "@ckeditor/ckeditor5-build-classic": "^44.1.0",
"@ckeditor/ckeditor5-dev-translations": "^43.0.1", "@ckeditor/ckeditor5-dev-translations": "^43.0.1",
+1 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "front", "name": "front",
"version": "0.0.83", "version": "0.0.84",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
@@ -36,7 +36,6 @@
"vuelidate": "^0.7.7", "vuelidate": "^0.7.7",
"vuetify": "^3.7.8", "vuetify": "^3.7.8",
"webfontloader": "^1.6.28" "webfontloader": "^1.6.28"
}, },
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
@@ -47,6 +46,5 @@
"sass-embedded": "^1.83.4", "sass-embedded": "^1.83.4",
"vite": "^6.0.11", "vite": "^6.0.11",
"vite-plugin-vuetify": "^2.0.4" "vite-plugin-vuetify": "^2.0.4"
} }
} }
+61 -8
View File
@@ -1,13 +1,16 @@
<template> <template>
<v-carousel
interval="10000" <v-carousel
v-model="currentslide"
:interval="interval"
cover cover
cycle
height="450" height="450"
hide-delimiters hide-delimiters
hide-delimiter-background hide-delimiter-background
:show-arrows="carous.length<2?false:'hover'" :show-arrows="carous.length<2?false:'hover'"
color="white" color="white"
@update:modelValue="slidechanged"
> >
<template v-for="(x, i) in carous" :key="i"> <template v-for="(x, i) in carous" :key="i">
@@ -71,22 +74,28 @@
<div class="d-flex justify-center"> <div class="d-flex justify-center">
<video <video
style="height: 450px;" ref="videoElement"
style="height: 450px"
controls controls
preload="metadata"
@ended="ended"
@loadedmetadata="interval = 10000000000"
> >
<source :src="`${burl}${x.link}`" type="video/mp4" /> <source :src="`${burl}${x.link}`" type="video/mp4" />
Текущий браузер не поддерживает воспроизведение этого видео. Текущий браузер не поддерживает воспроизведение этого видео.
</video> </video>
</div> </div>
<!-- currentslide=currentslide<carous.length-1?currentslide+1:0 -->
</v-carousel-item> </v-carousel-item>
</template> </template>
</v-carousel> </v-carousel>
</template> </template>
<script> <script>
import { ref } from "vue"; import { ref, computed } from "vue";
import { baseURL } from "@/utils/axios-api"; import { baseURL } from "@/utils/axios-api";
import { axiosApiInstance } from "@/utils/axios-api"; import { axiosApiInstance } from "@/utils/axios-api";
import { useAlertStore } from "@/store/useAlertStore"; import { useAlertStore } from "@/store/useAlertStore";
@@ -94,9 +103,9 @@ import { useAlertStore } from "@/store/useAlertStore";
export default { export default {
setup() { setup() {
const currentslide=ref(0)
const burl = baseURL.slice(0, -1); const burl = baseURL.slice(0, -1);
const videoElement=ref(null)
const carous = ref([{ link: `/media/newsimage/scales.jpg`, "title": null, "text": "" }]); const carous = ref([{ link: `/media/newsimage/scales.jpg`, "title": null, "text": "" }]);
const feedalert = useAlertStore().alert; const feedalert = useAlertStore().alert;
@@ -118,10 +127,54 @@ export default {
}; };
getfromserver(); getfromserver();
const interval=ref(10000)
const slidechanged=()=>{
console.log(videoElement.value);
if (carous.value[currentslide.value].link.endsWith('mp4')){
videoElement.value.forEach((e)=>{
if(e.currentSrc!=burl+carous.value[currentslide.value].link){
e.pause()
}
// else{
// console.log("sdflkhlh");
// e.play()
// }
})
}
if(carous.value[currentslide.value].link.endsWith('mp4')){
interval.value = 10000000000
}else{
interval.value=10000
}
}
const ended = (val)=>{
val.target.currentTime = 0
val.target.pause();
document.exitFullscreen()
currentslide.value=currentslide.value<carous.value.length-1?currentslide.value+1:0
}
return { return {
slidechanged,
videoElement,
currentslide,
interval,
// intervalcomp,
burl, burl,
carous, carous,
ended
}; };
}, },
}; };