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
ae34c4e9
Commit
ae34c4e9
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
use HXDynSel for SubsidyAttachment linking
parent
b30d31dd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scipost_django/finances/forms.py
+13
-19
13 additions, 19 deletions
scipost_django/finances/forms.py
scipost_django/finances/urls.py
+10
-0
10 additions, 0 deletions
scipost_django/finances/urls.py
scipost_django/finances/views.py
+23
-0
23 additions, 0 deletions
scipost_django/finances/views.py
with
46 additions
and
19 deletions
scipost_django/finances/forms.py
+
13
−
19
View file @
ae34c4e9
...
@@ -17,6 +17,7 @@ from crispy_bootstrap5.bootstrap5 import FloatingField
...
@@ -17,6 +17,7 @@ from crispy_bootstrap5.bootstrap5 import FloatingField
from
dal
import
autocomplete
from
dal
import
autocomplete
from
dateutil.rrule
import
rrule
,
MONTHLY
from
dateutil.rrule
import
rrule
,
MONTHLY
from
common.forms
import
HTMXDynSelWidget
from
finances.constants
import
(
from
finances.constants
import
(
SUBSIDY_STATUS
,
SUBSIDY_STATUS
,
SUBSIDY_TYPE_SPONSORSHIPAGREEMENT
,
SUBSIDY_TYPE_SPONSORSHIPAGREEMENT
,
...
@@ -299,12 +300,13 @@ class SubsidyAttachmentInlineLinkForm(forms.ModelForm):
...
@@ -299,12 +300,13 @@ class SubsidyAttachmentInlineLinkForm(forms.ModelForm):
)
)
subsidy
=
forms
.
ModelChoiceField
(
subsidy
=
forms
.
ModelChoiceField
(
queryset
=
Subsidy
.
objects
.
all
(),
queryset
=
Subsidy
.
objects
.
all
(),
widget
=
autocomplete
.
ModelSelect2
(
widget
=
HTMXDynSelWidget
(
url
=
reverse_lazy
(
"
finances:subsidy_autocomplete
"
),
dynsel_context
=
{
attrs
=
{
"
results_page_url
"
:
reverse_lazy
(
"
data-html
"
:
True
,
"
finances:_hx_dynsel_subsidy_result_page
"
"
style
"
:
"
width: 100%
"
,
),
},
"
collection_name
"
:
"
subsidies
"
,
}
),
),
help_text
=
(
"
Start typing, and select from the popup.
"
),
help_text
=
(
"
Start typing, and select from the popup.
"
),
required
=
False
,
required
=
False
,
...
@@ -325,7 +327,7 @@ class SubsidyAttachmentInlineLinkForm(forms.ModelForm):
...
@@ -325,7 +327,7 @@ class SubsidyAttachmentInlineLinkForm(forms.ModelForm):
self
.
fields
[
"
filename
"
].
initial
=
self
.
instance
.
filename
self
.
fields
[
"
filename
"
].
initial
=
self
.
instance
.
filename
def
clean
(
self
):
def
clean
(
self
):
orphaned
=
self
.
cleaned_data
[
"
subsidy
"
]
is
None
orphaned
=
self
.
cleaned_data
.
get
(
"
subsidy
"
)
is
None
filename
=
self
.
cleaned_data
[
"
filename
"
]
filename
=
self
.
cleaned_data
[
"
filename
"
]
# Allow misnamed orphans
# Allow misnamed orphans
...
@@ -355,18 +357,10 @@ class SubsidyAttachmentInlineLinkForm(forms.ModelForm):
...
@@ -355,18 +357,10 @@ class SubsidyAttachmentInlineLinkForm(forms.ModelForm):
instance
.
filename
,
filename
instance
.
filename
,
filename
)
)
try
:
instance
.
attachment
.
storage
.
save
(
new_relative_path
,
instance
.
attachment
)
instance
.
attachment
.
storage
.
save
(
new_relative_path
,
instance
.
attachment
)
instance
.
attachment
.
name
=
new_relative_path
instance
.
attachment
.
storage
.
delete
(
old_relative_path
)
instance
.
save
()
instance
.
attachment
.
name
=
new_relative_path
instance
.
attachment
.
storage
.
delete
(
old_relative_path
)
except
Exception
as
e
:
self
.
add_error
(
"
filename
"
,
f
"
An error occurred while renaming the file:
{
e
}
"
,
)
if
commit
:
instance
.
save
()
return
instance
return
instance
...
...
This diff is collapsed.
Click to expand it.
scipost_django/finances/urls.py
+
10
−
0
View file @
ae34c4e9
...
@@ -106,6 +106,16 @@ urlpatterns = [
...
@@ -106,6 +106,16 @@ urlpatterns = [
views
.
SubsidyAutocompleteView
.
as_view
(),
views
.
SubsidyAutocompleteView
.
as_view
(),
name
=
"
subsidy_autocomplete
"
,
name
=
"
subsidy_autocomplete
"
,
),
),
path
(
"
subsidies/_hx_dynsel_/page
"
,
views
.
HXDynselSubsidyResultPage
.
as_view
(),
name
=
"
_hx_dynsel_subsidy_result_page
"
,
),
path
(
"
subsidies/_hx_dynsel/select_option
"
,
views
.
HXDynselSubsidySelectOption
.
as_view
(),
name
=
"
_hx_dynsel_subsidy_select_option
"
,
),
path
(
path
(
"
subsidies/<int:pk>/
"
,
views
.
SubsidyDetailView
.
as_view
(),
name
=
"
subsidy_details
"
"
subsidies/<int:pk>/
"
,
views
.
SubsidyDetailView
.
as_view
(),
name
=
"
subsidy_details
"
),
),
...
...
This diff is collapsed.
Click to expand it.
scipost_django/finances/views.py
+
23
−
0
View file @
ae34c4e9
...
@@ -12,6 +12,8 @@ from django.template.response import TemplateResponse
...
@@ -12,6 +12,8 @@ from django.template.response import TemplateResponse
from
django.utils.html
import
format_html
from
django.utils.html
import
format_html
import
matplotlib
import
matplotlib
from
common.views
import
HXDynselResultPage
,
HXDynselSelectOptionView
matplotlib
.
use
(
"
Agg
"
)
matplotlib
.
use
(
"
Agg
"
)
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
io
,
base64
import
io
,
base64
...
@@ -590,6 +592,27 @@ def _hx_subsidyattachment_link_form(request, attachment_id):
...
@@ -590,6 +592,27 @@ def _hx_subsidyattachment_link_form(request, attachment_id):
return
render
(
request
,
"
finances/_hx_subsidyattachment_link_form.html
"
,
context
)
return
render
(
request
,
"
finances/_hx_subsidyattachment_link_form.html
"
,
context
)
class
HXDynselSubsidyResultPage
(
HXDynselResultPage
):
model
=
Subsidy
collection_name
=
"
subsidies
"
obj_select_option_url
=
reverse_lazy
(
"
finances:_hx_dynsel_subsidy_select_option
"
)
def
search
(
self
,
queryset
,
q
):
return
queryset
.
filter
(
Q
(
organization__name__unaccent__icontains
=
q
)
|
Q
(
organization__name_original__unaccent__icontains
=
q
)
|
Q
(
organization__acronym__unaccent__icontains
=
q
)
|
Q
(
amount__icontains
=
q
)
|
Q
(
description__icontains
=
q
)
|
Q
(
date_from__year__icontains
=
q
)
|
Q
(
date_until__year__icontains
=
q
)
)
class
HXDynselSubsidySelectOption
(
HXDynselSelectOptionView
):
model
=
Subsidy
def
subsidy_attachment
(
request
,
attachment_id
):
def
subsidy_attachment
(
request
,
attachment_id
):
attachment
=
get_object_or_404
(
SubsidyAttachment
.
objects
,
id
=
attachment_id
)
attachment
=
get_object_or_404
(
SubsidyAttachment
.
objects
,
id
=
attachment_id
)
if
not
(
request
.
user
.
is_authenticated
and
attachment
.
visible_to_user
(
request
.
user
)):
if
not
(
request
.
user
.
is_authenticated
and
attachment
.
visible_to_user
(
request
.
user
)):
...
...
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