-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.py
executable file
·86 lines (65 loc) · 1.91 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Базовая модель через которую будет происходить обращение к базе данных
from symbol import yield_arg
import bson
import motor
from system.utils.loader import Loader
from tornado.concurrent import return_future
from tornado import gen
import system.configuration
class BaseModel(motor.MotorCollection, Loader):
_client = None
_collection = None
def __init__(self):
"""
:return:
"""
self.__get_db()
self._collection = self.__get_collection(self.get_name_collection())
motor.MotorCollection.__init__(self, self._client, self.get_name_collection())
Loader.__init__(self)
def __get_db(self, db_name=None):
"""
:param db_name:
:return:
"""
if db_name is None:
db_name = system.configuration.DB_NAME
self._client = motor.MotorClient(system.configuration.DB_HOST, system.configuration.DB_PORT)[db_name]
def __get_collection(self, collection_name):
"""
Инициализация коллекции для определенной модели
:param collection_name:
:return:
"""
return self._client[collection_name]
def get_name_collection(self):
"""
Название коллекции
:return:
"""
pass
def references(self):
"""
Описание ссылок на другие модели
:return:
"""
pass
def save(self):
self.insert(self.get_data())
def one(self, *args, **kwargs):
return self.find_one(*args, **kwargs)
class ErrorModel(Exception):
"""
All error class
"""
pass
class FailedOperationsDB(ErrorModel):
"""
Operation not executed
"""
pass
class SuccessOperationDB(ErrorModel):
"""
Operation completed successfully
"""
pass