Commit 47f224f8 authored by c24b's avatar c24b

Default Langue Fr for user in views

parent 801a279d
from gargantext.util.http import *
from gargantext.util.db import *
from gargantext.util.db_cache import cache
from gargantext.models import *
from gargantext.constants import *
from gargantext.settings import *
from datetime import datetime
def get_node_user(user):
node_user = session.query(Node).filter(Node.user_id == user.id, Node.typename== "USER").first()
if node_user is None:
node_user = Node(typename== "USER", user_id = user.id, name= user.name)
#default language for now is 'fr'
node_user["hyperdata"]["language"] = "fr"
session.add(node_user)
session.commit()
return node_user
from gargantext.util.http import *
from gargantext.util.db import *
from gargantext.util.db_cache import cache
from gargantext.models import *
from gargantext.constants import *
from gargantext.settings import *
from datetime import datetime
from .main import get_node_user
def _get_user_project_corpus(request, project_id, corpus_id):
"""Helper method to get a corpus, knowing the project's and corpus' ID.
......
from gargantext.util.http import *
from gargantext.util.http import *
from gargantext.util.db import session
from gargantext.models import Node, User
import datetime
from gargantext.util.generators import paragraphs, credits
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 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,
......@@ -19,12 +43,15 @@ def home(request):
'paragraph_gargantua': paragraphs.gargantua(),
'paragraph_lorem' : paragraphs.lorem(),
'paragraph_tutoreil': paragraphs.tutoreil(),
'user_parameters': user_node.hyperdata
},
)
def about(request):
'''About Gargantext, its team and sponsors
'''
user_node = get_user_node(request.user)
return render(
template_name = 'pages/main/about.html',
request = request,
......@@ -35,6 +62,7 @@ def about(request):
'institutions': credits.institutions(),
'labos': credits.labs(),
'grants': credits.grants(),
'user_parameters': user_node.hyperdata
},
)
......@@ -50,11 +78,13 @@ def robots(request):
def maintenance(request):
'''Gargantext out of service
'''
user_node = get_user_node(request.user)
return render(
template_name = 'pages/main/maintenance.html',
request = request,
context = {
'user': request.user,
'date': datetime.datetime.now(),
'user_parameters': user_node.hyperdata
},
)
......@@ -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 gargantext.util.scheduling import scheduled
from gargantext.util.toolchain import parse_extract_indexhyperdata
......
......@@ -3,19 +3,9 @@ from gargantext.util.db import session
from gargantext.util.db_cache import cache
from gargantext.models import Node
from gargantext.constants import get_resource
from .main import get_node_user
from datetime import datetime
def get_node_user(user):
#load user parameters
node_user = session.query(Node).filter(Node.user_id == user.id, Node.typename== "USER").first()
if node_user is None:
node_user = Node(typename== "USER", user_id = user.id, name= user.name)
#default language for now is 'fr'
node_user["hyperdata"]["language"] = "fr"
session.add(node_user)
session.commit()
return node_user
@requires_auth
def ngramtable(request, project_id, corpus_id):
......
......@@ -4,6 +4,7 @@ from gargantext.util.db_cache import cache
from gargantext.models import *
from gargantext.constants import *
from gargantext.settings import *
from gargantext.views.pages.main import get_node_user
from datetime import datetime
......@@ -19,9 +20,10 @@ def explorer(request, project_id, corpus_id):
# we pass our corpus
corpus = cache.Node[corpus_id]
# security check
user = cache.User[request.user.id]
node_user = get_node_user(user)
if corpus is None:
raise Http404()
if not user.owns(corpus):
......@@ -46,6 +48,7 @@ def explorer(request, project_id, corpus_id):
'corpus' : corpus ,
'maplist_id': maplist_id ,
'view' : 'graph' ,
'user_parameters': node_user.hyperdata,
},
)
......@@ -61,6 +64,7 @@ def myGraphs(request, project_id, corpus_id):
'''
user = cache.User[request.user.id]
node_user = get_node_user(user)
# we pass our corpus
corpus = cache.Node[corpus_id]
......@@ -99,6 +103,7 @@ def myGraphs(request, project_id, corpus_id):
'corpus' : corpus,
'view' : 'myGraph',
'coocs' : coocs,
'coocs_count' : coocs_count
'coocs_count' : coocs_count,
'user_parameters': user_node.hyperdata,
},
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment