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
44e148e7
Commit
44e148e7
authored
Aug 16, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] Workaround to fix error when creating a corpus with a long query
parent
91ad791f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
base.py
gargantext/models/base.py
+21
-1
nodes.py
gargantext/models/nodes.py
+6
-2
No files found.
gargantext/models/base.py
View file @
44e148e7
from
sqlalchemy.schema
import
Column
,
ForeignKey
,
UniqueConstraint
,
Index
from
sqlalchemy.orm
import
relationship
from
sqlalchemy.orm
import
relationship
,
validates
from
sqlalchemy.types
import
TypeDecorator
,
\
Integer
,
Float
,
Boolean
,
DateTime
,
String
,
Text
from
sqlalchemy.dialects.postgresql
import
JSONB
,
DOUBLE_PRECISION
as
Double
...
...
@@ -7,6 +7,7 @@ from sqlalchemy.ext.mutable import MutableDict, MutableList
from
sqlalchemy.ext.declarative
import
declarative_base
__all__
=
[
"Column"
,
"ForeignKey"
,
"UniqueConstraint"
,
"relationship"
,
"validates"
,
"ValidatorMixin"
,
"Integer"
,
"Float"
,
"Boolean"
,
"DateTime"
,
"String"
,
"Text"
,
"TypeDecorator"
,
"JSONB"
,
"Double"
,
...
...
@@ -18,6 +19,25 @@ __all__ = ["Column", "ForeignKey", "UniqueConstraint", "relationship",
# all tables handled by Alembic migration scripts.
Base
=
declarative_base
()
# To be used by tables already handled by Django ORM, such as User model. We
# separate them in order to keep those out of Alembic sight.
DjangoBase
=
declarative_base
()
class
ValidatorMixin
(
object
):
def
enforce_length
(
self
,
key
,
value
):
"""Truncate a string according to its column length
Usage example:
.. code-block:: python
@validates('some_column')
def validate_some_column(self, key, value):
self.enforce_length(key, value)
"""
max_len
=
getattr
(
self
.
__class__
,
key
)
.
prop
.
columns
[
0
]
.
type
.
length
if
value
and
len
(
value
)
>
max_len
:
return
value
[:
max_len
]
return
value
gargantext/models/nodes.py
View file @
44e148e7
...
...
@@ -9,7 +9,7 @@ from datetime import datetime
from
.base
import
Base
,
Column
,
ForeignKey
,
relationship
,
TypeDecorator
,
Index
,
\
Integer
,
Float
,
String
,
DateTime
,
JSONB
,
\
MutableList
,
MutableDict
MutableList
,
MutableDict
,
validates
,
ValidatorMixin
from
.users
import
User
__all__
=
[
'Node'
,
'NodeNode'
,
'CorpusNode'
]
...
...
@@ -26,7 +26,7 @@ class NodeType(TypeDecorator):
return
NODETYPES
[
typeindex
]
class
Node
(
Base
):
class
Node
(
ValidatorMixin
,
Base
):
"""This model can fit many purposes:
myFirstCorpus = session.query(CorpusNode).first()
...
...
@@ -112,6 +112,10 @@ class Node(Base):
'user_id={0.user_id}, parent_id={0.parent_id}, '
\
'name={0.name!r}, date={0.date})>'
.
format
(
self
)
@
validates
(
'name'
)
def
validate_name
(
self
,
key
,
value
):
return
self
.
enforce_length
(
key
,
value
)
@
property
def
ngrams
(
self
):
"""Pseudo-attribute allowing to retrieve a node's ngrams.
...
...
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