xync-schema 0.6.25.dev3__py3-none-any.whl → 0.6.27__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.
xync_schema/models.py CHANGED
@@ -1,10 +1,8 @@
1
1
  from datetime import datetime
2
2
  from enum import IntEnum
3
-
4
- from pydantic import create_model
5
3
  from tortoise import fields
6
- from tortoise.contrib.pydantic import PydanticModel
7
- from tortoise_api_model import Model, TsModel, DatetimeSecField, User as BaseUser
4
+ from x_model.model import Model, TsTrait, DatetimeSecField
5
+ from tg_auth.models import UserRefTrait, UserInfoTrait, User as BaseUser, UserStatus
8
6
 
9
7
 
10
8
  class AdvStatus(IntEnum):
@@ -66,20 +64,6 @@ class TaskType(IntEnum):
66
64
  invite_approve = 1
67
65
 
68
66
 
69
- class UserStatus(IntEnum):
70
- CREATOR = 5
71
- ADMINISTRATOR = 4
72
- MEMBER = 3
73
- RESTRICTED = 2
74
- LEFT = 1
75
- KICKED = 0
76
-
77
-
78
- class Lang(IntEnum):
79
- ru = 1
80
- en = 2
81
-
82
-
83
67
  class ExAction(IntEnum):
84
68
  """Public"""
85
69
 
@@ -122,7 +106,7 @@ class ExAction(IntEnum):
122
106
 
123
107
 
124
108
  class Country(Model):
125
- id = fields.SmallIntField(pk=True)
109
+ id = fields.SmallIntField(True)
126
110
  code: int | None = fields.IntField(null=True)
127
111
  short: str | None = fields.CharField(3, unique=True, null=True)
128
112
  name: str | None = fields.CharField(63, unique=True, null=True)
@@ -134,7 +118,7 @@ class Country(Model):
134
118
 
135
119
 
136
120
  class Cur(Model):
137
- id = fields.SmallIntField(pk=True)
121
+ id = fields.SmallIntField(True)
138
122
  ticker: str = fields.CharField(3, unique=True)
139
123
  rate: float | None = fields.FloatField(null=True)
140
124
  country: str | None = fields.CharField(63, null=True)
@@ -152,7 +136,7 @@ class Cur(Model):
152
136
 
153
137
 
154
138
  class Coin(Model):
155
- id: int = fields.SmallIntField(pk=True)
139
+ id: int = fields.SmallIntField(True)
156
140
  ticker: str = fields.CharField(15, unique=True)
157
141
  rate: float | None = fields.FloatField(null=True)
158
142
  is_fiat: bool = fields.BooleanField(default=False)
@@ -175,7 +159,7 @@ class Coin(Model):
175
159
 
176
160
 
177
161
  class Ex(Model):
178
- id: int = fields.SmallIntField(pk=True)
162
+ id: int = fields.SmallIntField(True)
179
163
  name: str = fields.CharField(31)
180
164
  host: str | None = fields.CharField(31, null=True)
181
165
  url: str | None = fields.CharField(63, null=True)
@@ -211,8 +195,8 @@ class Curex(Model):
211
195
  _name = {"cur__ticker", "ex__name"}
212
196
 
213
197
 
214
- class Pair(TsModel):
215
- id = fields.SmallIntField(pk=True)
198
+ class Pair(Model, TsTrait):
199
+ id = fields.SmallIntField(True)
216
200
  coin: fields.ForeignKeyRelation[Coin] = fields.ForeignKeyField("models.Coin", related_name="pairs")
217
201
  cur: fields.ForeignKeyRelation[Cur] = fields.ForeignKeyField("models.Cur", related_name="pairs")
218
202
  fee: float = fields.FloatField()
@@ -231,7 +215,7 @@ class Pair(TsModel):
231
215
 
232
216
 
233
217
  class Direction(Model):
234
- id = fields.SmallIntField(pk=True)
218
+ id = fields.SmallIntField(True)
235
219
  pair: fields.ForeignKeyRelation[Pair] = fields.ForeignKeyField("models.Pair", related_name="directions")
236
220
  sell: bool = fields.BooleanField()
