SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
SciPost
SciPost
Commits
126bd07b
Commit
126bd07b
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
allow replacement of subsidy attachments
parent
25b74518
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scipost_django/finances/forms.py
+5
-0
5 additions, 0 deletions
scipost_django/finances/forms.py
scipost_django/finances/models.py
+13
-0
13 additions, 0 deletions
scipost_django/finances/models.py
with
18 additions
and
0 deletions
scipost_django/finances/forms.py
+
5
−
0
View file @
126bd07b
...
@@ -263,6 +263,11 @@ class SubsidyAttachmentForm(forms.ModelForm):
...
@@ -263,6 +263,11 @@ class SubsidyAttachmentForm(forms.ModelForm):
def
clean_attachment
(
self
):
def
clean_attachment
(
self
):
attachment
=
self
.
cleaned_data
[
"
attachment
"
]
attachment
=
self
.
cleaned_data
[
"
attachment
"
]
# Allow already uploaded attachments
if
hasattr
(
self
.
instance
,
"
attachment
"
)
and
not
attachment
is
None
:
return
attachment
filename_regex
=
(
filename_regex
=
(
"
^SciPost_
"
"
^SciPost_
"
"
[0-9]{4,}(-[0-9]{4,})?_[A-Z]{2,}_[\w]+_
"
"
[0-9]{4,}(-[0-9]{4,})?_[A-Z]{2,}_[\w]+_
"
...
...
This diff is collapsed.
Click to expand it.
scipost_django/finances/models.py
+
13
−
0
View file @
126bd07b
...
@@ -10,6 +10,8 @@ from django.contrib.contenttypes.models import ContentType
...
@@ -10,6 +10,8 @@ from django.contrib.contenttypes.models import ContentType
from
django.contrib.contenttypes.fields
import
GenericForeignKey
from
django.contrib.contenttypes.fields
import
GenericForeignKey
from
django.db
import
models
from
django.db
import
models
from
django.db.models
import
Sum
from
django.db.models
import
Sum
from
django.db.models.signals
import
pre_save
from
django.dispatch
import
receiver
from
django.urls
import
reverse
from
django.urls
import
reverse
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.html
import
format_html
from
django.utils.html
import
format_html
...
@@ -280,6 +282,17 @@ class SubsidyAttachment(models.Model):
...
@@ -280,6 +282,17 @@ class SubsidyAttachment(models.Model):
return
False
return
False
# Delete attachment files with same name if they exist, allowing replacement without name change
@receiver
(
pre_save
,
sender
=
SubsidyAttachment
)
def
delete_old_attachment_file
(
sender
,
instance
,
**
kwargs
):
if
instance
.
pk
:
old_attachment
=
SubsidyAttachment
.
objects
.
get
(
pk
=
instance
.
pk
)
old_filename
=
old_attachment
.
attachment
.
name
.
split
(
"
/
"
)[
-
1
]
if
old_attachment
.
attachment
and
old_filename
==
instance
.
attachment
.
name
:
old_attachment
.
attachment
.
delete
(
save
=
False
)
###########################
###########################
# Work hours registration #
# Work hours registration #
###########################
###########################
...
...
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