From 1aa39d1d20a2365db0ecec5ffa899a818112e236 Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Wed, 21 Jun 2023 17:02:53 +0300 Subject: [PATCH] added promocodes, senetry --- .env.example | 1 + README.md | 9 + akarpov/files/urls.py | 2 + akarpov/files/views.py | 12 + akarpov/templates/base.html | 1 + akarpov/templates/files/view.html | 2 +- .../templates/tools/promocodes/activate.html | 32 + akarpov/tools/promocodes/__init__.py | 0 akarpov/tools/promocodes/admin.py | 6 + akarpov/tools/promocodes/apps.py | 6 + akarpov/tools/promocodes/forms.py | 5 + .../promocodes/migrations/0001_initial.py | 103 ++ .../tools/promocodes/migrations/__init__.py | 0 akarpov/tools/promocodes/models.py | 37 + akarpov/tools/promocodes/services.py | 64 + akarpov/tools/promocodes/urls.py | 9 + akarpov/tools/promocodes/views.py | 26 + akarpov/tools/urls.py | 3 + config/settings/base.py | 27 +- poetry.lock | 1095 ++++++++++------- 20 files changed, 1017 insertions(+), 423 deletions(-) create mode 100644 akarpov/templates/tools/promocodes/activate.html create mode 100644 akarpov/tools/promocodes/__init__.py create mode 100644 akarpov/tools/promocodes/admin.py create mode 100644 akarpov/tools/promocodes/apps.py create mode 100644 akarpov/tools/promocodes/forms.py create mode 100644 akarpov/tools/promocodes/migrations/0001_initial.py create mode 100644 akarpov/tools/promocodes/migrations/__init__.py create mode 100644 akarpov/tools/promocodes/models.py create mode 100644 akarpov/tools/promocodes/services.py create mode 100644 akarpov/tools/promocodes/urls.py create mode 100644 akarpov/tools/promocodes/views.py diff --git a/.env.example b/.env.example index 1b4f42b..92c3193 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,4 @@ REDIS_CACHE=rediscache://localhost:6379/1 USE_DOCKER=no EMAIL_HOST=127.0.0.1 EMAIL_PORT=1025 +SENTRY_DSN= diff --git a/README.md b/README.md index 7240295..d59ec5f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,15 @@ My collection of apps and tools Writen in Python 3.11 and Django 4.2 +### local run via docker + +```shell +$ python3 manage.py migrate +$ python3 manage.py runserver +$ celery -A config.celery_app worker --loglevel=info +``` + + ### local run via docker ```shell diff --git a/akarpov/files/urls.py b/akarpov/files/urls.py index 4843f68..688fead 100644 --- a/akarpov/files/urls.py +++ b/akarpov/files/urls.py @@ -6,6 +6,7 @@ TopFolderView, delete_file_view, delete_folder_view, + file_download_view, file_report_list, file_table, file_update, @@ -34,6 +35,7 @@ path("api/chunked_upload/", ChunkedUploadView.as_view(), name="api_chunked_upload"), path("api/folder/create/", folder_create, name="folder_create"), path("api/file/report/", report_file, name="file_report"), + path("api/file/download/", file_download_view, name="file_download"), path("api/file/delete/", delete_file_view, name="delete"), path("api/folder/create/", folder_create, name="sub_folder_create"), path("api/folder/delete/", delete_folder_view, name="folder_delete"), diff --git a/akarpov/files/views.py b/akarpov/files/views.py index 7d5b858..fd70e14 100644 --- a/akarpov/files/views.py +++ b/akarpov/files/views.py @@ -6,6 +6,7 @@ from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.urls import reverse +from django.views import View from django.views.generic import ( CreateView, DetailView, @@ -342,3 +343,14 @@ def get_redirect_url(self, *args, **kwargs): delete_folder_view = DeleteFolderView.as_view() + + +class FileDownloadView(View): + def get(self, request, slug): + file = get_object_or_404(File, slug=slug) + file.downloads += 1 + file.save(update_fields=["downloads"]) + return HttpResponseRedirect(file.file.url) + + +file_download_view = FileDownloadView.as_view() diff --git a/akarpov/templates/base.html b/akarpov/templates/base.html index 1db5043..74a2779 100644 --- a/akarpov/templates/base.html +++ b/akarpov/templates/base.html @@ -84,6 +84,7 @@