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
a45c9ade
Commit
a45c9ade
authored
6 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Improve form field formatting
parent
e930186b
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
finances/forms.py
+5
-2
5 additions, 2 deletions
finances/forms.py
production/forms.py
+2
-5
2 additions, 5 deletions
production/forms.py
scipost/fields.py
+5
-0
5 additions, 0 deletions
scipost/fields.py
with
12 additions
and
7 deletions
finances/forms.py
+
5
−
2
View file @
a45c9ade
...
@@ -10,6 +10,8 @@ from django.utils import timezone
...
@@ -10,6 +10,8 @@ from django.utils import timezone
from
ajax_select.fields
import
AutoCompleteSelectField
from
ajax_select.fields
import
AutoCompleteSelectField
from
scipost.fields
import
UserModelChoiceField
from
.models
import
Subsidy
,
WorkLog
from
.models
import
Subsidy
,
WorkLog
today
=
timezone
.
now
().
date
()
today
=
timezone
.
now
().
date
()
...
@@ -50,7 +52,7 @@ class LogsActiveFilter(forms.Form):
...
@@ -50,7 +52,7 @@ class LogsActiveFilter(forms.Form):
Filter work logs given the requested date range and users.
Filter work logs given the requested date range and users.
"""
"""
employee
=
forms
.
ModelChoiceField
(
employee
=
User
ModelChoiceField
(
queryset
=
get_user_model
().
objects
.
filter
(
work_logs__isnull
=
False
),
required
=
False
)
queryset
=
get_user_model
().
objects
.
filter
(
work_logs__isnull
=
False
),
required
=
False
)
month
=
forms
.
ChoiceField
(
month
=
forms
.
ChoiceField
(
choices
=
[(
None
,
9
*
'
-
'
)]
+
[(
k
,
v
)
for
k
,
v
in
MONTHS
.
items
()],
required
=
False
)
choices
=
[(
None
,
9
*
'
-
'
)]
+
[(
k
,
v
)
for
k
,
v
in
MONTHS
.
items
()],
required
=
False
)
...
@@ -74,7 +76,8 @@ class LogsActiveFilter(forms.Form):
...
@@ -74,7 +76,8 @@ class LogsActiveFilter(forms.Form):
"""
Filter work logs and return in output-convenient format.
"""
"""
Filter work logs and return in output-convenient format.
"""
output
=
[]
output
=
[]
if
self
.
is_valid
():
if
self
.
is_valid
():
user_qs
=
get_user_model
().
objects
.
filter
(
work_logs__isnull
=
False
)
user_qs
=
get_user_model
().
objects
.
filter
(
work_logs__isnull
=
False
,
work_logs__work_date__year
=
self
.
cleaned_data
[
'
year
'
])
if
self
.
cleaned_data
[
'
employee
'
]:
if
self
.
cleaned_data
[
'
employee
'
]:
# Get as a queryset instead of single instead.
# Get as a queryset instead of single instead.
user_qs
=
user_qs
.
filter
(
id
=
self
.
cleaned_data
[
'
employee
'
].
id
)
user_qs
=
user_qs
.
filter
(
id
=
self
.
cleaned_data
[
'
employee
'
].
id
)
...
...
This diff is collapsed.
Click to expand it.
production/forms.py
+
2
−
5
View file @
a45c9ade
...
@@ -7,6 +7,8 @@ import datetime
...
@@ -7,6 +7,8 @@ import datetime
from
django
import
forms
from
django
import
forms
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
from
scipost.fields
import
UserModelChoiceField
from
.
import
constants
from
.
import
constants
from
.models
import
ProductionUser
,
ProductionStream
,
ProductionEvent
,
Proofs
,
\
from
.models
import
ProductionUser
,
ProductionStream
,
ProductionEvent
,
Proofs
,
\
ProductionEventAttachment
ProductionEventAttachment
...
@@ -127,11 +129,6 @@ class StreamStatusForm(forms.ModelForm):
...
@@ -127,11 +129,6 @@ class StreamStatusForm(forms.ModelForm):
return
stream
return
stream
class
UserModelChoiceField
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
return
'
{}, {} ({})
'
.
format
(
obj
.
last_name
,
obj
.
first_name
,
obj
.
email
)
class
UserToOfficerForm
(
forms
.
ModelForm
):
class
UserToOfficerForm
(
forms
.
ModelForm
):
user
=
UserModelChoiceField
(
queryset
=
get_user_model
().
objects
.
filter
(
user
=
UserModelChoiceField
(
queryset
=
get_user_model
().
objects
.
filter
(
production_user__isnull
=
True
).
order_by
(
'
last_name
'
))
production_user__isnull
=
True
).
order_by
(
'
last_name
'
))
...
...
This diff is collapsed.
Click to expand it.
scipost/fields.py
+
5
−
0
View file @
a45c9ade
...
@@ -87,3 +87,8 @@ class ReCaptchaField(forms.CharField):
...
@@ -87,3 +87,8 @@ class ReCaptchaField(forms.CharField):
self
.
error_messages
[
'
captcha_invalid
'
]
self
.
error_messages
[
'
captcha_invalid
'
]
)
)
return
values
[
0
]
return
values
[
0
]
class
UserModelChoiceField
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
return
'
{}, {} ({})
'
.
format
(
obj
.
last_name
,
obj
.
first_name
,
obj
.
email
)
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