Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
2c5b3da6
Commit
2c5b3da6
authored
Nov 16, 2014
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUGFIX] Had to fix the python library "cte_node"
(see init/post-install-fixes.README for more details)
parent
89762429
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
20 deletions
+72
-20
api.py
gargantext_web/api.py
+10
-17
post-install-fixes.README
init/post-install-fixes.README
+57
-0
models.py
node/models.py
+5
-3
No files found.
gargantext_web/api.py
View file @
2c5b3da6
...
...
@@ -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
=
[]
...
...
init/post-install-fixes.README
0 → 100644
View file @
2c5b3da6
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
node/models.py
View file @
2c5b3da6
...
...
@@ -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
.
CTE
QuerySet
):
"""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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment