Commit 90dd952b authored by Mathieu Rodic's avatar Mathieu Rodic

[FEAT] started working on the `/projects/(\d+)` page

[CODE] more cleaning (espacially in the views)
parent 0f8fc1ea
...@@ -34,6 +34,7 @@ class User(Base): ...@@ -34,6 +34,7 @@ class User(Base):
def get_nodes(self, nodetype=None): def get_nodes(self, nodetype=None):
"""get all nodes belonging to the user""" """get all nodes belonging to the user"""
# ↓ this below is a workaround because of Python's lame import system
from .nodes import Node from .nodes import Node
query = (session query = (session
.query(Node) .query(Node)
...@@ -54,7 +55,7 @@ class Contact(Base): ...@@ -54,7 +55,7 @@ class Contact(Base):
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
user1_id = Column(Integer, primary_key=True) user1_id = Column(Integer, primary_key=True)
user2_id = Column(Integer, primary_key=True) user2_id = Column(Integer, primary_key=True)
is_blocked = Column(Boolean()) is_blocked = Column(Boolean(), default=False)
date_creation = DateTime(timezone=False) date_creation = Column(DateTime(timezone=False))
__table_args__ = (UniqueConstraint('user1_id', 'user2_id'), ) __table_args__ = (UniqueConstraint('user1_id', 'user2_id'), )
from django.template.loader import get_template from django.template.loader import get_template
from django.template import Context, RequestContext
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseForbidden from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
......
...@@ -4,45 +4,40 @@ from django.contrib import auth ...@@ -4,45 +4,40 @@ from django.contrib import auth
def login(request): def login(request):
"""Performs user login
logout(request) """
username = password = '' auth.logout(request)
# if the user wants to access the login form
next_page = "" if request.method == 'GET':
if request.method == "GET":
additional_context = {} additional_context = {}
# if for exemple: auth/?next=/project/5/corpus/554/document/556/ # if for exemple: auth/?next=/project/5/corpus/554/document/556/
# => we'll forward ?next="..." into template with form # => we'll forward ?next="..." into template with form
if ('next' in request.GET): if 'next' in request.GET:
additional_context = {'next_page':request.GET['next']} additional_context = {'next_page':request.GET['next']}
return render_to_response('pages/auth/login.html', return render(
additional_context, template_name = 'pages/auth/login.html',
context_instance=RequestContext(request) request = request,
) context = additional_context,
)
# if the user send her authentication data to the page
elif request.method == "POST": elif request.method == "POST":
username = request.POST['username'] # /!\ pass is sent clear in POST data: use SSL
user = auth.authenticate(
# /!\ pass is sent clear in POST data username = request.POST['username'],
password = request.POST['password'] password = request.POST['password']
)
user = auth.authenticate(username=username, password=password) if user is not None and user.is_active:
if user is not None: auth.login(request, user)
# if "next" forwarded from the GET via the template form
if user.is_active: if 'the_next_page' in request.POST:
auth.login(request, user) return redirect(request.POST['the_next_page'])
else:
# if "next" forwarded from the GET via the template form return redirect('/projects/')
if ('the_next_page' in request.POST):
return HttpResponseRedirect(request.POST['the_next_page'])
else:
return HttpResponseRedirect('/projects/')
def logout(request): def logout(request):
'''Logout the user, and redirect to main page """Logout the user, and redirect to main page
''' """
auth.logout(request) auth.logout(request)
return HttpResponseRedirect('/') return redirect('/')
...@@ -9,49 +9,45 @@ def home(request): ...@@ -9,49 +9,45 @@ def home(request):
A video draws the narratives. A video draws the narratives.
If not logged a project test is shown. If not logged a project test is shown.
''' '''
template = get_template('pages/main/home.html') return render(
user = request.user template_name = 'pages/main/home.html',
date = datetime.datetime.now() request = request,
html = t.render(Context({ context = {
'debug': settings.DEBUG, 'debug': settings.DEBUG,
'user': user, 'user': request.user,
'date': date, 'date': datetime.datetime.now(),
'paragraph_gargantua': paragraphs.gargantua(), 'paragraph_gargantua': paragraphs.gargantua(),
'paragraph_lorem' : paragraphs.lorem(), 'paragraph_lorem' : paragraphs.lorem(),
'paragraph_tutoreil': paragraphs.tutoreil(), 'paragraph_tutoreil': paragraphs.tutoreil(),
})) },
return HttpResponse(html) )
def about(request): def about(request):
'''About Gargantext, its team and sponsors '''About Gargantext, its team and sponsors
''' '''
template = get_template('pages/main/about.html') return render(
user = request.user template_name = 'pages/main/about.html',
date = datetime.datetime.now() request = request,
context = {
html = template.render(Context({ 'user': request.user,
'user': user, 'date': datetime.datetime.now(),
'date': date, 'team': credits.members(),
'team': credits.members(), 'institutions': credits.institutions(),
'institutions': credits.institutions(), 'labos': credits.labs(),
'labos': credits.labs(), 'grants': credits.grants(),
'grants': credits.grants(), },
})) )
return HttpResponse(html)
def maintenance(request): def maintenance(request):
'''Gargantext out of service '''Gargantext out of service
''' '''
template = get_template('pages/main/maintenance.html') return render(
user = request.user template_name = 'pages/main/maintenance.html',
date = datetime.datetime.now() request = request,
context = {
html = template.render(Context({\ 'user': request.user,
'user': user,\ 'date': datetime.datetime.now(),
'date': date,\ },
})) )
return HttpResponse(html)
...@@ -58,3 +58,21 @@ def overview(request): ...@@ -58,3 +58,21 @@ def overview(request):
'common_projects': contacts_projects if len(contacts_projects) else False, 'common_projects': contacts_projects if len(contacts_projects) else False,
}, },
) )
@requires_auth
def project(request, project_id):
return render(
template_name = 'pages/projects/project.html',
request = request,
context = {
# 'debug': settings.DEBUG,
# 'date': datetime.now(),
# # projects owned by the user
# 'number': len(user_projects),
# 'projects': user_projects,
# # projects owned by the user's contacts
# 'common_users': contacts if len(contacts) else False,
# 'common_projects': contacts_projects if len(contacts_projects) else False,
},
)
...@@ -16,5 +16,6 @@ urlpatterns = [ ...@@ -16,5 +16,6 @@ urlpatterns = [
# overview on projects # overview on projects
url(r'^projects/?$', projects.overview), url(r'^projects/?$', projects.overview),
url(r'^projects/(\d+)/?$', projects.project),
] ]
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
<li><a href="/projects/" title="All your projects are here.">Projects</a></li> <li><a href="/projects/" title="All your projects are here.">Projects</a></li>
{% endif %} {% endif %}
{% if project %} {% if project %}
<li><a href="/project/{{project.id}}">{{project.name}}</a></li> <li><a href="/projects/{{project.id}}">{{project.name}}</a></li>
{% endif %} {% endif %}
{% if corpus %} {% if corpus %}
<li><a href="/project/{{project.id}}/corpus/{{corpus.id}}">{{corpus.name}}</a></li> <li><a href="/projects/{{project.id}}/corpora/{{corpus.id}}">{{corpus.name}}</a></li>
{% endif %} {% endif %}
</ul> </ul>
......
...@@ -46,13 +46,13 @@ ...@@ -46,13 +46,13 @@
{% for project in projects %} {% for project in projects %}
<!--<div class="col-md-offset-7 col-md-4 content" style="background-color:grey">!--> <!--<div class="col-md-offset-7 col-md-4 content" style="background-color:grey">!-->
<div class="col-md-3 content"> <div class="col-md-3 content">
<h3><a href="/project/{{ project.id }}">{{ project.name }}</a> <h3><a href="/projects/{{ project.id }}">{{ project.name }}</a>
<button type="button" class="btn btn-xs btn-default" data-container="body" data-toggle="popover" data-placement="bottom" <button type="button" class="btn btn-xs btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content=' data-content='
<ul> <ul>
<li> Rename </li> <li> Rename </li>
<li><a href="/project/{{ project.id }}">Add new corpus</a></li> <li><a href="/projects/{{ project.id }}">Add new corpus</a></li>
<li><a href="/delete/{{ project.id }}">Delete</a></li> <li><a href="/delete/{{ project.id }}">Delete</a></li>
</ul> </ul>
'>Manage</button> '>Manage</button>
...@@ -73,12 +73,12 @@ ...@@ -73,12 +73,12 @@
{% for project in common_projects %} {% for project in common_projects %}
<!--<div class="col-md-offset-7 col-md-4 content" style="background-color:grey">!--> <!--<div class="col-md-offset-7 col-md-4 content" style="background-color:grey">!-->
<div class="col-md-3 content"> <div class="col-md-3 content">
<h3><a href="/project/{{ project.id }}">{{ project.name }}</a> <h3><a href="/projects/{{ project.id }}">{{ project.name }}</a>
<button type="button" class="btn btn-xs btn-default" data-container="body" data-toggle="popover" data-placement="bottom" <button type="button" class="btn btn-xs btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content=' data-content='
<ul> <ul>
<li> Rename </li> <li> Rename </li>
<li><a href="/project/{{ project.id }}">Add new corpus</a></li> <li><a href="/projects/{{ project.id }}">Add new corpus</a></li>
<li><a href="/delete/{{ project.id }}">Delete</a></li> <li><a href="/delete/{{ project.id }}">Delete</a></li>
</ul> </ul>
'>Manage</button> '>Manage</button>
......
This diff is collapsed.
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