Skip to content
Snippets Groups Projects
Commit eb54ac1d authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

fix admin file viewing

parent f2d8433c
No related branches found
No related tags found
1 merge request!2Release
Pipeline #12471 passed
# Generated by Django 4.1.4 on 2023-04-21 12:10
import contracts.models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('contracts', '0052_remove_contract_legal_state_contract_is_valid'),
]
operations = [
migrations.AlterField(
model_name='contractfile',
name='file',
field=contracts.models.ContractFileField(upload_to=contracts.models.get_contract_file_loaction, verbose_name='Soubor'),
),
]
......@@ -2,12 +2,14 @@ import datetime
import mimetypes
import os
import typing
import uuid
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator, URLValidator
from django.db import models
from django.db.models.signals import post_save
from django.db.models.fields.files import FieldFile
from django.dispatch import receiver
from django.urls import reverse
from django.utils.safestring import mark_safe
......@@ -809,15 +811,29 @@ def get_contract_file_loaction(instance, filename):
continue
extension = mapper[guessed_type]
if isinstance(extension, list):
extension = extension[0]
break
return (
"_private/"
f"{current_time.year}/{current_time.month}/{current_time.day}/"
f"{str(instance.id)}{extension}"
f"{uuid.uuid4()}{extension}"
)
class ContractFileProxy(FieldFile):
@property
def url(self) -> str:
return reverse("contracts:download_contract_file", args=(str(self.instance.id),))
class ContractFileField(models.FileField):
attr_class = ContractFileProxy
class ContractFile(NameStrMixin, models.Model):
name = models.CharField(
max_length=256,
......@@ -830,7 +846,7 @@ class ContractFile(NameStrMixin, models.Model):
verbose_name="Veřejně dostupný",
)
file = models.FileField(
file = ContractFileField(
verbose_name="Soubor",
upload_to=get_contract_file_loaction,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment