diff --git a/src/back/vote/models.py b/src/back/vote/models.py index a4e3ca20d..c48afc998 100644 --- a/src/back/vote/models.py +++ b/src/back/vote/models.py @@ -37,7 +37,7 @@ class Answer(models.Model): return self.answer class Result(models.Model): - user = models.ForeignKey(DictEmployee, on_delete=models.CASCADE) + user = models.ForeignKey(User, on_delete=models.CASCADE) answer = models.ForeignKey(Answer, on_delete=models.CASCADE) comment = models.TextField(null=True, blank=True) diff --git a/src/back/vote/views.py b/src/back/vote/views.py index c3f277fd3..96b4dd8dc 100644 --- a/src/back/vote/views.py +++ b/src/back/vote/views.py @@ -13,19 +13,21 @@ class GetVotes(APIView): def get(self, request): user = request.user + print(type(user)) # user = DictEmployee.objects.get(login='9966-00-125') now = 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): + print(status) status_filters = { 'active': Vote.objects.filter(dateend__gt=now), 'completed': Vote.objects.filter(dateend__lt=now), @@ -49,8 +51,9 @@ class VoteDetail(generics.RetrieveUpdateDestroyAPIView): lookup_url_kwarg = 'id' lookup_field = 'id' -class VoteCreate(APIView): +import json +class VoteCreate(APIView): def post(self, request): try: vote = self.create_vote(request) @@ -64,8 +67,8 @@ class VoteCreate(APIView): user = User.objects.get(user=request.user) # for test - # user = DictEmployee.objects.get(login='9966-00-125') - # user = User.objects.get(user=user) + # # user = DictEmployee.objects.get(login='9966-00-125') + # # user = User.objects.get(user=user) vote = Vote( name=request.data['title'], @@ -76,19 +79,23 @@ class VoteCreate(APIView): author=user, ) vote.save() - - for count, question_data in enumerate(request.data['questions'], start=1): + + questions = json.loads(request.data['questions']) + for count, question_data in enumerate(questions, start=1): question = Question( question=question_data['text'], vote=vote, - # file=question.get('image', None), - file = request.FILES.get('image'), + file=request.FILES.get('image'), numb=count, ) question.save() for answer in question_data['answers']: - Answer(answer=answer['text'], file=request.FILES.get('image'), question=question).save() - + Answer( + answer=answer['text'], + file=request.FILES.get('image'), + question=question + ).save() + return vote def create_news(self, request): @@ -111,4 +118,4 @@ class VoteCreate(APIView): author = vote_author, link = None, ) - news.save() \ No newline at end of file + news.save() diff --git a/src/front/src/components/vote/CurrentVote.vue b/src/front/src/components/vote/CurrentVote.vue new file mode 100644 index 000000000..ac56960fa --- /dev/null +++ b/src/front/src/components/vote/CurrentVote.vue @@ -0,0 +1,170 @@ + + + + + diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue new file mode 100644 index 000000000..2aae8177e --- /dev/null +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -0,0 +1,363 @@ + + + diff --git a/src/front/src/components/vote/VoteForm.vue b/src/front/src/components/vote/VoteForm.vue index 55fe248d0..af235cb07 100644 --- a/src/front/src/components/vote/VoteForm.vue +++ b/src/front/src/components/vote/VoteForm.vue @@ -1,148 +1,147 @@ \ No newline at end of file + diff --git a/src/front/src/router/index.js b/src/front/src/router/index.js index b48ed3f02..df4371b8e 100644 --- a/src/front/src/router/index.js +++ b/src/front/src/router/index.js @@ -140,14 +140,14 @@ const routes = [ ico: "mdi-account", }, }, + // { + // path: "/vote", + // name: "Vote", + // component: () => + // import("@/views/Vote.vue") + // }, { path: "/vote", - name: "Vote", - component: () => - import("@/views/Vote.vue") - }, - { - path: "/votehomepage", name: "VoteHomePage", component: () => import("@/views/VoteHomePage.vue") diff --git a/src/front/src/test/testDataForVote.js b/src/front/src/test/testDataForVote.js new file mode 100644 index 000000000..f436ff040 --- /dev/null +++ b/src/front/src/test/testDataForVote.js @@ -0,0 +1,48 @@ +export const votingData = { + description: "Описание первой голосовалки", + endDate: "2025-01-27T10:43:04+03:00", + questions: [ + { + answers: [ + { + text: "аыфавы", + image: null + }, + { + text: "оаок5е", + image: null + } + ], + image: { + name: "ed777ac1e74742aa118f59d72e231763d08ac93fv2_hq.jpg", + size: 11530 + }, + selectedEmployeeImages: {}, + selectedEmployees: [], + text: "Опрос1", + type: "Ввести вручную" + }, + { + answers: [], + image: { + name: "ed777ac1e74742aa118f59d72e231763d08ac93fv2_hq.jpg", + size: 11530 + }, + selectedEmployeeImages: {}, + selectedEmployees: [ + { + id: 1, + name: "Сотрудник 1" + }, + { + id: 2, + name: "Сотрудник 2" + } + ], + text: "Опрос2", + type: "Выбрать сотрудника" + } + ], + startDate: "2025-01-13T10:43:04+03:00", + title: "Заголовок голосовалки" +} diff --git a/src/front/src/utils/axios-api.js b/src/front/src/utils/axios-api.js index 6d88670c9..212b8f7d5 100644 --- a/src/front/src/utils/axios-api.js +++ b/src/front/src/utils/axios-api.js @@ -90,13 +90,7 @@ async error => { async function getVotes(status) { try { - const response = await axiosApiInstance.get(`/api/vote/getvotes?status=${status}`, - // { - // params: { - // status, - // } - // } - ); + const response = await axiosApiInstance.get(`/api/vote/getvotes?status=${status}`); return response.data; } catch (error) { console.error('Ошибка запроса голосования:', error); @@ -120,6 +114,25 @@ getVotes('active') console.error('Ошибка:', err); }); +async function createVote(voteData, files) { + try { + const formData = new FormData(); + formData.append('title', voteData.title); + formData.append('description', voteData.description); + formData.append('startDate', new Date(voteData.startDate).toISOString()); + formData.append('endDate', new Date(voteData.endDate).toISOString()); + formData.append('questions', JSON.stringify(voteData.questions)); -export { axiosApiInstance, clearAxios, baseURL,spravURL, spravURLBase, baseWS, getVotes } + const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, { + headers: { 'Content-Type': 'multipart/form-data' }, + }); + + return response.data; + } catch (error) { + console.error('Ошибка создания голосования:', error); + throw error; + } +} + +export { axiosApiInstance, clearAxios, baseURL,spravURL, spravURLBase, baseWS, getVotes, createVote } diff --git a/src/front/src/views/VoteConstructor.vue b/src/front/src/views/VoteConstructor.vue deleted file mode 100644 index c4586668e..000000000 --- a/src/front/src/views/VoteConstructor.vue +++ /dev/null @@ -1,325 +0,0 @@ - - - diff --git a/src/front/src/views/VoteHomePage.vue b/src/front/src/views/VoteHomePage.vue index cab3df511..2a8160870 100644 --- a/src/front/src/views/VoteHomePage.vue +++ b/src/front/src/views/VoteHomePage.vue @@ -18,13 +18,13 @@ {{ voting.title }} - + mdi-pencil @@ -36,15 +36,15 @@ Проголосовать - Уже проголосовали - + Проголосовали + mdi-delete @@ -59,9 +59,9 @@ {{ voting.title }} @@ -89,21 +89,43 @@ - + + + + + + mdi-close-thick + + + + + + + + + + Голосование: {{ selectedVoting?.title }} -

Описание голосования...

+ +
- Проголосовать - Закрыть + Сохранить + Закрыть
- + Результаты голосования: {{ selectedVoting?.title }} @@ -119,10 +141,17 @@