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 @@