Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Public contract registry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Public contract registry
Commits
eb54ac1d
Commit
eb54ac1d
authored
2 years ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
fix admin file viewing
parent
f2d8433c
No related branches found
No related tags found
1 merge request
!2
Release
Pipeline
#12471
passed
2 years ago
Stage: build
Stage: test_deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contracts/migrations/0053_alter_contractfile_file.py
+19
-0
19 additions, 0 deletions
contracts/migrations/0053_alter_contractfile_file.py
contracts/models.py
+18
-2
18 additions, 2 deletions
contracts/models.py
with
37 additions
and
2 deletions
contracts/migrations/0053_alter_contractfile_file.py
0 → 100644
+
19
−
0
View file @
eb54ac1d
# 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
'
),
),
]
This diff is collapsed.
Click to expand it.
contracts/models.py
+
18
−
2
View file @
eb54ac1d
...
...
@@ -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
=
Contract
FileField
(
verbose_name
=
"
Soubor
"
,
upload_to
=
get_contract_file_loaction
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment