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
e930186b
Commit
e930186b
authored
6 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Improve team timesheets page format
parent
b3ab3a95
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
+32
-19
32 additions, 19 deletions
finances/forms.py
finances/templates/finances/timesheets.html
+6
-6
6 additions, 6 deletions
finances/templates/finances/timesheets.html
finances/views.py
+3
-3
3 additions, 3 deletions
finances/views.py
with
41 additions
and
28 deletions
finances/forms.py
+
32
−
19
View file @
e930186b
...
...
@@ -45,8 +45,15 @@ class WorkLogForm(forms.ModelForm):
}
class
LogsMonthlyActiveFilter
(
forms
.
Form
):
month
=
forms
.
ChoiceField
(
choices
=
[(
k
,
v
)
for
k
,
v
in
MONTHS
.
items
()])
class
LogsActiveFilter
(
forms
.
Form
):
"""
Filter work logs given the requested date range and users.
"""
employee
=
forms
.
ModelChoiceField
(
queryset
=
get_user_model
().
objects
.
filter
(
work_logs__isnull
=
False
),
required
=
False
)
month
=
forms
.
ChoiceField
(
choices
=
[(
None
,
9
*
'
-
'
)]
+
[(
k
,
v
)
for
k
,
v
in
MONTHS
.
items
()],
required
=
False
)
year
=
forms
.
ChoiceField
(
choices
=
[(
y
,
y
)
for
y
in
reversed
(
range
(
today
.
year
-
6
,
today
.
year
+
1
))])
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -63,22 +70,28 @@ class LogsMonthlyActiveFilter(forms.Form):
}
super
().
__init__
(
*
args
,
**
kwargs
)
def
get_totals
(
self
):
# Make accessible without need to explicitly check validity of form.
self
.
is_valid
()
users
=
get_user_model
().
objects
.
filter
(
work_logs__work_date__month
=
self
.
cleaned_data
[
'
month
'
],
work_logs__work_date__year
=
self
.
cleaned_data
[
'
year
'
]).
distinct
()
def
filter
(
self
):
"""
Filter work logs and return in output-convenient format.
"""
output
=
[]
for
user
in
users
:
logs
=
user
.
work_logs
.
filter
(
work_date__month
=
self
.
cleaned_data
[
'
month
'
],
work_date__year
=
self
.
cleaned_data
[
'
year
'
])
output
.
append
({
'
logs
'
:
logs
,
'
duration
'
:
logs
.
aggregate
(
total
=
Sum
(
'
duration
'
)),
'
user
'
:
user
})
if
self
.
is_valid
():
user_qs
=
get_user_model
().
objects
.
filter
(
work_logs__isnull
=
False
)
if
self
.
cleaned_data
[
'
employee
'
]:
# Get as a queryset instead of single instead.
user_qs
=
user_qs
.
filter
(
id
=
self
.
cleaned_data
[
'
employee
'
].
id
)
user_qs
=
user_qs
.
distinct
()
output
=
[]
for
user
in
user_qs
:
logs
=
user
.
work_logs
.
filter
(
work_date__year
=
self
.
cleaned_data
[
'
year
'
])
if
self
.
cleaned_data
[
'
month
'
]:
logs
=
logs
.
filter
(
work_date__month
=
self
.
cleaned_data
[
'
month
'
])
logs
=
logs
.
distinct
()
if
logs
:
# If logs exists for given filters
output
.
append
({
'
logs
'
:
logs
,
'
duration
'
:
logs
.
aggregate
(
total
=
Sum
(
'
duration
'
)),
'
user
'
:
user
,
})
return
output
This diff is collapsed.
Click to expand it.
finances/templates/finances/timesheets.html
+
6
−
6
View file @
e930186b
...
...
@@ -25,8 +25,8 @@
<div
class=
"row"
>
<div
class=
"col-12"
>
<h2
class=
"mb-2 mt-4"
>
Team Timesheets
</h2>
{% for
total in total
s %}
<h
3
class=
"mb-1"
>
{{
total
.user.first_name }} {{
total
.user.last_name }}
</h
3
>
{% for
user_log in user_log
s %}
<h
4
class=
"mb-1"
>
{{
user_log
.user.first_name }} {{
user_log
.user.last_name }}
</h
4
>
<table
class=
"table"
>
<thead
class=
"thead-default"
>
<tr>
...
...
@@ -38,7 +38,7 @@
</tr>
</thead>
<tbody>
{% for log in
total
.logs %}
{% for log in
user_log
.logs %}
<tr>
<td>
{{ log.work_date }}
</td>
<td>
{{ log.content }}
</td>
...
...
@@ -48,13 +48,13 @@
</tr>
{% endfor %}
<tr>
<td
colspan=
"4"
>
</td>
<td><strong>
{{
total
.duration.total }}
</strong></td>
<td
colspan=
"4"
class=
"text-right"
>
Total:
</td>
<td><strong>
{{
user_log
.duration.total
|duration
}}
</strong></td>
</tr>
</tbody>
</table>
{% empty %}
<
h3>
Timesheet is empty for this month
.
</
h3
>
<
p>
No logs found
.
</
p
>
{% endfor %}
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
finances/views.py
+
3
−
3
View file @
e930186b
...
...
@@ -12,7 +12,7 @@ from django.views.generic.detail import DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
,
DeleteView
from
django.views.generic.list
import
ListView
from
.forms
import
SubsidyForm
,
Logs
Monthly
ActiveFilter
from
.forms
import
SubsidyForm
,
LogsActiveFilter
from
.models
import
Subsidy
,
WorkLog
from
.utils
import
slug_to_id
...
...
@@ -87,13 +87,13 @@ def timesheets(request):
"""
See an overview per month of all timesheets.
"""
form
=
Logs
Monthly
ActiveFilter
(
request
.
GET
or
None
)
form
=
LogsActiveFilter
(
request
.
GET
or
None
)
context
=
{
'
form
'
:
form
,
}
# if form.is_valid():
context
[
'
total
s
'
]
=
form
.
get_totals
()
context
[
'
user_log
s
'
]
=
form
.
filter
()
return
render
(
request
,
'
finances/timesheets.html
'
,
context
)
...
...
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