Skip to content

Commit f9461ca

Browse files
Improved consistency
1 parent 1018dd4 commit f9461ca

6 files changed

Lines changed: 40 additions & 22 deletions

File tree

‎DOCS.md‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SERVER_NAME = localhost
3535
SECRET_KEY = supersecret
3636
3737
[database]
38-
DATABASE_URL = sqlite:///appdata.db
38+
DATABASE_URI = sqlite:///appdata.db
3939
4040
[redis]
4141
REDIS_URL = redis://localhost:6379
@@ -109,7 +109,7 @@ class DefaultConfig:
109109
# -------------------------------------------------
110110
# Flask-SQLAlchemy & Flask-Migrate
111111
# -------------------------------------------------
112-
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL", "sqlite:///database.db")
112+
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URI", "sqlite:///database.db")
113113
SQLALCHEMY_TRACK_MODIFICATIONS = False
114114

115115
# -------------------------------------------------
@@ -311,9 +311,9 @@ module = Module(
311311
# "api",
312312
# "jwt_extended"
313313
],
314-
315-
# And you can optionally turn off init_routes_on_enable (default is True):
316-
False
314+
# init_routes_on_enable=False
315+
# -> You can optionally turn off automated route initialization when the module gets enabled.
316+
# This could be especially useful, if you are working with socket i18n. (More in the later chapters.)
317317
)
318318

319319
# Now if you need to do stuff when your module gets enabled:
@@ -354,11 +354,15 @@ def init_handling(mod: Module):
354354
for file in _package.rglob("*.py"):
355355
if file.stem == "__init__" or file.stem.startswith("noinit"):
356356
continue
357-
handler_name = file.stem
357+
358+
rel = file.relative_to(_package).with_suffix("")
359+
handler_name = ".".join(rel.parts)
360+
358361
handler = import_module(f"{mod.import_name}.handling.{handler_name}")
359362
handle_request = getattr(handler, "handle_request", None)
360363
if not handle_request:
361364
continue
365+
362366
mod.handler(handler_name)(handle_request)
363367
```
364368

@@ -427,7 +431,8 @@ def init_models(mod: Module):
427431
for file in _package.rglob("*.py"):
428432
if file.stem == "__init__" or file.stem.startswith("noinit"):
429433
continue
430-
import_module(f"{mod.import_name}.data.{file.stem}")
434+
rel = file.relative_to(_package).with_suffix("")
435+
import_module(f"{mod.import_name}.data.{".".join(rel.parts)}")
431436
```
432437

433438
### Working with Modules
@@ -624,7 +629,10 @@ module = Module(
624629
"sqlalchemy",
625630
"socket",
626631
"babel"
627-
]
632+
],
633+
False
634+
# -> False to install translations before route setup.
635+
# This is especially useful if you are using translations inside your route setup.
628636
)
629637

630638
@module.on_enable
@@ -639,6 +647,9 @@ def enable(app: FlaskPP):
639647
# -> default is module.name
640648
) # This will register the domain_name as the modules translation domain, pass it as a variable called "DOMAIN" to the
641649
# context processor and automatically cause _ and ngettext to primarily resolve translation keys from that domain.
650+
651+
# Now you can enable routes after you registered your translations
652+
module.init_routes()
642653

