Save the setting to disk and persist the setting to session state Args: user_id: the user id args: all the values from the settings
(self, user_id: int, *args)
| 405 | return updates |
| 406 | |
| 407 | def save_setting(self, user_id: int, *args): |
| 408 | """Save the setting to disk and persist the setting to session state |
| 409 | |
| 410 | Args: |
| 411 | user_id: the user id |
| 412 | args: all the values from the settings |
| 413 | """ |
| 414 | setting = {key: value for key, value in zip(self.component_names(), args)} |
| 415 | if user_id is None: |
| 416 | gr.Warning("Need to login before saving settings") |
| 417 | return setting |
| 418 | |
| 419 | with Session(engine) as session: |
| 420 | statement = select(Settings).where(Settings.user == user_id) |
| 421 | try: |
| 422 | user_setting = session.exec(statement).one() |
| 423 | except Exception: |
| 424 | user_setting = Settings() |
| 425 | user_setting.user = user_id |
| 426 | user_setting.setting = setting |
| 427 | session.add(user_setting) |
| 428 | session.commit() |
| 429 | |
| 430 | gr.Info("Setting saved") |
| 431 | return setting |
| 432 | |
| 433 | def components(self) -> list: |
| 434 | """Get the setting components""" |
nothing calls this directly
no test coverage detected