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
+177 -67

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ SWAGGER_SETTINGS = {
}
}
}
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*","portal-t",'portal9966']
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
+17 -6
View File
@@ -132,11 +132,21 @@ class TestResultCreate(generics.ListCreateAPIView):
queryset = TestResult.objects.all()
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):
user = request.user
# user = User.objects.get(username = "9966-00-125")
test_info = self.get_test_info(request)
answer_ids = [item['answer'] for item in request.data]
test_info = self.get_test_info(answer_ids)
test_attempt = self.create_test_attempt(user, test_info)
serializer = self.get_serializer(data=request.data, many=True)
@@ -144,7 +154,7 @@ class TestResultCreate(generics.ListCreateAPIView):
serializer.save(attempt=test_attempt)
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):
test = test_info['test']
@@ -158,11 +168,11 @@ class TestResultCreate(generics.ListCreateAPIView):
test_passed = test_info['is_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 = test_answers[0].question.test
answered_questions_total = test_answers.values('question').distinct().count()
correct_questions = sum(
TestAnswer.objects.filter(
@@ -179,7 +189,8 @@ class TestResultCreate(generics.ListCreateAPIView):
result = {
"is_passed": correct_questions >= pass_perc,
"score": correct_questions,
"test": test
"test": test,
"answered_questions_total": answered_questions_total,
}
return result
+90 -42
View File
@@ -25,16 +25,8 @@ class GetVotes(APIView):
status = request.query_params.get('status')
votes = self.get_votes_by_status(status, now)
serialized_votes = VotesSerializer(votes, many=True).data
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)
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]
questions_by_vote_id = self.get_questions_by_vote_id(votes)
self.enrich_votes(serialized_votes, questions_by_vote_id, user)
return Response(serialized_votes)
@@ -50,6 +42,20 @@ class GetVotes(APIView):
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):
return Result.objects.filter(user=employee, answer__question__vote=vote).exists()
@@ -60,27 +66,49 @@ class VoteDetail(generics.RetrieveUpdateDestroyAPIView):
lookup_field = 'id'
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)
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:
vote = Vote.objects.get(id=kwargs['id'])
vote = Vote.objects.get(id=vote_id)
if vote.dateend < datetime.now(timezone.utc):
return Response({'status': 'error', 'message': 'Voting is over'}, status=400)
return vote
except Exception as e:
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')
answers_names = [item['name'] for item in answers_employee]
question_ids = [item['question'] for item in answers_employee]
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):
if answers_employee:
employees_serializer = get_employees_serializer(answers_names)
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 add_employee_info(self, serialized_data, answers_employee, answers_names, employee_dict):
serialized_data = self.retrieve(request, *args, **kwargs).data
question_ids = [item['question'] for item in answers_employee]
for question in serialized_data['questions']:
for answer in question['answers']:
@@ -88,8 +116,6 @@ class VoteDetail(generics.RetrieveUpdateDestroyAPIView):
if answer['name'] in answers_names:
answer['employee'] = employee_dict.get(int(answer['name']))
return Response(serialized_data)
class VoteCreate(APIView):
def post(self, request):
try:
@@ -166,45 +192,67 @@ class GetResults(APIView):
def get(self, request):
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:
vote = Vote.objects.get(id=vote_id)
return vote
except Vote.DoesNotExist:
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(
question__vote=vote,
question__settings__choice="employee"
).values('name', 'question')
answers_names = [item['name'] for item in answers_employee]
question_ids = [item['question'] for item in answers_employee]
employee_dict = {}
if answers_employee:
employees_serializer = get_employees_serializer(answers_names)
employee_dict = {employee['id']: employee for employee in employees_serializer}
return answers_employee
def create_employee_dict(self, answers_names):
if not answers_names:
return {}
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(
answer__question__vote=vote
).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 answer in question['answers']:
answer['count'] = result_dict.get(int(answer['id']), 0)
if question['id'] in question_ids:
if answer['name'] in answers_names:
answer['employee'] = employee_dict.get(int(answer['name']))
users = Result.objects.filter(answer__question__vote=vote).values('user_id')
users = User.objects.filter(created_at__lt=vote.dateend).exclude(id__in=users)
employee_ids = users.values_list('user_id', flat=True)
serialized_data['nonvoting'] = get_employees_serializer(employee_ids)
return Response(serialized_data)
def get_non_voting_employees(self, vote):
users = Result.objects.filter(answer__question__vote=vote).values('user_id')
non_voting_users = User.objects.filter(created_at__lt=vote.dateend).exclude(id__in=users)
employee_ids = non_voting_users.values_list('user_id', flat=True)
return get_employees_serializer(employee_ids)
class VoteResultCreate(generics.ListCreateAPIView):
queryset = Result.objects.all()
serializer_class = ResultSerializer
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "front",
"version": "0.0.83",
"version": "0.0.84",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "front",
"version": "0.0.83",
"version": "0.0.84",
"dependencies": {
"@ckeditor/ckeditor5-build-classic": "^44.1.0",
"@ckeditor/ckeditor5-dev-translations": "^43.0.1",
+5 -7
View File
@@ -1,6 +1,6 @@
{
"name": "front",
"version": "0.0.83",
"version": "0.0.84",
"scripts": {
"dev": "vite",
"build": "vite build",
@@ -12,7 +12,7 @@
"@ckeditor/ckeditor5-build-classic": "^44.1.0",
"@ckeditor/ckeditor5-dev-translations": "^43.0.1",
"@ckeditor/ckeditor5-vue": "^7.3.0",
"@mdi/font": "7.4.47",
"@mdi/font": "7.4.47",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"adapter": "^1.0.0-beta.10",
@@ -20,12 +20,12 @@
"chart.js": "^4.4.7",
"chartjs-adapter-moment": "^1.0.1",
"chartjs-plugin-datalabels": "^2.2.0",
"date-fns": "^4.1.0",
"date-fns": "^4.1.0",
"file-saver": "^2.0.5",
"ical.js": "^2.1.0",
"moment": "^2.30.1",
"pinia": "^2.3.1",
"rrule": "^2.8.1",
"pinia": "^2.3.1",
"rrule": "^2.8.1",
"vue": "^3.5.13",
"vue-cal": "^4.10.2",
"vue-chartjs": "^5.3.2",
@@ -36,7 +36,6 @@
"vuelidate": "^0.7.7",
"vuetify": "^3.7.8",
"webfontloader": "^1.6.28"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1",
@@ -47,6 +46,5 @@
"sass-embedded": "^1.83.4",
"vite": "^6.0.11",
"vite-plugin-vuetify": "^2.0.4"
}
}
+62 -9
View File
@@ -1,13 +1,16 @@
<template>
<v-carousel
interval="10000"
v-model="currentslide"
:interval="interval"
cover
cycle
height="450"
hide-delimiters
hide-delimiter-background
:show-arrows="carous.length<2?false:'hover'"
color="white"
@update:modelValue="slidechanged"
>
<template v-for="(x, i) in carous" :key="i">
@@ -70,23 +73,29 @@
<v-carousel-item v-else >
<div class="d-flex justify-center">
<video
style="height: 450px;"
<video
ref="videoElement"
style="height: 450px"
controls
preload="metadata"
@ended="ended"
@loadedmetadata="interval = 10000000000"
>
<source :src="`${burl}${x.link}`" type="video/mp4" />
Текущий браузер не поддерживает воспроизведение этого видео.
</video>
</div>
<!-- currentslide=currentslide<carous.length-1?currentslide+1:0 -->
</v-carousel-item>
</template>
</v-carousel>
</template>
<script>
import { ref } from "vue";
import { ref, computed } from "vue";
import { baseURL } from "@/utils/axios-api";
import { axiosApiInstance } from "@/utils/axios-api";
import { useAlertStore } from "@/store/useAlertStore";
@@ -94,9 +103,9 @@ import { useAlertStore } from "@/store/useAlertStore";
export default {
setup() {
const currentslide=ref(0)
const burl = baseURL.slice(0, -1);
const videoElement=ref(null)
const carous = ref([{ link: `/media/newsimage/scales.jpg`, "title": null, "text": "" }]);
const feedalert = useAlertStore().alert;
@@ -118,10 +127,54 @@ export default {
};
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 {
slidechanged,
videoElement,
currentslide,
interval,
// intervalcomp,
burl,
carous,
ended
};
},
};