added file icons, made file list prettier

This commit is contained in:
Alexander Karpov 2023-04-08 18:17:16 +03:00
parent 75ca7ee75c
commit 88c3c2d41a
68 changed files with 68 additions and 15 deletions

View 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"]},
),
]

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -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">
<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 %}
</div>
{% 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 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 %}