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
02ac9b4b
Unverified
Commit
02ac9b4b
authored
4 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Replace naive datetime with timezone aware.
- Add missing Serializer, - also clean-up unused imports.
parent
aa69e1c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/views.py
+20
-20
20 additions, 20 deletions
program/views.py
with
20 additions
and
20 deletions
program/views.py
+
20
−
20
View file @
02ac9b4b
# -*- coding: utf-8 -*-
import
json
import
json
from
datetime
import
date
,
datetime
,
time
,
timedelta
from
datetime
import
date
,
datetime
,
time
,
timedelta
from
django.db.models
import
Q
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.http
import
Http404
,
HttpResponse
,
JsonResponse
from
django.db.models
import
Q
from
django.http
import
HttpResponse
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.generic.base
import
TemplateView
from
django.views.generic.base
import
TemplateView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
django.views.generic.list
import
ListView
from
django.forms.models
import
model_to_dict
from
rest_framework
import
permissions
,
status
,
viewsets
from
rest_framework
import
permissions
,
serializers
,
status
,
viewsets
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.pagination
import
LimitOffsetPagination
from
rest_framework.pagination
import
LimitOffsetPagination
from
rest_framework.response
import
Response
from
program.models
import
Type
,
MusicFocus
,
Language
,
Note
,
Show
,
Category
,
FundingCategory
,
Topic
,
TimeSlot
,
Host
,
Schedule
,
RRule
from
program.models
import
Type
,
MusicFocus
,
Language
,
Note
,
Show
,
Category
,
FundingCategory
,
Topic
,
TimeSlot
,
Host
,
Schedule
from
program.serializers
import
TypeSerializer
,
LanguageSerializer
,
MusicFocusSerializer
,
NoteSerializer
,
ShowSerializer
,
ScheduleSerializer
,
CategorySerializer
,
FundingCategorySerializer
,
TopicSerializer
,
TimeSlotSerializer
,
HostSerializer
,
UserSerializer
from
program.serializers
import
TypeSerializer
,
LanguageSerializer
,
MusicFocusSerializer
,
NoteSerializer
,
ShowSerializer
,
\
ScheduleSerializer
,
CategorySerializer
,
FundingCategorySerializer
,
TopicSerializer
,
TimeSlotSerializer
,
HostSerializer
,
\
UserSerializer
from
program.utils
import
tofirstdayinisoweek
,
get_cached_shows
from
program.utils
import
tofirstdayinisoweek
,
get_cached_shows
# Deprecated
# Deprecated
class
CalendarView
(
TemplateView
):
class
CalendarView
(
TemplateView
):
template_name
=
'
calendar.html
'
template_name
=
'
calendar.html
'
...
@@ -30,7 +29,7 @@ class CalendarView(TemplateView):
...
@@ -30,7 +29,7 @@ class CalendarView(TemplateView):
# Deprecated
# Deprecated
class
HostListView
(
ListView
):
class
HostListView
(
ListView
):
context_object_name
=
'
host_list
'
context_object_name
=
'
host_list
'
queryset
=
Host
.
objects
.
filter
(
Q
(
is_active
=
True
)
|
Q
(
shows__schedules__until__gt
=
datetim
e
.
now
())).
distinct
()
queryset
=
Host
.
objects
.
filter
(
Q
(
is_active
=
True
)
|
Q
(
shows__schedules__until__gt
=
timezon
e
.
now
())).
distinct
()
template_name
=
'
host_list.html
'
template_name
=
'
host_list.html
'
...
@@ -85,7 +84,7 @@ class RecommendationsListView(ListView):
...
@@ -85,7 +84,7 @@ class RecommendationsListView(ListView):
context_object_name
=
'
recommendation_list
'
context_object_name
=
'
recommendation_list
'
template_name
=
'
recommendation_list.html
'
template_name
=
'
recommendation_list.html
'
now
=
datetim
e
.
now
()
now
=
timezon
e
.
now
()
end
=
now
+
timedelta
(
weeks
=
1
)
end
=
now
+
timedelta
(
weeks
=
1
)
queryset
=
TimeSlot
.
objects
.
filter
(
Q
(
note__isnull
=
False
,
note__status
=
1
,
queryset
=
TimeSlot
.
objects
.
filter
(
Q
(
note__isnull
=
False
,
note__status
=
1
,
...
@@ -167,7 +166,7 @@ class WeekScheduleView(TemplateView):
...
@@ -167,7 +166,7 @@ class WeekScheduleView(TemplateView):
week
=
self
.
kwargs
.
get
(
'
week
'
,
None
)
week
=
self
.
kwargs
.
get
(
'
week
'
,
None
)
if
year
is
None
and
week
is
None
:
if
year
is
None
and
week
is
None
:
year
,
week
=
datetim
e
.
now
().
strftime
(
'
%G__%V
'
).
split
(
'
__
'
)
year
,
week
=
timezon
e
.
now
().
strftime
(
'
%G__%V
'
).
split
(
'
__
'
)
monday
=
tofirstdayinisoweek
(
int
(
year
),
int
(
week
))
monday
=
tofirstdayinisoweek
(
int
(
year
),
int
(
week
))
tuesday
=
monday
+
timedelta
(
days
=
1
)
tuesday
=
monday
+
timedelta
(
days
=
1
)
...
@@ -335,7 +334,7 @@ def json_timeslots_specials(request):
...
@@ -335,7 +334,7 @@ def json_timeslots_specials(request):
if
show
[
'
type
'
]
==
'
s
'
:
if
show
[
'
type
'
]
==
'
s
'
:
specials
[
show
[
'
id
'
]]
=
show
specials
[
show
[
'
id
'
]]
=
show
for
ts
in
TimeSlot
.
objects
.
filter
(
end__gt
=
datetim
e
.
now
(),
for
ts
in
TimeSlot
.
objects
.
filter
(
end__gt
=
timezon
e
.
now
(),
schedule__automation_id__in
=
specials
.
iterkeys
()).
select_related
(
'
show
'
):
schedule__automation_id__in
=
specials
.
iterkeys
()).
select_related
(
'
show
'
):
automation_id
=
ts
.
schedule
.
automation_id
automation_id
=
ts
.
schedule
.
automation_id
start
=
ts
.
start
.
strftime
(
'
%Y-%m-%d_%H:%M:%S
'
)
start
=
ts
.
start
.
strftime
(
'
%Y-%m-%d_%H:%M:%S
'
)
...
@@ -418,6 +417,7 @@ class APIUserViewSet(viewsets.ModelViewSet):
...
@@ -418,6 +417,7 @@ class APIUserViewSet(viewsets.ModelViewSet):
def
update
(
self
,
request
,
pk
=
None
):
def
update
(
self
,
request
,
pk
=
None
):
serializer
=
UserSerializer
(
data
=
request
.
data
)
# Common users may only edit themselves
# Common users may only edit themselves
if
not
request
.
user
.
is_superuser
and
int
(
pk
)
!=
request
.
user
.
id
:
if
not
request
.
user
.
is_superuser
and
int
(
pk
)
!=
request
.
user
.
id
:
return
Response
(
serializer
.
initial_data
,
status
=
status
.
HTTP_401_UNAUTHORIZED
)
return
Response
(
serializer
.
initial_data
,
status
=
status
.
HTTP_401_UNAUTHORIZED
)
...
@@ -730,8 +730,8 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
...
@@ -730,8 +730,8 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
end
=
start
+
timedelta
(
days
=
60
)
end
=
start
+
timedelta
(
days
=
60
)
if
self
.
request
.
GET
.
get
(
'
start
'
)
and
self
.
request
.
GET
.
get
(
'
end
'
):
if
self
.
request
.
GET
.
get
(
'
start
'
)
and
self
.
request
.
GET
.
get
(
'
end
'
):
start
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
GET
.
get
(
'
start
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
0
,
0
))
start
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
GET
.
get
(
'
start
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
0
,
0
))
end
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
GET
.
get
(
'
end
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
23
,
59
))
end
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
GET
.
get
(
'
end
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
23
,
59
))
'''
Endpoints
'''
'''
Endpoints
'''
...
@@ -776,7 +776,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
...
@@ -776,7 +776,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
Timeslots may only be created by adding/updating schedules
Timeslots may only be created by adding/updating schedules
TODO: Adding single timeslot which fits to schedule?
TODO: Adding single timeslot which fits to schedule?
"""
"""
return
Response
(
status
=
HTTP_401_UNAUTHORIZED
)
return
Response
(
status
=
status
.
HTTP_401_UNAUTHORIZED
)
def
update
(
self
,
request
,
pk
=
None
,
schedule_pk
=
None
,
show_pk
=
None
):
def
update
(
self
,
request
,
pk
=
None
,
schedule_pk
=
None
,
show_pk
=
None
):
...
@@ -1178,4 +1178,4 @@ class APIHostViewSet(viewsets.ModelViewSet):
...
@@ -1178,4 +1178,4 @@ class APIHostViewSet(viewsets.ModelViewSet):
if
self
.
request
.
GET
.
get
(
'
active
'
)
==
'
false
'
:
if
self
.
request
.
GET
.
get
(
'
active
'
)
==
'
false
'
:
return
Host
.
objects
.
filter
(
is_active
=
False
)
return
Host
.
objects
.
filter
(
is_active
=
False
)
return
Host
.
objects
.
all
()
return
Host
.
objects
.
all
()
\ No newline at end of file
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