For use in your Centric Engineers tools
Project description
Summary
Use this package with your Centric Engineers tools to acquire user access levels from centricengineers.com.
Usage
Single Page Dash App
In a simple single page Dash-Plotly application.
import dash
from dash import dcc, html, Input, Output
from cedashtools.user_access import validator
from cedashtools.user_access.website import AccessLevel
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='content'),
])
@app.callback(Output('content', 'children'),
Input('url', 'search'))
def display_content_based_on_access(search: str):
# Tool ID provided by centricengineers.com
tool_id = 'a_tool_id'
# run the validator
url_vars = validator.parse_url_params(search) # URL vars contain user information
access_level = validator.get_access_level(url_vars, tool_id)
# provide access based on the users AccessLevel
if access_level == AccessLevel.PRO:
layout = html.Div([html.H1(["Paid Content"])])
else:
layout = html.Div([html.H1(["Free Content"])])
return layout
Mult-Page Dash App
In a multi-page Dash-Plotly application (using pages).
app.py
import dash
from dash import html, dcc
APP_TITLE = "Dash App"
app = dash.Dash(
__name__,
title=APP_TITLE,
use_pages=True, # New in Dash 2.7 - Allows us to register pages
)
app.layout = html.Div([dash.page_container])
server = app.server
if __name__ == '__main__':
app.run_server(debug=True)
home.py
from dash import html, register_page
from cedashtools.user_access import validator
from cedashtools.user_access.website import AccessLevel
register_page(
__name__,
name='Home',
path='/'
)
def layout(**url_vars): # URL vars contain user information
# Tool ID provided by centricengineers.com
tool_id = 'a_tool_id'
# run the validator on the home page
access_level = validator.get_access_level(url_vars, tool_id)
# provide access based on the users AccessLevel
if access_level == AccessLevel.PRO:
layout = html.Div([html.H1(["Paid Content"])])
else:
layout = html.Div([html.H1(["Free Content"])])
return layout
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cedashtools-0.2.0.tar.gz
(3.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cedashtools-0.2.0.tar.gz.
File metadata
- Download URL: cedashtools-0.2.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb75c3398c727235f2f2af81db157876348b381afe0f7decd5c6ff0173ef8b09
|
|
| MD5 |
4a327e5d4b7d941026dca0a7fa7950ff
|
|
| BLAKE2b-256 |
7763cc48d8164b02b562f8f6fefcff9de0517f3aeb8ce0bf216577460f8f41ee
|
File details
Details for the file cedashtools-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cedashtools-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a1f941b4414ec4035ea8645e20c8b8ab913e6c30d0074fbc344f87ea5a05456
|
|
| MD5 |
c7a434f64b81e1826ce87377d153865b
|
|
| BLAKE2b-256 |
9a08e444fd9e9b4a8b4d2cc95c1705cebde40cdcbfbc7420efbfb8eef6989e2a
|