Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nk20-scripts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
BDE
nk20-scripts
Commits
580948fe
Commit
580948fe
authored
4 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
➕
Add refresh highlighted buttons script
parent
f5967359
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
management/commands/refresh_highlighted_buttons.py
+27
-0
27 additions, 0 deletions
management/commands/refresh_highlighted_buttons.py
with
27 additions
and
0 deletions
management/commands/refresh_highlighted_buttons.py
0 → 100644
+
27
−
0
View file @
580948fe
#!/usr/bin/env python3
from
datetime
import
timedelta
from
django.core.management.base
import
BaseCommand
from
django.db.models
import
Count
from
django.utils
import
timezone
from
note.models
import
RecurrentTransaction
,
TransactionTemplate
class
Command
(
BaseCommand
):
"""
Command to add the ten most used buttons of the past month to the highlighted buttons.
"""
def
add_arguments
(
self
,
parser
):
return
parser
def
handle
(
self
,
*
args
,
**
kwargs
):
queryset
=
RecurrentTransaction
.
objects
.
filter
(
template__display
=
True
,
created_at__gte
=
timezone
.
now
()
-
timedelta
(
days
=
30
)).
values
(
"
template
"
).
annotate
(
transaction_count
=
Count
(
"
template
"
)).
order_by
(
"
-transaction_count
"
)[:
10
]
for
d
in
queryset
.
all
():
button_id
=
d
[
"
template
"
]
button
=
TransactionTemplate
.
objects
.
get
(
pk
=
button_id
)
self
.
stdout
.
write
(
self
.
style
.
WARNING
(
"
Highlight button {name} ({count:d} transactions)...
"
.
format
(
name
=
button
.
name
,
count
=
d
[
"
transaction_count
"
])))
button
.
highlighted
=
True
button
.
save
()
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