Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
django-panik-nonstop
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
radiopanik
django-panik-nonstop
Commits
843e845d
Commit
843e845d
authored
Nov 02, 2014
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add csv export of day playlists
parent
9ea1d6eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletion
+27
-1
nonstop/templates/nonstop/somalogline_archive_day.html
nonstop/templates/nonstop/somalogline_archive_day.html
+1
-0
nonstop/urls.py
nonstop/urls.py
+4
-1
nonstop/views.py
nonstop/views.py
+22
-0
No files found.
nonstop/templates/nonstop/somalogline_archive_day.html
View file @
843e845d
...
...
@@ -2,6 +2,7 @@
{% block appbar %}
<h2>
Nonstop - {{ day|date:"d/m/Y" }}
</h2>
<span><a
href=
"csv"
>
export CSV
</a></span>
{% endblock %}
{% block content %}
...
...
nonstop/urls.py
View file @
843e845d
from
django.conf.urls
import
url
from
.views
import
SomaDayArchiveView
,
RedirectTodayView
,
TrackDetailView
,
ArtistDetailView
from
.views
import
SomaDayArchiveView
,
SomaDayArchiveCsvView
,
RedirectTodayView
,
TrackDetailView
,
ArtistDetailView
urlpatterns
=
[
# Example: /2012/nov/10/
...
...
@@ -10,4 +10,7 @@ urlpatterns = [
url
(
r
'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/$'
,
SomaDayArchiveView
.
as_view
(),
name
=
"archive_day"
),
url
(
r
'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/csv$'
,
SomaDayArchiveCsvView
.
as_view
(),
name
=
"archive_day_csv"
),
]
nonstop/views.py
View file @
843e845d
import
csv
import
datetime
from
cStringIO
import
StringIO
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpResponse
from
django.views.generic.base
import
RedirectView
from
django.views.generic.dates
import
DayArchiveView
from
django.views.generic.detail
import
DetailView
...
...
@@ -15,6 +18,25 @@ class SomaDayArchiveView(DayArchiveView):
month_format
=
'%m'
class
SomaDayArchiveCsvView
(
SomaDayArchiveView
):
def
render_to_response
(
self
,
context
,
**
response_kwargs
):
out
=
StringIO
()
writer
=
csv
.
writer
(
out
)
for
line
in
context
[
'object_list'
]:
if
line
.
filepath
.
track
:
writer
.
writerow
([
line
.
play_timestamp
.
strftime
(
'%Y-%m-%d %H:%M'
),
line
.
filepath
.
short
.
encode
(
'utf-8'
,
'replace'
),
line
.
filepath
.
track
.
title
.
encode
(
'utf-8'
,
'replace'
),
line
.
filepath
.
track
.
artist
.
name
.
encode
(
'utf-8'
,
'replace'
),
line
.
filepath
.
track
.
language
,
line
.
filepath
.
track
.
instru
and
'instru'
or
''
,
line
.
filepath
.
track
.
cfwb
and
'cfwb'
or
''
])
else
:
writer
.
writerow
([
line
.
play_timestamp
.
strftime
(
'%Y-%m-%d %H:%M'
),
line
.
filepath
.
short
.
encode
(
'utf-8'
,
'replace'
)])
return
HttpResponse
(
out
.
getvalue
(),
mimetype
=
'text/csv; charset=utf-8'
)
class
RedirectTodayView
(
RedirectView
):
def
get_redirect_url
(
self
,
*
args
,
**
kwargs
):
today
=
datetime
.
datetime
.
today
()
...
...
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