- Remove welcome message from tenant make customisation

- Add possibility to add allowed_languages to tenant make
This commit is contained in:
Josako
2025-06-26 15:52:10 +02:00
parent fda267b479
commit 53e32a67bd
5 changed files with 78 additions and 5 deletions

View File

@@ -186,6 +186,7 @@ class TenantMake(db.Model):
active = db.Column(db.Boolean, nullable=False, default=True) active = db.Column(db.Boolean, nullable=False, default=True)
website = db.Column(db.String(255), nullable=True) website = db.Column(db.String(255), nullable=True)
logo_url = db.Column(db.String(255), nullable=True) logo_url = db.Column(db.String(255), nullable=True)
allowed_languages = db.Column(ARRAY(sa.String(2)), nullable=True)
# Chat customisation options # Chat customisation options
chat_customisation_options = db.Column(JSONB, nullable=True) chat_customisation_options = db.Column(JSONB, nullable=True)

View File

@@ -56,11 +56,6 @@ configuration:
description: "Sidebar Markdown-formatted Text" description: "Sidebar Markdown-formatted Text"
type: "text" type: "text"
required: false required: false
"welcome_message":
name: "Welcome Message"
description: "Text to be shown as Welcome"
type: "text"
required: false
metadata: metadata:
author: "Josako" author: "Josako"
date_added: "2024-06-06" date_added: "2024-06-06"

View File

@@ -196,6 +196,14 @@ class TenantMakeForm(DynamicFormBase):
active = BooleanField('Active', validators=[Optional()], default=True) active = BooleanField('Active', validators=[Optional()], default=True)
website = StringField('Website', validators=[DataRequired(), Length(max=255)]) website = StringField('Website', validators=[DataRequired(), Length(max=255)])
logo_url = StringField('Logo URL', validators=[Optional(), Length(max=255)]) logo_url = StringField('Logo URL', validators=[Optional(), Length(max=255)])
allowed_languages = SelectMultipleField('Allowed Languages', choices=[], validators=[Optional()])
def __init__(self, *args, **kwargs):
super(TenantMakeForm, self).__init__(*args, **kwargs)
# Initialiseer de taalopties met taalcodes en vlaggen
lang_details = current_app.config['SUPPORTED_LANGUAGE_DETAILS']
self.allowed_languages.choices = [(details['iso 639-1'], f"{details['flag']} {details['iso 639-1']}")
for name, details in lang_details.items()]
class EditTenantMakeForm(DynamicFormBase): class EditTenantMakeForm(DynamicFormBase):
id = IntegerField('ID', widget=HiddenInput()) id = IntegerField('ID', widget=HiddenInput())
@@ -204,6 +212,14 @@ class EditTenantMakeForm(DynamicFormBase):
active = BooleanField('Active', validators=[Optional()], default=True) active = BooleanField('Active', validators=[Optional()], default=True)
website = StringField('Website', validators=[DataRequired(), Length(max=255)]) website = StringField('Website', validators=[DataRequired(), Length(max=255)])
logo_url = StringField('Logo URL', validators=[Optional(), Length(max=255)]) logo_url = StringField('Logo URL', validators=[Optional(), Length(max=255)])
allowed_languages = SelectMultipleField('Allowed Languages', choices=[], validators=[Optional()])
def __init__(self, *args, **kwargs):
super(EditTenantMakeForm, self).__init__(*args, **kwargs)
# Initialiseer de taalopties met taalcodes en vlaggen
lang_details = current_app.config['SUPPORTED_LANGUAGE_DETAILS']
self.allowed_languages.choices = [(details['iso 639-1'], f"{details['flag']} {details['iso 639-1']}")
for name, details in lang_details.items()]

View File

@@ -655,6 +655,8 @@ def tenant_make():
new_tenant_make.tenant_id = tenant_id new_tenant_make.tenant_id = tenant_id
customisation_options = form.get_dynamic_data("configuration") customisation_options = form.get_dynamic_data("configuration")
new_tenant_make.chat_customisation_options = json.dumps(customisation_options) new_tenant_make.chat_customisation_options = json.dumps(customisation_options)
# Verwerk allowed_languages als array
new_tenant_make.allowed_languages = form.allowed_languages.data if form.allowed_languages.data else None
set_logging_information(new_tenant_make, dt.now(tz.utc)) set_logging_information(new_tenant_make, dt.now(tz.utc))
try: try:
@@ -703,6 +705,10 @@ def edit_tenant_make(tenant_make_id):
# Create form instance with the tenant make # Create form instance with the tenant make
form = EditTenantMakeForm(request.form, obj=tenant_make) form = EditTenantMakeForm(request.form, obj=tenant_make)
# Initialiseer de allowed_languages selectie met huidige waarden
if tenant_make.allowed_languages:
form.allowed_languages.data = tenant_make.allowed_languages
customisation_config = cache_manager.customisations_config_cache.get_config("CHAT_CLIENT_CUSTOMISATION") customisation_config = cache_manager.customisations_config_cache.get_config("CHAT_CLIENT_CUSTOMISATION")
form.add_dynamic_fields("configuration", customisation_config, tenant_make.chat_customisation_options) form.add_dynamic_fields("configuration", customisation_config, tenant_make.chat_customisation_options)
@@ -710,6 +716,8 @@ def edit_tenant_make(tenant_make_id):
# Update basic fields # Update basic fields
form.populate_obj(tenant_make) form.populate_obj(tenant_make)
tenant_make.chat_customisation_options = form.get_dynamic_data("configuration") tenant_make.chat_customisation_options = form.get_dynamic_data("configuration")
# Verwerk allowed_languages als array
tenant_make.allowed_languages = form.allowed_languages.data if form.allowed_languages.data else None
# Update logging information # Update logging information
update_logging_information(tenant_make, dt.now(tz.utc)) update_logging_information(tenant_make, dt.now(tz.utc))

View File

@@ -0,0 +1,53 @@
"""Add allowed_languages to TenantMake, introduce TranslationCache
Revision ID: e47dc002b678
Revises: 83d4e90f87c6
Create Date: 2025-06-26 13:43:43.719865
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'e47dc002b678'
down_revision = '83d4e90f87c6'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('translation_cache',
sa.Column('cache_key', sa.String(length=16), nullable=False),
sa.Column('source_text', sa.Text(), nullable=False),
sa.Column('translated_text', sa.Text(), nullable=False),
sa.Column('source_language', sa.String(length=2), nullable=False),
sa.Column('target_language', sa.String(length=2), nullable=False),
sa.Column('context', sa.Text(), nullable=True),
sa.Column('prompt_tokens', sa.Integer(), nullable=False),
sa.Column('completion_tokens', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_by', sa.Integer(), nullable=True),
sa.Column('last_used_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['public.user.id'], ),
sa.ForeignKeyConstraint(['updated_by'], ['public.user.id'], ),
sa.PrimaryKeyConstraint('cache_key'),
schema='public'
)
with op.batch_alter_table('tenant_make', schema=None) as batch_op:
batch_op.add_column(sa.Column('allowed_languages', postgresql.ARRAY(sa.String(length=2)), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tenant_make', schema=None) as batch_op:
batch_op.drop_column('allowed_languages')
op.drop_table('translation_cache', schema='public')
# ### end Alembic commands ###