237
221
  total: int = fields.IntField()
@@ -248,20 +232,9 @@ class Direction(Model):
248
232
  return f"{self.pair.coin.ticker}/{self.pair.cur.ticker} {'SELL' if self.sell else 'BUY'}"
249
233
 
250
234
 
251
- class User(BaseUser): # tg user
252
- id: int = fields.BigIntField(True)
253
- status: UserStatus = fields.IntEnumField(UserStatus, default=UserStatus.RESTRICTED)
254
- username: str | None = fields.CharField(95, unique=True, null=True)
235
+ class User(BaseUser, UserRefTrait, UserInfoTrait): # tg user
255
236
  chat_status: UserStatus = fields.IntEnumField(UserStatus, default=UserStatus.LEFT)
256
237
  in_channel: bool | None = fields.BooleanField(default=False, null=True)
257
- first_name: str | None = fields.CharField(95, null=True)
258
- last_name: str | None = fields.CharField(95, null=True)
259
- pic: str | None = fields.CharField(95, null=True)
260
- lang: Lang | None = fields.IntEnumField(Lang, default=Lang.ru, null=True)
261
- ref: fields.ForeignKeyNullableRelation["User"] = fields.ForeignKeyField(
262
- "models.User", related_name="proteges", null=True
263
- )
264
- ref_id: int | None
265
238
 
266
239
  agents: fields.BackwardFKRelation["Agent"]
267
240
  fiats: fields.BackwardFKRelation["Fiat"]
@@ -274,13 +247,8 @@ class User(BaseUser): # tg user
274
247
  borrows: fields.BackwardFKRelation["Credit"]
275
248
  investments: fields.BackwardFKRelation["Investment"]
276
249
 
277
- _icon = "user"
278
250
 
279
- class Meta:
280
- table_description = "Users"
281
-
282
-
283
- class Agent(TsModel):
251
+ class Agent(Model, TsTrait):
284
252
  id: int
285
253
  ex: fields.ForeignKeyRelation[Ex] = fields.ForeignKeyField("models.Ex", related_name="agents")
286
254
  # ex_id: int
@@ -297,18 +265,9 @@ class Agent(TsModel):
297
265
  def repr(self):
298
266
  return f"{self.ex.name}-{self.user.username}"
299
267
 
300
- @property
301
268
  def balance(self) -> float:
302
269
  return sum(asset.free * (asset.coin.rate or 0) for asset in self.assets)
303
270
 
304
- @classmethod
305
- def pydListItem(cls) -> type[PydanticModel]:
306
- return create_model(
307
- cls.__name__ + "ListItem",
308
- balance=(int, 0),
309
- __base__=super().pydListItem(),
310
- )
311
-
312
271
  class Meta:
313
272
  table_description = "Agents"
314
273
  unique_together = (("ex", "user"),)
@@ -319,9 +278,8 @@ class Agent(TsModel):
319
278
  class PydanticMetaListItem:
320
279
  max_recursion = 1
321
280
  backward_relations: bool = True
322
- exclude = "user",
323
- # include = "balance",
324
- # computed = ["balance"]
281
+ exclude = ("user",)
282
+ computed = ["balance"]
325
283
 
326
284
 
327
285
  class Adpm(Model):
@@ -335,8 +293,8 @@ class Adpm(Model):
335
293
  table_description = "P2P Advertisements - Payment methods"
336
294
 
337
295
 
338
- class Ad(TsModel):
339
- id: int = fields.BigIntField(pk=True)
296
+ class Ad(Model, TsTrait):
297
+ id: int = fields.BigIntField(True)
340
298
  direction: fields.ForeignKeyRelation[Direction] = fields.ForeignKeyField("models.Direction", related_name="ads")
341
299
  price: float = fields.FloatField()
342
300
  pms: fields.ManyToManyRelation["Pm"] = fields.ManyToManyField("models.Pm", through="adpm") # only root pms
@@ -539,8 +497,8 @@ class Asset(Model):
539
497
  exclude_raw_fields: bool = False
540
498
 
541
499
 
