Fixes in libraries

This commit is contained in:
Antonio de la Rosa 2025-03-18 01:33:39 +01:00
parent 5066f5320c
commit 885d3ca43a
6 changed files with 104 additions and 6 deletions

View file

@ -109,7 +109,31 @@ class I18n:
def __init__(self, module):
self.module=module
def clang(self, module, symbol, text_default):
"""Static method for get a string from selected language
Static method used to get the string of the selected language. If there is no string in the selected language, it returns text_default.
Args:
module (str): The module to which the translation string belongs
symbol (str): Simple symbol that is useful for identify the string
text_default (str): The text used by default when there are not translation in the selected language
"""
#if not lang:
# lang=I18n.get_default_lang()
lang=self.default_lang
I18n.l[lang]=I18n.l.get(lang, {})
I18n.l[lang][module]=I18n.l[lang].get(module, {})
I18n.l[lang][module][symbol]=I18n.l[lang][module].get(symbol, text_default)
return I18n.l[lang][module][symbol]
def slang(self, symbol, text_default, lang=None):
"""Method for get a string from selected language but object oriented
@ -136,6 +160,15 @@ class I18n:
return I18n.lang(self.module, symbol, text_default, lang)
@staticmethod
def add_lang(lang, module, symbol, text):
I18n.l[lang]=I18n.l.get(lang, {})
I18n.l[lang][module]=I18n.l[lang].get(module, {})
I18n.l[lang][module][symbol]=text
#@staticmethod
#def set_lang(code_lang):
# if default_lang

View file

@ -10,10 +10,12 @@ from paramecio.libraries.generate_admin_class import GenerateAdminClass
from paramecio.libraries.db.formsutils import show_form
from paramecio.libraries.db.coreforms import SelectForm
from paramecio.libraries.db.coreforms import PasswordForm
from paramecio.libraries.db.coreforms import HiddenForm
from paramecio.wsgiapp import app
from paramecio.libraries.db.webmodel import WebModel
from paramecio.modules.admin2.models.admin import UserAdmin2
from paramecio.modules.admin2.models.admin import UserAdmin2, PrivilegesModule2
from paramecio.libraries.urls import add_get_parameters
from paramecio.modules.admin2.libraries.config import modules_admin
env=env_theme(__file__)
@ -38,7 +40,7 @@ modules_admin_icons.append('<symbol id="people-circle" viewBox="0 0 16 16"><path
@admin_app.post('/ausers', name="admin_app.admin_users")
def admin_users(session={}):
i18n=I18n('admin2')
#i18n=I18n('admin2')
db=WebModel.connection()
@ -79,13 +81,55 @@ def admin_users(session={}):
return t.load_template('users.phtml', title=i18n.tlang('Admin users'), tlang=i18n.tlang, module_selected='admin_app.admin_users', slist=slist, session=session)
@admin_app.get('/ausers/permissions/<user_id:int>', name="admin_app.admin_permissions")
@admin_app.post('/ausers/permissions/<user_id:int>', name="admin_app.admin_permissions")
def admin_users(user_id, session={}):
db=WebModel.connection()
user_admin=UserAdmin2(db)
arr_user=user_admin.select_a_row(user_id, ['username'])
if arr_user:
priv=PrivilegesModule2(db)
url=app.get_url('admin_app.admin_permissions', user_id=user_id)
admin=GenerateAdminClass(priv, url, t)
admin.list.fields_showed=['module']
admin.list.search_fields=['module']
priv.fields['module'].name_form=SelectForm
arr_modules={v[0]:i18n.clang('admin2', v[0], v[0]) for v in modules_admin}
priv.fields['user_id'].name_form=HiddenForm
priv.fields['user_id'].extra_parameters=[]
priv.fields['user_id'].default_value=user_id
priv.create_forms()
priv.set_conditions('WHERE user_id=%s', [user_id])
priv.forms['module'].arr_select=arr_modules
#print(user_id)
#with db.query('select *')
privileges_admin=admin.show()
else:
arr_user={'username': i18n.tlang('User not found')}
privileges_admin=''
db.close()
return ""
return t.load_template('access.phtml', title=i18n.tlang('Users permissions'), privileges_admin=privileges_admin, user=arr_user, module_selected='admin_app.admin_users')
def user_options(url, id, arr_row):

View file

@ -1,4 +1,4 @@
from parameciofast.libraries.i18n import I18n
from paramecio.libraries.i18n import I18n
"""
I18n.l['en-US']=I18n.l.get('en-US', {})

View file

@ -11,6 +11,13 @@ from paramecio.libraries.db.extrafields.ipfield import IpField
from paramecio.libraries.db.extrafields.datetimefield import DateTimeField
from paramecio.libraries.db.usermodel import UserModel
class ModuleField(corefields.CharField):
def show_formatted(self, value):
return I18n.lang('admin2', value, value)
class PrivilegesField2(corefields.IntegerField):
def show_formatted(self, value):
@ -76,3 +83,11 @@ class LoginTries2(WebModel):
self.register(corefields.IntegerField('num_tries', 1))
self.register(DateTimeField('last_login'))
class PrivilegesModule2(WebModel):
def __init__(self, connection=None):
super().__init__(connection)
self.register(corefields.ForeignKeyField('user_id', UserAdmin2(connection), 11, False, 'id', 'username', select_fields=[]), True)
self.register(ModuleField('module'), True)

View file

@ -1,4 +1,7 @@
<%inherit file="layout.phtml"/>
<%block name="content">
<h3>${tlang('User')}: ${user['username'].capitalize()}</h3>
<p><a href="${url_for('admin_app.admin_users')}">${tlang('Users')}</a> &gt;&gt; ${tlang('Permissions')}</p>
${privileges_admin|n}
<p><a href="${url_for('admin_app.admin_users')}">${tlang('Users')}</a> &gt;&gt; ${tlang('Permissions')}</p>
</%block>

View file

@ -1,13 +1,16 @@
<%
from paramecio.modules.admin2.libraries.config import modules_admin, modules_admin_icons
from parameciofast.libraries.i18n import I18n
from paramecio.libraries.i18n import I18n
from paramecio.libraries.sessionplugin import get_session
i18n=I18n('admin2')
dark_checked=""
dark_css=""
session=get_session()
if session.get('theme', '0')==True:
dark_checked='checked'
dark_css='dark'