tina4-python 0.2.35__tar.gz → 0.2.36__tar.gz

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.
Files changed (41) hide show
  1. {tina4_python-0.2.35 → tina4_python-0.2.36}/PKG-INFO +1 -1
  2. {tina4_python-0.2.35 → tina4_python-0.2.36}/pyproject.toml +1 -1
  3. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Database.py +1 -0
  4. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/DatabaseResult.py +9 -1
  5. tina4_python-0.2.36/tina4_python/ORM.py +131 -0
  6. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/__init__.py +22 -9
  7. {tina4_python-0.2.35 → tina4_python-0.2.36}/README.md +0 -0
  8. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Auth.py +0 -0
  9. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Constant.py +0 -0
  10. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Debug.py +0 -0
  11. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Env.py +0 -0
  12. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Localization.py +0 -0
  13. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Messages.py +0 -0
  14. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/MiddleWare.py +0 -0
  15. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Migration.py +0 -0
  16. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Request.py +0 -0
  17. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Response.py +0 -0
  18. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Router.py +0 -0
  19. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Session.py +0 -0
  20. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/ShellColors.py +0 -0
  21. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Swagger.py +0 -0
  22. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Template.py +0 -0
  23. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/Webserver.py +0 -0
  24. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/messages.pot +0 -0
  25. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/css/readme.md +0 -0
  26. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/favicon.ico +0 -0
  27. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/images/403.png +0 -0
  28. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/images/404.png +0 -0
  29. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/images/logo.png +0 -0
  30. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/images/readme.md +0 -0
  31. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/js/readme.md +0 -0
  32. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/js/tina4helper.js +0 -0
  33. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/swagger/index.html +0 -0
  34. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
  35. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/templates/errors/403.twig +0 -0
  36. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/templates/errors/404.twig +0 -0
  37. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/templates/readme.md +0 -0
  38. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
  39. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
  40. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
  41. {tina4_python-0.2.35 → tina4_python-0.2.36}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tina4-python
3
- Version: 0.2.35
3
+ Version: 0.2.36
4
4
  Summary: Tina4Python - This is not another framework for Python
5
5
  Author: Andre van Zuydam
6
6
  Author-email: andrevanzuydam@gmail.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tina4-python"
3
- version = "0.2.35"
3
+ version = "0.2.36"
4
4
  description = "Tina4Python - This is not another framework for Python"
5
5
  authors = ["Andre van Zuydam <andrevanzuydam@gmail.com>"]
6
6
  readme = "README.md"
@@ -8,6 +8,7 @@ import base64
8
8
  import importlib
9
9
  import datetime
10
10
  import json
11
+ from decimal import Decimal
11
12
 
12
13
  from tina4_python import Debug, Constant
13
14
  from tina4_python.DatabaseResult import DatabaseResult
@@ -7,6 +7,7 @@
7
7
  import base64
8
8
  import json
9
9
  import datetime
10
+ from decimal import Decimal
10
11
 
11
12
 
12
13
  class DatabaseResult:
@@ -34,7 +35,9 @@ class DatabaseResult:
34
35
  for record in self.records:
35
36
  json_record = {}
36
37
  for key in record:
37
- if isinstance(record[key], datetime.datetime):
38
+ if isinstance(record[key], Decimal):
39
+ json_record[key] = str(record[key])
40
+ elif isinstance(record[key], datetime.datetime):
38
41
  json_record[key] = record[key].isoformat()
39
42
  elif isinstance(record[key], bytes):
40
43
  json_record[key] = base64.b64encode(record[key]).decode('utf-8')
@@ -47,10 +50,14 @@ class DatabaseResult:
47
50
  else:
48
51
  return []
49
52
 
53
+ def to_list(self):
54
+ return self.to_array()
55
+
50
56
  def to_json(self):
51
57
  return json.dumps(self.to_array())
52
58
 
53
59
  def __getitem__(self, item):
60
+ print('ITEM', item)
54
61
  if item < len(self.records):
55
62
  return self.records[item]
56
63
  else:
@@ -58,3 +65,4 @@ class DatabaseResult:
58
65
 
59
66
  def __str__(self):
60
67
  return self.to_json()
