Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
beat
beat.web
Commits
63266e10
Commit
63266e10
authored
4 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[attestations][management][commands] Pre-commit cleanup
parent
dfc4805e
No related branches found
No related tags found
2 merge requests
!346
Cleanup attestations
,
!342
Django 3 migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/attestations/management/commands/send_attestation_cleanup_warning.py
+47
-27
47 additions, 27 deletions
...s/management/commands/send_attestation_cleanup_warning.py
with
47 additions
and
27 deletions
beat/web/attestations/management/commands/send_attestation_cleanup_warning.py
+
47
−
27
View file @
63266e10
...
...
@@ -27,48 +27,68 @@
###############################################################################
from
django.core.management
import
call_command
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.mail
import
send_mail
from
django.template.loader
import
render_to_string
from
datetime
import
date
from
datetime
import
datetime
from
datetime
import
time
from
datetime
import
timedelta
from
django.conf
import
settings
from
django.contrib.sites.models
import
Site
from
django.core.mail
import
send_mail
from
django.core.management
import
call_command
from
django.core.management.base
import
BaseCommand
from
django.template.loader
import
render_to_string
from
datetime
import
datetime
,
time
,
date
,
timedelta
from
...models
import
Attestation
from
....
import
__version__
from
...models
import
Attestation
import
sys
class
Command
(
BaseCommand
):
help
=
'
Send email warning for attestations about to expire
'
help
=
"
Send email warning for attestations about to expire
"
def
handle
(
self
,
*
args
,
**
options
):
for
expiration_reminder
in
settings
.
EXPIRATION_REMINDERS
:
expiration_date
=
date
.
today
()
+
timedelta
(
days
=
expiration_reminder
)
attestations_about_to_expire
=
Attestation
.
objects
.
filter
(
locked
=
True
,
expiration_date__range
=
(
datetime
.
combine
(
expiration_date
,
time
.
min
),
datetime
.
combine
(
expiration_date
,
time
.
max
)))
attestations_about_to_expire
=
Attestation
.
objects
.
filter
(
locked
=
True
,
expiration_date__range
=
(
datetime
.
combine
(
expiration_date
,
time
.
min
),
datetime
.
combine
(
expiration_date
,
time
.
max
),
),
)
if
attestations_about_to_expire
:
current_site
=
Site
.
objects
.
get_current
()
template_path
=
'
attestations/attestation_about_to_expire_email.txt
'
template_path
=
"
attestations/attestation_about_to_expire_email.txt
"
for
attestation
in
attestations_about_to_expire
:
subject
=
"
Attestation for experiment %s is about to expire
"
%
\
attestation
.
experiment
.
fullname
()
subject
=
(
"
Attestation for experiment %s is about to expire
"
%
attestation
.
experiment
.
fullname
()
)
send_mail
(
subject
,
render_to_string
(
template_path
,
{
'
attestation
'
:
attestation
,
'
beat_version
'
:
__version__
,
'
site
'
:
current_site
,
}
),
settings
.
DEFAULT_FROM_EMAIL
,
[
attestation
.
experiment
.
author
.
email
])
self
.
stdout
.
write
(
'
{} attestation(s) about to expire
'
.
format
(
attestations_about_to_expire
.
count
()))
send_mail
(
subject
,
render_to_string
(
template_path
,
{
"
attestation
"
:
attestation
,
"
beat_version
"
:
__version__
,
"
site
"
:
current_site
,
},
),
settings
.
DEFAULT_FROM_EMAIL
,
[
attestation
.
experiment
.
author
.
email
],
)
self
.
stdout
.
write
(
"
{} attestation(s) about to expire
"
.
format
(
attestations_about_to_expire
.
count
()
)
)
else
:
self
.
stdout
.
write
(
'
No attestation(s) about to expire in {} day(s)
'
.
format
(
expiration_reminder
))
self
.
stdout
.
write
(
"
No attestation(s) about to expire in {} day(s)
"
.
format
(
expiration_reminder
)
)
call_command
(
'
clean_attestations
'
,
'
--noinput
'
)
call_command
(
"
clean_attestations
"
,
"
--noinput
"
)
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