mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2025-02-22 06:00:33 +03:00
added list, file process
This commit is contained in:
parent
845c989718
commit
bad7355c96
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from akarpov.contrib.chunked_upload.constants import COMPLETE, UPLOADING
|
from akarpov.contrib.chunked_upload.constants import COMPLETE, UPLOADING
|
||||||
from akarpov.contrib.chunked_upload.models import ChunkedUpload
|
from akarpov.contrib.chunked_upload.models import ChunkedUpload
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from akarpov.files.models import File
|
from akarpov.files.models import File
|
||||||
from akarpov.files.tasks import generate_file_review
|
from akarpov.files.tasks import process_file
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=File)
|
@receiver(post_save, sender=File)
|
||||||
def post_on_create(sender, instance: File, created, **kwargs):
|
def post_on_create(sender, instance: File, created, **kwargs):
|
||||||
if created:
|
if created:
|
||||||
generate_file_review.apply_async(
|
process_file.apply_async(
|
||||||
kwargs={
|
kwargs={
|
||||||
"pk": instance.pk,
|
"pk": instance.pk,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
|
|
||||||
|
@ -6,14 +8,18 @@
|
||||||
|
|
||||||
|
|
||||||
@shared_task()
|
@shared_task()
|
||||||
def generate_file_review(pk: int):
|
def process_file(pk: int):
|
||||||
file = FileModel.objects.get(pk=pk)
|
file = FileModel.objects.get(pk=pk)
|
||||||
|
if not file.name:
|
||||||
|
file.name = file.file.name
|
||||||
pth = create_preview(file.file)
|
pth = create_preview(file.file)
|
||||||
with open(pth, "rb") as f:
|
with open(pth, "rb") as f:
|
||||||
file.preview.save(
|
file.preview.save(
|
||||||
pth.split("/")[-1],
|
pth.split("/")[-1],
|
||||||
File(f.read()),
|
File(f),
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
file.save(update_fields=["preview"])
|
file.save(update_fields=["preview"])
|
||||||
|
if os.path.isfile(pth):
|
||||||
|
os.remove(pth)
|
||||||
return pk
|
return pk
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
ChunkedUploadDemo,
|
ChunkedUploadDemo,
|
||||||
MyChunkedUploadCompleteView,
|
MyChunkedUploadCompleteView,
|
||||||
MyChunkedUploadView,
|
MyChunkedUploadView,
|
||||||
|
TopFolderView,
|
||||||
files_view,
|
files_view,
|
||||||
folder_view,
|
folder_view,
|
||||||
)
|
)
|
||||||
|
|
||||||
app_name = "files"
|
app_name = "files"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path("", TopFolderView.as_view(), name="main"),
|
||||||
path("upload", ChunkedUploadDemo.as_view(), name="chunked_upload"),
|
path("upload", ChunkedUploadDemo.as_view(), name="chunked_upload"),
|
||||||
path(
|
path(
|
||||||
"api/chunked_upload_complete/",
|
"api/chunked_upload_complete/",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.views.generic import DetailView
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.views.generic import DetailView, ListView
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
from akarpov.contrib.chunked_upload.exceptions import ChunkedUploadError
|
from akarpov.contrib.chunked_upload.exceptions import ChunkedUploadError
|
||||||
|
@ -12,6 +13,21 @@
|
||||||
from akarpov.files.models import File, Folder
|
from akarpov.files.models import File, Folder
|
||||||
|
|
||||||
|
|
||||||
|
class TopFolderView(LoginRequiredMixin, ListView):
|
||||||
|
template_name = "files/list.html"
|
||||||
|
model = File
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return File.objects.filter(user=self.request.user, folder__isnull=True)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
contex = super().get_context_data(**kwargs)
|
||||||
|
contex["folders"] = Folder.objects.filter(
|
||||||
|
user=self.request.user, parent__isnull=True
|
||||||
|
)
|
||||||
|
return contex
|
||||||
|
|
||||||
|
|
||||||
class FileView(DetailView):
|
class FileView(DetailView):
|
||||||
template_name = "files/view.html"
|
template_name = "files/view.html"
|
||||||
model = File
|
model = File
|
||||||
|
@ -69,4 +85,4 @@ def on_completion(self, uploaded_file, request):
|
||||||
os.remove(uploaded_file.file.path)
|
os.remove(uploaded_file.file.path)
|
||||||
|
|
||||||
def get_response_data(self, chunked_upload, request):
|
def get_response_data(self, chunked_upload, request):
|
||||||
return {"message": (self.message)}
|
return {"message": self.message}
|
||||||
|
|
|
@ -49,6 +49,12 @@
|
||||||
<a href="{% url 'about:about' %}" class="{% active_link 'about' %} text-muted nav-link px-sm-0 px-2">
|
<a href="{% url 'about:about' %}" class="{% active_link 'about' %} text-muted nav-link px-sm-0 px-2">
|
||||||
<i class="fs-5 bi-person"></i><span class="ms-1 d-none d-sm-inline">About me</span></a>
|
<i class="fs-5 bi-person"></i><span class="ms-1 d-none d-sm-inline">About me</span></a>
|
||||||
</li>
|
</li>
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'files:main' %}" class="{% active_link 'files' %} text-muted nav-link px-sm-0 px-2">
|
||||||
|
<i class="fs-5 bi-folder-fill"></i><span class="ms-1 d-none d-sm-inline">Files</span></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="text-muted nav-link dropdown-toggle px-sm-0 px-1" id="dropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
<a href="#" class="text-muted nav-link dropdown-toggle px-sm-0 px-1" id="dropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<i class="fs-5 bi-terminal-fill"></i><span class="ms-1 d-none d-sm-inline">Apps</span>
|
<i class="fs-5 bi-terminal-fill"></i><span class="ms-1 d-none d-sm-inline">Apps</span>
|
||||||
|
|
10
akarpov/templates/files/list.html
Normal file
10
akarpov/templates/files/list.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% for folder in folders %}
|
||||||
|
{{ folder.name }}
|
||||||
|
{% endfor %}
|
||||||
|
{% for file in file_list %}
|
||||||
|
{{ file.name }} - {{ file.file.url }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
|
@ -22,7 +22,7 @@
|
||||||
path("users/", include("akarpov.users.urls", namespace="users")),
|
path("users/", include("akarpov.users.urls", namespace="users")),
|
||||||
path("about/", include("akarpov.about.urls", namespace="about")),
|
path("about/", include("akarpov.about.urls", namespace="about")),
|
||||||
path("files/", include("akarpov.files.urls", namespace="files")),
|
path("files/", include("akarpov.files.urls", namespace="files")),
|
||||||
path("files/", include("akarpov.music.urls", namespace="music")),
|
path("music/", include("akarpov.music.urls", namespace="music")),
|
||||||
path("forms/", include("akarpov.test_platform.urls", namespace="forms")),
|
path("forms/", include("akarpov.test_platform.urls", namespace="forms")),
|
||||||
path("tools/", include("akarpov.tools.urls", namespace="tools")),
|
path("tools/", include("akarpov.tools.urls", namespace="tools")),
|
||||||
path("ckeditor/", include("ckeditor_uploader.urls")),
|
path("ckeditor/", include("ckeditor_uploader.urls")),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user