68
+
@@ -0,0 +1,131 @@
1
+ import base64
2
+ from datetime import datetime, date
3
+ import inspect
4
+ import ast
5
+ import json
6
+ import os
7
+ import tina4_python
8
+ from tina4_python.Debug import Debug
9
+
10
+
11
+ def orm(dba):
12
+ Debug("Initializing ORM")
13
+ orm_path = tina4_python.root_path+os.sep+"src"+os.sep+"orm"
14
+ # load and assign
15
+
16
+ for file in os.listdir(orm_path):
17
+ mod_name = file.removesuffix(".py")
18
+ if "__init__" not in mod_name and "__pycache__" not in mod_name:
19
+ # import and set the database object
20
+ Debug('from src.orm.'+mod_name+' import ' + mod_name)
21
+ exec('from src.orm.'+mod_name+' import ' + mod_name)
22
+ exec(mod_name+".__dba__ = dba")
23
+
24
+
25
+ class BaseField:
26
+ primary_key = False
27
+ column_type = None
28
+ default_value = None
29
+ column_name = None
30
+ auto_increment = False
31
+
32
+ def __init__(self, column_name=None, primary_key=False, default_value=None, auto_increment=False):
33
+ self.primary_key = primary_key
34
+ self.column_type = None
35
+ self.default_value = default_value
36
+ self.auto_increment = auto_increment
37
+
38
+ if column_name is None:
39
+ frame = inspect.stack()[1]
40
+ # Parse python syntax of the assignment line
41
+ st = ast.parse(frame.code_context[0].strip())
42
+ stmt = st.body[0]
43
+ # Assume class being instanced as simple assign statement
44
+ assert(isinstance(stmt, ast.Assign))
45
+ # Parse the target the class is assigned to
46
+ target = stmt.targets[0]
47
+ self.column_name = target.id
48
+ else:
49
+ self.column_name = column_name
50
+
51
+ class DateTimeField(BaseField):
52
+ column_type = datetime
53
+
54
+ class IntegerField(BaseField):
55
+ column_type = int
56
+
57
+ class NumericField(BaseField):
58
+ column_type = float
59
+
60
+ class StringField(BaseField):
61
+ column_type = str
62
+
63
+ class TextField(BaseField):
64
+ column_type = str
65
+
66
+ class BlobField(BaseField):
67
+ column_type = bytes
68
+
69
+ class ForeignKeyField:
70
+ field_type = None
71
+ references_table = None
72
+ references_column = None
73
+
74
+ def __init__(self, field_type=BaseField, references_table=None):
75
+ self.field_type = field_type
76
+ self.references_table = references_table
77
+ self.references_column = field_type.column_name
78
+
79
+ def json_serialize(obj):
80
+ """JSON serializer for objects not serializable by default json code"""
81
+
82
+ if isinstance(obj, (datetime, date)):
83
+ return obj.isoformat()
84
+ elif isinstance(obj, bytes):
85
+ return base64.b64encode(obj).decode('utf-8')
86
+ raise TypeError ("Type %s not serializable" % type(obj))
87
+
88
+
89
+ class ORM:
90
+ __table_name__ = None
91
+ __primary_key__ = "id"
92
+ __dba__ = None
93
+
94
+ def __init__(self, init_object=None, table_name=None):
95
+ class_name = self.__class__.__name__
96
+ if self.__table_name__ is None:
97
+ if table_name is None:
98
+ self.__table_name__ = class_name.lower()
99
+ else:
100
+ self.__table_name__ = table_name.lower()
101
+ if init_object is not None:
102
+ self.populate_orm(init_object)
103
+ print(self.__dba__, self.__table_name__, self.__primary_key__)
104
+
105
+ def populate_orm(self, init_object):
106
+ print("Populating ORM", init_object)
107
+ pass
108
+
109
+ def to_json(self):
110
+ return json.dumps(self.__dict__, default=json_serialize)
111
+
112
+ def to_dict(self):
113
+ return self.__dict__
114
+
115
+ def __str__(self):
116
+ return self.to_json()
117
+
118
+ def load(self, query="", params=[]):
119
+
120
+ pass
121
+
122
+ def save(self):
123
+ # check if record exists
124
+
125
+ # save or update record
126
+
127
+ return False
128
+
129
+ def delete(self):
130
+
131
+ pass
@@ -115,25 +115,38 @@ if not os.path.exists(root_path + os.sep + "src" + os.sep + "public"):
115
115
  # ignore F403
116
116
  if os.path.exists(root_path + os.sep + "src"):
117
117
  try:
118
- from src import *
119
- except ImportError:
120
- Debug("Cannot import src folder", Constant.TINA4_LOG_ERROR)
118
+ src_path = root_path + os.sep + "src"
119
+ for file in os.listdir(src_path):
120
+ if file.endswith(".py"):
121
+ file_name = file.removesuffix(".py")
122
+ exec("from src import "+ file_name)
123
+
124
+ except ImportError as e:
125
+ Debug("Cannot import src folder", str(e), Constant.TINA4_LOG_ERROR)
121
126
  else:
122
127
  Debug("Missing src folder", Constant.TINA4_LOG_WARNING)
123
128
 
124
129
  if os.path.exists(root_path + os.sep + "src" + os.sep + "routes"):
125
130
  try:
126
- from src.routes import *
127
- except ImportError:
128
- Debug("Cannot import src.routes folder", Constant.TINA4_LOG_ERROR)
131
+ src_path = root_path + os.sep + "src"+ os.sep + "routes"
132
+ for file in os.listdir(src_path):
133
+ if file.endswith(".py"):
134
+ file_name = file.removesuffix(".py")
135
+ exec("from src.routes import "+ file_name)
136
+ except ImportError as e:
137
+ Debug("Cannot import src.routes folder", str(e), Constant.TINA4_LOG_ERROR)
129
138
  else:
130
139
  Debug("Missing src/routes folder", Constant.TINA4_LOG_WARNING)
131
140
 
132
141
  if os.path.exists(root_path + os.sep + "src" + os.sep + "app"):
133
142
  try:
134
- from src.app import *
135
- except ImportError:
136
- Debug("Cannot import src.app folder", Constant.TINA4_LOG_ERROR)
143
+ src_path = root_path + os.sep + "src"+ os.sep + "app"
144
+ for file in os.listdir(src_path):
145
+ if file.endswith(".py"):
146
+ file_name = file.removesuffix(".py")
147
+ exec("from src.app import "+ file_name)
148
+ except ImportError as e:
149
+ Debug("Cannot import src.app folder", str(e), Constant.TINA4_LOG_ERROR)
137
150
  else:
138
151
  Debug("Missing src/app folder", Constant.TINA4_LOG_WARNING)
139
152
 
File without changes