Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
AURA
steering
Commits
914d2d67
Unverified
Commit
914d2d67
authored
4 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Replace naive datetime with timezone aware.
Also clean-up unused imports.
parent
9a83db63
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/admin.py
+18
-19
18 additions, 19 deletions
program/admin.py
with
18 additions
and
19 deletions
program/admin.py
+
18
−
19
View file @
914d2d67
# -*- coding: utf-8 -*-
from
datetime
import
date
,
datetime
,
timedelta
from
django.co
re.exceptions
import
ObjectDoesNotExist
from
django.co
nf
import
settings
from
django.contrib
import
admin
from
django.
utils.transla
tion
import
ugettext_lazy
as
_
from
django.
core.excep
tion
s
import
ObjectDoesNotExist
from
django.shortcuts
import
render
from
django.conf
import
settings
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
.models
import
Language
,
Type
,
MusicFocus
,
Category
,
Topic
,
FundingCategory
,
Host
,
Note
,
RRule
,
Schedule
,
Show
,
TimeSlot
from
.forms
import
MusicFocusForm
from
datetime
import
date
,
datetime
,
time
,
timedelta
from
.models
import
Language
,
Type
,
MusicFocus
,
Category
,
Topic
,
FundingCategory
,
Host
,
Note
,
RRule
,
Schedule
,
Show
,
TimeSlot
class
ActivityFilter
(
admin
.
SimpleListFilter
):
...
...
@@ -24,21 +23,21 @@ class ActivityFilter(admin.SimpleListFilter):
def
queryset
(
self
,
request
,
queryset
):
if
self
.
parameter_name
==
'
has_timeslots
'
:
# active/inactive Schedules
if
self
.
value
()
==
'
yes
'
:
return
queryset
.
filter
(
until__gt
=
datetim
e
.
now
()).
distinct
()
return
queryset
.
filter
(
until__gt
=
timezon
e
.
now
()).
distinct
()
if
self
.
value
()
==
'
no
'
:
return
queryset
.
filter
(
until__lt
=
datetim
e
.
now
()).
distinct
()
return
queryset
.
filter
(
until__lt
=
timezon
e
.
now
()).
distinct
()
if
self
.
parameter_name
==
'
has_schedules_timeslots
'
:
# active/inactive Shows
if
self
.
value
()
==
'
yes
'
:
return
queryset
.
filter
(
schedules__until__gt
=
datetim
e
.
now
()).
distinct
()
return
queryset
.
filter
(
schedules__until__gt
=
timezon
e
.
now
()).
distinct
()
if
self
.
value
()
==
'
no
'
:
return
queryset
.
filter
(
schedules__until__lt
=
datetim
e
.
now
()).
distinct
()
return
queryset
.
filter
(
schedules__until__lt
=
timezon
e
.
now
()).
distinct
()
if
self
.
parameter_name
==
'
has_shows_schedules_timeslots
'
:
# active/inactive Hosts
if
self
.
value
()
==
'
yes
'
:
return
queryset
.
filter
(
shows__schedules__until__gt
=
datetim
e
.
now
()).
distinct
()
return
queryset
.
filter
(
shows__schedules__until__gt
=
timezon
e
.
now
()).
distinct
()
if
self
.
value
()
==
'
no
'
:
return
queryset
.
filter
(
shows__schedules__until__lt
=
datetim
e
.
now
()).
distinct
()
return
queryset
.
filter
(
shows__schedules__until__lt
=
timezon
e
.
now
()).
distinct
()
class
ActiveSchedulesFilter
(
ActivityFilter
):
...
...
@@ -126,8 +125,8 @@ class NoteAdmin(admin.ModelAdmin):
def
formfield_for_foreignkey
(
self
,
db_field
,
request
=
None
,
**
kwargs
):
four_weeks_ago
=
datetim
e
.
now
()
-
timedelta
(
weeks
=
4
)
in_twelve_weeks
=
datetim
e
.
now
()
+
timedelta
(
weeks
=
12
)
four_weeks_ago
=
timezon
e
.
now
()
-
timedelta
(
weeks
=
4
)
in_twelve_weeks
=
timezon
e
.
now
()
+
timedelta
(
weeks
=
12
)
if
db_field
.
name
==
'
timeslot
'
:
# Adding/Editing a note: load timeslots of the user's shows into the dropdown
...
...
@@ -399,8 +398,8 @@ class ShowAdmin(admin.ModelAdmin):
tstart
=
datetime
.
strptime
(
request
.
POST
.
get
(
'
ps_save_tstart
'
),
'
%H:%M
'
).
time
()
tend
=
datetime
.
strptime
(
request
.
POST
.
get
(
'
ps_save_tend
'
),
'
%H:%M
'
).
time
()
dstart
=
datetime
.
strptime
(
request
.
POST
.
get
(
'
ps_save_dstart
'
),
'
%Y-%m-%d
'
).
date
()
if
dstart
<
datetime
.
today
().
date
():
# Create or delete upcoming timeslots only
dstart
=
datetime
.
today
().
date
()
if
dstart
<
timezone
.
now
().
date
():
# Create or delete upcoming timeslots only
dstart
=
timezone
.
now
().
date
()
until
=
datetime
.
strptime
(
request
.
POST
.
get
(
'
ps_save_until
'
),
'
%Y-%m-%d
'
).
date
()
is_repetition
=
request
.
POST
.
get
(
'
ps_save_is_repetition
'
)
automation_id
=
int
(
request
.
POST
.
get
(
'
ps_save_automation_id
'
))
if
request
.
POST
.
get
(
'
ps_save_automation_id
'
)
!=
'
None
'
else
0
...
...
@@ -486,7 +485,7 @@ class ShowAdmin(admin.ModelAdmin):
if
ts
!=
None
:
start_end
=
ts
.
split
(
'
-
'
)
# Only create upcoming timeslots
if
datetime
.
strptime
(
start_end
[
0
],
"
%Y-%m-%d %H:%M:%S
"
)
>
datetime
.
today
():
if
datetime
.
strptime
(
start_end
[
0
],
"
%Y-%m-%d %H:%M:%S
"
)
>
timezone
.
now
():
timeslot_created
=
TimeSlot
.
objects
.
create
(
schedule
=
new_schedule
,
is_repetition
=
new_schedule
.
is_repetition
,
start
=
start_end
[
0
],
end
=
start_end
[
1
])
# Link a note to the new timeslot
...
...
@@ -584,7 +583,7 @@ class ShowAdmin(admin.ModelAdmin):
'
num_inputs
'
:
len
(
self
.
timeslots
),
'
step
'
:
self
.
step
,
'
max_steps
'
:
self
.
max_steps
,
'
now
'
:
datetim
e
.
now
(),
'
now
'
:
timezon
e
.
now
(),
'
num_collisions
'
:
self
.
num_collisions
})
...
...
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