2021-05-03 14:50:25 +00:00
|
|
|
from mongoengine import (
|
|
|
|
StringField,
|
|
|
|
DateTimeField,
|
|
|
|
BooleanField,
|
2022-03-15 14:18:57 +00:00
|
|
|
EmbeddedDocumentField,
|
2021-05-03 14:50:25 +00:00
|
|
|
)
|
2019-06-10 21:24:35 +00:00
|
|
|
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database import Database, strict
|
2021-05-03 14:50:25 +00:00
|
|
|
from apiserver.database.fields import (
|
|
|
|
StrippedStringField,
|
|
|
|
SafeDictField,
|
|
|
|
SafeSortedListField,
|
2022-03-15 14:18:57 +00:00
|
|
|
SafeMapField,
|
2021-05-03 14:50:25 +00:00
|
|
|
)
|
2022-02-13 17:21:07 +00:00
|
|
|
from apiserver.database.model import AttributedDocument
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database.model.base import GetMixin
|
2021-05-03 14:50:25 +00:00
|
|
|
from apiserver.database.model.metadata import MetadataItem
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database.model.model_labels import ModelLabels
|
|
|
|
from apiserver.database.model.project import Project
|
|
|
|
from apiserver.database.model.task.task import Task
|
2019-06-10 21:24:35 +00:00
|
|
|
|
|
|
|
|
2022-02-13 17:21:07 +00:00
|
|
|
class Model(AttributedDocument):
|
2022-03-15 14:18:57 +00:00
|
|
|
_field_collation_overrides = {
|
|
|
|
"metadata.": AttributedDocument._numeric_locale,
|
|
|
|
}
|
|
|
|
|
2019-06-10 21:24:35 +00:00
|
|
|
meta = {
|
2020-04-01 16:20:53 +00:00
|
|
|
"db_alias": Database.backend,
|
|
|
|
"strict": strict,
|
|
|
|
"indexes": [
|
|
|
|
"parent",
|
|
|
|
"project",
|
|
|
|
"task",
|
2021-05-03 15:02:25 +00:00
|
|
|
"last_update",
|
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"),
|
2022-09-29 16:40:05 +00:00
|
|
|
("company", "uri"),
|
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",
|
2022-03-15 14:18:57 +00:00
|
|
|
"metadata.*",
|
2020-06-01 08:55:40 +00:00
|
|
|
),
|
2021-05-03 15:02:25 +00:00
|
|
|
datetime_fields=("last_update",),
|
2020-06-01 08:55:40 +00:00
|
|
|
)
|
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
|
|
|
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)
|
2021-05-03 15:02:25 +00:00
|
|
|
last_update = DateTimeField()
|
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)
|
2022-03-15 14:18:57 +00:00
|
|
|
metadata = SafeMapField(
|
|
|
|
field=EmbeddedDocumentField(MetadataItem), user_set_allowed=True
|
2021-05-03 14:50:25 +00:00
|
|
|
)
|
2022-11-29 15:34:06 +00:00
|
|
|
|
|
|
|
def get_index_company(self) -> str:
|
|
|
|
return self.company or self.company_origin or ""
|