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
cbb9f8b9
Commit
cbb9f8b9
authored
Jan 06, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] paginator progress: client and server (install django_dajax)
parent
ee94ae16
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
227 deletions
+136
-227
urls.py
gargantext_web/urls.py
+2
-0
views.py
gargantext_web/views.py
+69
-0
corpus.html
templates/corpus.html
+27
-227
subcorpus.html
templates/subcorpus.html
+38
-0
No files found.
gargantext_web/urls.py
View file @
cbb9f8b9
...
@@ -46,6 +46,8 @@ urlpatterns = patterns('',
...
@@ -46,6 +46,8 @@ urlpatterns = patterns('',
url
(
r'^api/nodes/(\d+)$'
,
gargantext_web
.
api
.
Nodes
.
as_view
()),
url
(
r'^api/nodes/(\d+)$'
,
gargantext_web
.
api
.
Nodes
.
as_view
()),
url
(
r'^api/nodes$'
,
gargantext_web
.
api
.
NodesList
.
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'^api/nodes/(\d+)/ngrams$'
,
gargantext_web
.
api
.
CorpusController
.
ngrams
),
url
(
r'^graph-it$'
,
views
.
graph_it
),
url
(
r'^graph-it$'
,
views
.
graph_it
),
...
...
gargantext_web/views.py
View file @
cbb9f8b9
...
@@ -434,6 +434,75 @@ def subcorpus(request, project_id, corpus_id, start , end ):
...
@@ -434,6 +434,75 @@ def subcorpus(request, project_id, corpus_id, start , end ):
return
HttpResponse
(
html
)
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'
)
...
...
templates/corpus.html
View file @
cbb9f8b9
This diff is collapsed.
Click to expand it.
templates/subcorpus.html
0 → 100644
View file @
cbb9f8b9
{% if date %}
<p>
Today: {{date}}
</p>
{% endif %}
{% 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>
<div
class=
"pagination"
>
<span
class=
"step-links"
>
{% if documents.has_previous %}
<a
href=
"?page={{ documents.previous_page_number }}"
>
previous
</a>
{% endif %}
<span
class=
"current"
>
Page {{ documents.number }} of {{ documents.paginator.num_pages }}.
</span>
{% if documents.has_next %}
<a
href=
"?page={{ documents.next_page_number }}"
>
next
</a>
{% endif %}
</span>
</div>
{% 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