Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
d18065e7
Commit
d18065e7
authored
Jan 07, 2015
by
Administrator
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'samuel'
Samuel's stuff integration
parents
96da88b7
bfdab6f5
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
267 additions
and
238 deletions
+267
-238
urls.py
gargantext_web/urls.py
+4
-0
views.py
gargantext_web/views.py
+159
-0
corpus.html
templates/corpus.html
+63
-237
node-info.html
templates/node-info.html
+7
-1
subcorpus.html
templates/subcorpus.html
+34
-0
No files found.
gargantext_web/urls.py
View file @
d18065e7
...
...
@@ -30,6 +30,8 @@ urlpatterns = patterns('',
url
(
r'^project/(\d+)/corpus/(\d+)/delete/$'
,
views
.
delete_corpus
),
url
(
r'^project/(\d+)/corpus/(\d+)/corpus.csv$'
,
views
.
corpus_csv
),
url
(
r'^project/(\d+)/corpus/(\d+)/timerange/(\d+)/(\d+)$'
,
views
.
subcorpus
),
# Visualizations
url
(
r'^project/(\d+)/corpus/(\d+)/chart$'
,
views
.
chart
),
url
(
r'^corpus/(\d+)/explorer$'
,
views
.
graph
),
...
...
@@ -48,6 +50,8 @@ urlpatterns = patterns('',
url
(
r'^api/nodes/(\d+)$'
,
gargantext_web
.
api
.
Nodes
.
as_view
()),
url
(
r'^api/nodes$'
,
gargantext_web
.
api
.
NodesList
.
as_view
()),
url
(
r'^api/project/(\d+)/corpus/(\d+)/timerange/(\d+)/(\d+)$'
,
views
.
subcorpusJSON
),
url
(
r'^api/nodes/(\d+)/ngrams$'
,
gargantext_web
.
api
.
CorpusController
.
ngrams
),
url
(
r'^ngrams$'
,
views
.
ngrams
),
...
...
gargantext_web/views.py
View file @
d18065e7
...
...
@@ -363,6 +363,165 @@ def corpus(request, project_id, corpus_id):
return
HttpResponse
(
html
)
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
def
subcorpus
(
request
,
project_id
,
corpus_id
,
start
,
end
):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/login/?next=
%
s'
%
request
.
path
)
try
:
offset
=
str
(
project_id
)
offset
=
str
(
corpus_id
)
offset
=
str
(
start
)
offset
=
str
(
end
)
except
ValueError
:
raise
Http404
()
# parameters received via web. Format = (yearmonthday = 20150106 = 06 jan 2015)
import
datetime
dateini
=
datetime
.
datetime
.
strptime
(
str
(
start
),
'
%
Y
%
m
%
d'
)
.
date
()
datefin
=
datetime
.
datetime
.
strptime
(
str
(
end
),
'
%
Y
%
m
%
d'
)
.
date
()
t
=
get_template
(
'subcorpus.html'
)
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
project
=
Node
.
objects
.
get
(
id
=
project_id
)
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
# retrieving all the documents
documents
=
corpus
.
children
.
all
()
number
=
corpus
.
children
.
count
()
filtered_docs
=
[]
# filtering documents by range-date
for
doc
in
documents
:
if
"publication_date"
in
doc
.
metadata
:
realdate
=
doc
.
metadata
[
"publication_date"
]
.
split
(
" "
)[
0
]
# in database is = (year-month-day = 2015-01-06 00:00:00 = 06 jan 2015 00 hrs)
realdate
=
datetime
.
datetime
.
strptime
(
str
(
realdate
),
'
%
Y-
%
m-
%
d'
)
.
date
()
# finalform = (yearmonthday = 20150106 = 06 jan 2015)
if
dateini
<=
realdate
<=
datefin
:
doc
.
date
=
realdate
filtered_docs
.
append
(
doc
)
# ordering from most recent to the older.
ordered
=
sorted
(
filtered_docs
,
key
=
lambda
x
:
x
.
date
,
reverse
=
True
)
# pages of 10 elements. Like a sir.
paginator
=
Paginator
(
ordered
,
10
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
results
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
# If page is not an integer, deliver first page.
results
=
paginator
.
page
(
1
)
except
EmptyPage
:
# If page is out of range (e.g. 9999), deliver last page of results.
results
=
paginator
.
page
(
paginator
.
num_pages
)
html
=
t
.
render
(
Context
({
\
'user'
:
user
,
\
'date'
:
date
,
\
'project'
:
project
,
\
'corpus'
:
corpus
,
\
'documents'
:
results
,
\
# 'number' : len(filtered_docs),\
# 'dates' : chart,\
}))
return
HttpResponse
(
html
)
import
json
def
subcorpusJSON
(
request
,
project_id
,
corpus_id
,
start
,
end
):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/login/?next=
%
s'
%
request
.
path
)
try
:
offset
=
str
(
project_id
)
offset
=
str
(
corpus_id
)
offset
=
str
(
start
)
offset
=
str
(
end
)
except
ValueError
:
raise
Http404
()
# parameters received via web. Format = (yearmonthday = 20150106 = 06 jan 2015)
import
datetime
dateini
=
datetime
.
datetime
.
strptime
(
str
(
start
),
'
%
Y
%
m
%
d'
)
.
date
()
datefin
=
datetime
.
datetime
.
strptime
(
str
(
end
),
'
%
Y
%
m
%
d'
)
.
date
()
t
=
get_template
(
'subcorpus.html'
)
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
project
=
Node
.
objects
.
get
(
id
=
project_id
)
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
# retrieving all the documents
documents
=
corpus
.
children
.
all
()
number
=
corpus
.
children
.
count
()
filtered_docs
=
[]
# filtering documents by range-date
for
doc
in
documents
:
if
"publication_date"
in
doc
.
metadata
:
realdate
=
doc
.
metadata
[
"publication_date"
]
.
split
(
" "
)[
0
]
# in database is = (year-month-day = 2015-01-06 00:00:00 = 06 jan 2015 00 hrs)
realdate
=
datetime
.
datetime
.
strptime
(
str
(
realdate
),
'
%
Y-
%
m-
%
d'
)
.
date
()
# finalform = (yearmonthday = 20150106 = 06 jan 2015)
if
dateini
<=
realdate
<=
datefin
:
doc
.
date
=
realdate
filtered_docs
.
append
(
doc
)
# ordering from most recent to the older.
ordered
=
sorted
(
filtered_docs
,
key
=
lambda
x
:
x
.
date
,
reverse
=
True
)
# pages of 10 elements. Like a sir.
paginator
=
Paginator
(
ordered
,
10
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
results
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
# If page is not an integer, deliver first page.
results
=
paginator
.
page
(
1
)
except
EmptyPage
:
# If page is out of range (e.g. 9999), deliver last page of results.
results
=
paginator
.
page
(
paginator
.
num_pages
)
from
rest_framework.pagination
import
PaginationSerializer
serializer
=
PaginationSerializer
(
instance
=
results
)
print
(
serializer
.
data
)
html
=
t
.
render
(
Context
({
\
'user'
:
user
,
\
'date'
:
date
,
\
'corpus'
:
corpus
,
\
}))
# return HttpResponse(html)
return
HttpResponse
(
serializer
.
data
,
content_type
=
'application/json'
)
# for pagexample.html
from
django.core.paginator
import
Paginator
,
InvalidPage
,
EmptyPage
def
get_pagination_page
(
page
=
1
):
items
=
range
(
0
,
100
)
paginator
=
Paginator
(
items
,
10
)
try
:
page
=
int
(
page
)
except
ValueError
:
page
=
1
try
:
items
=
paginator
.
page
(
page
)
except
(
EmptyPage
,
InvalidPage
):
items
=
paginator
.
page
(
paginator
.
num_pages
)
return
items
def
delete_project
(
request
,
node_id
):
Node
.
objects
.
filter
(
id
=
node_id
)
.
all
()
.
delete
()
return
HttpResponseRedirect
(
'/projects/'
)
...
...
templates/corpus.html
View file @
d18065e7
This diff is collapsed.
Click to expand it.
templates/node-info.html
View file @
d18065e7
...
...
@@ -81,9 +81,15 @@
output += "
<
div
class
=
'nodeinfo-container'
>
"
if(jsondata.title) output += "
<
div
class
=
'nodeinfo-elem'
>
<
div
class
=
'nodeinfo-head'
>
Title
<
/div> <div class='nodeinfo-content'>"+jsondata.title+"</
div
>
<
/div>"
;
if
(
jsondata
.
publication_date
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Publication Date</div> <div class='nodeinfo-content'>"
+
jsondata
.
publication_date
.
split
(
" "
)[
0
]
+
"</div> </div>"
;
if
(
jsondata
.
authors
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Authors</div> <div class='nodeinfo-content'>"
+
jsondata
.
authors
+
"</div> </div>"
;
if
(
jsondata
.
authors
&&
jsondata
.
authors
!=
"not found"
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Authors</div> <div class='nodeinfo-content'>"
+
jsondata
.
authors
+
"</div> </div>"
;
else
{
if
(
jsondata
.
source
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Published in</div> <div class='nodeinfo-content'>"
+
jsondata
.
source
+
"</div> </div>"
;
}
if
(
jsondata
.
fields
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Keywords</div> <div class='nodeinfo-content'>"
+
jsondata
.
fields
+
"</div> </div>"
;
if
(
jsondata
.
abstract
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Abstract</div> <div class='nodeinfo-content'>"
+
jsondata
.
abstract
+
"</div> </div>"
;
else
{
if
(
jsondata
.
text
)
output
+=
"<div class='nodeinfo-elem'> <div class='nodeinfo-head'>Abstract</div> <div class='nodeinfo-content'>"
+
jsondata
.
text
+
"</div> </div>"
;
}
output
+=
"</div>"
$
(
"#metadata"
).
html
(
output
);
...
...
templates/subcorpus.html
0 → 100644
View file @
d18065e7
{% if date %}
<p>
Today: {{date}}
</p>
{% endif %}
<div
class=
"pagination"
>
<span
class=
"step-links"
>
{% if documents.has_previous %}
<a
onclick=
"updateDocuments({{ documents.previous_page_number }},true);"
>
previous
</a>
{% endif %}
<span
class=
"current"
>
Page {{ documents.number }} of {{ documents.paginator.num_pages }}.
</span>
{% if documents.has_next %}
<a
onclick=
"updateDocuments({{ documents.next_page_number }},true);"
>
next
</a>
{% endif %}
</span>
</div>
{% if documents %}
<p>
Paginator stuff
</p>
<ul>
{% for doc in documents %}
{% if doc.date %}
<li>
<b>
{{ doc.date }}
</b>
,
<a
href=
"/admin/node/document/{{doc.id}}"
>
id:{{ doc.id}} title:{{ doc.name}}
</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
\ No newline at end of file
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