Skip to content

dlunch

Main Data-Lunch package.

Modules:

Name Description
__main__

Data-Lunch package entrypoint.

auth

Module with classes and functions used for authentication and password handling.

cli

Module with Data-Lunch's command line.

cloud

Module with functions to interact with GCP storage service.

conf

Package with Hydra configuration yaml files.

core
gui

Module that defines main graphic interface and backend graphic interface.

models

Module with database tables definitions.

scheduled_tasks

Module with functions used to execute scheduled tasks.

Functions:

Name Description
create_app

Panel main app factory function

create_backend

Panel backend app factory function

Attributes:

Name Type Description
log Logger

Module logger.

log module-attribute

log: Logger = getLogger(__name__)

Module logger.

create_app

create_app(config: DictConfig) -> Template

Panel main app factory function

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required

Returns:

Type Description
Template

Panel main app template.

Source code in dlunch/__init__.py
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def create_app(config: DictConfig) -> pn.Template:
    """Panel main app factory function

    Args:
        config (DictConfig): Hydra configuration dictionary.

    Returns:
        pn.Template: Panel main app template.
    """
    log.info("starting initialization process")

    log.info("initialize database")
    # Create tables
    models.create_database(
        config, add_basic_auth_users=auth.is_basic_auth_active(config=config)
    )

    log.info("initialize support variables")
    # Generate a random password only if requested (check on flag)
    log.debug("config guest user")
    guest_password = core.set_guest_user_password(config)

    log.info("instantiate app")

    # Panel configurations
    log.debug("set toggles initial state")
    # Set the no_more_orders flag if it is None (not found in flags table)
    if models.get_flag(config=config, id="no_more_orders") is None:
        models.set_flag(config=config, id="no_more_orders", value=False)
    # Set guest override flag if it is None (not found in flags table)
    # Guest override flag is per-user and is not set for guests
    if (
        models.get_flag(config=config, id=f"{pn_user(config)}_guest_override")
        is None
    ) and not auth.is_guest(
        user=pn_user(config), config=config, allow_override=False
    ):
        models.set_flag(
            config=config, id=f"{pn_user(config)}_guest_override", value=False
        )

    # DASHBOARD BASE TEMPLATE
    log.debug("instantiate base template")
    # Create web app template
    app = pn.template.VanillaTemplate(
        title=config.panel.gui.title,
        sidebar_width=gui.sidebar_width,
        favicon=config.panel.gui.favicon_path,
        logo=config.panel.gui.logo_path,
        css_files=OmegaConf.to_container(
            config.panel.gui.template_css_files, resolve=True
        ),
        raw_css=OmegaConf.to_container(
            config.panel.gui.template_raw_css, resolve=True
        ),
    )

    # CONFIGURABLE OBJECTS
    # Since Person class need the config variable for initialization, every
    # graphic element that require the Person class has to be instantiated
    # by a dedicated function
    # Create person instance, widget and column
    log.debug("instantiate person class and graphic graphic interface")
    person = gui.Person(config, name="User")
    gi = gui.GraphicInterface(config, app, person, guest_password)

    # DASHBOARD
    # Build dashboard (the header object is used if defined)
    app.header.append(gi.header_row)
    app.sidebar.append(gi.sidebar_tabs)
    app.main.append(gi.no_menu_col)
    app.main.append(gi.guest_override_alert)
    app.main.append(gi.no_more_order_alert)
    app.main.append(gi.main_header_row)
    app.main.append(gi.quote)
    app.main.append(pn.Spacer(height=15))
    app.main.append(gi.menu_flexbox)
    app.main.append(gi.buttons_flexbox)
    app.main.append(gi.results_divider)
    app.main.append(gi.res_col)
    app.modal.append(gi.error_message)

    # Set components visibility based on no_more_order_button state
    # and reload menu
    gi.reload_on_no_more_order(
        toggle=models.get_flag(config=config, id="no_more_orders"),
        reload=False,
    )
    gi.reload_on_guest_override(
        toggle=models.get_flag(
            config=config,
            id=f"{pn_user(config)}_guest_override",
            value_if_missing=False,
        ),
        reload=False,
    )
    core.reload_menu(
        None,
        config,
        gi,
    )

    app.servable()

    log.info("initialization process completed")

    return app

create_backend

create_backend(config: DictConfig) -> Template

Panel backend app factory function

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required

Returns:

Type Description
Template

Panel backend app template.

Source code in dlunch/__init__.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def create_backend(config: DictConfig) -> pn.Template:
    """Panel backend app factory function

    Args:
        config (DictConfig): Hydra configuration dictionary.

    Returns:
        pn.Template: Panel backend app template.
    """

    log.info("starting initialization process")

    log.info("initialize database")
    # Create tables
    models.create_database(
        config, add_basic_auth_users=auth.is_basic_auth_active(config=config)
    )

    log.info("instantiate backend")

    # DASHBOARD
    log.debug("instantiate base template")
    # Create web app template
    backend = pn.template.VanillaTemplate(
        title=f"{config.panel.gui.title} Backend",
        favicon=config.panel.gui.favicon_path,
        logo=config.panel.gui.logo_path,
        css_files=OmegaConf.to_container(
            config.panel.gui.template_css_files, resolve=True
        ),
        raw_css=OmegaConf.to_container(
            config.panel.gui.template_raw_css, resolve=True
        ),
    )

    # CONFIGURABLE OBJECTS
    backend_gi = gui.BackendInterface(config)

    # DASHBOARD
    # Build dashboard
    backend.header.append(backend_gi.header_row)
    backend.main.append(backend_gi.backend_controls)

    backend.servable()

    log.info("initialization process completed")

    return backend