added file icons, made file list prettier
17
akarpov/files/migrations/0013_alter_file_options.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-08 10:54
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("files", "0012_alter_file_options_alter_file_file"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="file",
|
||||
options={"ordering": ["-modified"]},
|
||||
),
|
||||
]
|
|
@ -1,3 +1,6 @@
|
|||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models import (
|
||||
CASCADE,
|
||||
BooleanField,
|
||||
|
@ -32,6 +35,16 @@ class File(TimeStampedModel, ShortLink):
|
|||
description = TextField(blank=True, null=True)
|
||||
file_type = CharField(max_length=50, null=True, blank=True)
|
||||
|
||||
@property
|
||||
def file_image_url(self):
|
||||
if self.preview:
|
||||
return self.preview.url
|
||||
end = self.file.path.split(".")[-1]
|
||||
path = settings.STATICFILES_DIRS[0] + f"/images/files/{end}.png"
|
||||
if os.path.isfile(path):
|
||||
return settings.STATIC_URL + f"images/files/{end}.png"
|
||||
return settings.STATIC_URL + "images/files/_blank.png"
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("files:view", kwargs={"slug": self.slug})
|
||||
|
||||
|
@ -39,7 +52,7 @@ def __str__(self):
|
|||
return f"file: {self.name}"
|
||||
|
||||
class Meta:
|
||||
ordering = ["modified"]
|
||||
ordering = ["-modified"]
|
||||
|
||||
|
||||
class FileInTrash(TimeStampedModel):
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
@shared_task()
|
||||
def process_file(pk: int):
|
||||
pth = None
|
||||
file = FileModel.objects.get(pk=pk)
|
||||
if not file.name:
|
||||
file.name = file.file.name.split("/")[-1]
|
||||
|
@ -31,8 +32,18 @@ def process_file(pk: int):
|
|||
except Exception as e:
|
||||
logger.error(e)
|
||||
file.type = get_file_mimetype(file.file.path)
|
||||
file.description = get_description(file.file.path)
|
||||
descr = None
|
||||
try:
|
||||
descr = get_description(file.file.path)
|
||||
if descr:
|
||||
with open(descr, encoding="utf-8") as f:
|
||||
data = f.read()
|
||||
file.description = data
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
file.save(update_fields=["preview", "name", "file_type", "description"])
|
||||
if pth and os.path.isfile(pth):
|
||||
os.remove(pth)
|
||||
if descr and os.path.isfile(descr):
|
||||
os.remove(descr)
|
||||
return pk
|
||||
|
|
BIN
akarpov/static/images/files/_blank.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
akarpov/static/images/files/_page.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
akarpov/static/images/files/aac.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
akarpov/static/images/files/ai.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
akarpov/static/images/files/aiff.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
akarpov/static/images/files/avi.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
akarpov/static/images/files/bmp.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/c.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
akarpov/static/images/files/cpp.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
akarpov/static/images/files/css.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
akarpov/static/images/files/csv.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
akarpov/static/images/files/dat.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
akarpov/static/images/files/dmg.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
akarpov/static/images/files/doc.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
akarpov/static/images/files/dotx.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/dwg.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
akarpov/static/images/files/dxf.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
akarpov/static/images/files/eps.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/exe.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
akarpov/static/images/files/flv.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
akarpov/static/images/files/gif.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
akarpov/static/images/files/h.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
akarpov/static/images/files/hpp.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
akarpov/static/images/files/html.png
Normal file
After Width: | Height: | Size: 9.6 KiB |
BIN
akarpov/static/images/files/ics.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
akarpov/static/images/files/iso.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
akarpov/static/images/files/java.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
akarpov/static/images/files/jpg.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
akarpov/static/images/files/js.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/key.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
akarpov/static/images/files/less.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
akarpov/static/images/files/mid.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
akarpov/static/images/files/mp3.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
akarpov/static/images/files/mp4.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
akarpov/static/images/files/mpg.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
akarpov/static/images/files/odf.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
akarpov/static/images/files/ods.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
akarpov/static/images/files/odt.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
akarpov/static/images/files/otp.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
akarpov/static/images/files/ots.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
akarpov/static/images/files/ott.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
akarpov/static/images/files/pdf.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
akarpov/static/images/files/php.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
akarpov/static/images/files/png.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
akarpov/static/images/files/ppt.png
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
akarpov/static/images/files/psd.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
akarpov/static/images/files/py.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
akarpov/static/images/files/qt.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
akarpov/static/images/files/rar.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
akarpov/static/images/files/rb.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
akarpov/static/images/files/rtf.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
akarpov/static/images/files/sass.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/scss.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/sql.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
akarpov/static/images/files/tga.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
akarpov/static/images/files/tgz.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
akarpov/static/images/files/tiff.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
akarpov/static/images/files/txt.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
akarpov/static/images/files/wav.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
akarpov/static/images/files/xls.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
akarpov/static/images/files/xlsx.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
akarpov/static/images/files/xml.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
akarpov/static/images/files/yml.png
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
akarpov/static/images/files/zip.png
Normal file
After Width: | Height: | Size: 23 KiB |
|
@ -1,23 +1,35 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
.row {
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.row > [class*='col-'] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% for folder in folders %}
|
||||
{{ folder.name }}
|
||||
{% endfor %}
|
||||
<div class="row">
|
||||
{% for file in file_list %}
|
||||
<div class="col-sm-2">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{% for file in file_list %}
|
||||
<div class="col-lg-2 col-md-4 col-sm-6 col-xs-12 mb-3 m-3 d-flex align-items-stretch card">
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">{{ file.name }}</h5>
|
||||
<p class="card-text">{{ file.description }}</p>
|
||||
<p class="card-text"><small class="text-body-secondary">Last updated 3 mins ago</small></p>
|
||||
</div>
|
||||
{% if file.preview %}
|
||||
<img src="{{ file.preview.url }}" class="card-img-bottom" alt="">
|
||||
{% endif %}
|
||||
<p class="card-text mb-4"><small class="text-muted">{{ file.edited | naturaltime }}</small></p>
|
||||
<img src="{{ file.file_image_url }}" class="card-img-bottom" alt="">
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|