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
# set default
USER_PAID = False
# Tool ID provided by centricengineers.com
TOOL_ID = 'a_tool_id'
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):
# run the validator and set the USER_PAID variable for the duration of this session
validator.website.login('username', 'password')
url_vars = validator.parse_url_params(search) # URL vars contain user information
access_level = validator.get_access_level(url_vars, TOOL_ID)
if access_level == AccessLevel.PAID:
global USER_PAID
USER_PAID = True # set USER_PAID variable for access-level testing throughout application
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
# set default
USER_PAID = False
# Tool ID provided by centricengineers.com
TOOL_ID = 'a_tool_id'
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
import app
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
# run the validator on the home page and set the app.USER_PAID variable for the duration of this session
validator.website.login('username', 'password')
access_level = validator.get_access_level(url_vars, app.TOOL_ID)
if access_level == AccessLevel.PAID:
app.USER_PAID = True # set app.USER_PAID for access-level testing throughout application
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-1.0.0b0.tar.gz
(3.8 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-1.0.0b0.tar.gz.
File metadata
- Download URL: cedashtools-1.0.0b0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a80db7f8eb7f8aa4a4818c666c141acc8bc9bc3d4698ab8bb1f1250291d002f4
|
|
| MD5 |
7560b7c7afc760476eda4ff13cec6dfb
|
|
| BLAKE2b-256 |
a9c1da8c862456d6a90c080f84a0ab2c99460cf94eaa11677ea5a4b12515bb86
|
File details
Details for the file cedashtools-1.0.0b0-py3-none-any.whl.
File metadata
- Download URL: cedashtools-1.0.0b0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1834121558bc2de0f51df3e45c356c88f1cdce81cc7e9faf05ef7b55f07f17fb
|
|
| MD5 |
a7ad040fd11524153acc13a4ea81f99c
|
|
| BLAKE2b-256 |
90ef159b43cc22cd72569cd54b9e65d939efc9c7b56bf9af4f1a29d58014e61b
|