542
- class Order(TsModel):
543
- id: int = fields.BigIntField(pk=True)
500
+ class Order(Model, TsTrait):
501
+ id: int = fields.BigIntField(True)
544
502
  ad: fields.ForeignKeyRelation[Ad] = fields.ForeignKeyField("models.Ad", related_name="ads")
545
503
  ad_id: int
546
504
  amount: float = fields.FloatField()
@@ -564,7 +522,7 @@ class Order(TsModel):
564
522
  table_description = "P2P Orders"
565
523
 
566
524
 
567
- class Dep(TsModel):
525
+ class Dep(Model, TsTrait):
568
526
  pid: str = fields.CharField(31) # product_id
569
527
  apr: float = fields.FloatField()
570
528
  fee: float | None = fields.FloatField(null=True)
@@ -602,7 +560,7 @@ class Dep(TsModel):
602
560
  unique_together = (("pid", "type", "ex"),)
603
561
 
604
562
 
605
- class Investment(TsModel):
563
+ class Investment(Model, TsTrait):
606
564
  dep: fields.ForeignKeyRelation[Dep] = fields.ForeignKeyField("models.Dep", related_name="investments")
607
565
  dep_id: int
608
566
  amount: float = fields.FloatField()
@@ -654,7 +612,7 @@ class Vpn(Model):
654
612
  table_description = "VPNs"
655
613
 
656
614
 
657
- class Invite(TsModel):
615
+ class Invite(Model, TsTrait):
658
616
  ref: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="invite_approvals")
659
617
  ref_id: int
660
618
  protege: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="invite_requests")
@@ -671,7 +629,7 @@ class Invite(TsModel):
671
629
  table_description = "Invites"
672
630
 
673
631
 
674
- class Credit(TsModel):
632
+ class Credit(Model, TsTrait):
675
633
  lender: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="lends")
676
634
  lender_id: int
677
635
  borrower: fields.ForeignKeyRelation[User] = fields.ForeignKeyField("models.User", related_name="borrows")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xync-schema
3
- Version: 0.6.25.dev3
3
+ Version: 0.6.27
4
4
  Summary: XyncNet project database model schema
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: EULA
@@ -8,8 +8,7 @@ Project-URL: Homepage, https://gitlab.com/xync/back/schema
8
8
  Project-URL: Repository, https://gitlab.com/xync/back/schema
9
9
  Requires-Python: >=3.11
10
10
  Description-Content-Type: text/markdown
11
- Requires-Dist: tortoise-api-model
12
- Requires-Dist: aiogram
11
+ Requires-Dist: xtg-auth
13
12
  Provides-Extra: dev
14
13
  Requires-Dist: pytest ; extra == 'dev'
15
14
  Requires-Dist: build ; extra == 'dev'
@@ -0,0 +1,6 @@
1
+ xync_schema/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ xync_schema/models.py,sha256=wLHrjmfX3N9p00Sz05q5hrZqBG0WyK__9jFbf3SWgAs,23639
3
+ xync_schema-0.6.27.dist-info/METADATA,sha256=A7YWe2JdvrippkxmVyfvNt1xKhfqWULGmPmLoyjK7zk,1133
4
+ xync_schema-0.6.27.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
5
+ xync_schema-0.6.27.dist-info/top_level.txt,sha256=jN8IBDfVY8b85Byyk8v0Gyj_0yLB8FO56WV4EvcXWY4,12
6
+ xync_schema-0.6.27.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- xync_schema/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- xync_schema/models.py,sha256=sfg4ftJ5gf2P96ZsPl6Vn9fEcT_1bGIFF0yb77QdUWg,24730
3
- xync_schema-0.6.25.dev3.dist-info/METADATA,sha256=uppTgZLst_v8RIo068fhCFL_2MyptPe5Z8UGAi6bXJk,1171
4
- xync_schema-0.6.25.dev3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
5
- xync_schema-0.6.25.dev3.dist-info/top_level.txt,sha256=jN8IBDfVY8b85Byyk8v0Gyj_0yLB8FO56WV4EvcXWY4,12
6
- xync_schema-0.6.25.dev3.dist-info/RECORD,,