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
ca24a30e
Commit
ca24a30e
authored
13 years ago
by
Johannes Raggam
Browse files
Options
Downloads
Patches
Plain Diff
finalize form with date/time submission functionality
parent
40c628c4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nop/templates/nop/nop_form.html
+20
-5
20 additions, 5 deletions
nop/templates/nop/nop_form.html
nop/views.py
+54
-18
54 additions, 18 deletions
nop/views.py
with
74 additions
and
23 deletions
nop/templates/nop/nop_form.html
+
20
−
5
View file @
ca24a30e
...
...
@@ -10,11 +10,11 @@
<script
type=
"text/javascript"
>
<!--
$
(
document
).
ready
(
function
()
{
$
(
"
:
date
"
).
dateinput
({
$
(
"
#nop_
date
"
).
dateinput
({
format
:
'
yyyy-mm-dd
'
,
firstDay
:
1
});
$
(
"
#time
"
).
AnyTime_picker
({
$
(
"
#
nop_
time
"
).
AnyTime_picker
({
format
:
"
%H:%i
"
,
labelTitle
:
"
Zeit
"
,
labelHour
:
"
Stunde
"
,
...
...
@@ -27,10 +27,25 @@
<body>
<div
id=
"content-main"
class=
"show-detail"
>
<input
type=
"date"
id=
"date"
class=
"date"
value=
""
/>
<input
type=
"text"
id=
"time"
class=
"date"
value=
""
/>
<form
action=
""
method=
"post"
>
{% csrf_token %}
{{ form.as_table }}
<input
type=
"submit"
value=
"senden"
/>
</form>
{% if nowplaying %}
<ul>
{% for track in nowplaying %}
<li>
<small>
{{track.datetime}}:
</small>
<strong>
{{track.artist}}
</strong>
-
{{track.title}} -
{{track.album}}
in der Sendung
<em>
{{track.showtitle}}
</em>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</body>
</html>
This diff is collapsed.
Click to expand it.
nop/views.py
+
54
−
18
View file @
ca24a30e
from
django.views.generic
import
simple
from
django.core.context_processors
import
csrf
from
django.shortcuts
import
render_to_response
from
django.http
import
HttpResponse
from
django
import
forms
from
models
import
Master
import
json
import
time
from
datetime
import
datetime
class
NopForm
(
forms
.
Form
):
date
=
forms
.
DateField
(
required
=
True
,
initial
=
datetime
.
date
(
datetime
.
now
()),
widget
=
forms
.
DateInput
(
format
=
'
%Y-%m-%d
'
,
attrs
=
{
'
id
'
:
'
nop_date
'
,
'
class
'
:
'
date
'
})
)
time
=
forms
.
TimeField
(
required
=
True
,
initial
=
datetime
.
time
(
datetime
.
now
()),
widget
=
forms
.
TimeInput
(
format
=
'
%H:%M
'
,
attrs
=
{
'
id
'
:
'
nop_time
'
,
'
class
'
:
'
date
'
})
)
def
get_current
(
request
):
def
_current
():
#current = int(time.time())*1000000
#time.gmtime(Master.objects.using('nop').all()[6000].timestamp//1000000)
# select all where timestamp < givenTS, get most recent one -> order DESC
# reverse sorted. get the first object = last played
result
=
Master
.
objects
.
using
(
'
nop
'
).
all
()[
0
]
response
=
json
.
dumps
({
'
artist
'
:
result
.
artist
,
'
title
'
:
result
.
title
})
#return HttpResponse(response, mimetype='application/json')
return
HttpResponse
(
response
,
mimetype
=
'
text/plain
'
)
def
get
(
request
,
year
=
None
,
month
=
None
,
day
=
None
,
hour
=
None
,
minute
=
None
):
return
{
'
artist
'
:
result
.
artist
,
'
title
'
:
result
.
title
}
def
_bydate
(
year
=
None
,
month
=
None
,
day
=
None
,
hour
=
None
,
minute
=
None
):
try
:
# tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst
ts
=
int
(
time
.
mktime
((
...
...
@@ -29,19 +44,40 @@ def get(request, year=None, month=None, day=None, hour=None, minute=None):
int
(
minute
),
0
,
0
,
0
,
-
1
)))
*
1000000
result
=
Master
.
objects
.
using
(
'
nop
'
).
filter
(
timestamp__lt
=
ts
)[:
5
]
response
=
json
.
dumps
(
[{
'
artist
'
:
item
.
artist
,
'
title
'
:
item
.
title
,
'
album
'
:
item
.
album
,
'
datetime
'
:
time
.
strftime
(
'
%Y-%m-%d %H:%M
'
,
time
.
localtime
(
item
.
timestamp
//
1000000
)),
'
showtitle
'
:
item
.
showtitle
}
for
item
in
result
])
return
[{
'
artist
'
:
item
.
artist
,
'
title
'
:
item
.
title
,
'
album
'
:
item
.
album
,
'
datetime
'
:
time
.
strftime
(
'
%Y-%m-%d %H:%M
'
,
time
.
localtime
(
item
.
timestamp
//
1000000
)),
'
showtitle
'
:
item
.
showtitle
}
for
item
in
result
]
except
:
# all errors
response
=
''
return
None
def
get_current
(
request
):
response
=
json
.
dumps
(
_current
())
#return HttpResponse(response, mimetype='application/json')
return
HttpResponse
(
response
,
mimetype
=
'
text/plain
'
)
def
get
(
request
,
year
=
None
,
month
=
None
,
day
=
None
,
hour
=
None
,
minute
=
None
):
response
=
json
.
dumps
(
_bydate
(
year
,
month
,
day
,
hour
,
minute
))
#return HttpResponse(response, mimetype='application/json')
return
HttpResponse
(
response
,
mimetype
=
'
text/plain
'
)
def
nop_form
(
request
):
extra_context
=
{
'
year
'
:
None
,
'
month
'
:
None
,
'
day
'
:
None
,
'
hour
'
:
None
,
'
minute
'
:
None
}
if
'
year
'
in
request
.
GET
:
pass
return
simple
.
direct_to_template
(
request
,
extra_context
=
extra_context
,
template
=
'
nop/nop_form.html
'
)
context
=
{}
context
.
update
(
csrf
(
request
))
if
request
.
method
==
'
POST
'
:
form
=
NopForm
(
request
.
POST
)
if
form
.
is_valid
():
date
=
form
.
cleaned_data
[
'
date
'
]
time
=
form
.
cleaned_data
[
'
time
'
]
else
:
form
=
NopForm
()
date
=
datetime
.
date
(
datetime
.
now
())
time
=
datetime
.
time
(
datetime
.
now
())
result
=
_bydate
(
date
.
year
,
date
.
month
,
date
.
day
,
time
.
hour
,
time
.
minute
)
context
[
'
nowplaying
'
]
=
result
context
[
'
form
'
]
=
form
return
render_to_response
(
'
nop/nop_form.html
'
,
context
)
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