diff --git a/common/models/user.py b/common/models/user.py index a29ff5d..7c895a1 100644 --- a/common/models/user.py +++ b/common/models/user.py @@ -186,6 +186,7 @@ class TenantMake(db.Model): active = db.Column(db.Boolean, nullable=False, default=True) website = 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 = db.Column(JSONB, nullable=True) diff --git a/config/customisations/globals/CHAT_CLIENT_CUSTOMISATION/1.0.0.yaml b/config/customisations/globals/CHAT_CLIENT_CUSTOMISATION/1.0.0.yaml index 2f08133..3b4d063 100644 --- a/config/customisations/globals/CHAT_CLIENT_CUSTOMISATION/1.0.0.yaml +++ b/config/customisations/globals/CHAT_CLIENT_CUSTOMISATION/1.0.0.yaml @@ -56,11 +56,6 @@ configuration: description: "Sidebar Markdown-formatted Text" type: "text" required: false - "welcome_message": - name: "Welcome Message" - description: "Text to be shown as Welcome" - type: "text" - required: false metadata: author: "Josako" date_added: "2024-06-06" diff --git a/eveai_app/views/user_forms.py b/eveai_app/views/user_forms.py index b364f36..6fa7b7d 100644 --- a/eveai_app/views/user_forms.py +++ b/eveai_app/views/user_forms.py @@ -196,6 +196,14 @@ class TenantMakeForm(DynamicFormBase): active = BooleanField('Active', validators=[Optional()], default=True) website = StringField('Website', validators=[DataRequired(), 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): id = IntegerField('ID', widget=HiddenInput()) @@ -204,6 +212,14 @@ class EditTenantMakeForm(DynamicFormBase): active = BooleanField('Active', validators=[Optional()], default=True) website = StringField('Website', validators=[DataRequired(), 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()] diff --git a/eveai_app/views/user_views.py b/eveai_app/views/user_views.py index 47855ce..5810587 100644 --- a/eveai_app/views/user_views.py +++ b/eveai_app/views/user_views.py @@ -655,6 +655,8 @@ def tenant_make(): new_tenant_make.tenant_id = tenant_id customisation_options = form.get_dynamic_data("configuration") 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)) try: @@ -703,6 +705,10 @@ def edit_tenant_make(tenant_make_id): # Create form instance with the 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") 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 form.populate_obj(tenant_make) 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(tenant_make, dt.now(tz.utc)) diff --git a/migrations/public/versions/e47dc002b678_add_allowed_languages_to_tenantmake_.py b/migrations/public/versions/e47dc002b678_add_allowed_languages_to_tenantmake_.py new file mode 100644 index 0000000..12b6668 --- /dev/null +++ b/migrations/public/versions/e47dc002b678_add_allowed_languages_to_tenantmake_.py @@ -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 ###