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
2e305077
Commit
2e305077
authored
8 months ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
add htmx dynsel widget to grants and funders
parent
de9ab5b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scipost_django/funders/forms.py
+5
-7
5 additions, 7 deletions
scipost_django/funders/forms.py
scipost_django/funders/urls.py
+2
-2
2 additions, 2 deletions
scipost_django/funders/urls.py
scipost_django/funders/views.py
+27
-56
27 additions, 56 deletions
scipost_django/funders/views.py
with
34 additions
and
65 deletions
scipost_django/funders/forms.py
+
5
−
7
View file @
2e305077
...
@@ -4,6 +4,8 @@ __license__ = "AGPL v3"
...
@@ -4,6 +4,8 @@ __license__ = "AGPL v3"
from
django
import
forms
from
django
import
forms
from
common.forms
import
HTMXDynSelWidget
from
.models
import
Funder
,
Grant
from
.models
import
Funder
,
Grant
from
dal
import
autocomplete
from
dal
import
autocomplete
...
@@ -28,7 +30,7 @@ class FunderForm(forms.ModelForm):
...
@@ -28,7 +30,7 @@ class FunderForm(forms.ModelForm):
class
FunderSelectForm
(
forms
.
Form
):
class
FunderSelectForm
(
forms
.
Form
):
funder
=
forms
.
ModelChoiceField
(
funder
=
forms
.
ModelChoiceField
(
queryset
=
Funder
.
objects
.
all
(),
queryset
=
Funder
.
objects
.
all
(),
widget
=
autocomplete
.
ModelSelect2
(
widget
=
HTMXDynSelWidget
(
url
=
"
/funders/funder-autocomplete
"
,
attrs
=
{
"
data-html
"
:
True
}
url
=
"
/funders/funder-autocomplete
"
,
attrs
=
{
"
data-html
"
:
True
}
),
),
)
)
...
@@ -56,9 +58,7 @@ class GrantForm(HttpRefererFormMixin, forms.ModelForm):
...
@@ -56,9 +58,7 @@ class GrantForm(HttpRefererFormMixin, forms.ModelForm):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
"
funder
"
]
=
forms
.
ModelChoiceField
(
self
.
fields
[
"
funder
"
]
=
forms
.
ModelChoiceField
(
queryset
=
Funder
.
objects
.
all
(),
queryset
=
Funder
.
objects
.
all
(),
widget
=
autocomplete
.
ModelSelect2
(
widget
=
HTMXDynSelWidget
(
url
=
"
/funders/funder-autocomplete
"
),
url
=
"
/funders/funder-autocomplete
"
,
attrs
=
{
"
data-html
"
:
True
}
),
)
)
self
.
fields
[
"
recipient
"
]
=
forms
.
ModelChoiceField
(
self
.
fields
[
"
recipient
"
]
=
forms
.
ModelChoiceField
(
queryset
=
Contributor
.
objects
.
select_related
(
"
user
"
).
order_by
(
queryset
=
Contributor
.
objects
.
select_related
(
"
user
"
).
order_by
(
...
@@ -71,7 +71,5 @@ class GrantForm(HttpRefererFormMixin, forms.ModelForm):
...
@@ -71,7 +71,5 @@ class GrantForm(HttpRefererFormMixin, forms.ModelForm):
class
GrantSelectForm
(
forms
.
Form
):
class
GrantSelectForm
(
forms
.
Form
):
grant
=
forms
.
ModelChoiceField
(
grant
=
forms
.
ModelChoiceField
(
queryset
=
Grant
.
objects
.
all
(),
queryset
=
Grant
.
objects
.
all
(),
widget
=
autocomplete
.
ModelSelect2
(
widget
=
HTMXDynSelWidget
(
url
=
"
/funders/grant-autocomplete
"
),
url
=
"
/funders/grant-autocomplete
"
,
attrs
=
{
"
data-html
"
:
True
}
),
)
)
This diff is collapsed.
Click to expand it.
scipost_django/funders/urls.py
+
2
−
2
View file @
2e305077
...
@@ -11,12 +11,12 @@ app_name = "funders"
...
@@ -11,12 +11,12 @@ app_name = "funders"
urlpatterns
=
[
urlpatterns
=
[
path
(
path
(
"
funder-autocomplete
"
,
"
funder-autocomplete
"
,
views
.
FunderAutocomplete
View
.
as_view
(),
views
.
HXDynsel
FunderAutocomplete
.
as_view
(),
name
=
"
funder-autocomplete
"
,
name
=
"
funder-autocomplete
"
,
),
),
path
(
path
(
"
grant-autocomplete
"
,
"
grant-autocomplete
"
,
views
.
GrantAutocomplete
View
.
as_view
(),
views
.
HXDynsel
GrantAutocomplete
.
as_view
(),
name
=
"
grant-autocomplete
"
,
name
=
"
grant-autocomplete
"
,
),
),
path
(
""
,
views
.
funders
,
name
=
"
funders
"
),
path
(
""
,
views
.
funders
,
name
=
"
funders
"
),
...
...
This diff is collapsed.
Click to expand it.
scipost_django/funders/views.py
+
27
−
56
View file @
2e305077
...
@@ -15,7 +15,7 @@ from django.utils.html import format_html
...
@@ -15,7 +15,7 @@ from django.utils.html import format_html
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.shortcuts
import
get_object_or_404
,
render
,
redirect
from
django.shortcuts
import
get_object_or_404
,
render
,
redirect
from
dal
import
a
utocomplete
from
common.views
import
HXDynselA
utocomplete
from
.models
import
Funder
,
Grant
from
.models
import
Funder
,
Grant
from
.forms
import
(
from
.forms
import
(
...
@@ -28,65 +28,36 @@ from .forms import (
...
@@ -28,65 +28,36 @@ from .forms import (
from
scipost.mixins
import
PermissionsMixin
from
scipost.mixins
import
PermissionsMixin
class
FunderAutocompleteView
(
autocomplete
.
Select2QuerySetView
):
class
HXDynselFunderAutocomplete
(
HXDynselAutocomplete
):
"""
model
=
Funder
View to feed the Select2 widget.
"""
def
search
(
self
,
queryset
,
q
):
return
queryset
.
filter
(
Q
(
name__unaccent__icontains
=
q
)
|
Q
(
acronym__unaccent__icontains
=
q
)
|
Q
(
identifier__icontains
=
q
)
|
Q
(
organization__name__unaccent__icontains
=
q
)
|
Q
(
organization__name_original__unaccent__icontains
=
q
)
|
Q
(
organization__acronym__unaccent__icontains
=
q
)
).
order_by
(
"
name
"
)
def
get_queryset
(
self
):
if
not
self
.
request
.
user
.
has_perm
(
"
scipost.can_draft_publication
"
):
return
None
qs
=
Funder
.
objects
.
all
()
if
self
.
q
:
qs
=
qs
.
filter
(
Q
(
name__unaccent__icontains
=
self
.
q
)
|
Q
(
acronym__unaccent__icontains
=
self
.
q
)
|
Q
(
identifier__icontains
=
self
.
q
)
|
Q
(
organization__name__unaccent__icontains
=
self
.
q
)
|
Q
(
organization__name_original__unaccent__icontains
=
self
.
q
)
|
Q
(
organization__acronym__unaccent__icontains
=
self
.
q
)
).
order_by
(
"
name
"
)
return
qs
def
get_result_label
(
self
,
item
):
if
item
.
organization
:
return
format_html
(
'
<span><i class=
"
{}
"
title=
"
{}
"
></i> {}</span>
'
,
item
.
organization
.
country
.
flag_css
,
item
.
organization
.
country
.
name
,
item
.
name
,
)
return
format_html
(
"
<span>{}</span>
"
,
item
.
name
)
class
GrantAutocompleteView
(
autocomplete
.
Select2QuerySetView
):
"""
View to feed the Select2 widget.
"""
def
get_queryset
(
self
):
class
HXDynselGrantAutocomplete
(
HXDynselAutocomplete
):
model
=
Grant
def
search
(
self
,
queryset
,
q
):
if
not
self
.
request
.
user
.
has_perm
(
"
scipost.can_draft_publication
"
):
if
not
self
.
request
.
user
.
has_perm
(
"
scipost.can_draft_publication
"
):
return
None
return
Grant
.
objects
.
none
()
qs
=
Grant
.
objects
.
all
()
else
:
if
self
.
q
:
return
queryset
.
filter
(
qs
=
qs
.
filter
(
Q
(
funder__name__unaccent__icontains
=
q
)
Q
(
funder__name__unaccent__icontains
=
self
.
q
)
|
Q
(
funder__acronym__icontains
=
q
)
|
Q
(
funder__acronym__icontains
=
self
.
q
)
|
Q
(
number__icontains
=
q
)
|
Q
(
number__icontains
=
self
.
q
)
|
Q
(
recipient_name__unaccent__icontains
=
q
)
|
Q
(
recipient_name__unaccent__icontains
=
self
.
q
)
|
Q
(
recipient__user__last_name__unaccent__icontains
=
q
)
|
Q
(
recipient__user__last_name__unaccent__icontains
=
self
.
q
)
|
Q
(
recipient__user__first_name__unaccent__icontains
=
q
)
|
Q
(
recipient__user__first_name__unaccent__icontains
=
self
.
q
)
|
Q
(
further_details__icontains
=
q
)
|
Q
(
further_details__icontains
=
self
.
q
)
).
order_by
(
"
funder__name
"
,
"
number
"
)
).
order_by
(
"
funder__name
"
,
"
number
"
)
return
qs
def
get_result_label
(
self
,
item
):
return
format_html
(
"
<span>Number: {}<br>Recipient: {}<br>From: {}
"
,
item
.
number
,
item
.
recipient
if
item
.
recipient
else
item
.
recipient_name
,
item
.
funder
,
)
@permission_required
(
"
scipost.can_view_all_funding_info
"
,
raise_exception
=
True
)
@permission_required
(
"
scipost.can_view_all_funding_info
"
,
raise_exception
=
True
)
...
...
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