Commit 2c5b3da6 authored by Mathieu Rodic's avatar Mathieu Rodic

[BUGFIX] Had to fix the python library "cte_node"

(see init/post-install-fixes.README for more details)
parent 89762429
......@@ -36,6 +36,8 @@ class CorpusController:
except:
raise ValidationError('Corpora are identified by an integer.', 400)
corpusQuery = Node.objects.filter(id = corpus_id)
# print(str(corpusQuery))
# raise Http404("C'est toujours ça de pris.")
if not corpusQuery:
raise Http404("No such corpus: %d" % (corpus_id, ))
corpus = corpusQuery.first()
......@@ -44,23 +46,14 @@ class CorpusController:
return corpus
@classmethod
def get_children(cls, corpus_id):
def get_descendants(cls, corpus_id):
corpus = cls.get(corpus_id)
children = Node.objects.descendants(corpus)
# children = Node.objects.filter(id=corpus_id).descendants()
# children = cls.get(corpus_id).descendants()
# childrenQuery = (cls.get(corpus_id)
# .children
# # .children()
# # .filter()
# .all()
# )
return HttpResponse("str(children.query)")
return HttpResponse(str(children.query))
# return childrenQuery
children = corpus.descendants().filter(type__name = "Document")
test = []
for child in children:
test.append(child.name)
return JsonHttpResponse(test)
return HttpResponse(str(children.count() ))
@classmethod
def ngrams(cls, request, corpus_id):
......@@ -113,7 +106,7 @@ class CorpusController:
@classmethod
def data(cls, request, corpus_id):
# parameters retrieval and validation
return cls.get_children(corpus_id)
return cls.get_descendants(corpus_id)
corpus = cls.get(corpus_id)
# query building: initialization
columns = []
......
POST-INSTALL FIXES
==================
The Python library "cte_node" is full of bugs.
Here are a few fixes, necessary for the library to work properly.
They apply to cte_tree/models.py
def maybe_cast(field):
# If the ordering information specified a type to cast
# to, then use this type immediately, otherwise
# determine whether a variable-length character field
# should be cast into TEXT or if no casting is
# necessary. A None type defaults to the latter.
if type(field) == tuple and not field[1] is None:
return 'CAST (T."%s" AS %s)' % field
else:
if type(field) == tuple:
name = field[0]
else:
name = field
if self.query.model._meta.get_field_by_name(name)[
0].db_type().startswith('varchar'):
return 'CAST (T."%s" AS TEXT)' % name
else:
return 'T."%s"' % name
...shall become...
def maybe_cast(field):
# If the ordering information specified a type to cast
# to, then use this type immediately, otherwise
# determine whether a variable-length character field
# should be cast into TEXT or if no casting is
# necessary. A None type defaults to the latter.
if type(field) == tuple and not field[1] is None:
return 'CAST (T."%s" AS %s)' % field
else:
if type(field) == tuple:
name = field[0]
else:
name = field
return 'T."%s"' % name
...and you should replace...
def maybe_alias(table):
if self.query.table_map.has_key(table):
return self.query.table_map[table][0]
return table
...with...
def maybe_alias(table):
if table in self.query.table_map:
return self.query.table_map[table][0]
return table
\ No newline at end of file
......@@ -4,7 +4,8 @@ from django.utils import timezone
from django.contrib.auth.models import User
from django_hstore import hstore
from cte_tree.models import CTENode, CTENodeManager
from cte_tree.models import CTENode, CTENodeManager
# from cte_tree.query import CTEQuerySet
#from cte_tree.fields import DepthField, PathField, OrderingField
from parsing.Caches import LanguagesCache, NgramsExtractorsCache, NgramsCaches
......@@ -58,7 +59,7 @@ class NodeType(models.Model):
def __str__(self):
return self.name
class NodeQuerySet(models.query.QuerySet):
class NodeQuerySet(CTENodeManager.CTEQuerySet):
"""Methods available from Node querysets."""
def extract_ngrams(self, keys, ngramsextractorscache=None, ngramscaches=None):
if ngramsextractorscache is None:
......@@ -71,7 +72,8 @@ class NodeQuerySet(models.query.QuerySet):
class NodeManager(CTENodeManager):
"""Methods available from Node.object."""
def get_queryset(self):
return NodeQuerySet(self.model)
self._ensure_parameters()
return NodeQuerySet(self.model, using=self._db)
def __getattr__(self, name, *args):
if name.startswith("_"):
raise AttributeError
......
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