643654
# If you now do something like this, for example:
644655
from flask import render_template_string

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "flaskpp"
3-
version = "0.3.8"
3+
version = "0.3.10"
44
description = "A Flask based framework for fast and easy app creation. Experience the real power of Flask without boilerplate, but therefore a well balanced mix of magic and the default Flask framework."
55
authors = [
66
{ name = "Pierre", email = "pierre@growv-mail.org" }

‎src/flaskpp/app/config/default.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DefaultConfig:
1111
PROXY_FIX = False
1212
PROXY_COUNT = 1
1313

14-
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL", "sqlite:///database.db")
14+
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URI", "sqlite:///database.db")
1515
SQLALCHEMY_TRACK_MODIFICATIONS = False
1616

1717
RATELIMIT_ENABLED = True

‎src/flaskpp/module.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,16 @@ def version_check(v: str) -> tuple[bool, str]:
252252

253253
first_char_invalid = False
254254
try:
255-
if version_str.startswith("v"):
256-
version_str = version_str[1:]
257255
int(version_str[0])
258256
except ValueError:
259257
first_char_invalid = True
260258

261259
if first_char_invalid \
262-
or (" " in version_str and not (version_str.endswith("alpha") or version_str.endswith("beta"))):
260+
or (" " in version_str and not (
261+
version_str.endswith("alpha")
262+
or version_str.endswith("beta")
263+
or version_str.endswith("rc")
264+
)):
263265
return False, "Invalid version string format."
264266

265267
try:

‎src/flaskpp/modules/creator_templates.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ def init_handling(mod: Module):
3636
for file in _package.rglob("*.py"):
3737
if file.stem == "__init__" or file.stem.startswith("noinit"):
3838
continue
39-
handler_name = file.stem
39+
40+
rel = file.relative_to(_package).with_suffix("")
41+
handler_name = ".".join(rel.parts)
42+
4043
handler = import_module(f"{mod.import_name}.handling.{handler_name}")
4144
handle_request = getattr(handler, "handle_request", None)
4245
if not handle_request:
4346
continue
47+
4448
mod.handler(handler_name)(handle_request)
4549
"""
4650

@@ -118,7 +122,8 @@ def init_models(mod: Module):
118122
for file in _package.rglob("*.py"):
119123
if file.stem == "__init__" or file.stem.startswith("noinit"):
120124
continue
121-
import_module(f"{mod.import_name}.data.{file.stem}")
125+
rel = file.relative_to(_package).with_suffix("")
126+
import_module(f"{mod.import_name}.data.{".".join(rel.parts)}")
122127
"""
123128

124129
tailwind_raw = """

‎src/flaskpp/utils/setup.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from configparser import ConfigParser
44
import typer
55

6-
from flaskpp.utils import prompt_yes_no
6+
from flaskpp.utils import prompt_yes_no, sanitize_text
77
from flaskpp.modules import generate_modlib
88

99
counting_map = {
@@ -23,7 +23,7 @@ def base_config():
2323
},
2424

2525
"database": {
26-
"default_DATABASE_URL": "sqlite:///appdata.db",
26+
"default_DATABASE_URI": "sqlite:///appdata.db",
2727
},
2828

2929
"redis": {
@@ -84,7 +84,7 @@ def welcome():
8484
" ------------------\n")
8585
typer.echo("Thank you for using our framework to build your own")
8686
typer.echo("Flask++ apps! We will try our best to get you ready")
87-
typer.echo("within the next two minutes. 💚 Start a timer! 😉\n")
87+
typer.echo("within the next two minutes. 💚 Start a timer! 😉\n")
8888
typer.echo(" " +
8989
typer.style(
9090
"~ GrowVolution 2025 - MIT License ~",
@@ -132,7 +132,7 @@ def setup_app(app_number: int):
132132
else:
133133
input_prompt = f"{key}: "
134134

135-
val = input(input_prompt).strip()
135+
val = sanitize_text(input(input_prompt)).strip()
136136
if not val:
137137
val = str(value)
138138
config[k][key] = val
@@ -148,9 +148,9 @@ def setup_app(app_number: int):
148148
) + "\n")
149149

150150
register_app = prompt_yes_no(typer.style(
151-
f"Do you want to register {app} as a service? (y/N): ",
152-
fg=typer.colors.MAGENTA, bold=True
153-
) + "\n")
151+
f"Do you want to register {app} as a service?",
152+
fg=typer.colors.YELLOW, bold=True
153+
) + " (y/N): ")
154154

155155
if register_app:
156156
from .service_registry import register

0 commit comments

Comments
 (0)