-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some features + edit docs + fixes
- Add `Website.redirect_response` - Add `Page.set_footer` - Fix `Element.get_attr` to return string instead of list when getting class - Add html_file parameter in `set_navigation_bar` - Add example for connecting to SQL for user data - Add error when an set_current_user_data tries to set a key for a column that was not added before in a SQL database.
- Loading branch information
1 parent
51e2e5a
commit 3d0d3dd
Showing
15 changed files
with
220 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ToUI | ||
==== | ||
|
||
Version: v3.0.4 | ||
Version: v3.1.0 | ||
|
||
.. include:: ../README.md | ||
:parser: myst_parser.sphinx_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.redirect_response | ||
---------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.redirect_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.redirect_response | ||
------------------------- | ||
|
||
.. automethod:: toui.apps.Website.redirect_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Page.set_footer | ||
--------------- | ||
|
||
.. automethod:: toui.pages.Page.set_footer |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
examples/advanced_example_5_toui_with_sql_user_database.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" | ||
ToUI with SQL User Database | ||
ToUI can be easily used with SQL database for: | ||
- User authentication | ||
- Storing user data in database | ||
This example uses the HTML file "test8.html": | ||
.. code-block:: html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<h1>Sign in users:</h1> | ||
<input id="username"/> | ||
<input id="password"/> | ||
<button id="sign-in">Sign in</button> | ||
<button id="sign-up">Sign up</button> | ||
<p id="output"></p> | ||
</body> | ||
</html> | ||
Python code: | ||
""" | ||
import sys | ||
sys.path.append("..") | ||
import os | ||
from toui import Website, Page | ||
|
||
app = Website(__name__, assets_folder="assets", secret_key="some text") | ||
SQL_URI = f"sqlite:///{os.getcwd()}/.test.db" # Change this value to match your SQL database URI | ||
app.add_user_database_using_sql(SQL_URI, other_columns=["age"]) # Connects to sql database. | ||
main_pg = Page(html_file="assets/test8.html", url="/") | ||
|
||
def sign_in(): | ||
pg = app.get_user_page() | ||
username = pg.get_element("username").get_value() | ||
password = pg.get_element("password").get_value() | ||
pg.get_element("output").set_content("loading") | ||
success = app.signin_user(username=username, password=password) | ||
if success: | ||
age = app.get_current_user_data("age") | ||
pg.get_element("output").set_content(f"Signed in successfully. Age of user: {age}") | ||
else: | ||
pg.get_element("output").set_content("Sign in failed") | ||
|
||
def sign_up(): | ||
pg = app.get_user_page() | ||
username = pg.get_element("username").get_value() | ||
password = pg.get_element("password").get_value() | ||
pg.get_element("output").set_content("loading") | ||
success = app.signup_user(username=username, password=password) | ||
if success: | ||
app.signin_user(username=username, password=password) | ||
value_added = app.set_current_user_data("age", 20) | ||
pg.get_element("output").set_content(f"Signed up successfully. Age added: {value_added}") | ||
else: | ||
pg.get_element("output").set_content("Sign up failed") | ||
|
||
def set_age(): | ||
pg = app.get_user_page() | ||
age = pg.get_element("age").get_value() | ||
app.set_current_user_data("age", age) | ||
pg.get_element("age-output").set_content(f"Age set to {age}") | ||
|
||
def get_age(): | ||
pg = app.get_user_page() | ||
age = app.get_current_user_data("age") | ||
pg.get_element("age-output").set_content(f"Age is {age}") | ||
|
||
main_pg.get_element("sign-in").onclick(sign_in) | ||
main_pg.get_element("sign-up").onclick(sign_up) | ||
main_pg.get_element("set-age").onclick(set_age) | ||
main_pg.get_element("get-age").onclick(get_age) | ||
|
||
|
||
app.add_pages(main_pg) | ||
|
||
if __name__ == '__main__': | ||
app.run() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Sign in users:</h1> | ||
<input id="username" /> | ||
<input id="password" /> | ||
<button id="sign-in">Sign in</button> | ||
<button id="sign-up">Sign up</button> | ||
<p id="output"></p> | ||
<p> | ||
<input type="text" id="age"><button id="set-age">Set Age</button> | ||
</p> | ||
<button id="get-age">Get Age</button> | ||
<p id="age-output"></p> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
from .structure import ToUIBlueprint | ||
from . import exceptions | ||
|
||
__version__ = "v3.0.4" | ||
__version__ = "v3.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters