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
3e3cd726
Commit
3e3cd726
authored
Oct 27, 2016
by
c24b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lang persistency Ok with user API params
parent
bb91a93b
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
89 additions
and
68 deletions
+89
-68
users.py
gargantext/models/users.py
+4
-2
urls.py
gargantext/views/api/urls.py
+1
-1
users.py
gargantext/views/api/users.py
+18
-4
auth.py
gargantext/views/pages/auth.py
+20
-0
corpora.py
gargantext/views/pages/corpora.py
+1
-1
main.py
gargantext/views/pages/main.py
+15
-27
projects.py
gargantext/views/pages/projects.py
+5
-5
terms.py
gargantext/views/pages/terms.py
+2
-2
views.py
graph/views.py
+2
-2
help.js
static/lib/gargantext/help.js
+19
-20
menu.html
templates/pages/menu.html
+0
-2
project.html
templates/pages/projects/project.html
+2
-2
No files found.
gargantext/models/users.py
View file @
3e3cd726
...
...
@@ -21,7 +21,7 @@ class User(Base):
is_active
=
Column
(
Boolean
(),
default
=
True
)
last_login
=
Column
(
DateTime
(
timezone
=
False
))
date_joined
=
Column
(
DateTime
(
timezone
=
False
),
default
=
datetime
.
now
)
def
contacts
(
self
):
"""get all contacts in relation with the user"""
Friend
=
aliased
(
User
)
...
...
@@ -61,7 +61,9 @@ class User(Base):
"""check if a given node is owned by the user"""
return
(
node
.
user_id
==
self
.
id
)
or
\
node
.
id
in
(
contact
.
id
for
contact
in
self
.
contacts
())
def
get_params
(
self
,
username
=
None
):
print
(
self
.
__dict__
.
items
())
return
self
.
hyperdata
class
Contact
(
Base
):
__tablename__
=
'contacts'
...
...
gargantext/views/api/urls.py
View file @
3e3cd726
...
...
@@ -91,6 +91,6 @@ urlpatterns = [ url(r'^nodes$' , nodes.NodeListResource.as_view()
,
url
(
r'^ngramlists/maplist$'
,
ngramlists
.
MapListGlance
.
as_view
()
)
# fast access to maplist, similarly formatted for termtable
,
url
(
r'^user
s/$'
,
users
.
UserItem
.
as_view
())
,
url
(
r'^user
/parameters/$'
,
users
.
UserParameters
.
as_view
())
]
gargantext/views/api/users.py
View file @
3e3cd726
...
...
@@ -6,8 +6,17 @@ from gargantext.util.toolchain import *
import
copy
from
gargantext.util.db
import
session
class
User
Item
(
APIView
):
class
User
Parameters
(
APIView
):
'''API endpoint that represent the parameters of the user'''
def
get
(
self
,
request
):
node_user
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
typename
==
"USER"
)
.
first
()
if
node_user
is
None
:
return
Response
({
"detail"
:
"Not Found"
},
status
=
HTTP_404
)
else
:
#context = format_response(node_user, )
return
Response
(
node_user
.
hyperdata
)
def
put
(
self
,
request
):
if
request
.
user
.
id
is
None
:
raise
TypeError
(
"This API request must come from an authenticated user."
)
...
...
@@ -17,9 +26,14 @@ class UserItem(APIView):
node_user
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user
.
id
,
Node
.
typename
==
"USER"
)
.
first
()
if
node_user
is
None
:
return
Response
({
"detail"
:
"Not Allowed"
},
status
=
HTTP_401_UNAUTHORIZED
)
for
k
,
v
in
request
.
data
.
items
():
setattr
(
node_user
.
hyperdata
,
key
,
val
)
for
k
,
v
in
request
.
data
.
items
():
node_user
.
hyperdata
[
k
]
=
v
# setattr(node_user.hyperdata, k, v)
# print(node_user.hyperdata)
# node_user.save_hyperdata()
session
.
add
(
node_user
)
session
.
commit
()
return
Response
({
"detail"
:
"Updated user parameters"
},
status
=
HTTP_202_ACCEPTED
)
node_user
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user
.
id
,
Node
.
typename
==
"USER"
)
.
first
()
print
(
node_user
.
hyperdata
)
return
Response
({
"detail"
:
"Updated user parameters"
,
"hyperdata"
:
node_user
.
hyperdata
},
status
=
HTTP_202_ACCEPTED
)
gargantext/views/pages/auth.py
View file @
3e3cd726
...
...
@@ -4,6 +4,7 @@ from django.views.generic import FormView
from
django.shortcuts
import
redirect
from
gargantext.models.users
import
User
from
django
import
forms
from
gargantext.models
import
Node
,
User
from
gargantext.views.pages.projects
import
overview
...
...
@@ -21,6 +22,25 @@ class LoginView(FormView):
if
user
is
not
None
and
user
.
is_active
:
login
(
self
.
request
,
user
)
node_user
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user
.
id
,
Node
.
typename
==
"USER"
)
.
first
()
if
"language"
not
in
node_user
[
"hyperdata"
]
.
keys
():
node_user
.
hyperdata
[
"language"
]
=
"fr"
session
.
add
(
node_user
)
session
.
commit
()
#user hasn't been found inside Node table
#create it from auth table => node table
if
node_user
is
None
:
node_user
=
Node
(
typename
=
'USER'
,
#in node = > name
#in user = > username
name
=
user
.
name
,
user_id
=
user
.
id
,
)
node_user
.
hyperdata
=
{
"language"
:
"fr"
}
session
.
add
(
node_user
)
session
.
commit
()
return
super
(
LoginView
,
self
)
.
form_valid
(
form
)
else
:
return
self
.
form_invalid
(
form
)
...
...
gargantext/views/pages/corpora.py
View file @
3e3cd726
...
...
@@ -5,7 +5,7 @@ from gargantext.models import *
from
gargantext.constants
import
*
from
gargantext.settings
import
*
from
datetime
import
datetime
from
.main
import
get_
node_user
from
.main
import
get_
user_params
from
gargantext.constants
import
USER_LANG
def
_get_user_project_corpus
(
request
,
project_id
,
corpus_id
):
...
...
gargantext/views/pages/main.py
View file @
3e3cd726
...
...
@@ -5,35 +5,23 @@ import datetime
from
gargantext.util.generators
import
paragraphs
,
credits
from
gargantext.constants
import
USER_LANG
def
get_node_user
(
user
):
#load user parameters from User(Node).hyperdata from request.user or cache.
node_user
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user
.
id
,
Node
.
typename
==
"USER"
)
.
first
()
if
node_user
is
None
:
try
:
node_user
=
Node
(
user_id
=
user
.
id
,
typename
=
'USER'
,
name
=
user
.
name
,
)
except
AttributeError
:
node_user
=
Node
(
user_id
=
user
.
id
,
typename
=
'USER'
,
name
=
"Anne Aunime"
,
)
#default language for now is 'fr'
node_user
.
hyperdata
.
language
=
"fr"
session
.
add
(
node_user
)
session
.
commit
()
return
node_user
def
get_user_node
(
user
):
if
user
.
is_authenticated
:
node_user
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user
.
id
,
Node
.
typename
==
"USER"
)
.
first
()
return
node_user
else
:
return
None
def
get_user_params
(
user
):
node_user
=
get_user_node
(
user
)
if
node_user
is
not
None
:
return
node_user
.
hyperdata
return
{}
def
home
(
request
):
'''Home describes the platform.
A video draws the narratives.
If not logged a project test is shown.
'''
user_node
=
get_node_user
(
request
.
user
)
return
render
(
template_name
=
'pages/main/home.html'
,
request
=
request
,
...
...
@@ -44,15 +32,15 @@ def home(request):
'paragraph_gargantua'
:
paragraphs
.
gargantua
(),
'paragraph_lorem'
:
paragraphs
.
lorem
(),
'paragraph_tutoreil'
:
paragraphs
.
tutoreil
(),
'user_parameters'
:
user_node
.
hyperdata
,
'languages'
:
USER_LANG
,
'user_parameters'
:
get_user_params
(
request
.
user
)
},
)
def
about
(
request
):
'''About Gargantext, its team and sponsors
'''
user_node
=
get_node_user
(
request
.
user
)
return
render
(
template_name
=
'pages/main/about.html'
,
request
=
request
,
...
...
@@ -63,7 +51,7 @@ def about(request):
'institutions'
:
credits
.
institutions
(),
'labos'
:
credits
.
labs
(),
'grants'
:
credits
.
grants
(),
'user_parameters'
:
user_node
.
hyperdata
,
'user_parameters'
:
get_user_params
(
request
.
user
)
,
'languages'
:
USER_LANG
,
},
)
...
...
@@ -87,6 +75,6 @@ def maintenance(request):
context
=
{
'user'
:
request
.
user
,
'date'
:
datetime
.
datetime
.
now
(),
'user_parameters'
:
user_node
.
hyperdata
'user_parameters'
:
get_user_params
(
request
.
user
)
},
)
gargantext/views/pages/projects.py
View file @
3e3cd726
...
...
@@ -4,7 +4,7 @@ from gargantext.util.db_cache import cache
from
gargantext.util.files
import
upload
from
gargantext.models
import
*
from
gargantext.constants
import
*
from
.main
import
get_
node_user
from
.main
import
get_
user_params
from
gargantext.util.scheduling
import
scheduled
from
gargantext.util.toolchain
import
parse_extract_indexhyperdata
...
...
@@ -18,7 +18,7 @@ def get_node_user(user):
if
node_user
is
None
:
node_user
=
Node
(
user_id
=
user
.
id
,
typename
=
'USER'
,
user
name
=
user
.
name
,
name
=
user
.
name
,
)
#default language for now is 'fr'
node_user
.
hyperdata
[
"language"
]
=
"fr"
...
...
@@ -67,7 +67,7 @@ def overview(request):
# projects owned by the user
'number'
:
user_projects
.
count
(),
'projects'
:
user_projects
,
"user_parameters"
:
node_user
.
hyperdata
,
'user_parameters'
:
get_user_params
(
request
.
user
)
,
'languages'
:
USER_LANG
,
# projects owned by the user's contacts
'common_users'
:
(
contact
for
contact
,
projects
in
contacts_projects
),
...
...
@@ -190,7 +190,7 @@ def project(request, project_id):
'form'
:
NewCorpusForm
,
'user'
:
request
.
user
,
"user_parameters"
:
node_user
.
hyperdata
,
'user_parameters'
:
get_user_params
(
request
.
user
)
,
'languages'
:
USER_LANG
,
'date'
:
datetime
.
now
(),
'project'
:
project
,
...
...
@@ -211,7 +211,7 @@ def project(request, project_id):
template_name
=
'pages/projects/project.html'
,
request
=
request
,
context
=
{
"user_parameters"
:
node_user
.
hyperdata
,
'user_parameters'
:
get_user_params
(
request
.
user
)
,
"languages"
:
USER_LANG
,
'form'
:
NewCorpusForm
,
'user'
:
request
.
user
,
...
...
gargantext/views/pages/terms.py
View file @
3e3cd726
...
...
@@ -4,7 +4,7 @@ from gargantext.util.db_cache import cache
from
gargantext.models
import
Node
from
gargantext.constants
import
get_resource
from
gargantext.constants
import
USER_LANG
from
.main
import
get_
node_user
from
.main
import
get_
user_params
from
datetime
import
datetime
...
...
@@ -53,7 +53,7 @@ def ngramtable(request, project_id, corpus_id):
'importroute'
:
"/api/ngramlists/import?onto_corpus=
%
i"
%
corpus
.
id
,
'corporainfos'
:
corpora_infos
,
#user params
'user_parameters'
:
user_node
.
hyperdata
,
'user_parameters'
:
get_user_params
(
request
.
user
)
,
'languages'
:
USER_LANG
},
)
graph/views.py
View file @
3e3cd726
...
...
@@ -6,7 +6,7 @@ from gargantext.constants import *
from
gargantext.settings
import
*
from
gargantext.constants
import
USER_LANG
from
datetime
import
datetime
from
gargantext.views.pages.main
import
get_
node_user
from
gargantext.views.pages.main
import
get_
user_params
@
requires_auth
def
explorer
(
request
,
project_id
,
corpus_id
):
...
...
@@ -48,7 +48,7 @@ def explorer(request, project_id, corpus_id):
'corpus'
:
corpus
,
'maplist_id'
:
maplist_id
,
'view'
:
'graph'
,
'user_parameters'
:
node_user
.
hyperdata
,
'user_parameters'
:
get_user_params
(
request
.
user
)
,
'languages'
:
USER_LANG
},
)
...
...
static/lib/gargantext/help.js
View file @
3e3cd726
...
...
@@ -180,11 +180,9 @@ lang = $("a#lang").data("lang")
loadHelp
(
lang
)
//change lang
$
(
"a.new_lang"
).
on
(
"click"
,
function
(){
//close all popo
//close all popover while changing lang
$
(
'.popover'
).
popover
(
'hide'
);
new_lang
=
$
(
this
).
data
(
"lang"
)
//new_lang.setAttr("data-lang", lang)
loadHelp
(
new_lang
);
//current lang in tab
$
(
"a#lang"
).
attr
(
"data-lang"
,
new_lang
);
...
...
@@ -203,27 +201,28 @@ $("a.new_lang").on("click", function(){
label
=
$
(
"a.new_lang > span"
)
label
.
text
(
lang
)
// console.log("AJAX")
// $.ajax({
// url: '/api/users/?'+jQuery.param({"default_language":new_lang}),
// type: 'PUT',
// beforeSend: function(xhr) {
// xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
// },
// success: function(response) {
// console.log(response);
// console.log("EDIT SUCCESS!");
// $("a#lang").attr("data-lang", new_lang);
$
.
ajax
({
url
:
'/api/user/parameters/'
,
type
:
'PUT'
,
data
:
{
"language"
:
new_lang
},
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
"X-CSRFToken"
,
getCookie
(
"csrftoken"
));
},
success
:
function
(
response
)
{
console
.
log
(
response
);
console
.
log
(
"EDIT SUCCESS!"
);
//$("a#lang").attr("data-lang", new_lang);
// console.log("a#lang")
// //$("a#lang").next("img").attr({"value": new_lang, "src":"/static/img/"+new_lang+".png")
// //$("a.new_lang").attr("data-lang", new_lang);
// //$("a.new_lang").next("img").attr({"value": lang, "src":"/static/img/"+lang+".png")
// //window.location.reload()
//
},
//
error: function(xhr) {
//
console.log("EDIT FAIL!")
//
//
},
//
});
},
error
:
function
(
xhr
)
{
console
.
log
(
"EDIT FAIL!"
)
},
});
});
...
...
@@ -244,7 +243,7 @@ function loadHelp(lang){
info
=
help
[
div_id
]
console
.
log
(
lang
)
console
.
log
(
info
[
lang
][
"content"
])
help_btn
=
'<span class="glyphicon glyphicon-question-sign help-btn" tab-index=0 data-container="body" data-toggle="popover" data-placement="'
+
info
[
lang
][
"placement"
]
+
'" title="'
+
info
[
lang
][
"title"
]
+
'" data-content="'
+
info
[
lang
][
"content"
]
+
'"></span>'
help_btn
=
'<span class="glyphicon glyphicon-question-sign help-btn"
data-html="true"
tab-index=0 data-container="body" data-toggle="popover" data-placement="'
+
info
[
lang
][
"placement"
]
+
'" title="'
+
info
[
lang
][
"title"
]
+
'" data-content="'
+
info
[
lang
][
"content"
]
+
'"></span>'
if
(
info
[
"position"
]
==
"inside"
){
...
...
templates/pages/menu.html
View file @
3e3cd726
...
...
@@ -120,8 +120,6 @@
<a
class=
"new_lang"
data-lang=
"{{lang}}"
><img
value=
"{{user_parameters.language}}"
src=
"/static/img/{{lang}}.png"
width=
"25%"
/>
<span>
{{lang}}
</span>
</a></li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
...
...
templates/pages/projects/project.html
View file @
3e3cd726
...
...
@@ -57,7 +57,7 @@
<center>
<a
data-toggle=
"modal"
href=
"#addcorpus"
>
<a
data-toggle=
"modal"
href=
"#addcorpus"
>
<button
type=
"button"
class=
"btn btn-primary btn-lg"
...
...
@@ -68,7 +68,7 @@
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
Add a corpus
</button>
<p
class=
"help"
id=
"corpus-btn"
></p>
<p
class=
"help"
id=
"corpus-btn"
></p>
</a>
</center>
...
...
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