- Modernized authentication with the introduction of TenantProject
- Created a base mail template - Adapt and improve document API to usage of catalogs and processors - Adapt eveai_sync to new authentication mechanism and usage of catalogs and processors
This commit is contained in:
@@ -2,7 +2,12 @@ from flask import session
|
||||
from flask_security import current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SelectField
|
||||
from wtforms.validators import DataRequired
|
||||
from wtforms.validators import DataRequired, Optional
|
||||
from wtforms_sqlalchemy.fields import QuerySelectField
|
||||
|
||||
from common.models.document import Catalog
|
||||
from common.models.user import Tenant
|
||||
from common.utils.database import Database
|
||||
|
||||
|
||||
class SessionDefaultsForm(FlaskForm):
|
||||
@@ -13,11 +18,32 @@ class SessionDefaultsForm(FlaskForm):
|
||||
tenant_name = StringField('Tenant Name', validators=[DataRequired()])
|
||||
default_language = SelectField('Default Language', choices=[], validators=[DataRequired()])
|
||||
|
||||
# Default Catalog - initialize as a regular SelectField
|
||||
catalog = SelectField('Catalog', choices=[], validators=[Optional()])
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# Set basic fields first (these don't require DB access)
|
||||
self.user_name.data = current_user.user_name
|
||||
self.user_email.data = current_user.email
|
||||
self.tenant_name.data = session.get('tenant').get('name')
|
||||
self.default_language.choices = [(lang, lang.lower()) for lang in
|
||||
session.get('tenant').get('allowed_languages')]
|
||||
self.default_language.data = session.get('default_language')
|
||||
self.default_language.data = session.get('default_language')
|
||||
|
||||
# Get a new session for catalog queries
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
tenant_session = Database(tenant_id).get_session()
|
||||
try:
|
||||
# Populate catalog choices using tenant session
|
||||
catalogs = tenant_session.query(Catalog).all()
|
||||
self.catalog.choices = [(str(c.id), c.name) for c in catalogs]
|
||||
self.catalog.choices.insert(0, ('', 'Select a Catalog')) # Add empty choice
|
||||
|
||||
# Set current catalog if exists
|
||||
catalog_id = session.get('catalog_id')
|
||||
if catalog_id:
|
||||
self.catalog.data = str(catalog_id)
|
||||
finally:
|
||||
tenant_session.close()
|
||||
|
||||
Reference in New Issue
Block a user