From e916d2749bfde34c02155ca6e67bd84c77f019df Mon Sep 17 00:00:00 2001 From: Nukeap <53114367+Nukeap@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:53:30 +0300 Subject: [PATCH 01/12] 1 --- .gitignore | 1 + src/back/.gitignore | 2 ++ src/back/portal/{ds.py => ds2.py} | 0 src/back/portal/{settings.py => settings2.py} | 0 4 files changed, 3 insertions(+) rename src/back/portal/{ds.py => ds2.py} (100%) rename src/back/portal/{settings.py => settings2.py} (100%) diff --git a/.gitignore b/.gitignore index 88cb8ad16..21ae74341 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ env/ + /src/__pycache__/ /src/*/__pycache__/ /src/*/migrations/ diff --git a/src/back/.gitignore b/src/back/.gitignore index 00e319c32..ff9ed2a56 100644 --- a/src/back/.gitignore +++ b/src/back/.gitignore @@ -1,8 +1,10 @@ env/ + /__pycache__/ /*/__pycache__/ /*/migrations/ portal/ds.py +portal/settings.py /front/node_modules/ *.sqlite3 /media/ diff --git a/src/back/portal/ds.py b/src/back/portal/ds2.py similarity index 100% rename from src/back/portal/ds.py rename to src/back/portal/ds2.py diff --git a/src/back/portal/settings.py b/src/back/portal/settings2.py similarity index 100% rename from src/back/portal/settings.py rename to src/back/portal/settings2.py From 8e887b9ee093a805698aefbd7a35c364365b179f Mon Sep 17 00:00:00 2001 From: Nukeap <53114367+Nukeap@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:53:54 +0300 Subject: [PATCH 02/12] qq --- src/back/portal/ds2.py | 19 --- src/back/portal/settings2.py | 301 ----------------------------------- 2 files changed, 320 deletions(-) delete mode 100644 src/back/portal/ds2.py delete mode 100644 src/back/portal/settings2.py diff --git a/src/back/portal/ds2.py b/src/back/portal/ds2.py deleted file mode 100644 index a6555567a..000000000 --- a/src/back/portal/ds2.py +++ /dev/null @@ -1,19 +0,0 @@ -from datetime import timedelta -class Settings(): - def __init__(self) -> None: - self.secret_key='V7bvDZMztr3EU8S9g1Dipw' - self.redis_hosts = [("127.0.0.1", 6379)] - self.access_token_lifetime = timedelta(minutes=480) - self.refresh_token_lifetime = timedelta(days=1) - self.db = { - 'default':{ - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'accounting', - 'USER': 'root', - 'PASSWORD': 'ADMIN', - 'HOST': '127.0.0.1', - 'PORT': '3306', - } - } - - pass diff --git a/src/back/portal/settings2.py b/src/back/portal/settings2.py deleted file mode 100644 index c7fed2c20..000000000 --- a/src/back/portal/settings2.py +++ /dev/null @@ -1,301 +0,0 @@ -""" -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' - ]), - } -} \ No newline at end of file From 1520c4ab0e787a51e6ce64b188a509517bcb6f08 Mon Sep 17 00:00:00 2001 From: Nukeap <53114367+Nukeap@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:35:05 +0300 Subject: [PATCH 03/12] 034 --- src/front/src/views/Vote.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/front/src/views/Vote.vue b/src/front/src/views/Vote.vue index 59aaf64b4..e65626da9 100644 --- a/src/front/src/views/Vote.vue +++ b/src/front/src/views/Vote.vue @@ -195,7 +195,7 @@ export default { isFlipped2.value = !isFlipped2.value; } - if (account_login == '9966-00-011') { + if (account_login == '9966-00-134') { admin_panel = true; } From c3439cb70f35d7e8b8e4623c1ec3ecaabdf8bbb6 Mon Sep 17 00:00:00 2001 From: Nukeap <53114367+Nukeap@users.noreply.github.com> Date: Fri, 8 Nov 2024 08:33:35 +0300 Subject: [PATCH 04/12] a --- src/front/src/views/Vote.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/front/src/views/Vote.vue b/src/front/src/views/Vote.vue index 1bf7ad433..36c30ef24 100644 --- a/src/front/src/views/Vote.vue +++ b/src/front/src/views/Vote.vue @@ -289,7 +289,7 @@ export default { height: 620px !important; } -.flip-card {} +/* .flip-card {} */ .flip-card-inner { display: flex; From 51d2c556e8f0d0fd0131ec8e365fb0bc5b87c47d Mon Sep 17 00:00:00 2001 From: Nukeap <53114367+Nukeap@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:18:06 +0300 Subject: [PATCH 05/12] 2 --- src/front/src/views/Vote.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/front/src/views/Vote.vue b/src/front/src/views/Vote.vue index 742cf438c..6f52f57c1 100644 --- a/src/front/src/views/Vote.vue +++ b/src/front/src/views/Vote.vue @@ -198,6 +198,7 @@ + From 277af6e790bbfba95e88c7648be539176bdee375 Mon Sep 17 00:00:00 2001 From: Nukeap <53114367+Nukeap@users.noreply.github.com> Date: Mon, 13 Jan 2025 08:17:47 +0300 Subject: [PATCH 06/12] Update .gitignore --- src/back/.gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/back/.gitignore b/src/back/.gitignore index 06d57e9ee..6826eca36 100644 --- a/src/back/.gitignore +++ b/src/back/.gitignore @@ -1,10 +1,7 @@ env/ - /__pycache__/ /*/__pycache__/ /*/migrations/ -portal/ds.py -portal/settings.py /front/node_modules/ *.sqlite3 /media/ From f3e918a63a117b2ecdcab0aeefad8c63b417f936 Mon Sep 17 00:00:00 2001 From: Cja Date: Mon, 13 Jan 2025 09:46:23 +0300 Subject: [PATCH 07/12] P-94 --- src/back/vote/views.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/back/vote/views.py b/src/back/vote/views.py index e98246257..fba3c503a 100644 --- a/src/back/vote/views.py +++ b/src/back/vote/views.py @@ -9,7 +9,7 @@ import datetime class GetVotes(APIView): - def get(self, request): + def post(self, request): user = request.user # user = DictEmployee.objects.get(login='9966-00-125') now = datetime.datetime.now() @@ -45,23 +45,40 @@ class GetVotes(APIView): ) vote.save() + def update_vote(self, request): + vote_id = request.data.get('id') + try: + vote = Vote.objects.get(id=vote_id) + + for field, value in request.data.items(): + if hasattr(vote, field): + setattr(vote, field, value) + vote.save() + return Response({'status': 'success', 'message': 'Vote updated successfully.'}, status=200) + except: + return Response({'error': 'Vote not found'}, status=404) + 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() + vote_id = request.data.get('id') + try: + vote = Vote.objects.get(id=vote_id) + questions = vote.questions.all() + for question in questions: + answers = question.answers.all() + answers.delete() - questions.delete() + questions.delete() - results = Result.objects.filter(answer__question__vote=vote) - results.delete() + results = Result.objects.filter(answer__question__vote=vote) + results.delete() - vote.delete() + vote.delete() + return Response({'status': 'success', 'message': 'Vote deleted successfully.'}, status=200) + except: + return Response({'error': 'Vote not found'}, status=404) def get_vote_results(self, request): - vote_id = request.data.get('vote_id') + vote_id = request.data.get('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 From ffb281ae7fe65a29a697dec6741661f8888dc90d Mon Sep 17 00:00:00 2001 From: Cja Date: Mon, 13 Jan 2025 09:49:46 +0300 Subject: [PATCH 08/12] P-94 --- src/back/vote/views.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/back/vote/views.py b/src/back/vote/views.py index fba3c503a..2adffb399 100644 --- a/src/back/vote/views.py +++ b/src/back/vote/views.py @@ -45,6 +45,23 @@ class GetVotes(APIView): ) vote.save() + def get_vote(self, request): + vote_id = request.query_params.get('id') + try: + vote = Vote.objects.get(id=vote_id) + vote_data = { + 'id': vote.id, + 'name': vote.name, + 'description': vote.description, + 'datestart': vote.datestart, + 'dateend': vote.dateend, + 'settings': vote.settings, + 'author': vote.author.username, + } + return Response({'status': 'success', 'vote': vote_data}, status=200) + except: + return Response({'error': 'Vote not found'}, status=404) + def update_vote(self, request): vote_id = request.data.get('id') try: From d78b7e2ce7403f146457055bf1e6535231480469 Mon Sep 17 00:00:00 2001 From: Cja Date: Mon, 13 Jan 2025 14:23:56 +0300 Subject: [PATCH 09/12] P-100 --- src/back/vote/serializers.py | 9 +++- src/back/vote/urls.py | 2 + src/back/vote/views.py | 101 ++++++++++++++--------------------- 3 files changed, 49 insertions(+), 63 deletions(-) diff --git a/src/back/vote/serializers.py b/src/back/vote/serializers.py index 6716093c5..f91992c59 100644 --- a/src/back/vote/serializers.py +++ b/src/back/vote/serializers.py @@ -6,7 +6,14 @@ from userauth.models import * class VoteSerializer(serializers.ModelSerializer): class Meta: model = Vote - fields = '__all__' + fields = ['id', 'name', 'description', 'datestart', 'dateend', 'settings', 'author'] + + def create(self, validated_data): + user = self.context['request'].user + if user.is_authenticated: + validated_data['author'] = user + + return super().create(validated_data) class QuestionSerializer(serializers.ModelSerializer): class Meta: diff --git a/src/back/vote/urls.py b/src/back/vote/urls.py index 77389fdc3..567e78a00 100644 --- a/src/back/vote/urls.py +++ b/src/back/vote/urls.py @@ -5,4 +5,6 @@ from .views import * urlpatterns = [ path('getvotes/', GetVotes.as_view(),name='GetVotes'), + path('votedetail//', VoteDetail.as_view(),name='VoteDetail'), + path('votecreate/', VoteCreate.as_view(),name='VoteCreate'), ] diff --git a/src/back/vote/views.py b/src/back/vote/views.py index 2adffb399..b859221a7 100644 --- a/src/back/vote/views.py +++ b/src/back/vote/views.py @@ -6,10 +6,11 @@ from .models import * from userauth.models import * from .serializers import * import datetime +from rest_framework import generics class GetVotes(APIView): - def post(self, request): + def get(self, request): user = request.user # user = DictEmployee.objects.get(login='9966-00-125') now = datetime.datetime.now() @@ -34,69 +35,45 @@ class GetVotes(APIView): def has_participated(self, employee, vote): return Result.objects.filter(user=employee, answer__question__vote=vote).exists() - 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, - ) - vote.save() - - def get_vote(self, request): - vote_id = request.query_params.get('id') - try: - vote = Vote.objects.get(id=vote_id) - vote_data = { - 'id': vote.id, - 'name': vote.name, - 'description': vote.description, - 'datestart': vote.datestart, - 'dateend': vote.dateend, - 'settings': vote.settings, - 'author': vote.author.username, - } - return Response({'status': 'success', 'vote': vote_data}, status=200) - except: - return Response({'error': 'Vote not found'}, status=404) - - def update_vote(self, request): - vote_id = request.data.get('id') - try: - vote = Vote.objects.get(id=vote_id) - - for field, value in request.data.items(): - if hasattr(vote, field): - setattr(vote, field, value) - vote.save() - return Response({'status': 'success', 'message': 'Vote updated successfully.'}, status=200) - except: - return Response({'error': 'Vote not found'}, status=404) - - def delete_vote(self,request): - vote_id = request.data.get('id') - try: - vote = Vote.objects.get(id=vote_id) - questions = vote.questions.all() - for question in questions: - answers = question.answers.all() - answers.delete() - - questions.delete() - - results = Result.objects.filter(answer__question__vote=vote) - results.delete() - - vote.delete() - return Response({'status': 'success', 'message': 'Vote deleted successfully.'}, status=200) - except: - return Response({'error': 'Vote not found'}, status=404) - def get_vote_results(self, request): vote_id = request.data.get('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) \ No newline at end of file + return Response(serialized_results) + +class VoteDetail(generics.RetrieveUpdateDestroyAPIView): + queryset = Vote.objects.all() + serializer_class = VoteSerializer + lookup_url_kwarg = 'id' + lookup_field = 'id' + +class VoteCreate(APIView): + + def post(self, request): + user = request.user + user = DictEmployee.objects.get(login='9966-00-125') + user = User.objects.get(user=user) + vote = Vote( + name=request.data['title'], + description=request.data['description'], + datestart=request.data['startDate'], + dateend=request.data['endDate'], + settings=request.data.get('settings', {}), + author=user, + ) + vote.save() + + for count, question_data in enumerate(request.data['questions'], start=1): + question = Question( + question=question_data['text'], + vote=vote, + # file=question.get('image', None), + 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() + + return Response({'status': 'success', 'message': 'Vote created successfully.'}, status=201) \ No newline at end of file From 95e9893482f11e0248b1eddca4c86d2a9d3cc122 Mon Sep 17 00:00:00 2001 From: Denzel Date: Tue, 14 Jan 2025 07:43:49 +0300 Subject: [PATCH 10/12] P-92 --- src/front/src/components/vote/CurrentVote.vue | 170 +++++++++ .../src/components/vote/VoteConstructor.vue | 356 ++++++++++++++++++ src/front/src/components/vote/VoteForm.vue | 259 +++++++------ src/front/src/router/index.js | 12 +- src/front/src/test/testDataForVote.js | 48 +++ src/front/src/utils/axios-api.js | 37 +- src/front/src/views/VoteConstructor.vue | 325 ---------------- src/front/src/views/VoteHomePage.vue | 91 +++-- 8 files changed, 805 insertions(+), 493 deletions(-) create mode 100644 src/front/src/components/vote/CurrentVote.vue create mode 100644 src/front/src/components/vote/VoteConstructor.vue create mode 100644 src/front/src/test/testDataForVote.js delete mode 100644 src/front/src/views/VoteConstructor.vue 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..1cd2261a4 --- /dev/null +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -0,0 +1,356 @@ + + + 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..66a723d99 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,33 @@ 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', 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' }, + }); + + getVotes('active') + .then(data => { + console.log('Активные голосования:', data); + }) + .catch(err => { + console.error('Ошибка:', err); + }); + + 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 @@