Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cedashtools-0.2.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

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

Hashes for cedashtools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cb75c3398c727235f2f2af81db157876348b381afe0f7decd5c6ff0173ef8b09
MD5 4a327e5d4b7d941026dca0a7fa7950ff
BLAKE2b-256 7763cc48d8164b02b562f8f6fefcff9de0517f3aeb8ce0bf216577460f8f41ee

See more details on using hashes here.

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

Hashes for cedashtools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a1f941b4414ec4035ea8645e20c8b8ab913e6c30d0074fbc344f87ea5a05456
MD5 c7a434f64b81e1826ce87377d153865b
BLAKE2b-256 9a08e444fd9e9b4a8b4d2cc95c1705cebde40cdcbfbc7420efbfb8eef6989e2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page