2020-06-01 10:00:35 +00:00
|
|
|
from mongoengine import Document, StringField, DateTimeField, BooleanField
|
2019-06-10 21:24:35 +00:00
|
|
|
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database import Database, strict
|
|
|
|
from apiserver.database.fields import StrippedStringField, SafeDictField, SafeSortedListField
|
|
|
|
from apiserver.database.model import DbModelMixin
|
|
|
|
from apiserver.database.model.base import GetMixin
|
|
|
|
from apiserver.database.model.model_labels import ModelLabels
|
|
|
|
from apiserver.database.model.company import Company
|
|
|
|
from apiserver.database.model.project import Project
|
|
|
|
from apiserver.database.model.task.task import Task
|
|
|
|
from apiserver.database.model.user import User
|
2019-06-10 21:24:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Model(DbModelMixin, Document):
|
|
|
|
meta = {
|
2020-04-01 16:20:53 +00:00
|
|
|
"db_alias": Database.backend,
|
|
|
|
"strict": strict,
|
|
|
|
"indexes": [
|
|
|
|
"parent",
|
|
|
|
"project",
|
|
|
|
"task",
|
2020-07-06 18:50:43 +00:00
|
|
|
("company", "framework"),
|
2020-04-01 16:20:53 +00:00
|
|
|
("company", "name"),
|
2020-06-01 08:55:40 +00:00
|
|
|
("company", "user"),
|
2019-06-10 21:24:35 +00:00
|
|
|
{
|
2020-04-01 16:20:53 +00:00
|
|
|
"name": "%s.model.main_text_index" % Database.backend,
|
|
|
|
"fields": ["$name", "$id", "$comment", "$parent", "$task", "$project"],
|
|
|
|
"default_language": "english",
|
|
|
|
"weights": {
|
|
|
|
"name": 10,
|
|
|
|
"id": 10,
|
|
|
|
"comment": 10,
|
|
|
|
"parent": 5,
|
|
|
|
"task": 3,
|
|
|
|
"project": 3,
|
|
|
|
},
|
|
|
|
},
|
2019-06-10 21:24:35 +00:00
|
|
|
],
|
|
|
|
}
|
2020-06-01 08:55:40 +00:00
|
|
|
get_all_query_options = GetMixin.QueryParameterOptions(
|
|
|
|
pattern_fields=("name", "comment"),
|
|
|
|
fields=("ready",),
|
|
|
|
list_fields=(
|
|
|
|
"tags",
|
|
|
|
"system_tags",
|
|
|
|
"framework",
|
|
|
|
"uri",
|
|
|
|
"id",
|
|
|
|
"user",
|
|
|
|
"project",
|
|
|
|
"task",
|
|
|
|
"parent",
|
|
|
|
),
|
|
|
|
)
|
2019-06-10 21:24:35 +00:00
|
|
|
|
|
|
|
id = StringField(primary_key=True)
|
|
|
|
name = StrippedStringField(user_set_allowed=True, min_length=3)
|
2020-04-01 16:20:53 +00:00
|
|
|
parent = StringField(reference_field="Model", required=False)
|
2019-06-10 21:24:35 +00:00
|
|
|
user = StringField(required=True, reference_field=User)
|
|
|
|
company = StringField(required=True, reference_field=Company)
|
|
|
|
project = StringField(reference_field=Project, user_set_allowed=True)
|
|
|
|
created = DateTimeField(required=True, user_set_allowed=True)
|
|
|
|
task = StringField(reference_field=Task)
|
|
|
|
comment = StringField(user_set_allowed=True)
|
2020-06-01 10:00:35 +00:00
|
|
|
tags = SafeSortedListField(StringField(required=True), user_set_allowed=True)
|
|
|
|
system_tags = SafeSortedListField(StringField(required=True), user_set_allowed=True)
|
2020-04-01 16:20:53 +00:00
|
|
|
uri = StrippedStringField(default="", user_set_allowed=True)
|
2019-06-10 21:24:35 +00:00
|
|
|
framework = StringField()
|
|
|
|
design = SafeDictField()
|
|
|
|
labels = ModelLabels()
|
|
|
|
ready = BooleanField(required=True)
|
2020-04-01 16:20:53 +00:00
|
|
|
ui_cache = SafeDictField(
|
|
|
|
default=dict, user_set_allowed=True, exclude_by_default=True
|
|
|
|
)
|
2020-08-10 05:30:40 +00:00
|
|
|
company_origin = StringField(exclude_by_default=True)
|