piccolo 1.4.2__py3-none-any.whl → 1.5.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.
- piccolo/__init__.py +1 -1
- piccolo/apps/asgi/commands/new.py +1 -0
- piccolo/apps/asgi/commands/templates/app/_lilya_app.py.jinja +45 -0
- piccolo/apps/asgi/commands/templates/app/app.py.jinja +2 -0
- piccolo/apps/asgi/commands/templates/app/home/_lilya_endpoints.py.jinja +21 -0
- piccolo/apps/asgi/commands/templates/app/home/endpoints.py.jinja +2 -0
- piccolo/apps/asgi/commands/templates/app/home/templates/home.html.jinja_raw +5 -0
- piccolo/apps/migrations/auto/migration_manager.py +9 -9
- piccolo/apps/migrations/auto/serialisation.py +2 -4
- piccolo/apps/migrations/commands/backwards.py +9 -7
- piccolo/apps/migrations/commands/base.py +3 -3
- piccolo/apps/migrations/commands/forwards.py +3 -3
- piccolo/apps/playground/commands/run.py +1 -0
- piccolo/apps/user/tables.py +1 -0
- piccolo/columns/base.py +5 -3
- piccolo/columns/column_types.py +97 -116
- piccolo/columns/reference.py +1 -0
- piccolo/conf/apps.py +1 -2
- piccolo/query/methods/objects.py +8 -8
- piccolo/query/methods/select.py +4 -8
- piccolo/query/mixins.py +3 -3
- piccolo/query/proxy.py +3 -2
- piccolo/table.py +19 -13
- piccolo/utils/pydantic.py +6 -0
- {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/METADATA +2 -2
- {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/RECORD +35 -33
- tests/columns/test_array.py +22 -0
- tests/columns/test_reference.py +1 -0
- tests/conf/example.py +1 -0
- tests/table/test_metaclass.py +12 -0
- tests/utils/test_pydantic.py +28 -0
- {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/LICENSE +0 -0
- {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/WHEEL +0 -0
- {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/entry_points.txt +0 -0
- {piccolo-1.4.2.dist-info → piccolo-1.5.1.dist-info}/top_level.txt +0 -0
piccolo/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__VERSION__ = "1.
|
1
|
+
__VERSION__ = "1.5.1"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from piccolo_admin.endpoints import create_admin
|
2
|
+
from piccolo_api.crud.endpoints import PiccoloCRUD
|
3
|
+
from piccolo.engine import engine_finder
|
4
|
+
from lilya.routing import Path, Include
|
5
|
+
from lilya.apps import Lilya
|
6
|
+
from lilya.staticfiles import StaticFiles
|
7
|
+
|
8
|
+
from home.endpoints import HomeController
|
9
|
+
from home.piccolo_app import APP_CONFIG
|
10
|
+
from home.tables import Task
|
11
|
+
|
12
|
+
|
13
|
+
app = Lilya(
|
14
|
+
routes=[
|
15
|
+
Path("/", HomeController),
|
16
|
+
Include(
|
17
|
+
"/admin/",
|
18
|
+
create_admin(
|
19
|
+
tables=APP_CONFIG.table_classes,
|
20
|
+
# Required when running under HTTPS:
|
21
|
+
# allowed_hosts=['my_site.com']
|
22
|
+
)
|
23
|
+
),
|
24
|
+
Include("/static/", StaticFiles(directory="static")),
|
25
|
+
Include("/tasks/", PiccoloCRUD(table=Task))
|
26
|
+
],
|
27
|
+
)
|
28
|
+
|
29
|
+
|
30
|
+
@app.on_event("on_startup")
|
31
|
+
async def open_database_connection_pool():
|
32
|
+
try:
|
33
|
+
engine = engine_finder()
|
34
|
+
await engine.start_connection_pool()
|
35
|
+
except Exception:
|
36
|
+
print("Unable to connect to the database")
|
37
|
+
|
38
|
+
|
39
|
+
@app.on_event("on_shutdown")
|
40
|
+
async def close_database_connection_pool():
|
41
|
+
try:
|
42
|
+
engine = engine_finder()
|
43
|
+
await engine.close_connection_pool()
|
44
|
+
except Exception:
|
45
|
+
print("Unable to connect to the database")
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
import jinja2
|
4
|
+
from lilya.controllers import Controller
|
5
|
+
from lilya.responses import HTMLResponse
|
6
|
+
|
7
|
+
|
8
|
+
ENVIRONMENT = jinja2.Environment(
|
9
|
+
loader=jinja2.FileSystemLoader(
|
10
|
+
searchpath=os.path.join(os.path.dirname(__file__), "templates")
|
11
|
+
)
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
class HomeController(Controller):
|
16
|
+
async def get(self, request):
|
17
|
+
template = ENVIRONMENT.get_template("home.html.jinja")
|
18
|
+
|
19
|
+
content = template.render(title="Piccolo + ASGI",)
|
20
|
+
|
21
|
+
return HTMLResponse(content)
|
@@ -61,6 +61,11 @@
|
|
61
61
|
<li><a href="/admin/">Admin</a></li>
|
62
62
|
<li><a href="/docs/swagger">Swagger API</a></li>
|
63
63
|
</ul>
|
64
|
+
<h3>Lilya</h3>
|
65
|
+
<ul>
|
66
|
+
<li><a href="/admin/">Admin</a></li>
|
67
|
+
<li><a href="/tasks/">JSON endpoint</a></li>
|
68
|
+
</ul>
|
64
69
|
</section>
|
65
70
|
</div>
|
66
71
|
{% endblock content %}
|
@@ -737,9 +737,9 @@ class MigrationManager:
|
|
737
737
|
async def _run_add_tables(self, backwards: bool = False):
|
738
738
|
table_classes: t.List[t.Type[Table]] = []
|
739
739
|
for add_table in self.add_tables:
|
740
|
-
add_columns: t.List[
|
741
|
-
|
742
|
-
|
740
|
+
add_columns: t.List[AddColumnClass] = (
|
741
|
+
self.add_columns.for_table_class_name(add_table.class_name)
|
742
|
+
)
|
743
743
|
_Table: t.Type[Table] = create_table_class(
|
744
744
|
class_name=add_table.class_name,
|
745
745
|
class_kwargs={
|
@@ -792,9 +792,9 @@ class MigrationManager:
|
|
792
792
|
if table_class_name in [i.class_name for i in self.add_tables]:
|
793
793
|
continue # No need to add columns to new tables
|
794
794
|
|
795
|
-
add_columns: t.List[
|
796
|
-
|
797
|
-
|
795
|
+
add_columns: t.List[AddColumnClass] = (
|
796
|
+
self.add_columns.for_table_class_name(table_class_name)
|
797
|
+
)
|
798
798
|
|
799
799
|
###############################################################
|
800
800
|
# Define the table, with the columns, so the metaclass
|
@@ -838,9 +838,9 @@ class MigrationManager:
|
|
838
838
|
else:
|
839
839
|
primary_key = existing_table._meta.primary_key
|
840
840
|
|
841
|
-
table_class_members[
|
842
|
-
primary_key
|
843
|
-
|
841
|
+
table_class_members[primary_key._meta.name] = (
|
842
|
+
primary_key
|
843
|
+
)
|
844
844
|
|
845
845
|
break
|
846
846
|
|
@@ -25,8 +25,7 @@ from .serialisation_legacy import deserialise_legacy_params
|
|
25
25
|
|
26
26
|
class CanConflictWithGlobalNames(abc.ABC):
|
27
27
|
@abc.abstractmethod
|
28
|
-
def warn_if_is_conflicting_with_global_name(self):
|
29
|
-
...
|
28
|
+
def warn_if_is_conflicting_with_global_name(self): ...
|
30
29
|
|
31
30
|
|
32
31
|
class UniqueGlobalNamesMeta(type):
|
@@ -237,8 +236,7 @@ class Import(CanConflictWithGlobalNames):
|
|
237
236
|
|
238
237
|
class Definition(CanConflictWithGlobalNames, abc.ABC):
|
239
238
|
@abc.abstractmethod
|
240
|
-
def __repr__(self):
|
241
|
-
...
|
239
|
+
def __repr__(self): ...
|
242
240
|
|
243
241
|
###########################################################################
|
244
242
|
# To allow sorting:
|
@@ -31,9 +31,9 @@ class BackwardsMigrationManager(BaseMigrationManager):
|
|
31
31
|
super().__init__()
|
32
32
|
|
33
33
|
async def run_migrations_backwards(self, app_config: AppConfig):
|
34
|
-
migration_modules: t.Dict[
|
35
|
-
|
36
|
-
|
34
|
+
migration_modules: t.Dict[str, MigrationModule] = (
|
35
|
+
self.get_migration_modules(app_config.migrations_folder_path)
|
36
|
+
)
|
37
37
|
|
38
38
|
ran_migration_ids = await Migration.get_migrations_which_ran(
|
39
39
|
app_name=self.app_name
|
@@ -78,9 +78,11 @@ class BackwardsMigrationManager(BaseMigrationManager):
|
|
78
78
|
_continue = (
|
79
79
|
"y"
|
80
80
|
if self.auto_agree
|
81
|
-
else input(
|
81
|
+
else input(
|
82
|
+
f"Reverse {n} migration{'s' if n != 1 else ''}? [y/N] "
|
83
|
+
).lower()
|
82
84
|
)
|
83
|
-
if _continue
|
85
|
+
if _continue == "y":
|
84
86
|
for migration_id in reversed_migration_ids:
|
85
87
|
migration_module = migration_modules[migration_id]
|
86
88
|
response = await migration_module.forwards()
|
@@ -131,10 +133,10 @@ async def run_backwards(
|
|
131
133
|
"apps:\n"
|
132
134
|
f"{', '.join(names)}\n"
|
133
135
|
"Are you sure you want to continue? [y/N] "
|
134
|
-
)
|
136
|
+
).lower()
|
135
137
|
)
|
136
138
|
|
137
|
-
if _continue
|
139
|
+
if _continue != "y":
|
138
140
|
return MigrationResult(success=False, message="user cancelled")
|
139
141
|
for _app_name in sorted_app_names:
|
140
142
|
print_heading(_app_name)
|
@@ -88,9 +88,9 @@ class BaseMigrationManager(Finder):
|
|
88
88
|
|
89
89
|
migrations_folder = app_config.migrations_folder_path
|
90
90
|
|
91
|
-
migration_modules: t.Dict[
|
92
|
-
|
93
|
-
|
91
|
+
migration_modules: t.Dict[str, MigrationModule] = (
|
92
|
+
self.get_migration_modules(migrations_folder)
|
93
|
+
)
|
94
94
|
|
95
95
|
migration_ids = sorted(migration_modules.keys())
|
96
96
|
|
@@ -32,9 +32,9 @@ class ForwardsMigrationManager(BaseMigrationManager):
|
|
32
32
|
app_name=app_config.app_name
|
33
33
|
)
|
34
34
|
|
35
|
-
migration_modules: t.Dict[
|
36
|
-
|
37
|
-
|
35
|
+
migration_modules: t.Dict[str, MigrationModule] = (
|
36
|
+
self.get_migration_modules(app_config.migrations_folder_path)
|
37
|
+
)
|
38
38
|
|
39
39
|
ids = self.get_migration_ids(migration_modules)
|
40
40
|
n = len(ids)
|
piccolo/apps/user/tables.py
CHANGED
piccolo/columns/base.py
CHANGED
@@ -887,9 +887,11 @@ class Column(Selectable):
|
|
887
887
|
return (
|
888
888
|
"'{"
|
889
889
|
+ ", ".join(
|
890
|
-
|
891
|
-
|
892
|
-
|
890
|
+
(
|
891
|
+
f'"{i}"'
|
892
|
+
if isinstance(i, str)
|
893
|
+
else str(self.get_sql_value(i))
|
894
|
+
)
|
893
895
|
for i in value
|
894
896
|
)
|
895
897
|
) + "}'"
|