Commit cbfe3da3 authored by delanoe's avatar delanoe

[FIX] Editing ngrams (post/create, delete) with lists

parent 8c0e06ad
...@@ -12,7 +12,6 @@ from rest_framework.renderers import JSONRenderer ...@@ -12,7 +12,6 @@ from rest_framework.renderers import JSONRenderer
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException
from rest_framework.authentication import SessionAuthentication, BasicAuthentication from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from node.models import Node from node.models import Node
from gargantext_web.db import * from gargantext_web.db import *
from ngram.lists import listIds, listNgramIds from ngram.lists import listIds, listNgramIds
...@@ -30,7 +29,6 @@ def main(request, project_id, corpus_id, document_id): ...@@ -30,7 +29,6 @@ def main(request, project_id, corpus_id, document_id):
'nodes_api_url': urljoin(request.get_host(), '/api/'), 'nodes_api_url': urljoin(request.get_host(), '/api/'),
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
class NgramList(APIView): class NgramList(APIView):
"""Read and Write Annotations""" """Read and Write Annotations"""
renderer_classes = (JSONRenderer,) renderer_classes = (JSONRenderer,)
...@@ -59,7 +57,6 @@ class NgramList(APIView): ...@@ -59,7 +57,6 @@ class NgramList(APIView):
}} }}
return Response(data) return Response(data)
class NgramEdit(APIView): class NgramEdit(APIView):
""" """
Actions on one existing Ngram in one list Actions on one existing Ngram in one list
...@@ -67,34 +64,39 @@ class NgramEdit(APIView): ...@@ -67,34 +64,39 @@ class NgramEdit(APIView):
renderer_classes = (JSONRenderer,) renderer_classes = (JSONRenderer,)
authentication_classes = (SessionAuthentication, BasicAuthentication) authentication_classes = (SessionAuthentication, BasicAuthentication)
def post(self, request, list_id, ngram_id): def post(self, request, list_id, ngram_ids):
""" """
Edit an existing NGram in a given list Edit an existing NGram in a given list
""" """
list_id = int(list_id) list_id = int(list_id)
ngram_id = int(ngram_id)
# TODO remove the node_ngram from another conflicting list # TODO remove the node_ngram from another conflicting list
# FIXME session.query(Node_Ngram).filter(Node_Ngram.ngram_id==ngram_id).delete() # FIXME session.query(Node_Ngram).filter(Node_Ngram.ngram_id==ngram_id).delete()
# add the ngram to the list # add the ngram to the list
node_ngram = Node_Ngram(node_id=list_id, ngram_id=ngram_id, weight=1.0) for ngram_id in ngram_ids:
session.add(node_ngram) ngram_id = int(ngram_id)
node_ngram = Node_Ngram(node_id=list_id, ngram_id=ngram_id, weight=1.0)
session.add(node_ngram)
session.commit() session.commit()
# return the response # return the response
return Response({ return Response({
'uuid': ngram_id, 'uuid': ngram_id,
'list_id': list_id, 'list_id': list_id,
}) for ngram_id in ngram_ids})
def delete(self, request, list_id, ngram_id): def delete(self, request, list_id, ngram_ids):
""" """
Delete a ngram from a list Delete a ngram from a list
""" """
session.query(Node_Ngram).filter(Node_Ngram.node_id==list_id).filter(Node_Ngram.ngram_id==ngram_id).delete() for ngram_id in ngram_ids:
(session.query(Node_Ngram)
.filter(Node_Ngram.node_id==list_id)
.filter(Node_Ngram.ngram_id==ngram_id).delete()
)
session.commit() session.commit()
return Response(None, 204) return Response(None, 204)
class NgramCreate(APIView): class NgramCreate(APIView):
""" """
Create a new Ngram in one list Create a new Ngram in one list
...@@ -139,7 +141,6 @@ class NgramCreate(APIView): ...@@ -139,7 +141,6 @@ class NgramCreate(APIView):
'list_id': list_id, 'list_id': list_id,
}) })
def deleteMultiple(request, list_id): def deleteMultiple(request, list_id):
results = ["hola","mundo"] results = ["hola","mundo"]
...@@ -150,8 +151,14 @@ def deleteMultiple(request, list_id): ...@@ -150,8 +151,14 @@ def deleteMultiple(request, list_id):
if request.POST: if request.POST:
todel_ids = json.loads(request.POST['to_delete']) todel_ids = json.loads(request.POST['to_delete'])
for ngram_id in todel_ids: for ngram_id in todel_ids:
# add the ngram to the list if not already done # add the ngram to the list if not already done
node_ngram = session.query(Node_Ngram).filter(Node_Ngram.node_id==list_id).filter(Node_Ngram.ngram_id==ngram_id).first() node_ngram = (session.query(Node_Ngram)
.filter(Node_Ngram.node_id==list_id)
.filter(Node_Ngram.ngram_id==ngram_id)
.first()
)
if node_ngram is None: if node_ngram is None:
node_ngram = Node_Ngram(node_id=list_id, ngram_id=ngram_id, weight=1.0) node_ngram = Node_Ngram(node_id=list_id, ngram_id=ngram_id, weight=1.0)
session.add(node_ngram) session.add(node_ngram)
...@@ -159,8 +166,6 @@ def deleteMultiple(request, list_id): ...@@ -159,8 +166,6 @@ def deleteMultiple(request, list_id):
return JsonHttpResponse(results) return JsonHttpResponse(results)
class Document(APIView): class Document(APIView):
""" """
Read-only Document view, similar to /api/nodes/ Read-only Document view, similar to /api/nodes/
......
A
ABOUT
ABOVE
ACCORDING
ACROSS
ACTUAL
ADDED
AFTER
AGAINST
AHEAD
ALL
ALMOST
ALONE
ALONG
ALSO
AMONG
AMONGST
AN
AND
AND-OR
AND/OR
ANON
ANOTHER
ANY
ARE
ARISING
AROUND
AS
AT
AWARD
AWAY
BE
BECAUSE
BECOME
BECOMES
BEEN
BEFORE
BEHIND
BEING
BELOW
BEST
BETTER
BETWEEN
BEYOND
BIRTHDAY
BOTH
BUT
BY
CAN
CERTAIN
COME
COMES
COMING
COMPLETELY
CONCERNING
CONSIDER
CONSIDERED
CONSIDERING
CONSISTING
DE
DEPARTMENT
DER
DESPITE
DISCUSSION
DO
DOES
DOESNT
DOING
DOWN
DR
DU
DUE
DURING
EACH
EITHER
ESPECIALLY
ET
FEW
FOR
FORWARD
FROM
FURTHER
GET
GIVE
GIVEN
GIVING
HAS
HAVE
HAVING
HIS
HONOR
HOW
IN
INSIDE
INSTEAD
INTO
IS
IT
ITEMS
ITS
JUST
LET
LETS
LITTLE
LOOK
LOOKS
MADE
MAKE
MAKES
MAKING
MANY
MEET
MEETS
MORE
MOST
MUCH
MUST
MY
NEAR
NEARLY
NEXT
NOT
NOW
OF
OFF
ON
ONLY
ONTO
OR
OTHER
OUR
OUT
OUTSIDE
OVER
OVERALL
PER
POSSIBLY
PT
PUT
REALLY
REGARDING
REPRINTED
SAME
SEEN
SEVERAL
SHOULD
SHOWN
SINCE
SO-CALLED
SOME
SPP
STUDIES
STUDY
SUCH
TAKE
TAKEN
TAKES
TAKING
THAN
THAT
THE
THEIR
THEM
THEN
THERE
THEREFROM
THESE
THEY
THIS
THOSE
THROUGH
THROUGHOUT
TO
TOGETHER
TOWARD
TOWARDS
UNDER
UNDERGOING
UP
UPON
UPWARD
VARIOUS
VERSUS
VERY
VIA
VOL
VOLS
VS
WAS
WAY
WAYS
WE
WERE
WHAT
WHATS
WHEN
WHERE
WHICH
WHILE
WHITHER
WHO
WHOM
WHOS
WHOSE
WHY
WITH
WITHIN
WITHOUT
YET
YOU
YOUR
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