Commit 4a565104 authored by c24b's avatar c24b

Generic fonction get_node_user(user) for both

parent 34c0afda
......@@ -7,6 +7,16 @@ 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")
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
def _get_user_project_corpus(request, project_id, corpus_id):
"""Helper method to get a corpus, knowing the project's and corpus' ID.
......@@ -42,7 +52,7 @@ def docs_by_titles(request, project_id, corpus_id):
'resourcename' : get_resource(source_type)['name'],
'view': 'titles',
'user': request.user,
'user_parameters': node_user.hyperdata
'user_parameters': get_node_user(user)["hyperdata"]
},
)
......@@ -58,9 +68,9 @@ def docs_by_sources(request, project_id, corpus_id):
# and the project just for project.id in corpusBannerTop
project = cache.Node[project_id]
user = cache.User[request.user.id]
source_type = corpus.resources()[0]['type']
node_user = session.query(Node).filter(Node.user_id == user.id & Node.typename== "USER")
# rendered page : sources.html
return render(
template_name = 'pages/corpora/sources.html',
......@@ -72,7 +82,7 @@ def docs_by_sources(request, project_id, corpus_id):
'corpus' : corpus,
'resourcename' : get_resource(source_type)['name'],
'user': request.user,
"user_parameters": node_user.hyperdata,
'user_parameters': get_node_user(user)["hyperdata"]
'view': 'sources'
},
)
......@@ -89,9 +99,9 @@ def docs_by_authors(request, project_id, corpus_id):
# and the project just for project.id in corpusBannerTop
project = cache.Node[project_id]
user = cache.User[request.user.id]
source_type = corpus.resources()[0]['type']
node_user = session.query(Node).filter(Node.user_id == user.id & Node.typename== "USER")
# rendered page : sources.html
return render(
template_name = 'pages/corpora/authors.html',
......@@ -104,7 +114,7 @@ def docs_by_authors(request, project_id, corpus_id):
'resourcename' : get_resource(source_type)['name'],
'view': 'authors',
'user': request.user,
"user_parameters": node_user.hyperdata
'user_parameters': get_node_user(user)["hyperdata"]
},
)
......@@ -116,7 +126,7 @@ def analytics(request, project_id, corpus_id):
return HttpResponseForbidden()
source_type = corpus.resources()[0]['type']
node_user = session.query(Node).filter(Node.user_id == user.id & Node.typename== "USER")
# response!
return render(
template_name = 'pages/analytics/histories.html',
......@@ -129,6 +139,6 @@ def analytics(request, project_id, corpus_id):
'resourcename' : get_resource(source_type)['name'],
'view': 'analytics',
'user': request.user,
'user_parameters': node_user.hyperdata,
'user_parameters': get_node_user(user)["hyperdata"]
},
)
......@@ -13,6 +13,15 @@ from collections import defaultdict
from django.utils.translation import ugettext_lazy
import re
def get_node_user(user):
node_user = session.query(Node).filter(Node.user_id == user.id & Node.typename== "USER")
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 overview(request):
......@@ -22,15 +31,7 @@ def overview(request):
'''
user = cache.User[request.user.id]
node_user_id = session.query(Node.id).filter(Node.user_id == user.id & Node.typename== "USER")
if node_user_id is None:
node_user = Node(typename== "USER", user_id = user.id, name= request.user.name)
#default language for now is 'fr'
node_user.hyperdata["language"] = "fr"
session.add(node_user)
session.commit()
node_user_id = node_user.id
node_user = get_node_user(user)
# If POST method, creates a new project...
if request.method == 'POST':
name = str(request.POST['name'])
......@@ -39,13 +40,12 @@ def overview(request):
user_id = user.id,
typename = 'PROJECT',
name = name,
parent_id = node_user_id,
parent_id = node_user.id,
)
session.add(new_project)
session.commit()
user_parameters = session.query(Node).filter(Node.id == node_user_id
& Node.typename == "USER")["hyperdata"]
# list of projects created by the logged user
user_projects = user.nodes(typename='PROJECT', order=True)
......@@ -62,7 +62,7 @@ def overview(request):
# projects owned by the user
'number': user_projects.count(),
'projects': user_projects,
"user_parameters":user_parameters,
"user_parameters":node_user["hyperdata"],
# projects owned by the user's contacts
'common_users': (contact for contact, projects in contacts_projects),
'common_projects': sum((projects for contact, projects in contacts_projects), []),
......@@ -102,6 +102,7 @@ def project(request, project_id):
# security check
project = session.query(Node).filter(Node.id == project_id).first()
user = cache.User[request.user.id]
node_user = get_node_user(user)
if project is None:
raise Http404()
......@@ -183,7 +184,7 @@ def project(request, project_id):
'form': NewCorpusForm,
'user': request.user,
"user_parameters":user_parameters,
"user_parameters":node_user["hyperdata"],
'date': datetime.now(),
'project': project,
'donut': donut,
......@@ -203,7 +204,7 @@ def project(request, project_id):
template_name = 'pages/projects/project.html',
request = request,
context = {
"user_parameters":user_parameters,
"user_parameters":node_user["hyperdata"],
'form': NewCorpusForm,
'user': request.user,
'date': datetime.now(),
......
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