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
b0c2267b
Commit
b0c2267b
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
add autocomplete for subsidies and renewal field
fix
#189
parent
a68d4b1b
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
+16
-5
16 additions, 5 deletions
scipost_django/finances/forms.py
scipost_django/finances/urls.py
+5
-0
5 additions, 0 deletions
scipost_django/finances/urls.py
scipost_django/finances/views.py
+26
-1
26 additions, 1 deletion
scipost_django/finances/views.py
with
47 additions
and
6 deletions
scipost_django/finances/forms.py
+
16
−
5
View file @
b0c2267b
...
...
@@ -6,6 +6,7 @@ import re
from
django
import
forms
from
django.contrib.auth
import
get_user_model
from
django.urls
import
reverse_lazy
from
django.utils.dates
import
MONTHS
from
django.db.models
import
Q
,
Case
,
DateField
,
Max
,
Min
,
Sum
,
Value
,
When
,
F
from
django.utils
import
timezone
...
...
@@ -36,6 +37,14 @@ class SubsidyForm(forms.ModelForm):
),
)
renewal_of
=
forms
.
ModelChoiceField
(
queryset
=
Subsidy
.
objects
.
all
(),
widget
=
autocomplete
.
ModelSelect2
(
url
=
reverse_lazy
(
"
finances:subsidy_autocomplete
"
)
),
help_text
=
(
"
Start typing, and select from the popup.
"
),
)
class
Meta
:
model
=
Subsidy
fields
=
[
...
...
@@ -453,11 +462,13 @@ class LogsFilterForm(forms.Form):
if
self
.
cleaned_data
[
"
hourly_rate
"
]:
salary_per_month
=
[
duration
.
total_seconds
()
/
3600
# Convert to hours
*
self
.
cleaned_data
[
"
hourly_rate
"
]
if
duration
is
not
None
else
0
(
duration
.
total_seconds
()
/
3600
# Convert to hours
*
self
.
cleaned_data
[
"
hourly_rate
"
]
if
duration
is
not
None
else
0
)
for
duration
in
total_time_per_month
]
else
:
...
...
This diff is collapsed.
Click to expand it.
scipost_django/finances/urls.py
+
5
−
0
View file @
b0c2267b
...
...
@@ -101,6 +101,11 @@ urlpatterns = [
views
.
SubsidyDeleteView
.
as_view
(),
name
=
"
subsidy_delete
"
,
),
path
(
"
subsidies/autocomplete/
"
,
views
.
SubsidyAutocompleteView
.
as_view
(),
name
=
"
subsidy_autocomplete
"
,
),
path
(
"
subsidies/<int:pk>/
"
,
views
.
SubsidyDetailView
.
as_view
(),
name
=
"
subsidy_details
"
),
...
...
This diff is collapsed.
Click to expand it.
scipost_django/finances/views.py
+
26
−
1
View file @
b0c2267b
...
...
@@ -4,8 +4,9 @@ __license__ = "AGPL v3"
import
datetime
from
itertools
import
accumulate
import
mimetypes
from
dal
import
autocomplete
from
django.db.models
import
Q
import
matplotlib
matplotlib
.
use
(
"
Agg
"
)
...
...
@@ -290,6 +291,30 @@ class SubsidyDeleteView(PermissionsMixin, DeleteView):
success_url
=
reverse_lazy
(
"
finances:subsidies
"
)
class
SubsidyAutocompleteView
(
autocomplete
.
Select2QuerySetView
):
"""
Autocomplete for Subsidy, meant to be used with Select2.
Will only show subsidies whose amounts are publicly visible
for users without the
'
can_manage_subsidies
'
permission.
"""
def
get_queryset
(
self
):
qs
=
Subsidy
.
objects
.
all
()
if
not
self
.
request
.
user
.
has_perm
(
"
scipost.can_manage_subsidies
"
):
qs
=
qs
.
filter
(
amount_publicly_shown
=
True
)
if
self
.
q
:
qs
=
qs
.
filter
(
Q
(
organization__name__unaccent__icontains
=
self
.
q
)
|
Q
(
organization__name_original__unaccent__icontains
=
self
.
q
)
|
Q
(
organization__acronym__unaccent__icontains
=
self
.
q
)
|
Q
(
amount__icontains
=
self
.
q
)
|
Q
(
description__icontains
=
self
.
q
)
|
Q
(
date_from__year__icontains
=
self
.
q
)
|
Q
(
date_until__year__icontains
=
self
.
q
)
)
return
qs
class
SubsidyListView
(
ListView
):
model
=
Subsidy
template_name
=
"
finances/subsidy_list_old.html
"
...
...
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