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
18e0f108
Commit
18e0f108
authored
2 years ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
split stored files, ID-based names
parent
e4f9ff78
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#12281
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/0033_alter_contractfile_file.py
+19
-0
19 additions, 0 deletions
contracts/migrations/0033_alter_contractfile_file.py
contracts/models.py
+26
-1
26 additions, 1 deletion
contracts/models.py
with
45 additions
and
1 deletion
contracts/migrations/0033_alter_contractfile_file.py
0 → 100644
+
19
−
0
View file @
18e0f108
# Generated by Django 4.1.4 on 2023-04-10 21:45
import
contracts.models
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
contracts
'
,
'
0032_alter_signee_address_country
'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'
contractfile
'
,
name
=
'
file
'
,
field
=
models
.
FileField
(
upload_to
=
contracts
.
models
.
get_contract_file_loaction
,
verbose_name
=
'
Soubor
'
),
),
]
This diff is collapsed.
Click to expand it.
contracts/models.py
+
26
−
1
View file @
18e0f108
import
datetime
import
os
import
mimetypes
import
typing
from
django.conf
import
settings
...
...
@@ -740,6 +742,29 @@ class Contract(NameStrMixin, models.Model):
]
+
OwnPermissionsMixin
.
Meta
.
permissions
def
get_contract_file_loaction
(
instance
,
filename
):
mimetypes_instance
=
mimetypes
.
MimeTypes
()
current_time
=
datetime
.
datetime
.
today
()
guessed_type
=
mimetypes_instance
.
guess_type
(
filename
,
strict
=
False
)[
0
]
extension
=
""
if
guessed_type
is
not
None
:
for
mapper
in
mimetypes_instance
.
types_map_inv
:
if
guessed_type
not
in
mapper
:
continue
extension
=
mapper
[
guessed_type
]
break
return
(
"
_private/
"
f
"
{
current_time
.
year
}
/
{
current_time
.
month
}
/
{
current_time
.
day
}
/
"
f
"
{
str
(
instance
.
id
)
}{
extension
}
"
)
class
ContractFile
(
NameStrMixin
,
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
128
,
...
...
@@ -754,7 +779,7 @@ class ContractFile(NameStrMixin, models.Model):
file
=
models
.
FileField
(
verbose_name
=
"
Soubor
"
,
upload_to
=
"
_private/
"
,
upload_to
=
get_contract_file_loaction
,
)
contract
=
models
.
ForeignKey
(
...
...
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