masonite-framework-orm 3.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- masonite_framework_orm-3.0.1.dist-info/METADATA +87 -0
- masonite_framework_orm-3.0.1.dist-info/RECORD +116 -0
- masonite_framework_orm-3.0.1.dist-info/WHEEL +5 -0
- masonite_framework_orm-3.0.1.dist-info/entry_points.txt +3 -0
- masonite_framework_orm-3.0.1.dist-info/licenses/LICENSE +21 -0
- masonite_framework_orm-3.0.1.dist-info/top_level.txt +1 -0
- masoniteorm/__init__.py +1 -0
- masoniteorm/collection/Collection.py +605 -0
- masoniteorm/collection/__init__.py +1 -0
- masoniteorm/commands/CanOverrideConfig.py +16 -0
- masoniteorm/commands/CanOverrideOptionsDefault.py +22 -0
- masoniteorm/commands/Command.py +6 -0
- masoniteorm/commands/Entry.py +43 -0
- masoniteorm/commands/MakeMigrationCommand.py +57 -0
- masoniteorm/commands/MakeModelCommand.py +78 -0
- masoniteorm/commands/MakeModelDocstringCommand.py +37 -0
- masoniteorm/commands/MakeObserverCommand.py +54 -0
- masoniteorm/commands/MakeSeedCommand.py +54 -0
- masoniteorm/commands/MigrateCommand.py +46 -0
- masoniteorm/commands/MigrateFreshCommand.py +41 -0
- masoniteorm/commands/MigrateRefreshCommand.py +41 -0
- masoniteorm/commands/MigrateResetCommand.py +25 -0
- masoniteorm/commands/MigrateRollbackCommand.py +26 -0
- masoniteorm/commands/MigrateStatusCommand.py +51 -0
- masoniteorm/commands/SeedRunCommand.py +35 -0
- masoniteorm/commands/ShellCommand.py +205 -0
- masoniteorm/commands/__init__.py +18 -0
- masoniteorm/commands/stubs/create_migration.stub +20 -0
- masoniteorm/commands/stubs/create_seed.stub +9 -0
- masoniteorm/commands/stubs/model.stub +9 -0
- masoniteorm/commands/stubs/observer.stub +101 -0
- masoniteorm/commands/stubs/table_migration.stub +19 -0
- masoniteorm/config.py +123 -0
- masoniteorm/connections/BaseConnection.py +101 -0
- masoniteorm/connections/ConnectionFactory.py +59 -0
- masoniteorm/connections/ConnectionResolver.py +132 -0
- masoniteorm/connections/MSSQLConnection.py +176 -0
- masoniteorm/connections/MySQLConnection.py +232 -0
- masoniteorm/connections/PostgresConnection.py +225 -0
- masoniteorm/connections/SQLiteConnection.py +179 -0
- masoniteorm/connections/__init__.py +6 -0
- masoniteorm/exceptions.py +38 -0
- masoniteorm/expressions/__init__.py +1 -0
- masoniteorm/expressions/expressions.py +288 -0
- masoniteorm/factories/Factory.py +112 -0
- masoniteorm/factories/__init__.py +1 -0
- masoniteorm/helpers/__init__.py +0 -0
- masoniteorm/helpers/misc.py +22 -0
- masoniteorm/migrations/Migration.py +330 -0
- masoniteorm/migrations/__init__.py +1 -0
- masoniteorm/models/MigrationModel.py +9 -0
- masoniteorm/models/Model.py +1209 -0
- masoniteorm/models/Model.pyi +1366 -0
- masoniteorm/models/Pivot.py +5 -0
- masoniteorm/models/__init__.py +1 -0
- masoniteorm/observers/ObservesEvents.py +27 -0
- masoniteorm/observers/__init__.py +1 -0
- masoniteorm/pagination/BasePaginator.py +10 -0
- masoniteorm/pagination/LengthAwarePaginator.py +34 -0
- masoniteorm/pagination/SimplePaginator.py +28 -0
- masoniteorm/pagination/__init__.py +2 -0
- masoniteorm/providers/ORMProvider.py +39 -0
- masoniteorm/providers/__init__.py +1 -0
- masoniteorm/query/EagerRelation.py +42 -0
- masoniteorm/query/QueryBuilder.py +2486 -0
- masoniteorm/query/__init__.py +1 -0
- masoniteorm/query/grammars/BaseGrammar.py +1027 -0
- masoniteorm/query/grammars/MSSQLGrammar.py +194 -0
- masoniteorm/query/grammars/MySQLGrammar.py +238 -0
- masoniteorm/query/grammars/PostgresGrammar.py +213 -0
- masoniteorm/query/grammars/SQLiteGrammar.py +228 -0
- masoniteorm/query/grammars/__init__.py +4 -0
- masoniteorm/query/processors/MSSQLPostProcessor.py +58 -0
- masoniteorm/query/processors/MySQLPostProcessor.py +48 -0
- masoniteorm/query/processors/PostgresPostProcessor.py +49 -0
- masoniteorm/query/processors/SQLitePostProcessor.py +49 -0
- masoniteorm/query/processors/__init__.py +4 -0
- masoniteorm/relationships/BaseRelationship.py +161 -0
- masoniteorm/relationships/BelongsTo.py +124 -0
- masoniteorm/relationships/BelongsToMany.py +604 -0
- masoniteorm/relationships/HasMany.py +66 -0
- masoniteorm/relationships/HasManyThrough.py +269 -0
- masoniteorm/relationships/HasOne.py +111 -0
- masoniteorm/relationships/HasOneThrough.py +275 -0
- masoniteorm/relationships/MorphMany.py +152 -0
- masoniteorm/relationships/MorphOne.py +156 -0
- masoniteorm/relationships/MorphTo.py +111 -0
- masoniteorm/relationships/MorphToMany.py +108 -0
- masoniteorm/relationships/__init__.py +10 -0
- masoniteorm/schema/Blueprint.py +1161 -0
- masoniteorm/schema/Column.py +144 -0
- masoniteorm/schema/ColumnDiff.py +0 -0
- masoniteorm/schema/Constraint.py +5 -0
- masoniteorm/schema/ForeignKeyConstraint.py +28 -0
- masoniteorm/schema/Index.py +5 -0
- masoniteorm/schema/Schema.py +359 -0
- masoniteorm/schema/Table.py +94 -0
- masoniteorm/schema/TableDiff.py +86 -0
- masoniteorm/schema/__init__.py +3 -0
- masoniteorm/schema/platforms/MSSQLPlatform.py +367 -0
- masoniteorm/schema/platforms/MySQLPlatform.py +513 -0
- masoniteorm/schema/platforms/Platform.py +97 -0
- masoniteorm/schema/platforms/PostgresPlatform.py +551 -0
- masoniteorm/schema/platforms/SQLitePlatform.py +481 -0
- masoniteorm/schema/platforms/__init__.py +4 -0
- masoniteorm/scopes/BaseScope.py +6 -0
- masoniteorm/scopes/SoftDeleteScope.py +56 -0
- masoniteorm/scopes/SoftDeletesMixin.py +13 -0
- masoniteorm/scopes/TimeStampsMixin.py +12 -0
- masoniteorm/scopes/TimeStampsScope.py +47 -0
- masoniteorm/scopes/UUIDPrimaryKeyMixin.py +8 -0
- masoniteorm/scopes/UUIDPrimaryKeyScope.py +51 -0
- masoniteorm/scopes/__init__.py +8 -0
- masoniteorm/scopes/scope.py +15 -0
- masoniteorm/seeds/Seeder.py +42 -0
- masoniteorm/seeds/__init__.py +1 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
from ..helpers.misc import deprecated
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class QueryExpression:
|
|
5
|
+
"""A helper class to manage query expressions."""
|
|
6
|
+
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
column,
|
|
10
|
+
equality,
|
|
11
|
+
value,
|
|
12
|
+
value_type="value",
|
|
13
|
+
keyword=None,
|
|
14
|
+
raw=False,
|
|
15
|
+
bindings=(),
|
|
16
|
+
):
|
|
17
|
+
self.column = column
|
|
18
|
+
self.equality = equality
|
|
19
|
+
self.value = value
|
|
20
|
+
self.value_type = value_type
|
|
21
|
+
self.keyword = keyword
|
|
22
|
+
self.raw = raw
|
|
23
|
+
self.bindings = bindings
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class HavingExpression:
|
|
27
|
+
"""A helper class to manage having expressions."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, column, equality=None, value=None, raw=False):
|
|
30
|
+
self.column = column
|
|
31
|
+
self.raw = raw
|
|
32
|
+
|
|
33
|
+
if equality and not value:
|
|
34
|
+
value = equality
|
|
35
|
+
equality = "="
|
|
36
|
+
|
|
37
|
+
self.equality = equality
|
|
38
|
+
self.value = value
|
|
39
|
+
self.value_type = "having"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class FromTable:
|
|
43
|
+
"""A helper class to manage having expressions."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, name, raw=False):
|
|
46
|
+
self.name = name
|
|
47
|
+
self.raw = raw
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class UpdateQueryExpression:
|
|
51
|
+
"""A helper class to manage update expressions."""
|
|
52
|
+
|
|
53
|
+
def __init__(self, column, value=None, update_type="keyvalue"):
|
|
54
|
+
self.column = column
|
|
55
|
+
self.value = value
|
|
56
|
+
self.update_type = update_type
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class BetweenExpression:
|
|
60
|
+
"""A helper class to manage where between expressions."""
|
|
61
|
+
|
|
62
|
+
def __init__(self, column, low, high, equality="BETWEEN"):
|
|
63
|
+
self.column = column
|
|
64
|
+
self.low = low
|
|
65
|
+
self.high = high
|
|
66
|
+
self.equality = equality
|
|
67
|
+
self.value = None
|
|
68
|
+
self.value_type = "BETWEEN"
|
|
69
|
+
self.raw = False
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class SubSelectExpression:
|
|
73
|
+
"""A helper class to manage subselect expressions."""
|
|
74
|
+
|
|
75
|
+
def __init__(self, builder):
|
|
76
|
+
self.builder = builder
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class SubGroupExpression:
|
|
80
|
+
"""A helper class to manage subgroup expressions."""
|
|
81
|
+
|
|
82
|
+
def __init__(self, builder, alias="group"):
|
|
83
|
+
self.builder = builder
|
|
84
|
+
self.alias = alias
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class SelectExpression:
|
|
88
|
+
"""A helper class to manage select expressions."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, column, raw=False):
|
|
91
|
+
self.column = column.strip()
|
|
92
|
+
self.alias = None
|
|
93
|
+
self.raw = raw
|
|
94
|
+
if raw is False and " as " in self.column:
|
|
95
|
+
self.column, self.alias = self.column.split(" as ")
|
|
96
|
+
self.column = self.column.strip()
|
|
97
|
+
self.alias = self.alias.strip()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class OrderByExpression:
|
|
101
|
+
"""A helper class to manage select expressions."""
|
|
102
|
+
|
|
103
|
+
def __init__(self, column, direction="ASC", raw=False, bindings=()):
|
|
104
|
+
self.column = column.strip()
|
|
105
|
+
|
|
106
|
+
self.raw = raw
|
|
107
|
+
|
|
108
|
+
self.direction = direction
|
|
109
|
+
self.bindings = bindings
|
|
110
|
+
|
|
111
|
+
if raw is False:
|
|
112
|
+
if self.column.endswith(" desc"):
|
|
113
|
+
self.column = self.column.split(" desc")[0].strip()
|
|
114
|
+
self.direction = "DESC"
|
|
115
|
+
|
|
116
|
+
if self.column.endswith(" asc"):
|
|
117
|
+
self.column = self.column.split(" asc")[0].strip()
|
|
118
|
+
self.direction = "ASC"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class GroupByExpression:
|
|
122
|
+
"""A helper class to manage select expressions."""
|
|
123
|
+
|
|
124
|
+
def __init__(self, column=None, raw=False, bindings=()):
|
|
125
|
+
self.column = column.strip()
|
|
126
|
+
|
|
127
|
+
self.raw = raw
|
|
128
|
+
self.bindings = bindings
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class AggregateExpression:
|
|
132
|
+
def __init__(self, aggregate=None, column=None, alias=False):
|
|
133
|
+
self.aggregate = aggregate
|
|
134
|
+
self.column = column.strip()
|
|
135
|
+
self.alias = alias
|
|
136
|
+
if " as " in self.column:
|
|
137
|
+
self.column, self.alias = self.column.split(" as ")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class Raw:
|
|
141
|
+
def __init__(self, expression):
|
|
142
|
+
self.expression = expression
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class JoinClause:
|
|
146
|
+
def __init__(self, table, clause="join"):
|
|
147
|
+
self.table = table
|
|
148
|
+
self.alias = None
|
|
149
|
+
self.clause = clause
|
|
150
|
+
self.on_clauses = []
|
|
151
|
+
|
|
152
|
+
if " as " in self.table:
|
|
153
|
+
self.table = table.split(" as ")[0]
|
|
154
|
+
self.alias = table.split(" as ")[1]
|
|
155
|
+
|
|
156
|
+
def on(self, column1, equality, column2):
|
|
157
|
+
self.on_clauses.append(OnClause(column1, equality, column2))
|
|
158
|
+
return self
|
|
159
|
+
|
|
160
|
+
def or_on(self, column1, equality, column2):
|
|
161
|
+
self.on_clauses.append(OnClause(column1, equality, column2, "or"))
|
|
162
|
+
return self
|
|
163
|
+
|
|
164
|
+
def on_value(self, column, *args):
|
|
165
|
+
equality, value = self._extract_operator_value(*args)
|
|
166
|
+
self.on_clauses += ((OnValueClause(column, equality, value, "value")),)
|
|
167
|
+
return self
|
|
168
|
+
|
|
169
|
+
def or_on_value(self, column, *args):
|
|
170
|
+
equality, value = self._extract_operator_value(*args)
|
|
171
|
+
self.on_clauses += (
|
|
172
|
+
(OnValueClause(column, equality, value, "value", operator="or")),
|
|
173
|
+
)
|
|
174
|
+
return self
|
|
175
|
+
|
|
176
|
+
def on_null(self, column):
|
|
177
|
+
"""Specifies an ON expression where the column IS NULL.
|
|
178
|
+
|
|
179
|
+
Arguments:
|
|
180
|
+
column {string} -- The name of the column.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
self
|
|
184
|
+
"""
|
|
185
|
+
self.on_clauses += ((OnValueClause(column, "=", None, "NULL")),)
|
|
186
|
+
return self
|
|
187
|
+
|
|
188
|
+
def on_not_null(self, column: str):
|
|
189
|
+
"""Specifies an ON expression where the column IS NOT NULL.
|
|
190
|
+
|
|
191
|
+
Arguments:
|
|
192
|
+
column {string} -- The name of the column.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
self
|
|
196
|
+
"""
|
|
197
|
+
self.on_clauses += ((OnValueClause(column, "=", True, "NOT NULL")),)
|
|
198
|
+
return self
|
|
199
|
+
|
|
200
|
+
def or_on_null(self, column):
|
|
201
|
+
"""Specifies an ON expression where the column IS NULL.
|
|
202
|
+
|
|
203
|
+
Arguments:
|
|
204
|
+
column {string} -- The name of the column.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
self
|
|
208
|
+
"""
|
|
209
|
+
self.on_clauses += (
|
|
210
|
+
(OnValueClause(column, "=", None, "NULL", operator="or")),
|
|
211
|
+
)
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
def or_on_not_null(self, column: str):
|
|
215
|
+
"""Specifies an ON expression where the column IS NOT NULL.
|
|
216
|
+
|
|
217
|
+
Arguments:
|
|
218
|
+
column {string} -- The name of the column.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
self
|
|
222
|
+
"""
|
|
223
|
+
self.on_clauses += (
|
|
224
|
+
(OnValueClause(column, "=", True, "NOT NULL", operator="or")),
|
|
225
|
+
)
|
|
226
|
+
return self
|
|
227
|
+
|
|
228
|
+
@deprecated(
|
|
229
|
+
"Using where() in a Join clause has been superceded by on_value()"
|
|
230
|
+
)
|
|
231
|
+
def where(self, column, *args):
|
|
232
|
+
return self.on_value(column, *args)
|
|
233
|
+
|
|
234
|
+
def _extract_operator_value(self, *args):
|
|
235
|
+
operators = ["=", ">", ">=", "<", "<=", "!=", "<>", "like", "not like"]
|
|
236
|
+
|
|
237
|
+
operator = operators[0]
|
|
238
|
+
|
|
239
|
+
value = None
|
|
240
|
+
|
|
241
|
+
if (len(args)) >= 2:
|
|
242
|
+
operator = args[0]
|
|
243
|
+
value = args[1]
|
|
244
|
+
elif len(args) == 1:
|
|
245
|
+
value = args[0]
|
|
246
|
+
|
|
247
|
+
if operator not in operators:
|
|
248
|
+
raise ValueError(
|
|
249
|
+
"Invalid comparison operator. The operator can be %s"
|
|
250
|
+
% ", ".join(operators)
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
return operator, value
|
|
254
|
+
|
|
255
|
+
def get_on_clauses(self):
|
|
256
|
+
return self.on_clauses
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class OnClause:
|
|
260
|
+
def __init__(self, column1, equality, column2, operator="and"):
|
|
261
|
+
self.column1 = column1
|
|
262
|
+
self.column2 = column2
|
|
263
|
+
self.equality = equality
|
|
264
|
+
self.operator = operator
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class OnValueClause:
|
|
268
|
+
"""A helper class to manage ON expressions in joins with a value."""
|
|
269
|
+
|
|
270
|
+
def __init__(
|
|
271
|
+
self,
|
|
272
|
+
column,
|
|
273
|
+
equality,
|
|
274
|
+
value,
|
|
275
|
+
value_type="value",
|
|
276
|
+
keyword=None,
|
|
277
|
+
raw=False,
|
|
278
|
+
bindings=(),
|
|
279
|
+
operator="and",
|
|
280
|
+
):
|
|
281
|
+
self.column = column
|
|
282
|
+
self.equality = equality
|
|
283
|
+
self.value = value
|
|
284
|
+
self.value_type = value_type
|
|
285
|
+
self.keyword = keyword
|
|
286
|
+
self.raw = raw
|
|
287
|
+
self.bindings = bindings
|
|
288
|
+
self.operator = operator
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Factory:
|
|
5
|
+
_factories = {}
|
|
6
|
+
_after_creates = {}
|
|
7
|
+
_faker = None
|
|
8
|
+
|
|
9
|
+
@property
|
|
10
|
+
def faker(self):
|
|
11
|
+
try:
|
|
12
|
+
from faker import Faker
|
|
13
|
+
except ImportError:
|
|
14
|
+
raise ImportError(
|
|
15
|
+
"Could not find the 'faker' library. Run 'pip install faker' to fix this."
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
if not Factory._faker:
|
|
19
|
+
Factory._faker = Faker()
|
|
20
|
+
random.seed()
|
|
21
|
+
Factory._faker.seed_instance(random.randint(1, 10000))
|
|
22
|
+
|
|
23
|
+
return Factory._faker
|
|
24
|
+
|
|
25
|
+
def __init__(self, model, number=1):
|
|
26
|
+
self.model = model
|
|
27
|
+
self.number = number
|
|
28
|
+
|
|
29
|
+
def make(self, dictionary=None, name="default"):
|
|
30
|
+
if dictionary is None:
|
|
31
|
+
dictionary = {}
|
|
32
|
+
|
|
33
|
+
if self.number == 1 and not isinstance(dictionary, list):
|
|
34
|
+
called = self._factories[self.model][name](self.faker)
|
|
35
|
+
called.update(dictionary)
|
|
36
|
+
model = self.model.hydrate(called)
|
|
37
|
+
self.run_after_creates(model)
|
|
38
|
+
return model
|
|
39
|
+
elif isinstance(dictionary, list):
|
|
40
|
+
results = []
|
|
41
|
+
for index in range(0, len(dictionary)):
|
|
42
|
+
called = self._factories[self.model][name](self.faker)
|
|
43
|
+
called.update(dictionary)
|
|
44
|
+
results.append(called)
|
|
45
|
+
models = self.model.hydrate(results)
|
|
46
|
+
for model in models:
|
|
47
|
+
self.run_after_creates(model)
|
|
48
|
+
return models
|
|
49
|
+
|
|
50
|
+
else:
|
|
51
|
+
results = []
|
|
52
|
+
for index in range(0, self.number):
|
|
53
|
+
called = self._factories[self.model][name](self.faker)
|
|
54
|
+
called.update(dictionary)
|
|
55
|
+
results.append(called)
|
|
56
|
+
models = self.model.hydrate(results)
|
|
57
|
+
for model in models:
|
|
58
|
+
self.run_after_creates(model)
|
|
59
|
+
return models
|
|
60
|
+
|
|
61
|
+
def create(self, dictionary=None, name="default"):
|
|
62
|
+
if dictionary is None:
|
|
63
|
+
dictionary = {}
|
|
64
|
+
|
|
65
|
+
if self.number == 1 and not isinstance(dictionary, list):
|
|
66
|
+
called = self._factories[self.model][name](self.faker)
|
|
67
|
+
called.update(dictionary)
|
|
68
|
+
model = self.model.create(called)
|
|
69
|
+
self.run_after_creates(model)
|
|
70
|
+
return model
|
|
71
|
+
elif isinstance(dictionary, list):
|
|
72
|
+
results = []
|
|
73
|
+
for index in range(0, len(dictionary)):
|
|
74
|
+
called = self._factories[self.model][name](self.faker)
|
|
75
|
+
called.update(dictionary)
|
|
76
|
+
results.append(called)
|
|
77
|
+
|
|
78
|
+
models = self.model.create(results)
|
|
79
|
+
for model in models:
|
|
80
|
+
self.run_after_creates(model)
|
|
81
|
+
return models
|
|
82
|
+
else:
|
|
83
|
+
full_collection = []
|
|
84
|
+
for index in range(0, self.number):
|
|
85
|
+
called = self._factories[self.model][name](self.faker)
|
|
86
|
+
called.update(dictionary)
|
|
87
|
+
full_collection.append(called)
|
|
88
|
+
model = self.model.create(called)
|
|
89
|
+
self.run_after_creates(model)
|
|
90
|
+
|
|
91
|
+
return self.model.hydrate(full_collection)
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def register(cls, model, call, name="default"):
|
|
95
|
+
if model not in cls._factories:
|
|
96
|
+
cls._factories[model] = {name: call}
|
|
97
|
+
else:
|
|
98
|
+
cls._factories[model][name] = call
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def after_creating(cls, model, call, name="default"):
|
|
102
|
+
if model not in cls._after_creates:
|
|
103
|
+
cls._after_creates[model] = {name: call}
|
|
104
|
+
else:
|
|
105
|
+
cls._after_creates[model][name] = call
|
|
106
|
+
|
|
107
|
+
def run_after_creates(self, model):
|
|
108
|
+
if self.model not in self._after_creates:
|
|
109
|
+
return model
|
|
110
|
+
|
|
111
|
+
for name, callback in self._after_creates[self.model].items():
|
|
112
|
+
callback(model, self.faker)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .Factory import Factory
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Module for miscellaneous helper methods."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def deprecated(message):
|
|
7
|
+
warnings.simplefilter("default", DeprecationWarning)
|
|
8
|
+
|
|
9
|
+
def deprecated_decorator(func):
|
|
10
|
+
def deprecated_func(*args, **kwargs):
|
|
11
|
+
warnings.warn(
|
|
12
|
+
"{} is a deprecated function. {}".format(
|
|
13
|
+
func.__name__, message
|
|
14
|
+
),
|
|
15
|
+
category=DeprecationWarning,
|
|
16
|
+
stacklevel=2,
|
|
17
|
+
)
|
|
18
|
+
return func(*args, **kwargs)
|
|
19
|
+
|
|
20
|
+
return deprecated_func
|
|
21
|
+
|
|
22
|
+
return deprecated_decorator
|