Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
m3_webInterface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
m3
m3_webInterface
Commits
d38a524d
Commit
d38a524d
authored
Oct 23, 2017
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin
parent
8732738a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
11 deletions
+51
-11
admin.py
catalog/admin.py
+5
-1
admin.pyc
catalog/admin.pyc
+0
-0
leftMenuBar.html
catalog/templates/leftMenuBar.html
+2
-2
views.py
catalog/views.py
+44
-8
views.pyc
catalog/views.pyc
+0
-0
No files found.
catalog/admin.py
View file @
d38a524d
...
...
@@ -5,5 +5,9 @@ from django.contrib import admin
from
catalog.models
import
Publisher
admin
.
site
.
register
(
Publisher
)
#admin.site.register(Publisher)
class
PublisherAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'name'
,
'shortName'
,
'type'
,
'url'
)
admin
.
site
.
register
(
Publisher
,
PublisherAdmin
)
catalog/admin.pyc
View file @
d38a524d
No preview for this file type
catalog/templates/leftMenuBar.html
View file @
d38a524d
...
...
@@ -53,11 +53,11 @@
<ul
class=
"nav nav-second-level"
aria-expanded=
"true"
>
<form
role=
"form"
>
<li>
<a
href=
"
#
"
>
JSON
</a>
<a
href=
"
{% url 'ws-download-news' %}?{{ request.GET.urlencode }}&format=JSON"
target=
"blank
"
>
JSON
</a>
</li>
<li>
<a
href=
"#
"
>
CSV
</a>
<a
href=
"{% url 'ws-download-news' %}?{{ request.GET.urlencode }}&format=CSV"
target=
"blank
"
>
CSV
</a>
</li>
...
...
catalog/views.py
View file @
d38a524d
...
...
@@ -19,9 +19,24 @@ import urllib
from
django.db.models
import
Count
from
django.core.urlresolvers
import
reverse
import
json
import
StringIO
import
time
import
zipfile
import
csv
from
django.db.models.functions
import
TruncMonth
,
TruncYear
#-------------------------------------------------------------------------------
def
news2JSON
(
news
):
data
=
list
()
for
n
in
news
:
item
=
dict
()
item
[
'date'
]
=
n
.
date
.
strftime
(
'
%
Y-
%
m-
%
d'
)
item
[
'publisher'
]
=
n
.
publisher
.
name
item
[
'title'
]
=
n
.
title
item
[
'text'
]
=
n
.
text
item
[
'url'
]
=
n
.
url
data
.
append
(
item
)
return
data
#-------------------------------------------------------------------------------
def
getNewsByRequest
(
request
):
print
"getNewsByRequest
\n\n\n
"
...
...
@@ -54,6 +69,7 @@ def index(request):
news
=
getNewsByRequest
(
request
)
form
=
SearchForm
(
request
.
GET
.
copy
())
if
len
(
news
)
>
0
:
if
'startDate'
not
in
form
or
(
'startDate'
in
form
and
form
[
'startDate'
]
.
value
==
""
):
form
.
data
.
update
({
'startDate'
:
news
.
earliest
(
'date'
)
.
date
.
strftime
(
"
%
Y-
%
m-
%
d"
)})
...
...
@@ -188,8 +204,28 @@ def wsGraphs(request):
return
HttpResponse
(
json
.
dumps
(
data
),
content_type
=
"application/json"
)
#-------------------------------------------------------------------------------
def
wsDownloadNews
(
request
):
data
=
dict
()
news
=
getNewsByRequest
(
request
)
s
=
StringIO
.
StringIO
()
# Open StringIO to grab in-memory ZIP contents
zf
=
zipfile
.
ZipFile
(
s
,
"w"
)
# The zip compressor
zf
.
writestr
(
"setting.txt"
,
json
.
dumps
(
request
.
GET
))
data
=
news2JSON
(
news
);
if
request
.
GET
[
'format'
]
==
"JSON"
:
data
=
0
;
return
HttpResponse
(
json
.
dumps
(
data
),
content_type
=
"application/json"
)
zf
.
writestr
(
"data.json"
,
json
.
dumps
(
data
))
if
request
.
GET
[
'format'
]
==
"CSV"
:
csvString
=
StringIO
.
StringIO
()
writer
=
csv
.
writer
(
csvString
,
quoting
=
csv
.
QUOTE_ALL
)
#, fieldnames=[k for k in data[0]])
# writer.writeheader()
for
d
in
data
:
row
=
[
d
[
k
]
.
encode
(
'utf-8'
)
for
k
in
d
]
writer
.
writerow
(
row
)
zf
.
writestr
(
"data.csv"
,
csvString
.
getvalue
())
zf
.
close
()
response
=
HttpResponse
(
s
.
getvalue
(),
content_type
=
"application/x-zip-compressed"
)
response
[
'Content-Disposition'
]
=
'attachment; filename="news_'
+
str
(
int
(
time
.
time
()))
+
'.zip"'
return
response
catalog/views.pyc
View file @
d38a524d
No preview for this file type
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