Skip to content

gui

Module that defines main graphic interface and backend graphic interface.

Classes that uses param are then used to create Panel widget directly (see Panel docs <https://panel.holoviz.org/how_to/param/uis.html>__).

Modules:

Name Description
auth

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

core
models

Module with database tables definitions.

Classes:

Name Description
BackendAddPrivilegedUser

Param class used inside the backend to create the widget add new users to the privileged_user table.

BackendInterface

Class with widgets for the backend graphic interface.

BackendPasswordRenewer

Param class used inside the backend to create the widget that collect info to renew users password.

BackendUserEraser

Param class used inside the backend to create the widget that delete users.

GraphicInterface

Class with widgets for the main graphic interface.

PasswordRenewer

Param class used to create the widget that collect info to renew users password.

Person

Param class that define user data and lunch preferences for its order.

Attributes:

Name Type Description
backend_min_height int

Backend minimum height.

df_quote DataFrame

Dataframe with the quote of the day.

df_quotes DataFrame

Dataframe with quotes.

download_text str

info Text used in Download Orders tab.

generic_button_height int

Button height.

guest_user_text str

info Text used in guest Password widget.

header_button_width int

Width for buttons used in top header.

header_row_height int

Top header height.

log Logger

Module logger.

main_area_min_width int

Main area width. It's the area with menu and order summary.

person_text str

info Text used in User tab.

quotes_filename Path

Excel file with quotes.

seed_day int

seed to Select the quote of the day.

sidebar_content_width int

Sidebar content width. Should be smaller than sidebar width.

sidebar_width int

Sidebar width.

time_col_spacer_width int

Time column spacer width.

time_col_width int

Time column width (the time column is on the side of the menu table).

upload_text str

info Text used in Menu Upload tab.

backend_min_height module-attribute

backend_min_height: int = 500

Backend minimum height.

df_quote module-attribute

df_quote: DataFrame = sample(n=1, random_state=seed_day)

Dataframe with the quote of the day.

df_quotes module-attribute

Dataframe with quotes.

download_text module-attribute

download_text: str = (
    "\n### Download Orders\nDownload the order list.\n"
)

info Text used in Download Orders tab.

generic_button_height module-attribute

generic_button_height: int = 45

Button height.

guest_user_text module-attribute

guest_user_text: str = '\n### Guest user\n'

info Text used in guest Password widget.

header_button_width module-attribute

header_button_width: int = 50

Width for buttons used in top header.

header_row_height module-attribute

header_row_height: int = 55

Top header height.

log module-attribute

log: Logger = getLogger(__name__)

Module logger.

main_area_min_width module-attribute

main_area_min_width: int = (
    580 + time_col_spacer_width + time_col_width
)

Main area width. It's the area with menu and order summary.

person_text module-attribute

person_text: str = (
    "\n### User Data\n\n_Privileged users_ do not need to fill the username.<br>\n_Guest users_ shall use a valid _unique_ name and select a guest type.\n"
)

info Text used in User tab.

quotes_filename module-attribute

quotes_filename: Path = parent / 'quotes.xlsx'

Excel file with quotes.

seed_day module-attribute

seed_day: int = int(strftime('%Y%m%d'))

seed to Select the quote of the day.

sidebar_content_width module-attribute

sidebar_content_width: int = sidebar_width - 10

Sidebar content width. Should be smaller than sidebar width.

sidebar_width module-attribute

sidebar_width: int = 400

Sidebar width.

time_col_spacer_width module-attribute

time_col_spacer_width: int = 5

Time column spacer width.

time_col_width module-attribute

time_col_width: int = 90

Time column width (the time column is on the side of the menu table).

upload_text module-attribute

upload_text: str = (
    "\n### Menu Upload\nSelect a .png, .jpg or .xlsx file with the menu.<br>\nThe app may add some default items to the menu.\n\n**For .xlsx:** list menu items starting from cell A1, one per each row.\n"
)

info Text used in Menu Upload tab.

BackendAddPrivilegedUser

Bases: Parameterized

Param class used inside the backend to create the widget add new users to the privileged_user table.

Methods:

Name Description
__str__

String representation of this object.

Attributes:

Name Type Description
admin Boolean

Admin flag (true if admin).

user String

Username of the new user.

Source code in dlunch/gui.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
class BackendAddPrivilegedUser(param.Parameterized):
    """Param class used inside the backend to create the widget add new users to the `privileged_user` table."""

    user: param.String = param.String(default="", doc="user to add")
    """Username of the new user."""
    admin: param.Boolean = param.Boolean(
        default=False, doc="add admin privileges"
    )
    """Admin flag (true if admin)."""

    def __str__(self):
        """String representation of this object.

        Returns:
            (str): string representation.
        """
        return "BackendAddUser"

admin class-attribute instance-attribute

admin: Boolean = Boolean(
    default=False, doc="add admin privileges"
)

Admin flag (true if admin).

user class-attribute instance-attribute

user: String = String(default='', doc='user to add')

Username of the new user.

__str__

__str__()

String representation of this object.

Returns:

Type Description
str

string representation.

Source code in dlunch/gui.py
176
177
178
179
180
181
182
def __str__(self):
    """String representation of this object.

    Returns:
        (str): string representation.
    """
    return "BackendAddUser"

BackendInterface

Class with widgets for the backend graphic interface.

All widgets are instantiated at class initialization.

Class methods handle specific operations that may be repeated multiple time after class instantiation.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required

Methods:

Name Description
__init__
exit_backend

Return to main homepage.

reload_backend

Reload backend by updating user lists and privileges.

Attributes:

Name Type Description
access_denied_text
add_privileged_user_button
add_privileged_user_column
add_privileged_user_widget
add_update_user_column
backend_controls
clear_flags_button
clear_flags_column
delete_user_button
delete_user_column
exit_button
flags_content
header_row
list_user_column
password_widget
submit_password_button
user_eraser
users_tabulator
Source code in dlunch/gui.py
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
class BackendInterface:
    """Class with widgets for the backend graphic interface.

    All widgets are instantiated at class initialization.

    Class methods handle specific operations that may be repeated multiple time after class instantiation.

    Args:
        config (DictConfig): Hydra configuration dictionary.
    """

    def __init__(
        self,
        config: DictConfig,
    ):
        # HEADER SECTION ------------------------------------------------------
        # WIDGET

        # BUTTONS
        self.exit_button = pnw.Button(
            name="",
            button_type="primary",
            button_style="solid",
            width=header_button_width,
            height=generic_button_height,
            icon="home-move",
            icon_size="2em",
        )

        # ROW
        # Create column for person data (add logout button only if auth is active)
        self.header_row = pn.Row(
            height=header_row_height,
            sizing_mode="stretch_width",
        )
        # Append a controls to the right side of header
        self.header_row.append(pn.HSpacer())
        self.header_row.append(self.exit_button)
        self.header_row.append(
            pn.pane.HTML(styles=dict(background="white"), width=2, height=45)
        )

        # CALLBACKS
        # Exit callback
        self.exit_button.on_click(lambda e: self.exit_backend())

        # MAIN SECTION --------------------------------------------------------
        # Backend main section

        # TEXTS
        # "no more order" message
        self.access_denied_text = pn.pane.HTML(
            """
            <div class="no-more-order-flag">
                <div class="icon-container">
                    <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-shield-lock-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                        <path d="M11.998 2l.118 .007l.059 .008l.061 .013l.111 .034a.993 .993 0 0 1 .217 .112l.104 .082l.255 .218a11 11 0 0 0 7.189 2.537l.342 -.01a1 1 0 0 1 1.005 .717a13 13 0 0 1 -9.208 16.25a1 1 0 0 1 -.502 0a13 13 0 0 1 -9.209 -16.25a1 1 0 0 1 1.005 -.717a11 11 0 0 0 7.531 -2.527l.263 -.225l.096 -.075a.993 .993 0 0 1 .217 -.112l.112 -.034a.97 .97 0 0 1 .119 -.021l.115 -.007zm.002 7a2 2 0 0 0 -1.995 1.85l-.005 .15l.005 .15a2 2 0 0 0 .995 1.581v1.769l.007 .117a1 1 0 0 0 1.993 -.117l.001 -1.768a2 2 0 0 0 -1.001 -3.732z" stroke-width="0" fill="currentColor"></path>
                    </svg>
                    <span><strong>Insufficient privileges!</strong></span>
                </div>
            </div>
            """,
            margin=5,
            sizing_mode="stretch_width",
            stylesheets=[config.panel.gui.css_files.no_more_orders_path],
        )

        # WIDGET
        # Password renewer (only basic auth)
        self.password_widget = pn.Param(
            BackendPasswordRenewer().param,
            widgets={
                "new_password": pnw.PasswordInput(
                    name="New password", placeholder="New Password"
                ),
                "repeat_new_password": pnw.PasswordInput(
                    name="Repeat new password",
                    placeholder="Repeat New Password",
                ),
            },
            name="Add/Update User Credentials",
            width=sidebar_content_width,
        )
        # Add user (only oauth)
        self.add_privileged_user_widget = pn.Param(
            BackendAddPrivilegedUser().param,
            name="Add Privileged User",
            width=sidebar_content_width,
        )
        # User eraser
        self.user_eraser = pn.Param(
            BackendUserEraser().param,
            name="Delete User",
            width=sidebar_content_width,
        )
        # User list
        self.users_tabulator = pn.widgets.Tabulator(
            value=auth.list_users_guests_and_privileges(config),
            sizing_mode="stretch_height",
        )
        # Flags content (use empty dataframe to instantiate)
        df_flags = models.Flags.read_as_df(
            config=config,
            index_col="id",
        )
        self.flags_content = pn.widgets.Tabulator(
            value=df_flags,
            sizing_mode="stretch_height",
        )

        # BUTTONS
        # Exit button
        # Password button
        self.submit_password_button = pnw.Button(
            name="Submit",
            button_type="success",
            height=generic_button_height,
            icon="key",
            icon_size="2em",
            sizing_mode="stretch_width",
        )
        # Delete User button
        self.add_privileged_user_button = pnw.Button(
            name="Add",
            button_type="success",
            height=generic_button_height,
            icon="user-plus",
            icon_size="2em",
            sizing_mode="stretch_width",
        )
        # Delete User button
        self.delete_user_button = pnw.Button(
            name="Delete",
            button_type="danger",
            height=generic_button_height,
            icon="user-minus",
            icon_size="2em",
            sizing_mode="stretch_width",
        )
        # Clear flags table button
        self.clear_flags_button = pnw.Button(
            name="Clear Guest Override Flags",
            button_type="danger",
            height=generic_button_height,
            icon="file-shredder",
            icon_size="2em",
            sizing_mode="stretch_width",
        )

        # COLUMN
        # Create column with user credentials controls (basic auth)
        self.add_update_user_column = pn.Column(
            config.panel.gui.psw_text,
            self.password_widget,
            pn.VSpacer(),
            self.submit_password_button,
            width=sidebar_width,
            sizing_mode="stretch_height",
            min_height=backend_min_height,
        )
        # Create column with user authenthication controls (oauth)
        self.add_privileged_user_column = pn.Column(
            self.add_privileged_user_widget,
            pn.VSpacer(),
            self.add_privileged_user_button,
            width=sidebar_width,
            sizing_mode="stretch_height",
            min_height=backend_min_height,
        )
        # Create column for deleting users
        self.delete_user_column = pn.Column(
            self.user_eraser,
            pn.VSpacer(),
            self.delete_user_button,
            width=sidebar_width,
            sizing_mode="stretch_height",
            min_height=backend_min_height,
        )
        # Create column with flags' list
        self.clear_flags_column = pn.Column(
            pn.pane.HTML("<b>Flags Table Content</b>"),
            self.flags_content,
            self.clear_flags_button,
            width=sidebar_width,
            sizing_mode="stretch_height",
            min_height=backend_min_height,
        )
        # Create column for users' list
        self.list_user_column = pn.Column(
            pn.pane.HTML("<b>Users and Privileges</b>"),
            self.users_tabulator,
            width=sidebar_width,
            sizing_mode="stretch_height",
            min_height=backend_min_height,
        )

        # ROWS
        self.backend_controls = pn.Row(
            name="Actions",
            sizing_mode="stretch_both",
            min_height=backend_min_height,
        )
        # Add controls only for admin users
        if not auth.is_admin(user=pn_user(config), config=config):
            self.backend_controls.append(self.access_denied_text)
            self.backend_controls.append(pn.Spacer(height=15))
        else:
            # For basic auth use a password renewer, for oauth a widget for
            # adding privileged users
            if auth.is_basic_auth_active(config=config):
                self.backend_controls.append(self.add_update_user_column)
            else:
                self.backend_controls.append(self.add_privileged_user_column)
            self.backend_controls.append(
                pn.pane.HTML(
                    styles=dict(background="lightgray"),
                    width=2,
                    sizing_mode="stretch_height",
                )
            )
            self.backend_controls.append(self.delete_user_column)
            self.backend_controls.append(
                pn.pane.HTML(
                    styles=dict(background="lightgray"),
                    width=2,
                    sizing_mode="stretch_height",
                )
            )
            self.backend_controls.append(self.clear_flags_column)
            self.backend_controls.append(
                pn.pane.HTML(
                    styles=dict(background="lightgray"),
                    width=2,
                    sizing_mode="stretch_height",
                )
            )
            self.backend_controls.append(self.list_user_column)

        # CALLBACKS
        # Submit password button callback
        def submit_password_button_callback(self, config):
            success = core.backend_submit_password(
                gi=self,
                is_admin=self.password_widget.object.admin,
                is_guest=self.password_widget.object.guest,
                config=config,
            )
            if success:
                self.reload_backend(config)

        self.submit_password_button.on_click(
            lambda e: submit_password_button_callback(self, config)
        )

        # Add privileged user callback
        def add_privileged_user_button_callback(self):
            # Get username, updated at each key press
            username_key_press = self.add_privileged_user_widget._widgets[
                "user"
            ].value_input
            # Add user
            auth.add_privileged_user(
                username_key_press,
                is_admin=self.add_privileged_user_widget.object.admin,
                config=config,
            )

            self.reload_backend(config)
            pn.state.notifications.success(
                f"User '{username_key_press}' added",
                duration=config.panel.notifications.duration,
            )

        self.add_privileged_user_button.on_click(
            lambda e: add_privileged_user_button_callback(self)
        )

        # Delete user callback
        def delete_user_button_callback(self):
            # Get username, updated at each key press
            username_key_press = self.user_eraser._widgets["user"].value_input
            # Delete user
            deleted_data = auth.remove_user(
                user=username_key_press, config=config
            )
            if (deleted_data["privileged_users_deleted"] > 0) or (
                deleted_data["credentials_deleted"] > 0
            ):
                self.reload_backend(config)
                pn.state.notifications.success(
                    f"User '{self.user_eraser.object.user}' deleted<br>auth: {deleted_data['privileged_users_deleted']}<br>cred: {deleted_data['credentials_deleted']}",
                    duration=config.panel.notifications.duration,
                )
            else:
                pn.state.notifications.error(
                    f"User '{username_key_press}' does not exist",
                    duration=config.panel.notifications.duration,
                )

        self.delete_user_button.on_click(
            lambda e: delete_user_button_callback(self)
        )

        # Clear flags callback
        def clear_flags_button_callback(self):
            # Clear flags
            num_rows_deleted = models.Flags.clear_guest_override(config=config)
            # Reload and notify user
            self.reload_backend(config)
            pn.state.notifications.success(
                f"Guest override flags cleared<br>{num_rows_deleted} rows deleted",
                duration=config.panel.notifications.duration,
            )

        self.clear_flags_button.on_click(
            lambda e: clear_flags_button_callback(self)
        )

    # UTILITY FUNCTIONS
    # MAIN SECTION
    def reload_backend(self, config: DictConfig) -> None:
        """Reload backend by updating user lists and privileges.
        Read also flags from `flags` table.

        Args:
            config (DictConfig): Hydra configuration dictionary.
        """
        # Users and guests lists
        self.users_tabulator.value = auth.list_users_guests_and_privileges(
            config
        )
        # Flags table content
        df_flags = models.Flags.read_as_df(
            config=config,
            index_col="id",
        )
        self.flags_content.value = df_flags

    def exit_backend(self) -> None:
        """Return to main homepage."""
        # Edit pathname to force exit
        pn.state.location.pathname = (
            pn.state.location.pathname.split("/")[0] + "/"
        )
        pn.state.location.reload = True

access_denied_text instance-attribute

access_denied_text = HTML(
    '\n            <div class="no-more-order-flag">\n                <div class="icon-container">\n                    <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-shield-lock-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">\n                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>\n                        <path d="M11.998 2l.118 .007l.059 .008l.061 .013l.111 .034a.993 .993 0 0 1 .217 .112l.104 .082l.255 .218a11 11 0 0 0 7.189 2.537l.342 -.01a1 1 0 0 1 1.005 .717a13 13 0 0 1 -9.208 16.25a1 1 0 0 1 -.502 0a13 13 0 0 1 -9.209 -16.25a1 1 0 0 1 1.005 -.717a11 11 0 0 0 7.531 -2.527l.263 -.225l.096 -.075a.993 .993 0 0 1 .217 -.112l.112 -.034a.97 .97 0 0 1 .119 -.021l.115 -.007zm.002 7a2 2 0 0 0 -1.995 1.85l-.005 .15l.005 .15a2 2 0 0 0 .995 1.581v1.769l.007 .117a1 1 0 0 0 1.993 -.117l.001 -1.768a2 2 0 0 0 -1.001 -3.732z" stroke-width="0" fill="currentColor"></path>\n                    </svg>\n                    <span><strong>Insufficient privileges!</strong></span>\n                </div>\n            </div>\n            ',
    margin=5,
    sizing_mode="stretch_width",
    stylesheets=[no_more_orders_path],
)

add_privileged_user_button instance-attribute

add_privileged_user_button = Button(
    name="Add",
    button_type="success",
    height=generic_button_height,
    icon="user-plus",
    icon_size="2em",
    sizing_mode="stretch_width",
)

add_privileged_user_column instance-attribute

add_privileged_user_column = Column(
    add_privileged_user_widget,
    VSpacer(),
    add_privileged_user_button,
    width=sidebar_width,
    sizing_mode="stretch_height",
    min_height=backend_min_height,
)

add_privileged_user_widget instance-attribute

add_privileged_user_widget = Param(
    param,
    name="Add Privileged User",
    width=sidebar_content_width,
)

add_update_user_column instance-attribute

add_update_user_column = Column(
    psw_text,
    password_widget,
    VSpacer(),
    submit_password_button,
    width=sidebar_width,
    sizing_mode="stretch_height",
    min_height=backend_min_height,
)

backend_controls instance-attribute

backend_controls = Row(
    name="Actions",
    sizing_mode="stretch_both",
    min_height=backend_min_height,
)

clear_flags_button instance-attribute

clear_flags_button = Button(
    name="Clear Guest Override Flags",
    button_type="danger",
    height=generic_button_height,
    icon="file-shredder",
    icon_size="2em",
    sizing_mode="stretch_width",
)

clear_flags_column instance-attribute

clear_flags_column = Column(
    HTML("<b>Flags Table Content</b>"),
    flags_content,
    clear_flags_button,
    width=sidebar_width,
    sizing_mode="stretch_height",
    min_height=backend_min_height,
)

delete_user_button instance-attribute

delete_user_button = Button(
    name="Delete",
    button_type="danger",
    height=generic_button_height,
    icon="user-minus",
    icon_size="2em",
    sizing_mode="stretch_width",
)

delete_user_column instance-attribute

delete_user_column = Column(
    user_eraser,
    VSpacer(),
    delete_user_button,
    width=sidebar_width,
    sizing_mode="stretch_height",
    min_height=backend_min_height,
)

exit_button instance-attribute

exit_button = Button(
    name="",
    button_type="primary",
    button_style="solid",
    width=header_button_width,
    height=generic_button_height,
    icon="home-move",
    icon_size="2em",
)

flags_content instance-attribute

flags_content = Tabulator(
    value=df_flags, sizing_mode="stretch_height"
)

header_row instance-attribute

header_row = Row(
    height=header_row_height, sizing_mode="stretch_width"
)

list_user_column instance-attribute

list_user_column = Column(
    HTML("<b>Users and Privileges</b>"),
    users_tabulator,
    width=sidebar_width,
    sizing_mode="stretch_height",
    min_height=backend_min_height,
)

password_widget instance-attribute

password_widget = Param(
    param,
    widgets={
        "new_password": PasswordInput(
            name="New password", placeholder="New Password"
        ),
        "repeat_new_password": PasswordInput(
            name="Repeat new password",
            placeholder="Repeat New Password",
        ),
    },
    name="Add/Update User Credentials",
    width=sidebar_content_width,
)

submit_password_button instance-attribute

submit_password_button = Button(
    name="Submit",
    button_type="success",
    height=generic_button_height,
    icon="key",
    icon_size="2em",
    sizing_mode="stretch_width",
)

user_eraser instance-attribute

user_eraser = Param(
    param, name="Delete User", width=sidebar_content_width
)

users_tabulator instance-attribute

users_tabulator = Tabulator(
    value=list_users_guests_and_privileges(config),
    sizing_mode="stretch_height",
)

__init__

__init__(config: DictConfig)
Source code in dlunch/gui.py
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
def __init__(
    self,
    config: DictConfig,
):
    # HEADER SECTION ------------------------------------------------------
    # WIDGET

    # BUTTONS
    self.exit_button = pnw.Button(
        name="",
        button_type="primary",
        button_style="solid",
        width=header_button_width,
        height=generic_button_height,
        icon="home-move",
        icon_size="2em",
    )

    # ROW
    # Create column for person data (add logout button only if auth is active)
    self.header_row = pn.Row(
        height=header_row_height,
        sizing_mode="stretch_width",
    )
    # Append a controls to the right side of header
    self.header_row.append(pn.HSpacer())
    self.header_row.append(self.exit_button)
    self.header_row.append(
        pn.pane.HTML(styles=dict(background="white"), width=2, height=45)
    )

    # CALLBACKS
    # Exit callback
    self.exit_button.on_click(lambda e: self.exit_backend())

    # MAIN SECTION --------------------------------------------------------
    # Backend main section

    # TEXTS
    # "no more order" message
    self.access_denied_text = pn.pane.HTML(
        """
        <div class="no-more-order-flag">
            <div class="icon-container">
                <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-shield-lock-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <path d="M11.998 2l.118 .007l.059 .008l.061 .013l.111 .034a.993 .993 0 0 1 .217 .112l.104 .082l.255 .218a11 11 0 0 0 7.189 2.537l.342 -.01a1 1 0 0 1 1.005 .717a13 13 0 0 1 -9.208 16.25a1 1 0 0 1 -.502 0a13 13 0 0 1 -9.209 -16.25a1 1 0 0 1 1.005 -.717a11 11 0 0 0 7.531 -2.527l.263 -.225l.096 -.075a.993 .993 0 0 1 .217 -.112l.112 -.034a.97 .97 0 0 1 .119 -.021l.115 -.007zm.002 7a2 2 0 0 0 -1.995 1.85l-.005 .15l.005 .15a2 2 0 0 0 .995 1.581v1.769l.007 .117a1 1 0 0 0 1.993 -.117l.001 -1.768a2 2 0 0 0 -1.001 -3.732z" stroke-width="0" fill="currentColor"></path>
                </svg>
                <span><strong>Insufficient privileges!</strong></span>
            </div>
        </div>
        """,
        margin=5,
        sizing_mode="stretch_width",
        stylesheets=[config.panel.gui.css_files.no_more_orders_path],
    )

    # WIDGET
    # Password renewer (only basic auth)
    self.password_widget = pn.Param(
        BackendPasswordRenewer().param,
        widgets={
            "new_password": pnw.PasswordInput(
                name="New password", placeholder="New Password"
            ),
            "repeat_new_password": pnw.PasswordInput(
                name="Repeat new password",
                placeholder="Repeat New Password",
            ),
        },
        name="Add/Update User Credentials",
        width=sidebar_content_width,
    )
    # Add user (only oauth)
    self.add_privileged_user_widget = pn.Param(
        BackendAddPrivilegedUser().param,
        name="Add Privileged User",
        width=sidebar_content_width,
    )
    # User eraser
    self.user_eraser = pn.Param(
        BackendUserEraser().param,
        name="Delete User",
        width=sidebar_content_width,
    )
    # User list
    self.users_tabulator = pn.widgets.Tabulator(
        value=auth.list_users_guests_and_privileges(config),
        sizing_mode="stretch_height",
    )
    # Flags content (use empty dataframe to instantiate)
    df_flags = models.Flags.read_as_df(
        config=config,
        index_col="id",
    )
    self.flags_content = pn.widgets.Tabulator(
        value=df_flags,
        sizing_mode="stretch_height",
    )

    # BUTTONS
    # Exit button
    # Password button
    self.submit_password_button = pnw.Button(
        name="Submit",
        button_type="success",
        height=generic_button_height,
        icon="key",
        icon_size="2em",
        sizing_mode="stretch_width",
    )
    # Delete User button
    self.add_privileged_user_button = pnw.Button(
        name="Add",
        button_type="success",
        height=generic_button_height,
        icon="user-plus",
        icon_size="2em",
        sizing_mode="stretch_width",
    )
    # Delete User button
    self.delete_user_button = pnw.Button(
        name="Delete",
        button_type="danger",
        height=generic_button_height,
        icon="user-minus",
        icon_size="2em",
        sizing_mode="stretch_width",
    )
    # Clear flags table button
    self.clear_flags_button = pnw.Button(
        name="Clear Guest Override Flags",
        button_type="danger",
        height=generic_button_height,
        icon="file-shredder",
        icon_size="2em",
        sizing_mode="stretch_width",
    )

    # COLUMN
    # Create column with user credentials controls (basic auth)
    self.add_update_user_column = pn.Column(
        config.panel.gui.psw_text,
        self.password_widget,
        pn.VSpacer(),
        self.submit_password_button,
        width=sidebar_width,
        sizing_mode="stretch_height",
        min_height=backend_min_height,
    )
    # Create column with user authenthication controls (oauth)
    self.add_privileged_user_column = pn.Column(
        self.add_privileged_user_widget,
        pn.VSpacer(),
        self.add_privileged_user_button,
        width=sidebar_width,
        sizing_mode="stretch_height",
        min_height=backend_min_height,
    )
    # Create column for deleting users
    self.delete_user_column = pn.Column(
        self.user_eraser,
        pn.VSpacer(),
        self.delete_user_button,
        width=sidebar_width,
        sizing_mode="stretch_height",
        min_height=backend_min_height,
    )
    # Create column with flags' list
    self.clear_flags_column = pn.Column(
        pn.pane.HTML("<b>Flags Table Content</b>"),
        self.flags_content,
        self.clear_flags_button,
        width=sidebar_width,
        sizing_mode="stretch_height",
        min_height=backend_min_height,
    )
    # Create column for users' list
    self.list_user_column = pn.Column(
        pn.pane.HTML("<b>Users and Privileges</b>"),
        self.users_tabulator,
        width=sidebar_width,
        sizing_mode="stretch_height",
        min_height=backend_min_height,
    )

    # ROWS
    self.backend_controls = pn.Row(
        name="Actions",
        sizing_mode="stretch_both",
        min_height=backend_min_height,
    )
    # Add controls only for admin users
    if not auth.is_admin(user=pn_user(config), config=config):
        self.backend_controls.append(self.access_denied_text)
        self.backend_controls.append(pn.Spacer(height=15))
    else:
        # For basic auth use a password renewer, for oauth a widget for
        # adding privileged users
        if auth.is_basic_auth_active(config=config):
            self.backend_controls.append(self.add_update_user_column)
        else:
            self.backend_controls.append(self.add_privileged_user_column)
        self.backend_controls.append(
            pn.pane.HTML(
                styles=dict(background="lightgray"),
                width=2,
                sizing_mode="stretch_height",
            )
        )
        self.backend_controls.append(self.delete_user_column)
        self.backend_controls.append(
            pn.pane.HTML(
                styles=dict(background="lightgray"),
                width=2,
                sizing_mode="stretch_height",
            )
        )
        self.backend_controls.append(self.clear_flags_column)
        self.backend_controls.append(
            pn.pane.HTML(
                styles=dict(background="lightgray"),
                width=2,
                sizing_mode="stretch_height",
            )
        )
        self.backend_controls.append(self.list_user_column)

    # CALLBACKS
    # Submit password button callback
    def submit_password_button_callback(self, config):
        success = core.backend_submit_password(
            gi=self,
            is_admin=self.password_widget.object.admin,
            is_guest=self.password_widget.object.guest,
            config=config,
        )
        if success:
            self.reload_backend(config)

    self.submit_password_button.on_click(
        lambda e: submit_password_button_callback(self, config)
    )

    # Add privileged user callback
    def add_privileged_user_button_callback(self):
        # Get username, updated at each key press
        username_key_press = self.add_privileged_user_widget._widgets[
            "user"
        ].value_input
        # Add user
        auth.add_privileged_user(
            username_key_press,
            is_admin=self.add_privileged_user_widget.object.admin,
            config=config,
        )

        self.reload_backend(config)
        pn.state.notifications.success(
            f"User '{username_key_press}' added",
            duration=config.panel.notifications.duration,
        )

    self.add_privileged_user_button.on_click(
        lambda e: add_privileged_user_button_callback(self)
    )

    # Delete user callback
    def delete_user_button_callback(self):
        # Get username, updated at each key press
        username_key_press = self.user_eraser._widgets["user"].value_input
        # Delete user
        deleted_data = auth.remove_user(
            user=username_key_press, config=config
        )
        if (deleted_data["privileged_users_deleted"] > 0) or (
            deleted_data["credentials_deleted"] > 0
        ):
            self.reload_backend(config)
            pn.state.notifications.success(
                f"User '{self.user_eraser.object.user}' deleted<br>auth: {deleted_data['privileged_users_deleted']}<br>cred: {deleted_data['credentials_deleted']}",
                duration=config.panel.notifications.duration,
            )
        else:
            pn.state.notifications.error(
                f"User '{username_key_press}' does not exist",
                duration=config.panel.notifications.duration,
            )

    self.delete_user_button.on_click(
        lambda e: delete_user_button_callback(self)
    )

    # Clear flags callback
    def clear_flags_button_callback(self):
        # Clear flags
        num_rows_deleted = models.Flags.clear_guest_override(config=config)
        # Reload and notify user
        self.reload_backend(config)
        pn.state.notifications.success(
            f"Guest override flags cleared<br>{num_rows_deleted} rows deleted",
            duration=config.panel.notifications.duration,
        )

    self.clear_flags_button.on_click(
        lambda e: clear_flags_button_callback(self)
    )

exit_backend

exit_backend() -> None

Return to main homepage.

Source code in dlunch/gui.py
1404
1405
1406
1407
1408
1409
1410
def exit_backend(self) -> None:
    """Return to main homepage."""
    # Edit pathname to force exit
    pn.state.location.pathname = (
        pn.state.location.pathname.split("/")[0] + "/"
    )
    pn.state.location.reload = True

reload_backend

reload_backend(config: DictConfig) -> None

Reload backend by updating user lists and privileges. Read also flags from flags table.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required
Source code in dlunch/gui.py
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
def reload_backend(self, config: DictConfig) -> None:
    """Reload backend by updating user lists and privileges.
    Read also flags from `flags` table.

    Args:
        config (DictConfig): Hydra configuration dictionary.
    """
    # Users and guests lists
    self.users_tabulator.value = auth.list_users_guests_and_privileges(
        config
    )
    # Flags table content
    df_flags = models.Flags.read_as_df(
        config=config,
        index_col="id",
    )
    self.flags_content.value = df_flags

BackendPasswordRenewer

Bases: Parameterized

Param class used inside the backend to create the widget that collect info to renew users password.

It has more options compared to the standard PasswordRenewer.

This widget is used only if basic authentication is active.

Methods:

Name Description
__str__

String representation of this object.

Attributes:

Name Type Description
admin Boolean

Admin flag (true if admin).

guest Boolean

Guest flag (true if guest).

new_password String

New password.

repeat_new_password String

Repeat the new password. This field tests if the new password is as intended.

user String

Username.

Source code in dlunch/gui.py
129
130
131
132
133
134
135
136
137
138
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
class BackendPasswordRenewer(param.Parameterized):
    """Param class used inside the backend to create the widget that collect info to renew users password.

    It has more options compared to the standard `PasswordRenewer`.

    This widget is used only if basic authentication is active."""

    user: param.String = param.String(
        default="",
        doc="username for password update (use 'guest' for guest user)",
    )
    """Username."""
    new_password: param.String = param.String(default="")
    """New password."""
    repeat_new_password: param.String = param.String(default="")
    """Repeat the new password. This field tests if the new password is as intended."""
    admin: param.Boolean = param.Boolean(
        default=False, doc="add admin privileges"
    )
    """Admin flag (true if admin)."""
    guest: param.Boolean = param.Boolean(
        default=False,
        doc="guest account (don't add user to privileged users' table)",
    )
    """Guest flag (true if guest).

    User credentials are added to `credentials` table, but the user is not listed in `privileged_users` table."""

    def __str__(self):
        """String representation of this object.

        Returns:
            (str): string representation.
        """
        return "BackendPasswordRenewer"

admin class-attribute instance-attribute

admin: Boolean = Boolean(
    default=False, doc="add admin privileges"
)

Admin flag (true if admin).

guest class-attribute instance-attribute

guest: Boolean = Boolean(
    default=False,
    doc="guest account (don't add user to privileged users' table)",
)

Guest flag (true if guest).

User credentials are added to credentials table, but the user is not listed in privileged_users table.

new_password class-attribute instance-attribute

new_password: String = String(default='')

New password.

repeat_new_password class-attribute instance-attribute

repeat_new_password: String = String(default='')

Repeat the new password. This field tests if the new password is as intended.

user class-attribute instance-attribute

user: String = String(
    default="",
    doc="username for password update (use 'guest' for guest user)",
)

Username.

__str__

__str__()

String representation of this object.

Returns:

Type Description
str

string representation.

Source code in dlunch/gui.py
157
158
159
160
161
162
163
def __str__(self):
    """String representation of this object.

    Returns:
        (str): string representation.
    """
    return "BackendPasswordRenewer"

BackendUserEraser

Bases: Parameterized

Param class used inside the backend to create the widget that delete users.

Users are deleted from both credentials and privileged_user tables.

Methods:

Name Description
__str__

String representation of this object.

Attributes:

Name Type Description
user String

User to be deleted.

Source code in dlunch/gui.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
class BackendUserEraser(param.Parameterized):
    """Param class used inside the backend to create the widget that delete users.

    Users are deleted from both `credentials` and `privileged_user` tables."""

    user: param.String = param.String(default="", doc="user to be deleted")
    """User to be deleted."""

    def __str__(self):
        """String representation of this object.

        Returns:
            (str): string representation.
        """
        return "BackendUserEraser"

user class-attribute instance-attribute

user: String = String(default='', doc='user to be deleted')

User to be deleted.

__str__

__str__()

String representation of this object.

Returns:

Type Description
str

string representation.

Source code in dlunch/gui.py
193
194
195
196
197
198
199
def __str__(self):
    """String representation of this object.

    Returns:
        (str): string representation.
    """
    return "BackendUserEraser"

GraphicInterface

Class with widgets for the main graphic interface.

All widgets are instantiated at class initialization.

Class methods handle specific operations that may be repeated multiple time after class instantiation.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required
app Template

App panel template (see Panel docs <https://panel.holoviz.org/how_to/templates/index.html>__).

required
person Person

Object with user data and preferences for the lunch order.

required
guest_password str

guest password to show in password tab. Used only if basic authentication is active. Defaults to empty string ("").

''

Methods:

Name Description
__init__
build_order_table

Build Tabulator object to display placed orders.

build_stats_and_info_text

Build text used for statistics under the stats tab, and info under the user tab.

build_time_label

Build HTML field to display the time label.

load_sidebar_tabs

Append tabs to the app template sidebar.

Attributes:

Name Type Description
additional_items_details
backend_button
build_menu_button
buttons_flexbox
change_order_time_takeaway_button
dataframe
delete_order_button
download_button
error_message
file_widget
guest_override_alert
guest_password_widget
guest_username_widget
header_object
header_row
logout_button
main_header_row
menu_flexbox
no_menu_col
no_menu_image
no_menu_image_attribution
no_more_order_alert
password_widget
person_widget
quote
refresh_button
reload_on_guest_override
reload_on_no_more_order
res_col
results_divider
send_order_button
sidebar_download_orders_col
sidebar_menu_upload_col
sidebar_password
sidebar_person_column
sidebar_stats_col
sidebar_tabs
stats_widget
submit_password_button
takeaway_alert_sign
takeaway_alert_text
time_col
time_col_title
toggle_guest_override_button
toggle_no_more_order_button
Source code in dlunch/gui.py
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
class GraphicInterface:
    """Class with widgets for the main graphic interface.

    All widgets are instantiated at class initialization.

    Class methods handle specific operations that may be repeated multiple time after class instantiation.

    Args:
        config (DictConfig): Hydra configuration dictionary.
        app (pn.Template): App panel template (see `Panel docs <https://panel.holoviz.org/how_to/templates/index.html>`__).
        person (Person): Object with user data and preferences for the lunch order.
        guest_password (str, optional): guest password to show in password tab. Used only if basic authentication is active.
            Defaults to empty string (`""`).

    """

    def __init__(
        self,
        config: DictConfig,
        app: pn.Template,
        person: Person,
        guest_password: str = "",
    ):
        # HEADER SECTION ------------------------------------------------------
        # WIDGET
        # Create PNG pane with app icon
        self.header_object = instantiate(config.panel.gui.header_object)

        # BUTTONS
        # Backend button
        self.backend_button = pnw.Button(
            name="",
            button_type="primary",
            button_style="solid",
            width=header_button_width,
            height=generic_button_height,
            icon="adjustments",
            icon_size="2em",
        )
        # Guest override toggle button (if pressed the user act as a guest)
        self.toggle_guest_override_button = pnw.Toggle(
            button_type="primary",
            button_style="solid",
            width=header_button_width,
            height=generic_button_height,
            icon="user-bolt",
            icon_size="2em",
            stylesheets=[config.panel.gui.css_files.guest_override_path],
        )
        # Logout button
        self.logout_button = pnw.Button(
            name="",
            button_type="primary",
            button_style="solid",
            width=header_button_width,
            height=generic_button_height,
            icon="door-exit",
            icon_size="2em",
        )

        # ROW
        # Create column for person data (add logout button only if auth is active)
        self.header_row = pn.Row(
            height=header_row_height,
            sizing_mode="stretch_width",
        )
        # Append a graphic element to the left side of header
        if config.panel.gui.header_object:
            self.header_row.append(self.header_object)
        # Append a controls to the right side of header
        if auth.is_auth_active(config=config):
            self.header_row.append(pn.HSpacer())
            # Backend only for admin
            if auth.is_admin(user=pn_user(config), config=config):
                self.header_row.append(self.backend_button)
            # Guest override only for non guests
            if not auth.is_guest(
                user=pn_user(config), config=config, allow_override=False
            ):
                self.header_row.append(self.toggle_guest_override_button)
            self.header_row.append(self.logout_button)
            self.header_row.append(
                pn.pane.HTML(
                    styles=dict(background="white"), width=2, height=45
                )
            )

        # CALLBACKS
        # Backend callback
        self.backend_button.on_click(lambda e: auth.open_backend())

        # Guest override callback
        @pn.depends(self.toggle_guest_override_button, watch=True)
        def reload_on_guest_override_callback(
            toggle: pnw.ToggleIcon, reload: bool = True
        ):
            # Update global variable that control guest override
            # Only non guest can store this value in 'flags' table (guest users
            # are always guests, there is no use in sotring a flag for them)
            if 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=toggle,
                )
            # Show banner if override is active
            self.guest_override_alert.visible = toggle
            # Simply reload the menu when the toggle button value changes
            if reload:
                core.reload_menu(
                    None,
                    config,
                    self,
                )

        # Add callback to attribute
        self.reload_on_guest_override = reload_on_guest_override_callback

        # Logout callback
        self.logout_button.on_click(lambda e: auth.force_logout())

        # MAIN SECTION --------------------------------------------------------
        # Elements required for build the main section of the web app

        # TEXTS
        # Quote of the day
        self.quote = pn.pane.Markdown(
            f"""
            _{df_quote.quote.iloc[0]}_

            **{df_quote.author.iloc[0]}**
            """
        )
        # Time column title
        self.time_col_title = pn.pane.Markdown(
            config.panel.time_column_text,
            sizing_mode="stretch_width",
            styles={"text-align": "center"},
        )
        # "no more order" message
        self.no_more_order_alert = pn.pane.HTML(
            """
            <div class="no-more-order-flag">
                <div class="icon-container">
                    <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-alert-circle-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                        <path d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm.01 13l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -8a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" stroke-width="0" fill="currentColor"></path>
                    </svg>
                    <span><strong>Oh no! You missed this train...</strong></span>
                </div>
                <div>
                    Orders are closed, better luck next time.
                </div>
            </div>
            """,
            margin=5,
            sizing_mode="stretch_width",
            stylesheets=[config.panel.gui.css_files.no_more_orders_path],
        )
        # Alert for guest override
        self.guest_override_alert = pn.pane.HTML(
            """
            <div class="guest-override-flag">
                <div class="icon-container">
                    <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-radioactive-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                        <path d="M21 11a1 1 0 0 1 1 1a10 10 0 0 1 -5 8.656a1 1 0 0 1 -1.302 -.268l-.064 -.098l-3 -5.19a.995 .995 0 0 1 -.133 -.542l.01 -.11l.023 -.106l.034 -.106l.046 -.1l.056 -.094l.067 -.089a.994 .994 0 0 1 .165 -.155l.098 -.064a2 2 0 0 0 .993 -1.57l.007 -.163a1 1 0 0 1 .883 -.994l.117 -.007h6z" stroke-width="0" fill="currentColor" />
                        <path d="M7 3.344a10 10 0 0 1 10 0a1 1 0 0 1 .418 1.262l-.052 .104l-3 5.19l-.064 .098a.994 .994 0 0 1 -.155 .165l-.089 .067a1 1 0 0 1 -.195 .102l-.105 .034l-.107 .022a1.003 1.003 0 0 1 -.547 -.07l-.104 -.052a2 2 0 0 0 -1.842 -.082l-.158 .082a1 1 0 0 1 -1.302 -.268l-.064 -.098l-3 -5.19a1 1 0 0 1 .366 -1.366z" stroke-width="0" fill="currentColor" />
                        <path d="M9 11a1 1 0 0 1 .993 .884l.007 .117a2 2 0 0 0 .861 1.645l.237 .152a.994 .994 0 0 1 .165 .155l.067 .089l.056 .095l.045 .099c.014 .036 .026 .07 .035 .106l.022 .107l.011 .11a.994 .994 0 0 1 -.08 .437l-.053 .104l-3 5.19a1 1 0 0 1 -1.366 .366a10 10 0 0 1 -5 -8.656a1 1 0 0 1 .883 -.993l.117 -.007h6z" stroke-width="0" fill="currentColor" />
                    </svg>
                    <span><strong>Watch out! You are a guest now...</strong></span>
                </div>
                <div>
                    Guest override is active.
                </div>
            </div>
            """,
            margin=5,
            sizing_mode="stretch_width",
            stylesheets=[config.panel.gui.css_files.guest_override_path],
        )
        # Takeaway alert
        self.takeaway_alert_sign = f"<span {config.panel.gui.takeaway_alert_icon_options}>{config.panel.gui.takeaway_svg_icon}</span>"
        self.takeaway_alert_text = f"<span {config.panel.gui.takeaway_alert_text_options}>{config.panel.gui.takeaway_id}</span> "
        # No menu image attribution
        self.no_menu_image_attribution = pn.pane.HTML(
            """
            <i>
                Image by
                <a
                    href="https://www.freepik.com/free-vector/tiny-cooks-making-spaghetti-dinner-isolated-flat-illustration_11235909.htm"
                    referrerpolicy="no-referrer"
                    rel="external"
                    target="_blank"
                >
                    pch.vector
                </a>
                on Freepik
            </i>
            """,
            align="end",
            styles={
                "color": "darkgray",
                "font-size": "10px",
                "font-weight": "light",
            },
        )

        # WIDGETS
        # JPG shown when no menu is available
        self.no_menu_image = pn.pane.JPG(
            config.panel.gui.no_menu_image_path, alt_text="no menu"
        )
        # Create dataframe instance
        self.dataframe = pnw.Tabulator(
            name="Order",
            widths={config.panel.gui.note_column_name: 180},
            selectable=False,
            stylesheets=[config.panel.gui.css_files.custom_tabulator_path],
        )

        # BUTTONS
        # Create refresh button
        self.refresh_button = pnw.Button(
            name="",
            button_style="outline",
            button_type="light",
            width=45,
            height=generic_button_height,
            icon="reload",
            icon_size="2em",
        )
        # Create send button
        self.send_order_button = pnw.Button(
            name="Send Order",
            button_type="success",
            height=generic_button_height,
            icon="circle-check-filled",
            icon_size="2em",
            sizing_mode="stretch_width",
        )
        # Create toggle button that stop orders (used in time column)
        # Initialized to False, but checked on app creation
        self.toggle_no_more_order_button = pnw.Toggle(
            name="Stop Orders",
            button_style="outline",
            button_type="warning",
            height=generic_button_height,
            icon="hand-stop",
            icon_size="2em",
            sizing_mode="stretch_width",
        )
        # Create change time
        self.change_order_time_takeaway_button = pnw.Button(
            name="Change Time/Takeaway",
            button_type="primary",
            button_style="outline",
            height=generic_button_height,
            icon="clock-edit",
            icon_size="2em",
            sizing_mode="stretch_width",
        )
        # Create delete order
        self.delete_order_button = pnw.Button(
            name="Delete Order",
            button_type="danger",
            height=generic_button_height,
            icon="trash-filled",
            icon_size="2em",
            sizing_mode="stretch_width",
        )

        # ROWS
        self.main_header_row = pn.Row(
            "# Menu",
            pn.layout.HSpacer(),
            self.refresh_button,
        )

        # COLUMNS
        # Create column shown when no menu is available
        self.no_menu_col = pn.Column(
            self.no_menu_image,
            self.no_menu_image_attribution,
            sizing_mode="stretch_width",
            min_width=main_area_min_width,
        )
        # Create column for lunch time labels
        self.time_col = pn.Column(width=time_col_width)
        # Create column for resulting menus
        self.res_col = pn.Column(
            sizing_mode="stretch_width", min_width=main_area_min_width
        )

        # FLEXBOXES
        self.menu_flexbox = pn.FlexBox(
            *[
                self.dataframe,
                pn.Spacer(width=time_col_spacer_width),
                self.time_col,
            ],
            min_width=main_area_min_width,
        )
        self.buttons_flexbox = pn.FlexBox(
            *[
                self.send_order_button,
                self.toggle_no_more_order_button,
                self.change_order_time_takeaway_button,
                self.delete_order_button,
            ],
            flex_wrap="nowrap",
            min_width=main_area_min_width,
            sizing_mode="stretch_width",
        )
        self.results_divider = pn.layout.Divider(
            sizing_mode="stretch_width", min_width=main_area_min_width
        )

        # CALLBACKS
        # Callback on every "toggle" action
        @pn.depends(self.toggle_no_more_order_button, watch=True)
        def reload_on_no_more_order_callback(
            toggle: pnw.Toggle, reload: bool = True
        ):
            # Update global variable
            models.set_flag(config=config, id="no_more_orders", value=toggle)

            # Show "no more order" text
            self.no_more_order_alert.visible = toggle

            # Deactivate send, delete and change order buttons
            self.send_order_button.disabled = toggle
            self.delete_order_button.disabled = toggle
            self.change_order_time_takeaway_button.disabled = toggle

            # Simply reload the menu when the toggle button value changes
            if reload:
                core.reload_menu(
                    None,
                    config,
                    self,
                )

        # Add callback to attribute
        self.reload_on_no_more_order = reload_on_no_more_order_callback

        # Refresh button callback
        self.refresh_button.on_click(
            lambda e: core.reload_menu(
                e,
                config,
                self,
            )
        )
        # Send order button callback
        self.send_order_button.on_click(
            lambda e: core.send_order(
                e,
                config,
                app,
                person,
                self,
            )
        )
        # Delete order button callback
        self.delete_order_button.on_click(
            lambda e: core.delete_order(
                e,
                config,
                app,
                self,
            )
        )
        # Change order time button callback
        self.change_order_time_takeaway_button.on_click(
            lambda e: core.change_order_time_takeaway(
                e,
                config,
                person,
                self,
            )
        )

        # MODAL WINDOW --------------------------------------------------------
        # Error message
        self.error_message = pn.pane.HTML(
            styles={"color": "red", "font-weight": "bold"},
            sizing_mode="stretch_width",
        )
        self.error_message.visible = False

        # SIDEBAR -------------------------------------------------------------
        # TEXTS
        # Foldable additional item details dropdown menu
        jinja_template = jinja2.Environment(
            loader=jinja2.BaseLoader
        ).from_string(config.panel.gui.additional_item_details_template)
        self.additional_items_details = pn.pane.HTML(
            jinja_template.render(
                items=config.panel.additional_items_to_concat
            ),
            width=sidebar_content_width,
        )

        # WIDGET
        # Person data
        self.person_widget = pn.Param(
            person.param,
            widgets={
                "guest": pnw.RadioButtonGroup(
                    options=OmegaConf.to_container(
                        config.panel.guest_types, resolve=True
                    ),
                    button_type="primary",
                    button_style="outline",
                ),
                "username": pnw.TextInput(
                    value=person.username,
                    value_input=person.username,
                    description=person.param.username.doc,
                ),
            },
            width=sidebar_content_width,
        )
        # File upload
        self.file_widget = pnw.FileInput(
            accept=".png,.jpg,.jpeg,.xlsx", sizing_mode="stretch_width"
        )
        # Stats table
        # Create stats table (non-editable)
        self.stats_widget = pnw.Tabulator(
            name="Statistics",
            hidden_columns=["index"],
            width=sidebar_content_width - 20,
            layout="fit_columns",
            stylesheets=[
                config.panel.gui.css_files.custom_tabulator_path,
                config.panel.gui.css_files.stats_tabulator_path,
            ],
        )
        # Password renewer
        self.password_widget = pn.Param(
            PasswordRenewer().param,
            widgets={
                "old_password": pnw.PasswordInput(
                    name="Old password", placeholder="Old Password"
                ),
                "new_password": pnw.PasswordInput(
                    name="New password", placeholder="New Password"
                ),
                "repeat_new_password": pnw.PasswordInput(
                    name="Repeat new password",
                    placeholder="Repeat New Password",
                ),
            },
            name="Change password",
            width=sidebar_content_width,
        )
        # Guest password text
        self.guest_username_widget = pnw.TextInput(
            name="Username",
            placeholder="If empty reload this page.",
            value="guest",
        )
        self.guest_password_widget = pnw.PasswordInput(
            name="Password",
            placeholder="If empty reload this page.",
            value=guest_password,
        )
        # Turn off guest user if no password is set (empty string)
        if not guest_password:
            self.guest_username_widget.value = ""
            self.guest_username_widget.disabled = True
            self.guest_username_widget.placeholder = "NOT ACTIVE"
            self.guest_password_widget.value = ""
            self.guest_password_widget.disabled = True
            self.guest_password_widget.placeholder = "NOT ACTIVE"

        # BUTTONS
        # Create menu button
        self.build_menu_button = pnw.Button(
            name="Build Menu",
            button_type="primary",
            sizing_mode="stretch_width",
            icon="tools-kitchen-2",
            icon_size="2em",
        )
        # Download button and callback
        self.download_button = pn.widgets.FileDownload(
            callback=lambda: core.download_dataframe(config, self),
            filename=config.panel.file_name + ".xlsx",
            sizing_mode="stretch_width",
            icon="download",
            icon_size="2em",
        )
        # Password button
        self.submit_password_button = pnw.Button(
            name="Submit",
            button_type="success",
            button_style="outline",
            height=generic_button_height,
            icon="key",
            icon_size="2em",
            sizing_mode="stretch_width",
        )

        # COLUMNS
        # Create column for person data
        self.sidebar_person_column = pn.Column(
            person_text,
            self.person_widget,
            pn.Spacer(height=5),
            self.additional_items_details,
            name="User",
            width=sidebar_content_width,
        )
        # Leave an empty widget for the 'other info' section
        self.sidebar_person_column.append(
            pn.pane.HTML(),
        )

        # Create column for uploading image/Excel with the menu
        self.sidebar_menu_upload_col = pn.Column(
            upload_text,
            self.file_widget,
            self.build_menu_button,
            name="Menu Upload",
            width=sidebar_content_width,
        )
        # Create column for downloading Excel with orders
        self.sidebar_download_orders_col = pn.Column(
            download_text,
            self.download_button,
            name="Download Orders",
            width=sidebar_content_width,
        )
        # Create column for statistics
        self.sidebar_stats_col = pn.Column(
            name="Stats", width=sidebar_content_width
        )

        self.sidebar_password = pn.Column(
            config.panel.gui.psw_text,
            self.password_widget,
            self.submit_password_button,
            pn.Spacer(height=5),
            pn.layout.Divider(),
            guest_user_text,
            self.guest_username_widget,
            self.guest_password_widget,
            name="Password",
            width=sidebar_content_width,
        )

        # TABS
        # The person widget is defined in the app factory function because
        # lunch times are configurable
        self.sidebar_tabs = pn.Tabs(
            width=sidebar_content_width,
        )
        # Reload tabs according to auth.is_guest results and guest_override
        # flag (no need to cleans, tabs are already empty)
        self.load_sidebar_tabs(config=config, clear_before_loading=False)

        # CALLBACKS
        # Build menu button callback
        self.build_menu_button.on_click(
            lambda e: core.build_menu(
                e,
                config,
                app,
                self,
            )
        )
        # Submit password button callback
        self.submit_password_button.on_click(
            lambda e: core.submit_password(gi=self, config=config)
        )

    # UTILITY FUNCTIONS
    # MAIN SECTION
    def build_order_table(
        self,
        config: DictConfig,
        df: pd.DataFrame,
        time: str,
        guests_lists: dict = {},
    ) -> pnw.Tabulator:
        """Build `Tabulator` object to display placed orders.

        Args:
            config (DictConfig): Hydra configuration dictionary.
            df (pd.DataFrame): Table with orders. It has columns for each user that placed an order, total and a note columns.
            time (str): Lunch time.
            guests_lists (dict, optional): Dictionary with lists of users dived by guest type.
                Keys of the dictionary are the type of guest listed.
                Defaults to empty dictionary (`{}`).

        Returns:
            pnw.Tabulator: Panel `Tabulator` object representing placed orders.
        """
        # Add guest icon to users' id
        columns_with_guests_icons = df.columns.to_series()
        for guest_type, guests_list in guests_lists.items():
            columns_with_guests_icons[
                columns_with_guests_icons.isin(guests_list)
            ] += f" {config.panel.gui.guest_icons[guest_type]}"
        df.columns = columns_with_guests_icons.to_list()
        # Create table widget
        orders_table_widget = pnw.Tabulator(
            name=time,
            value=df,
            frozen_columns=[0],
            layout="fit_data_table",
            stylesheets=[config.panel.gui.css_files.custom_tabulator_path],
        )
        # Make the table non-editable
        orders_table_widget.editors = {c: None for c in df.columns}
        return orders_table_widget

    def build_time_label(
        self,
        time: str,
        diners_n: str,
        separator: str = " &#10072; ",
        emoji: str = "&#127829;",
        per_icon: str = " &#10006; ",
        is_takeaway: bool = False,
        takeaway_alert_sign: str = "TAKEAWAY",
        css_classes: list = [],
        stylesheets: list = [],
        **kwargs,
    ) -> pn.pane.HTML:
        """Build HTML field to display the time label.

        This function is used to display labels that summarize an order.

        Those are shown on the side of the menu table as well as labels above each order table.

        Args:
            time (str): Lunch time.
            diners_n (str): Number of people that placed an order.
            separator (str, optional): Separator between lunch time and order data. Defaults to " &#10072; ".
            emoji (str, optional): Emoji used as number lunch symbol. Defaults to "&#127829;".
            per_icon (str, optional): icon used between the lunch emoji and the number of people that placed an order.
                Usually a multiply operator.
                Defaults to " &#10006; ".
            is_takeaway (bool, optional): takeaway flag (true if the order is to takeaway). Defaults to False.
            takeaway_alert_sign (str, optional): warning text to highlight that the order is to takeaway. Defaults to "TAKEAWAY".
            css_classes (list, optional): CSS classes to assign to the resulting HTML pane. Defaults to [].
            stylesheets (list, optional): Stylesheets to assign to the resulting HTML pane
                (see `Panel docs <https://panel.holoviz.org/how_to/styling/apply_css.html>`__). Defaults to [].

        Returns:
            pn.pane.HTML: HTML pane representing a label with order summary.
        """
        # If takeaway add alert sign
        if is_takeaway:
            takeaway = f"{separator}{takeaway_alert_sign}"
        else:
            takeaway = ""
        # Time label pane
        classes_str = " ".join(css_classes)
        time_label = pn.pane.HTML(
            f'<span class="{classes_str}">{time}{separator}{emoji}{per_icon}{diners_n}{takeaway}</span>',
            stylesheets=stylesheets,
            **kwargs,
        )

        return time_label

    # SIDEBAR SECTION
    def load_sidebar_tabs(
        self, config: DictConfig, clear_before_loading: bool = True
    ) -> None:
        """Append tabs to the app template sidebar.

        The flag `clear_before_loading` is set to true only during first instantiation, because the sidebar is empty at first.
        Use the default value during normal operation to avoid tabs duplication.

        Args:
            config (DictConfig): Hydra configuration dictionary.
            clear_before_loading (bool, optional): Set to true to remove all tabs before appending the new ones. Defaults to True.
        """
        # Clean tabs
        if clear_before_loading:
            self.sidebar_tabs.clear()
        # Append User tab
        self.sidebar_tabs.append(self.sidebar_person_column)
        # Append upload, download and stats only for non-guest
        # Append password only for non-guest users if auth is active
        if not auth.is_guest(
            user=pn_user(config), config=config, allow_override=False
        ):
            self.sidebar_tabs.append(self.sidebar_menu_upload_col)
            self.sidebar_tabs.append(self.sidebar_download_orders_col)
            self.sidebar_tabs.append(self.sidebar_stats_col)
            if auth.is_basic_auth_active(config=config):
                self.sidebar_tabs.append(self.sidebar_password)

    def build_stats_and_info_text(
        self,
        config: DictConfig,
        df_stats: pd.DataFrame,
        user: str,
        version: str,
        host_name: str,
        stylesheets: list = [],
    ) -> dict:
        """Build text used for statistics under the `stats` tab, and info under the `user` tab.

        This functions needs Data-Lunch version and the name of the hosting machine to populate the info section.

        Args:
            config (DictConfig): Hydra configuration dictionary.
            df_stats (pd.DataFrame): dataframe with statistics.
            user (str): username.
            version (str): Data-Lunch version.
            host_name (str): host name.
            stylesheets (list, optional): Stylesheets to assign to the resulting HTML pane
                (see `Panel docs <https://panel.holoviz.org/how_to/styling/apply_css.html>`__). Defaults to [].

        Returns:
            dict: _description_
        """
        # Stats top text
        stats = pn.pane.HTML(
            f"""
            <h3>Statistics</h3>
            <div>
                Grumbling stomachs fed:<br>
                <span id="stats-locals">Locals&nbsp;&nbsp;{df_stats[df_stats["Guest"] == "NotAGuest"]['Hungry People'].sum()}</span><br>
                <span id="stats-guests">Guests&nbsp;&nbsp;{df_stats[df_stats["Guest"] != "NotAGuest"]['Hungry People'].sum()}</span><br>
                =================<br>
                <strong>TOTAL&nbsp;&nbsp;{df_stats['Hungry People'].sum()}</strong><br>
                <br>
            </div>
            <div>
                <i>See the table for details</i>
            </div>
            """,
            stylesheets=stylesheets,
        )
        # Define user group
        if auth.is_guest(user=user, config=config, allow_override=False):
            user_group = "guest"
        elif auth.is_admin(user=user, config=config):
            user_group = "admin"
        else:
            user_group = "user"
        # Other info
        other_info = pn.pane.HTML(
            f"""
            <details>
                <summary><strong>Other Info</strong></summary>
                <div class="icon-container">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user-square" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                        <path d="M9 10a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" />
                        <path d="M6 21v-1a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v1" />
                        <path d="M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z" />
                    </svg>
                    <span>
                        <strong>User:</strong> <i>{user}</i>
                    </span>
                </div>
                <div class="icon-container">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-users-group" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                        <path d="M10 13a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
                        <path d="M8 21v-1a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v1" />
                        <path d="M15 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
                        <path d="M17 10h2a2 2 0 0 1 2 2v1" />
                        <path d="M5 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
                        <path d="M3 13v-1a2 2 0 0 1 2 -2h2" />
                    </svg>
                    <span>
                        <strong>Group:</strong> <i>{user_group}</i>
                    </span>
                </div>
                <div class="icon-container">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-pizza" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                        <path d="M12 21.5c-3.04 0 -5.952 -.714 -8.5 -1.983l8.5 -16.517l8.5 16.517a19.09 19.09 0 0 1 -8.5 1.983z" />
                        <path d="M5.38 15.866a14.94 14.94 0 0 0 6.815 1.634a14.944 14.944 0 0 0 6.502 -1.479" />
                        <path d="M13 11.01v-.01" />
                        <path d="M11 14v-.01" />
                    </svg>
                    <span>
                        <strong>Data-Lunch:</strong> <i>v{version}</i>
                    </span>
                </div>
                <div class="icon-container">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-cpu" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                        <path d="M5 5m0 1a1 1 0 0 1 1 -1h12a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-12a1 1 0 0 1 -1 -1z"></path>
                        <path d="M9 9h6v6h-6z"></path>
                        <path d="M3 10h2"></path>
                        <path d="M3 14h2"></path>
                        <path d="M10 3v2"></path>
                        <path d="M14 3v2"></path>
                        <path d="M21 10h-2"></path>
                        <path d="M21 14h-2"></path>
                        <path d="M14 21v-2"></path>
                        <path d="M10 21v-2"></path>
                    </svg>
                    <span>
                        <strong>Host:</strong> <i>{host_name}</i>
                    </span>
                </div>
            </details>
            """,
            sizing_mode="stretch_width",
            stylesheets=stylesheets,
        )

        return {"stats": stats, "info": other_info}

additional_items_details instance-attribute

additional_items_details = HTML(
    render(items=additional_items_to_concat),
    width=sidebar_content_width,
)

backend_button instance-attribute

backend_button = Button(
    name="",
    button_type="primary",
    button_style="solid",
    width=header_button_width,
    height=generic_button_height,
    icon="adjustments",
    icon_size="2em",
)

build_menu_button instance-attribute

build_menu_button = Button(
    name="Build Menu",
    button_type="primary",
    sizing_mode="stretch_width",
    icon="tools-kitchen-2",
    icon_size="2em",
)

buttons_flexbox instance-attribute

buttons_flexbox = FlexBox(
    *[
        send_order_button,
        toggle_no_more_order_button,
        change_order_time_takeaway_button,
        delete_order_button,
    ],
    flex_wrap="nowrap",
    min_width=main_area_min_width,
    sizing_mode="stretch_width"
)

change_order_time_takeaway_button instance-attribute

change_order_time_takeaway_button = Button(
    name="Change Time/Takeaway",
    button_type="primary",
    button_style="outline",
    height=generic_button_height,
    icon="clock-edit",
    icon_size="2em",
    sizing_mode="stretch_width",
)

dataframe instance-attribute

dataframe = Tabulator(
    name="Order",
    widths={note_column_name: 180},
    selectable=False,
    stylesheets=[custom_tabulator_path],
)

delete_order_button instance-attribute

delete_order_button = Button(
    name="Delete Order",
    button_type="danger",
    height=generic_button_height,
    icon="trash-filled",
    icon_size="2em",
    sizing_mode="stretch_width",
)

download_button instance-attribute

download_button = FileDownload(
    callback=lambda: download_dataframe(config, self),
    filename=file_name + ".xlsx",
    sizing_mode="stretch_width",
    icon="download",
    icon_size="2em",
)

error_message instance-attribute

error_message = HTML(
    styles={"color": "red", "font-weight": "bold"},
    sizing_mode="stretch_width",
)

file_widget instance-attribute

file_widget = FileInput(
    accept=".png,.jpg,.jpeg,.xlsx",
    sizing_mode="stretch_width",
)

guest_override_alert instance-attribute

guest_override_alert = HTML(
    '\n            <div class="guest-override-flag">\n                <div class="icon-container">\n                    <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-radioactive-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>\n                        <path d="M21 11a1 1 0 0 1 1 1a10 10 0 0 1 -5 8.656a1 1 0 0 1 -1.302 -.268l-.064 -.098l-3 -5.19a.995 .995 0 0 1 -.133 -.542l.01 -.11l.023 -.106l.034 -.106l.046 -.1l.056 -.094l.067 -.089a.994 .994 0 0 1 .165 -.155l.098 -.064a2 2 0 0 0 .993 -1.57l.007 -.163a1 1 0 0 1 .883 -.994l.117 -.007h6z" stroke-width="0" fill="currentColor" />\n                        <path d="M7 3.344a10 10 0 0 1 10 0a1 1 0 0 1 .418 1.262l-.052 .104l-3 5.19l-.064 .098a.994 .994 0 0 1 -.155 .165l-.089 .067a1 1 0 0 1 -.195 .102l-.105 .034l-.107 .022a1.003 1.003 0 0 1 -.547 -.07l-.104 -.052a2 2 0 0 0 -1.842 -.082l-.158 .082a1 1 0 0 1 -1.302 -.268l-.064 -.098l-3 -5.19a1 1 0 0 1 .366 -1.366z" stroke-width="0" fill="currentColor" />\n                        <path d="M9 11a1 1 0 0 1 .993 .884l.007 .117a2 2 0 0 0 .861 1.645l.237 .152a.994 .994 0 0 1 .165 .155l.067 .089l.056 .095l.045 .099c.014 .036 .026 .07 .035 .106l.022 .107l.011 .11a.994 .994 0 0 1 -.08 .437l-.053 .104l-3 5.19a1 1 0 0 1 -1.366 .366a10 10 0 0 1 -5 -8.656a1 1 0 0 1 .883 -.993l.117 -.007h6z" stroke-width="0" fill="currentColor" />\n                    </svg>\n                    <span><strong>Watch out! You are a guest now...</strong></span>\n                </div>\n                <div>\n                    Guest override is active.\n                </div>\n            </div>\n            ',
    margin=5,
    sizing_mode="stretch_width",
    stylesheets=[guest_override_path],
)

guest_password_widget instance-attribute

guest_password_widget = PasswordInput(
    name="Password",
    placeholder="If empty reload this page.",
    value=guest_password,
)

guest_username_widget instance-attribute

guest_username_widget = TextInput(
    name="Username",
    placeholder="If empty reload this page.",
    value="guest",
)

header_object instance-attribute

header_object = instantiate(header_object)

header_row instance-attribute

header_row = Row(
    height=header_row_height, sizing_mode="stretch_width"
)

logout_button instance-attribute

logout_button = Button(
    name="",
    button_type="primary",
    button_style="solid",
    width=header_button_width,
    height=generic_button_height,
    icon="door-exit",
    icon_size="2em",
)

main_header_row instance-attribute

main_header_row = Row('# Menu', HSpacer(), refresh_button)

menu_flexbox instance-attribute

menu_flexbox = FlexBox(
    *[
        dataframe,
        Spacer(width=time_col_spacer_width),
        time_col,
    ],
    min_width=main_area_min_width
)

no_menu_col instance-attribute

no_menu_col = Column(
    no_menu_image,
    no_menu_image_attribution,
    sizing_mode="stretch_width",
    min_width=main_area_min_width,
)

no_menu_image instance-attribute

no_menu_image = JPG(no_menu_image_path, alt_text='no menu')

no_menu_image_attribution instance-attribute

no_menu_image_attribution = HTML(
    '\n            <i>\n                Image by\n                <a\n                    href="https://www.freepik.com/free-vector/tiny-cooks-making-spaghetti-dinner-isolated-flat-illustration_11235909.htm"\n                    referrerpolicy="no-referrer"\n                    rel="external"\n                    target="_blank"\n                >\n                    pch.vector\n                </a>\n                on Freepik\n            </i>\n            ',
    align="end",
    styles={
        "color": "darkgray",
        "font-size": "10px",
        "font-weight": "light",
    },
)

no_more_order_alert instance-attribute

no_more_order_alert = HTML(
    '\n            <div class="no-more-order-flag">\n                <div class="icon-container">\n                    <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-alert-circle-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">\n                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>\n                        <path d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm.01 13l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -8a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" stroke-width="0" fill="currentColor"></path>\n                    </svg>\n                    <span><strong>Oh no! You missed this train...</strong></span>\n                </div>\n                <div>\n                    Orders are closed, better luck next time.\n                </div>\n            </div>\n            ',
    margin=5,
    sizing_mode="stretch_width",
    stylesheets=[no_more_orders_path],
)

password_widget instance-attribute

password_widget = Param(
    param,
    widgets={
        "old_password": PasswordInput(
            name="Old password", placeholder="Old Password"
        ),
        "new_password": PasswordInput(
            name="New password", placeholder="New Password"
        ),
        "repeat_new_password": PasswordInput(
            name="Repeat new password",
            placeholder="Repeat New Password",
        ),
    },
    name="Change password",
    width=sidebar_content_width,
)

person_widget instance-attribute

person_widget = Param(
    param,
    widgets={
        "guest": RadioButtonGroup(
            options=to_container(guest_types, resolve=True),
            button_type="primary",
            button_style="outline",
        ),
        "username": TextInput(
            value=username,
            value_input=username,
            description=doc,
        ),
    },
    width=sidebar_content_width,
)

quote instance-attribute

quote = Markdown(f'
            _{iloc[0]}_

            **{iloc[0]}**
            ')

refresh_button instance-attribute

refresh_button = Button(
    name="",
    button_style="outline",
    button_type="light",
    width=45,
    height=generic_button_height,
    icon="reload",
    icon_size="2em",
)

reload_on_guest_override instance-attribute

reload_on_guest_override = reload_on_guest_override_callback

reload_on_no_more_order instance-attribute

reload_on_no_more_order = reload_on_no_more_order_callback

res_col instance-attribute

res_col = Column(
    sizing_mode="stretch_width",
    min_width=main_area_min_width,
)

results_divider instance-attribute

results_divider = Divider(
    sizing_mode="stretch_width",
    min_width=main_area_min_width,
)

send_order_button instance-attribute

send_order_button = Button(
    name="Send Order",
    button_type="success",
    height=generic_button_height,
    icon="circle-check-filled",
    icon_size="2em",
    sizing_mode="stretch_width",
)

sidebar_download_orders_col instance-attribute

sidebar_download_orders_col = Column(
    download_text,
    download_button,
    name="Download Orders",
    width=sidebar_content_width,
)

sidebar_menu_upload_col instance-attribute

sidebar_menu_upload_col = Column(
    upload_text,
    file_widget,
    build_menu_button,
    name="Menu Upload",
    width=sidebar_content_width,
)

sidebar_password instance-attribute

sidebar_password = Column(
    psw_text,
    password_widget,
    submit_password_button,
    Spacer(height=5),
    Divider(),
    guest_user_text,
    guest_username_widget,
    guest_password_widget,
    name="Password",
    width=sidebar_content_width,
)

sidebar_person_column instance-attribute

sidebar_person_column = Column(
    person_text,
    person_widget,
    Spacer(height=5),
    additional_items_details,
    name="User",
    width=sidebar_content_width,
)

sidebar_stats_col instance-attribute

sidebar_stats_col = Column(
    name="Stats", width=sidebar_content_width
)

sidebar_tabs instance-attribute

sidebar_tabs = Tabs(width=sidebar_content_width)

stats_widget instance-attribute

stats_widget = Tabulator(
    name="Statistics",
    hidden_columns=["index"],
    width=sidebar_content_width - 20,
    layout="fit_columns",
    stylesheets=[
        custom_tabulator_path,
        stats_tabulator_path,
    ],
)

submit_password_button instance-attribute

submit_password_button = Button(
    name="Submit",
    button_type="success",
    button_style="outline",
    height=generic_button_height,
    icon="key",
    icon_size="2em",
    sizing_mode="stretch_width",
)

takeaway_alert_sign instance-attribute

takeaway_alert_sign = f"<span {takeaway_alert_icon_options}>{takeaway_svg_icon}</span>"

takeaway_alert_text instance-attribute

takeaway_alert_text = f"<span {takeaway_alert_text_options}>{takeaway_id}</span> "

time_col instance-attribute

time_col = Column(width=time_col_width)

time_col_title instance-attribute

time_col_title = Markdown(
    time_column_text,
    sizing_mode="stretch_width",
    styles={"text-align": "center"},
)

toggle_guest_override_button instance-attribute

toggle_guest_override_button = Toggle(
    button_type="primary",
    button_style="solid",
    width=header_button_width,
    height=generic_button_height,
    icon="user-bolt",
    icon_size="2em",
    stylesheets=[guest_override_path],
)

toggle_no_more_order_button instance-attribute

toggle_no_more_order_button = Toggle(
    name="Stop Orders",
    button_style="outline",
    button_type="warning",
    height=generic_button_height,
    icon="hand-stop",
    icon_size="2em",
    sizing_mode="stretch_width",
)

__init__

__init__(
    config: DictConfig,
    app: Template,
    person: Person,
    guest_password: str = "",
)
Source code in dlunch/gui.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
def __init__(
    self,
    config: DictConfig,
    app: pn.Template,
    person: Person,
    guest_password: str = "",
):
    # HEADER SECTION ------------------------------------------------------
    # WIDGET
    # Create PNG pane with app icon
    self.header_object = instantiate(config.panel.gui.header_object)

    # BUTTONS
    # Backend button
    self.backend_button = pnw.Button(
        name="",
        button_type="primary",
        button_style="solid",
        width=header_button_width,
        height=generic_button_height,
        icon="adjustments",
        icon_size="2em",
    )
    # Guest override toggle button (if pressed the user act as a guest)
    self.toggle_guest_override_button = pnw.Toggle(
        button_type="primary",
        button_style="solid",
        width=header_button_width,
        height=generic_button_height,
        icon="user-bolt",
        icon_size="2em",
        stylesheets=[config.panel.gui.css_files.guest_override_path],
    )
    # Logout button
    self.logout_button = pnw.Button(
        name="",
        button_type="primary",
        button_style="solid",
        width=header_button_width,
        height=generic_button_height,
        icon="door-exit",
        icon_size="2em",
    )

    # ROW
    # Create column for person data (add logout button only if auth is active)
    self.header_row = pn.Row(
        height=header_row_height,
        sizing_mode="stretch_width",
    )
    # Append a graphic element to the left side of header
    if config.panel.gui.header_object:
        self.header_row.append(self.header_object)
    # Append a controls to the right side of header
    if auth.is_auth_active(config=config):
        self.header_row.append(pn.HSpacer())
        # Backend only for admin
        if auth.is_admin(user=pn_user(config), config=config):
            self.header_row.append(self.backend_button)
        # Guest override only for non guests
        if not auth.is_guest(
            user=pn_user(config), config=config, allow_override=False
        ):
            self.header_row.append(self.toggle_guest_override_button)
        self.header_row.append(self.logout_button)
        self.header_row.append(
            pn.pane.HTML(
                styles=dict(background="white"), width=2, height=45
            )
        )

    # CALLBACKS
    # Backend callback
    self.backend_button.on_click(lambda e: auth.open_backend())

    # Guest override callback
    @pn.depends(self.toggle_guest_override_button, watch=True)
    def reload_on_guest_override_callback(
        toggle: pnw.ToggleIcon, reload: bool = True
    ):
        # Update global variable that control guest override
        # Only non guest can store this value in 'flags' table (guest users
        # are always guests, there is no use in sotring a flag for them)
        if 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=toggle,
            )
        # Show banner if override is active
        self.guest_override_alert.visible = toggle
        # Simply reload the menu when the toggle button value changes
        if reload:
            core.reload_menu(
                None,
                config,
                self,
            )

    # Add callback to attribute
    self.reload_on_guest_override = reload_on_guest_override_callback

    # Logout callback
    self.logout_button.on_click(lambda e: auth.force_logout())

    # MAIN SECTION --------------------------------------------------------
    # Elements required for build the main section of the web app

    # TEXTS
    # Quote of the day
    self.quote = pn.pane.Markdown(
        f"""
        _{df_quote.quote.iloc[0]}_

        **{df_quote.author.iloc[0]}**
        """
    )
    # Time column title
    self.time_col_title = pn.pane.Markdown(
        config.panel.time_column_text,
        sizing_mode="stretch_width",
        styles={"text-align": "center"},
    )
    # "no more order" message
    self.no_more_order_alert = pn.pane.HTML(
        """
        <div class="no-more-order-flag">
            <div class="icon-container">
                <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-alert-circle-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <path d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm.01 13l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -8a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" stroke-width="0" fill="currentColor"></path>
                </svg>
                <span><strong>Oh no! You missed this train...</strong></span>
            </div>
            <div>
                Orders are closed, better luck next time.
            </div>
        </div>
        """,
        margin=5,
        sizing_mode="stretch_width",
        stylesheets=[config.panel.gui.css_files.no_more_orders_path],
    )
    # Alert for guest override
    self.guest_override_alert = pn.pane.HTML(
        """
        <div class="guest-override-flag">
            <div class="icon-container">
                <svg class="flashing-animation" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-radioactive-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <path d="M21 11a1 1 0 0 1 1 1a10 10 0 0 1 -5 8.656a1 1 0 0 1 -1.302 -.268l-.064 -.098l-3 -5.19a.995 .995 0 0 1 -.133 -.542l.01 -.11l.023 -.106l.034 -.106l.046 -.1l.056 -.094l.067 -.089a.994 .994 0 0 1 .165 -.155l.098 -.064a2 2 0 0 0 .993 -1.57l.007 -.163a1 1 0 0 1 .883 -.994l.117 -.007h6z" stroke-width="0" fill="currentColor" />
                    <path d="M7 3.344a10 10 0 0 1 10 0a1 1 0 0 1 .418 1.262l-.052 .104l-3 5.19l-.064 .098a.994 .994 0 0 1 -.155 .165l-.089 .067a1 1 0 0 1 -.195 .102l-.105 .034l-.107 .022a1.003 1.003 0 0 1 -.547 -.07l-.104 -.052a2 2 0 0 0 -1.842 -.082l-.158 .082a1 1 0 0 1 -1.302 -.268l-.064 -.098l-3 -5.19a1 1 0 0 1 .366 -1.366z" stroke-width="0" fill="currentColor" />
                    <path d="M9 11a1 1 0 0 1 .993 .884l.007 .117a2 2 0 0 0 .861 1.645l.237 .152a.994 .994 0 0 1 .165 .155l.067 .089l.056 .095l.045 .099c.014 .036 .026 .07 .035 .106l.022 .107l.011 .11a.994 .994 0 0 1 -.08 .437l-.053 .104l-3 5.19a1 1 0 0 1 -1.366 .366a10 10 0 0 1 -5 -8.656a1 1 0 0 1 .883 -.993l.117 -.007h6z" stroke-width="0" fill="currentColor" />
                </svg>
                <span><strong>Watch out! You are a guest now...</strong></span>
            </div>
            <div>
                Guest override is active.
            </div>
        </div>
        """,
        margin=5,
        sizing_mode="stretch_width",
        stylesheets=[config.panel.gui.css_files.guest_override_path],
    )
    # Takeaway alert
    self.takeaway_alert_sign = f"<span {config.panel.gui.takeaway_alert_icon_options}>{config.panel.gui.takeaway_svg_icon}</span>"
    self.takeaway_alert_text = f"<span {config.panel.gui.takeaway_alert_text_options}>{config.panel.gui.takeaway_id}</span> "
    # No menu image attribution
    self.no_menu_image_attribution = pn.pane.HTML(
        """
        <i>
            Image by
            <a
                href="https://www.freepik.com/free-vector/tiny-cooks-making-spaghetti-dinner-isolated-flat-illustration_11235909.htm"
                referrerpolicy="no-referrer"
                rel="external"
                target="_blank"
            >
                pch.vector
            </a>
            on Freepik
        </i>
        """,
        align="end",
        styles={
            "color": "darkgray",
            "font-size": "10px",
            "font-weight": "light",
        },
    )

    # WIDGETS
    # JPG shown when no menu is available
    self.no_menu_image = pn.pane.JPG(
        config.panel.gui.no_menu_image_path, alt_text="no menu"
    )
    # Create dataframe instance
    self.dataframe = pnw.Tabulator(
        name="Order",
        widths={config.panel.gui.note_column_name: 180},
        selectable=False,
        stylesheets=[config.panel.gui.css_files.custom_tabulator_path],
    )

    # BUTTONS
    # Create refresh button
    self.refresh_button = pnw.Button(
        name="",
        button_style="outline",
        button_type="light",
        width=45,
        height=generic_button_height,
        icon="reload",
        icon_size="2em",
    )
    # Create send button
    self.send_order_button = pnw.Button(
        name="Send Order",
        button_type="success",
        height=generic_button_height,
        icon="circle-check-filled",
        icon_size="2em",
        sizing_mode="stretch_width",
    )
    # Create toggle button that stop orders (used in time column)
    # Initialized to False, but checked on app creation
    self.toggle_no_more_order_button = pnw.Toggle(
        name="Stop Orders",
        button_style="outline",
        button_type="warning",
        height=generic_button_height,
        icon="hand-stop",
        icon_size="2em",
        sizing_mode="stretch_width",
    )
    # Create change time
    self.change_order_time_takeaway_button = pnw.Button(
        name="Change Time/Takeaway",
        button_type="primary",
        button_style="outline",
        height=generic_button_height,
        icon="clock-edit",
        icon_size="2em",
        sizing_mode="stretch_width",
    )
    # Create delete order
    self.delete_order_button = pnw.Button(
        name="Delete Order",
        button_type="danger",
        height=generic_button_height,
        icon="trash-filled",
        icon_size="2em",
        sizing_mode="stretch_width",
    )

    # ROWS
    self.main_header_row = pn.Row(
        "# Menu",
        pn.layout.HSpacer(),
        self.refresh_button,
    )

    # COLUMNS
    # Create column shown when no menu is available
    self.no_menu_col = pn.Column(
        self.no_menu_image,
        self.no_menu_image_attribution,
        sizing_mode="stretch_width",
        min_width=main_area_min_width,
    )
    # Create column for lunch time labels
    self.time_col = pn.Column(width=time_col_width)
    # Create column for resulting menus
    self.res_col = pn.Column(
        sizing_mode="stretch_width", min_width=main_area_min_width
    )

    # FLEXBOXES
    self.menu_flexbox = pn.FlexBox(
        *[
            self.dataframe,
            pn.Spacer(width=time_col_spacer_width),
            self.time_col,
        ],
        min_width=main_area_min_width,
    )
    self.buttons_flexbox = pn.FlexBox(
        *[
            self.send_order_button,
            self.toggle_no_more_order_button,
            self.change_order_time_takeaway_button,
            self.delete_order_button,
        ],
        flex_wrap="nowrap",
        min_width=main_area_min_width,
        sizing_mode="stretch_width",
    )
    self.results_divider = pn.layout.Divider(
        sizing_mode="stretch_width", min_width=main_area_min_width
    )

    # CALLBACKS
    # Callback on every "toggle" action
    @pn.depends(self.toggle_no_more_order_button, watch=True)
    def reload_on_no_more_order_callback(
        toggle: pnw.Toggle, reload: bool = True
    ):
        # Update global variable
        models.set_flag(config=config, id="no_more_orders", value=toggle)

        # Show "no more order" text
        self.no_more_order_alert.visible = toggle

        # Deactivate send, delete and change order buttons
        self.send_order_button.disabled = toggle
        self.delete_order_button.disabled = toggle
        self.change_order_time_takeaway_button.disabled = toggle

        # Simply reload the menu when the toggle button value changes
        if reload:
            core.reload_menu(
                None,
                config,
                self,
            )

    # Add callback to attribute
    self.reload_on_no_more_order = reload_on_no_more_order_callback

    # Refresh button callback
    self.refresh_button.on_click(
        lambda e: core.reload_menu(
            e,
            config,
            self,
        )
    )
    # Send order button callback
    self.send_order_button.on_click(
        lambda e: core.send_order(
            e,
            config,
            app,
            person,
            self,
        )
    )
    # Delete order button callback
    self.delete_order_button.on_click(
        lambda e: core.delete_order(
            e,
            config,
            app,
            self,
        )
    )
    # Change order time button callback
    self.change_order_time_takeaway_button.on_click(
        lambda e: core.change_order_time_takeaway(
            e,
            config,
            person,
            self,
        )
    )

    # MODAL WINDOW --------------------------------------------------------
    # Error message
    self.error_message = pn.pane.HTML(
        styles={"color": "red", "font-weight": "bold"},
        sizing_mode="stretch_width",
    )
    self.error_message.visible = False

    # SIDEBAR -------------------------------------------------------------
    # TEXTS
    # Foldable additional item details dropdown menu
    jinja_template = jinja2.Environment(
        loader=jinja2.BaseLoader
    ).from_string(config.panel.gui.additional_item_details_template)
    self.additional_items_details = pn.pane.HTML(
        jinja_template.render(
            items=config.panel.additional_items_to_concat
        ),
        width=sidebar_content_width,
    )

    # WIDGET
    # Person data
    self.person_widget = pn.Param(
        person.param,
        widgets={
            "guest": pnw.RadioButtonGroup(
                options=OmegaConf.to_container(
                    config.panel.guest_types, resolve=True
                ),
                button_type="primary",
                button_style="outline",
            ),
            "username": pnw.TextInput(
                value=person.username,
                value_input=person.username,
                description=person.param.username.doc,
            ),
        },
        width=sidebar_content_width,
    )
    # File upload
    self.file_widget = pnw.FileInput(
        accept=".png,.jpg,.jpeg,.xlsx", sizing_mode="stretch_width"
    )
    # Stats table
    # Create stats table (non-editable)
    self.stats_widget = pnw.Tabulator(
        name="Statistics",
        hidden_columns=["index"],
        width=sidebar_content_width - 20,
        layout="fit_columns",
        stylesheets=[
            config.panel.gui.css_files.custom_tabulator_path,
            config.panel.gui.css_files.stats_tabulator_path,
        ],
    )
    # Password renewer
    self.password_widget = pn.Param(
        PasswordRenewer().param,
        widgets={
            "old_password": pnw.PasswordInput(
                name="Old password", placeholder="Old Password"
            ),
            "new_password": pnw.PasswordInput(
                name="New password", placeholder="New Password"
            ),
            "repeat_new_password": pnw.PasswordInput(
                name="Repeat new password",
                placeholder="Repeat New Password",
            ),
        },
        name="Change password",
        width=sidebar_content_width,
    )
    # Guest password text
    self.guest_username_widget = pnw.TextInput(
        name="Username",
        placeholder="If empty reload this page.",
        value="guest",
    )
    self.guest_password_widget = pnw.PasswordInput(
        name="Password",
        placeholder="If empty reload this page.",
        value=guest_password,
    )
    # Turn off guest user if no password is set (empty string)
    if not guest_password:
        self.guest_username_widget.value = ""
        self.guest_username_widget.disabled = True
        self.guest_username_widget.placeholder = "NOT ACTIVE"
        self.guest_password_widget.value = ""
        self.guest_password_widget.disabled = True
        self.guest_password_widget.placeholder = "NOT ACTIVE"

    # BUTTONS
    # Create menu button
    self.build_menu_button = pnw.Button(
        name="Build Menu",
        button_type="primary",
        sizing_mode="stretch_width",
        icon="tools-kitchen-2",
        icon_size="2em",
    )
    # Download button and callback
    self.download_button = pn.widgets.FileDownload(
        callback=lambda: core.download_dataframe(config, self),
        filename=config.panel.file_name + ".xlsx",
        sizing_mode="stretch_width",
        icon="download",
        icon_size="2em",
    )
    # Password button
    self.submit_password_button = pnw.Button(
        name="Submit",
        button_type="success",
        button_style="outline",
        height=generic_button_height,
        icon="key",
        icon_size="2em",
        sizing_mode="stretch_width",
    )

    # COLUMNS
    # Create column for person data
    self.sidebar_person_column = pn.Column(
        person_text,
        self.person_widget,
        pn.Spacer(height=5),
        self.additional_items_details,
        name="User",
        width=sidebar_content_width,
    )
    # Leave an empty widget for the 'other info' section
    self.sidebar_person_column.append(
        pn.pane.HTML(),
    )

    # Create column for uploading image/Excel with the menu
    self.sidebar_menu_upload_col = pn.Column(
        upload_text,
        self.file_widget,
        self.build_menu_button,
        name="Menu Upload",
        width=sidebar_content_width,
    )
    # Create column for downloading Excel with orders
    self.sidebar_download_orders_col = pn.Column(
        download_text,
        self.download_button,
        name="Download Orders",
        width=sidebar_content_width,
    )
    # Create column for statistics
    self.sidebar_stats_col = pn.Column(
        name="Stats", width=sidebar_content_width
    )

    self.sidebar_password = pn.Column(
        config.panel.gui.psw_text,
        self.password_widget,
        self.submit_password_button,
        pn.Spacer(height=5),
        pn.layout.Divider(),
        guest_user_text,
        self.guest_username_widget,
        self.guest_password_widget,
        name="Password",
        width=sidebar_content_width,
    )

    # TABS
    # The person widget is defined in the app factory function because
    # lunch times are configurable
    self.sidebar_tabs = pn.Tabs(
        width=sidebar_content_width,
    )
    # Reload tabs according to auth.is_guest results and guest_override
    # flag (no need to cleans, tabs are already empty)
    self.load_sidebar_tabs(config=config, clear_before_loading=False)

    # CALLBACKS
    # Build menu button callback
    self.build_menu_button.on_click(
        lambda e: core.build_menu(
            e,
            config,
            app,
            self,
        )
    )
    # Submit password button callback
    self.submit_password_button.on_click(
        lambda e: core.submit_password(gi=self, config=config)
    )

build_order_table

build_order_table(
    config: DictConfig,
    df: DataFrame,
    time: str,
    guests_lists: dict = {},
) -> Tabulator

Build Tabulator object to display placed orders.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required
df DataFrame

Table with orders. It has columns for each user that placed an order, total and a note columns.

required
time str

Lunch time.

required
guests_lists dict

Dictionary with lists of users dived by guest type. Keys of the dictionary are the type of guest listed. Defaults to empty dictionary ({}).

{}

Returns:

Type Description
Tabulator

Panel Tabulator object representing placed orders.

Source code in dlunch/gui.py
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
def build_order_table(
    self,
    config: DictConfig,
    df: pd.DataFrame,
    time: str,
    guests_lists: dict = {},
) -> pnw.Tabulator:
    """Build `Tabulator` object to display placed orders.

    Args:
        config (DictConfig): Hydra configuration dictionary.
        df (pd.DataFrame): Table with orders. It has columns for each user that placed an order, total and a note columns.
        time (str): Lunch time.
        guests_lists (dict, optional): Dictionary with lists of users dived by guest type.
            Keys of the dictionary are the type of guest listed.
            Defaults to empty dictionary (`{}`).

    Returns:
        pnw.Tabulator: Panel `Tabulator` object representing placed orders.
    """
    # Add guest icon to users' id
    columns_with_guests_icons = df.columns.to_series()
    for guest_type, guests_list in guests_lists.items():
        columns_with_guests_icons[
            columns_with_guests_icons.isin(guests_list)
        ] += f" {config.panel.gui.guest_icons[guest_type]}"
    df.columns = columns_with_guests_icons.to_list()
    # Create table widget
    orders_table_widget = pnw.Tabulator(
        name=time,
        value=df,
        frozen_columns=[0],
        layout="fit_data_table",
        stylesheets=[config.panel.gui.css_files.custom_tabulator_path],
    )
    # Make the table non-editable
    orders_table_widget.editors = {c: None for c in df.columns}
    return orders_table_widget

build_stats_and_info_text

build_stats_and_info_text(
    config: DictConfig,
    df_stats: DataFrame,
    user: str,
    version: str,
    host_name: str,
    stylesheets: list = [],
) -> dict

Build text used for statistics under the stats tab, and info under the user tab.

This functions needs Data-Lunch version and the name of the hosting machine to populate the info section.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required
df_stats DataFrame

dataframe with statistics.

required
user str

username.

required
version str

Data-Lunch version.

required
host_name str

host name.

required
stylesheets list

Stylesheets to assign to the resulting HTML pane (see Panel docs <https://panel.holoviz.org/how_to/styling/apply_css.html>__). Defaults to [].

[]

Returns:

Type Description
dict

description

Source code in dlunch/gui.py
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
def build_stats_and_info_text(
    self,
    config: DictConfig,
    df_stats: pd.DataFrame,
    user: str,
    version: str,
    host_name: str,
    stylesheets: list = [],
) -> dict:
    """Build text used for statistics under the `stats` tab, and info under the `user` tab.

    This functions needs Data-Lunch version and the name of the hosting machine to populate the info section.

    Args:
        config (DictConfig): Hydra configuration dictionary.
        df_stats (pd.DataFrame): dataframe with statistics.
        user (str): username.
        version (str): Data-Lunch version.
        host_name (str): host name.
        stylesheets (list, optional): Stylesheets to assign to the resulting HTML pane
            (see `Panel docs <https://panel.holoviz.org/how_to/styling/apply_css.html>`__). Defaults to [].

    Returns:
        dict: _description_
    """
    # Stats top text
    stats = pn.pane.HTML(
        f"""
        <h3>Statistics</h3>
        <div>
            Grumbling stomachs fed:<br>
            <span id="stats-locals">Locals&nbsp;&nbsp;{df_stats[df_stats["Guest"] == "NotAGuest"]['Hungry People'].sum()}</span><br>
            <span id="stats-guests">Guests&nbsp;&nbsp;{df_stats[df_stats["Guest"] != "NotAGuest"]['Hungry People'].sum()}</span><br>
            =================<br>
            <strong>TOTAL&nbsp;&nbsp;{df_stats['Hungry People'].sum()}</strong><br>
            <br>
        </div>
        <div>
            <i>See the table for details</i>
        </div>
        """,
        stylesheets=stylesheets,
    )
    # Define user group
    if auth.is_guest(user=user, config=config, allow_override=False):
        user_group = "guest"
    elif auth.is_admin(user=user, config=config):
        user_group = "admin"
    else:
        user_group = "user"
    # Other info
    other_info = pn.pane.HTML(
        f"""
        <details>
            <summary><strong>Other Info</strong></summary>
            <div class="icon-container">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user-square" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <path d="M9 10a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" />
                    <path d="M6 21v-1a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v1" />
                    <path d="M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z" />
                </svg>
                <span>
                    <strong>User:</strong> <i>{user}</i>
                </span>
            </div>
            <div class="icon-container">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-users-group" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <path d="M10 13a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
                    <path d="M8 21v-1a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v1" />
                    <path d="M15 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
                    <path d="M17 10h2a2 2 0 0 1 2 2v1" />
                    <path d="M5 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
                    <path d="M3 13v-1a2 2 0 0 1 2 -2h2" />
                </svg>
                <span>
                    <strong>Group:</strong> <i>{user_group}</i>
                </span>
            </div>
            <div class="icon-container">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-pizza" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                    <path d="M12 21.5c-3.04 0 -5.952 -.714 -8.5 -1.983l8.5 -16.517l8.5 16.517a19.09 19.09 0 0 1 -8.5 1.983z" />
                    <path d="M5.38 15.866a14.94 14.94 0 0 0 6.815 1.634a14.944 14.944 0 0 0 6.502 -1.479" />
                    <path d="M13 11.01v-.01" />
                    <path d="M11 14v-.01" />
                </svg>
                <span>
                    <strong>Data-Lunch:</strong> <i>v{version}</i>
                </span>
            </div>
            <div class="icon-container">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-cpu" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <path d="M5 5m0 1a1 1 0 0 1 1 -1h12a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-12a1 1 0 0 1 -1 -1z"></path>
                    <path d="M9 9h6v6h-6z"></path>
                    <path d="M3 10h2"></path>
                    <path d="M3 14h2"></path>
                    <path d="M10 3v2"></path>
                    <path d="M14 3v2"></path>
                    <path d="M21 10h-2"></path>
                    <path d="M21 14h-2"></path>
                    <path d="M14 21v-2"></path>
                    <path d="M10 21v-2"></path>
                </svg>
                <span>
                    <strong>Host:</strong> <i>{host_name}</i>
                </span>
            </div>
        </details>
        """,
        sizing_mode="stretch_width",
        stylesheets=stylesheets,
    )

    return {"stats": stats, "info": other_info}

build_time_label

build_time_label(
    time: str,
    diners_n: str,
    separator: str = " &#10072; ",
    emoji: str = "&#127829;",
    per_icon: str = " &#10006; ",
    is_takeaway: bool = False,
    takeaway_alert_sign: str = "TAKEAWAY",
    css_classes: list = [],
    stylesheets: list = [],
    **kwargs
) -> HTML

Build HTML field to display the time label.

This function is used to display labels that summarize an order.

Those are shown on the side of the menu table as well as labels above each order table.

Parameters:

Name Type Description Default
time str

Lunch time.

required
diners_n str

Number of people that placed an order.

required
separator str

Separator between lunch time and order data. Defaults to " ❘ ".

' &#10072; '
emoji str

Emoji used as number lunch symbol. Defaults to "🍕".

'&#127829;'
per_icon str

icon used between the lunch emoji and the number of people that placed an order. Usually a multiply operator. Defaults to " ✖ ".

' &#10006; '
is_takeaway bool

takeaway flag (true if the order is to takeaway). Defaults to False.

False
takeaway_alert_sign str

warning text to highlight that the order is to takeaway. Defaults to "TAKEAWAY".

'TAKEAWAY'
css_classes list

CSS classes to assign to the resulting HTML pane. Defaults to [].

[]
stylesheets list

Stylesheets to assign to the resulting HTML pane (see Panel docs <https://panel.holoviz.org/how_to/styling/apply_css.html>__). Defaults to [].

[]

Returns:

Type Description
HTML

HTML pane representing a label with order summary.

Source code in dlunch/gui.py
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
def build_time_label(
    self,
    time: str,
    diners_n: str,
    separator: str = " &#10072; ",
    emoji: str = "&#127829;",
    per_icon: str = " &#10006; ",
    is_takeaway: bool = False,
    takeaway_alert_sign: str = "TAKEAWAY",
    css_classes: list = [],
    stylesheets: list = [],
    **kwargs,
) -> pn.pane.HTML:
    """Build HTML field to display the time label.

    This function is used to display labels that summarize an order.

    Those are shown on the side of the menu table as well as labels above each order table.

    Args:
        time (str): Lunch time.
        diners_n (str): Number of people that placed an order.
        separator (str, optional): Separator between lunch time and order data. Defaults to " &#10072; ".
        emoji (str, optional): Emoji used as number lunch symbol. Defaults to "&#127829;".
        per_icon (str, optional): icon used between the lunch emoji and the number of people that placed an order.
            Usually a multiply operator.
            Defaults to " &#10006; ".
        is_takeaway (bool, optional): takeaway flag (true if the order is to takeaway). Defaults to False.
        takeaway_alert_sign (str, optional): warning text to highlight that the order is to takeaway. Defaults to "TAKEAWAY".
        css_classes (list, optional): CSS classes to assign to the resulting HTML pane. Defaults to [].
        stylesheets (list, optional): Stylesheets to assign to the resulting HTML pane
            (see `Panel docs <https://panel.holoviz.org/how_to/styling/apply_css.html>`__). Defaults to [].

    Returns:
        pn.pane.HTML: HTML pane representing a label with order summary.
    """
    # If takeaway add alert sign
    if is_takeaway:
        takeaway = f"{separator}{takeaway_alert_sign}"
    else:
        takeaway = ""
    # Time label pane
    classes_str = " ".join(css_classes)
    time_label = pn.pane.HTML(
        f'<span class="{classes_str}">{time}{separator}{emoji}{per_icon}{diners_n}{takeaway}</span>',
        stylesheets=stylesheets,
        **kwargs,
    )

    return time_label

load_sidebar_tabs

load_sidebar_tabs(
    config: DictConfig, clear_before_loading: bool = True
) -> None

Append tabs to the app template sidebar.

The flag clear_before_loading is set to true only during first instantiation, because the sidebar is empty at first. Use the default value during normal operation to avoid tabs duplication.

Parameters:

Name Type Description Default
config DictConfig

Hydra configuration dictionary.

required
clear_before_loading bool

Set to true to remove all tabs before appending the new ones. Defaults to True.

True
Source code in dlunch/gui.py
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
def load_sidebar_tabs(
    self, config: DictConfig, clear_before_loading: bool = True
) -> None:
    """Append tabs to the app template sidebar.

    The flag `clear_before_loading` is set to true only during first instantiation, because the sidebar is empty at first.
    Use the default value during normal operation to avoid tabs duplication.

    Args:
        config (DictConfig): Hydra configuration dictionary.
        clear_before_loading (bool, optional): Set to true to remove all tabs before appending the new ones. Defaults to True.
    """
    # Clean tabs
    if clear_before_loading:
        self.sidebar_tabs.clear()
    # Append User tab
    self.sidebar_tabs.append(self.sidebar_person_column)
    # Append upload, download and stats only for non-guest
    # Append password only for non-guest users if auth is active
    if not auth.is_guest(
        user=pn_user(config), config=config, allow_override=False
    ):
        self.sidebar_tabs.append(self.sidebar_menu_upload_col)
        self.sidebar_tabs.append(self.sidebar_download_orders_col)
        self.sidebar_tabs.append(self.sidebar_stats_col)
        if auth.is_basic_auth_active(config=config):
            self.sidebar_tabs.append(self.sidebar_password)

PasswordRenewer

Bases: Parameterized

Param class used to create the widget that collect info to renew users password.

This widget is used only if basic authentication is active.

Methods:

Name Description
__str__

String representation of this object.

Attributes:

Name Type Description
new_password String

New password.

old_password String

Old password.

repeat_new_password String

Repeat the new password. This field tests if the new password is as intended.

Source code in dlunch/gui.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class PasswordRenewer(param.Parameterized):
    """Param class used to create the widget that collect info to renew users password.

    This widget is used only if basic authentication is active."""

    old_password: param.String = param.String(default="")
    """Old password."""
    new_password: param.String = param.String(default="")
    """New password."""
    repeat_new_password: param.String = param.String(default="")
    """Repeat the new password. This field tests if the new password is as intended."""

    def __str__(self):
        """String representation of this object.

        Returns:
            (str): string representation.
        """
        return "PasswordRenewer"

new_password class-attribute instance-attribute

new_password: String = String(default='')

New password.

old_password class-attribute instance-attribute

old_password: String = String(default='')

Old password.

repeat_new_password class-attribute instance-attribute

repeat_new_password: String = String(default='')

Repeat the new password. This field tests if the new password is as intended.

__str__

__str__()

String representation of this object.

Returns:

Type Description
str

string representation.

Source code in dlunch/gui.py
114
115
116
117
118
119
120
def __str__(self):
    """String representation of this object.

    Returns:
        (str): string representation.
    """
    return "PasswordRenewer"

Person

Bases: Parameterized

Param class that define user data and lunch preferences for its order.

username is automatically set for privileged users. It's left empty for guest users.

lunch_time and guest available value are set when instantiation happens. Check panel.lunch_times_options and panel.guest_types config keys.

Methods:

Name Description
__init__
__str__

String representation of this object.

Attributes:

Name Type Description
guest ObjectSelector

List of available guest types.

lunch_time ObjectSelector

List of available lunch times.

takeaway Boolean

Takeaway flag (true if takeaway).

username String

Username

Source code in dlunch/gui.py
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
class Person(param.Parameterized):
    """Param class that define user data and lunch preferences for its order.

    `username` is automatically set for privileged users. It's left empty for guest users.

    `lunch_time` and `guest` available value are set when instantiation happens.
    Check `panel.lunch_times_options` and `panel.guest_types` config keys.
    """

    username: param.String = param.String(default="", doc="your name")
    """Username"""
    lunch_time: param.ObjectSelector = param.ObjectSelector(
        default="12:30", doc="choose your lunch time", objects=["12:30"]
    )
    """List of available lunch times."""
    guest: param.ObjectSelector = param.ObjectSelector(
        default="Guest", doc="select guest type", objects=["Guest"]
    )
    """List of available guest types."""
    takeaway: param.Boolean = param.Boolean(
        default=False, doc="tick to order a takeaway meal"
    )
    """Takeaway flag (true if takeaway)."""

    def __init__(self, config: OmegaConf, **params):
        super().__init__(**params)
        # Set lunch times from config
        self.param.lunch_time.objects = config.panel.lunch_times_options
        # Set guest type from config
        self.param.guest.objects = config.panel.guest_types
        self.param.guest.default = config.panel.guest_types[0]
        self.guest = config.panel.guest_types[0]
        # Check user (a username is already set for privileged users)
        username = pn_user(config)
        if not auth.is_guest(
            user=username, config=config, allow_override=False
        ) and (username is not None):
            self.username = username

    def __str__(self):
        """String representation of this object.

        Returns:
            (str): string representation.
        """
        return f"PERSON:{self.name}"

guest class-attribute instance-attribute

guest: ObjectSelector = guest_types[0]

List of available guest types.

lunch_time class-attribute instance-attribute

lunch_time: ObjectSelector = ObjectSelector(
    default="12:30",
    doc="choose your lunch time",
    objects=["12:30"],
)

List of available lunch times.

takeaway class-attribute instance-attribute

takeaway: Boolean = Boolean(
    default=False, doc="tick to order a takeaway meal"
)

Takeaway flag (true if takeaway).

username class-attribute instance-attribute

username: String = String(default='', doc='your name')

Username

__init__

__init__(config: OmegaConf, **params)
Source code in dlunch/gui.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def __init__(self, config: OmegaConf, **params):
    super().__init__(**params)
    # Set lunch times from config
    self.param.lunch_time.objects = config.panel.lunch_times_options
    # Set guest type from config
    self.param.guest.objects = config.panel.guest_types
    self.param.guest.default = config.panel.guest_types[0]
    self.guest = config.panel.guest_types[0]
    # Check user (a username is already set for privileged users)
    username = pn_user(config)
    if not auth.is_guest(
        user=username, config=config, allow_override=False
    ) and (username is not None):
        self.username = username

__str__

__str__()

String representation of this object.

Returns:

Type Description
str

string representation.

Source code in dlunch/gui.py
93
94
95
96
97
98
99
def __str__(self):
    """String representation of this object.

    Returns:
        (str): string representation.
    """
    return f"PERSON:{self.name}"