Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open
Commits
118b97b4
Verified
Commit
118b97b4
authored
Oct 13, 2017
by
David Haynes
🙆
Browse files
List compss
- I figured out how to use list comps - let's clean some of these for loops
parent
1adaebb6
Pipeline
#1670
passed with stage
in 1 minute and 35 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
whats-open/api/views.py
View file @
118b97b4
...
...
@@ -124,11 +124,12 @@ class AlertViewSet(viewsets.ReadOnlyModelViewSet):
return
Alert
.
objects
.
all
()
# Default behavior
else
:
alertable
=
[]
# Enumerate all Alert objects that are active
for
alert
in
Alert
.
objects
.
all
():
if
alert
.
is_active
():
alertable
.
append
(
alert
.
pk
)
alertable
=
[
alert
.
pk
for
alert
in
Alert
.
objects
.
all
()
if
alert
.
is_active
()
]
# Return active Alerts
return
Alert
.
objects
.
filter
(
pk__in
=
alertable
)
...
...
@@ -403,11 +404,11 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
closed_now
=
self
.
request
.
query_params
.
get
(
'closed_now'
,
None
)
if
open_now
is
not
None
or
closed_now
is
not
None
:
# List of all open facilities
open_facilities
=
[
]
for
facility
in
Facility
.
objects
.
all
():
i
f
facility
.
is_open
()
:
# Append the primary key
open_facilities
.
append
(
facility
.
pk
)
open_facilities
=
[
facility
.
pk
f
or
facility
in
Facility
.
objects
.
all
()
if
facility
.
is_open
()
]
# Return all Facility objects with the primary keys located in the
# open_facilities list
if
open_now
:
...
...
@@ -503,13 +504,13 @@ class ScheduleViewSet(viewsets.ModelViewSet):
the API.
"""
# List of all schedules that are outdated
filter_old_schedules
=
[
]
for
schedule
in
Schedule
.
objects
.
all
():
i
f
schedule
.
valid_end
and
schedule
.
valid_start
:
# If the schedule ended before today
if
schedule
.
valid_end
<
datetime
.
date
.
today
():
# Add it to the list of objects we are excluding
filter_old_schedules
.
append
(
schedule
.
pk
)
filter_old_schedules
=
[
schedule
.
pk
f
or
schedule
in
Schedule
.
objects
.
all
()
# If the schedule ended before today
if
schedule
.
valid_end
and
schedule
.
valid_start
if
schedule
.
valid_end
<
datetime
.
date
.
today
()
]
# Return all Schedule objects that have not expired
return
Schedule
.
objects
.
exclude
(
pk__in
=
filter_old_schedules
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment