Skip to content

Commit

Permalink
Refactoring manage_lang (#198)
Browse files Browse the repository at this point in the history
Co-authored-by: zmsdev
  • Loading branch information
drfho authored Oct 13, 2023
1 parent 041797a commit e321739
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 207 deletions.
52 changes: 0 additions & 52 deletions Products/zms/IZMSLocale.py

This file was deleted.

7 changes: 1 addition & 6 deletions Products/zms/ZMSItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def zmi_body_class(self, *args, **kwargs):
l = ['zmi','zms', 'loading']
l.append(request.get('lang'))
l.append('lang-%s'%(request.get('lang')))
l.append('manage_lang-%s'%(request.get('manage_lang')))
l.extend(kwargs.values())
l.append(self.meta_id)
# FOR EVALUATION: adding node specific css classes [list]
Expand Down Expand Up @@ -128,14 +127,12 @@ def zmi_page_request(self, *args, **kwargs):
RESPONSE.setHeader('Cache-Control', 'no-cache')
RESPONSE.setHeader('Pragma', 'no-cache')
RESPONSE.setHeader('Content-Type', 'text/html;charset=%s'%request['ZMS_CHARSET'])
request.set( 'is_zmi', True)
if not request.get( 'preview'):
request.set( 'preview', 'preview')
request.set( 'is_zmi', True)
langs = self.getLanguages(request)
if request.get('lang') not in langs:
request.set('lang', langs[0])
if request.get('manage_lang') not in self.getLocale().get_manage_langs():
request.set('manage_lang', self.get_manage_lang())
if not request.get('manage_tabs_message'):
request.set( 'manage_tabs_message', self.getConfProperty('ZMS.manage_tabs_message', ''))
if 'zmi-manage-system' in request.form:
Expand All @@ -159,8 +156,6 @@ def f_standard_html_request(self, *args, **kwargs):
self._zmi_page_request()
if not request.get( 'lang'):
request.set( 'lang', self.getLanguage(request))
if not request.get('manage_lang') in self.getLocale().get_manage_langs():
request.set( 'manage_lang', self.get_manage_lang())


# --------------------------------------------------------------------------
Expand Down
19 changes: 7 additions & 12 deletions Products/zms/ZMSTextformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# ------------------------------------------------------------------------------
# br_quote
# ------------------------------------------------------------------------------
def br_quote(text, subtag, REQUEST):
def br_quote(self, text, subtag):
if len(subtag) == 0:
return text
if type(text) not in [str, str]:
Expand All @@ -34,8 +34,8 @@ def br_quote(text, subtag, REQUEST):
qcr = ''
qtab = ' '*6

if standard.isManagementInterface(REQUEST):
if 'format' not in REQUEST:
if standard.isManagementInterface(self):
if 'format' not in self.REQUEST:
qcr = '<span class="unicode">&crarr;</span>'
qtab = '<span class="unicode">&rarr;</span>' + '&nbsp;' * 5

Expand Down Expand Up @@ -131,14 +131,9 @@ class ZMSTextformat(object):
#
# Constructor.
# ----------------------------------------------------------------------------
def __init__(self, id, ob, REQUEST):
def __init__(self, id, ob, manage_lang):
self.setId(id)
if REQUEST is not None and \
'manage_lang' in REQUEST and \
REQUEST['manage_lang'] in ob['display']:
self.setDisplay(ob['display'][REQUEST['manage_lang']])
else:
self.setDisplay(id)
self.setDisplay(ob['display'].get(manage_lang,id))
self.setTag(ob['tag'])
self.setSubTag(ob['subtag'])
self.setAttrs(ob['attrs'])
Expand Down Expand Up @@ -272,12 +267,12 @@ def getHtml(self):
# Render text.
# ----------------------------------------------------------------------------
renderText__roles__ = None
def renderText(self, text, REQUEST, id=None, clazz=None, encoding='utf-8', errors='strict'):
def renderText(self, context, text, id=None, clazz=None, encoding='utf-8', errors='strict'):
html = ''
# Open tag.
html += self.getStartTag( id, clazz)
# Sub tag.
text = br_quote( text, self.getSubTag(), REQUEST)
text = br_quote( context, text, self.getSubTag())
# Value.
try:
html += str(text, encoding, errors)
Expand Down
3 changes: 2 additions & 1 deletion Products/zms/ZMSTextformatManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def getTextFormat(self, id, REQUEST):
if id in self.textformats:
i = self.textformats.index(id)
d = self.textformats[i+1]
return ZMSTextformat.ZMSTextformat(id, d, REQUEST)
manage_lang = self.get_manage_lang()
return ZMSTextformat.ZMSTextformat(id, d, manage_lang)
return None


Expand Down
27 changes: 0 additions & 27 deletions Products/zms/_confmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,33 +1101,6 @@ def getCatalogAdapter(self):
return adapter


############################################################################
###
### Interface IZMSLocale: delegate
###
############################################################################

def getLocale(self):
return self

"""
def get_manage_langs(self):
return self.getLocale().get_manage_langs()
def get_manage_lang(self):
return self.getLocale().get_manage_lang()
def getZMILangStr(self, key, REQUEST=None, RESPONSE=None):
return self.getLocale().getZMILangStr( key)
def getLangStr(self, key, lang=None):
return self.getLocale().getLangStr( key, lang)
def getPrimaryLanguage(self):
return self.getLocale().getPrimaryLanguage()
"""


# call this to initialize framework classes, which
# does the right thing with the security assertions.
InitializeClass(ConfManager)
Expand Down
37 changes: 20 additions & 17 deletions Products/zms/_multilangmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import json
from zope.interface import implementer
# Product Imports.
from Products.zms import IZMSLocale
from Products.zms import _fileutil
from Products.zms import _xmllib
from Products.zms import standard
Expand Down Expand Up @@ -222,7 +221,6 @@ def getDescendantLanguages(self, id, REQUEST=None, RESPONSE=None):
###
################################################################################
################################################################################
@implementer(IZMSLocale.IZMSLocale)
class MultiLanguageManager(object):

def get_manage_langs(self):
Expand All @@ -236,21 +234,26 @@ def get_manage_lang(self):
Returns preferred of manage-language for current content-language.
"""
manage_lang = None
req = getattr( self, 'REQUEST', None)
if req.get( 'is_zmi', False):
if req is not None:
sess = standard.get_session(self)
if 'manage_lang' in req:
manage_lang = req.get('manage_lang')
else:
if sess is not None and 'reset_manage_lang' not in req.form:
manage_lang = sess.get('manage_lang')
if manage_lang is None:
lang = req.get('lang')
if lang in self.getLangIds():
manage_lang = self.getLang(lang).get('manage')
if sess is not None:
sess.set('manage_lang', manage_lang)
request = self.REQUEST
if standard.isManagementInterface(self):
manage_langs = self.get_manage_langs()
# get manage_lang from request.form
if 'manage_lang' in request.form and request.form['manage_lang'] in manage_langs:
manage_lang = request.form['manage_lang']
# save manage_lang from request.form in session
standard.set_session_value(self, 'manage_lang', manage_lang)
else:
# get manage_lang from request or session
manage_lang = request.get('manage_lang', standard.get_session_value(self, 'manage_lang'))
if manage_lang not in manage_langs:
# get manage_lang from request.lang
manage_lang = None
lang = request.get('lang')
if lang in self.getLangIds():
manage_lang = self.getLang(lang).get('manage')
# save manage_lang from request.lang in session
standard.set_session_value(self, 'manage_lang', manage_lang)
# default manage_lang to English
if manage_lang is None:
manage_lang = 'eng'
return manage_lang
Expand Down
7 changes: 3 additions & 4 deletions Products/zms/_objattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,19 @@ def getObjAttr(self, key, meta_id=None):
# ObjAttrs.getObjAttrLabel:
# --------------------------------------------------------------------------
def getObjAttrLabel(self, obj_attr):
lang = self.REQUEST.get('manage_lang', self.REQUEST.get('lang', self.getPrimaryLanguage()))
for key in [ 'name', 'id']:
if key in obj_attr:
name = obj_attr.get( key)
lang_key = name
lang_str = self.getLangStr( lang_key, lang)
lang_str = self.getZMILangStr( lang_key)
if lang_key != lang_str:
return lang_str
lang_key = name.upper()
lang_str = self.getLangStr( lang_key, lang)
lang_str = self.getZMILangStr( lang_key)
if lang_key != lang_str:
return lang_str
lang_key = ('attr_'+name).upper()
lang_str = self.getLangStr( lang_key, lang)
lang_str = self.getZMILangStr( lang_key)
if lang_key != lang_str:
return lang_str
return obj_attr.get('name', obj_attr['id'].capitalize())
Expand Down
3 changes: 1 addition & 2 deletions Products/zms/_objinputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ def getUrlInput(self, fmName, elName, elTextName='', size=None, value='', enable
# @return String
# ----------------------------------------------------------------------------
def getDateTimeInput(self, fmName, elName, size=8, value=None, enabled=True, fmt_str='DATETIME_FMT', css='form-control'):
manage_lang = self.REQUEST.get('manage_lang', self.getPrimaryLanguage())
html = []
input_type = 'date'
if not isinstance(value, str):
fmt = {'DATE_FMT':'%Y-%m-%d','DATETIME_FMT':'%Y-%m-%dT%H:%M','TIME_FMT':'%H:%M'}
value = self.getLangFmtDate(value, manage_lang, fmt.get(fmt_str))
value = standard.getLangFmtDate(self, value, fmt_str=fmt.get(fmt_str))
if value is not None and standard.parseLangFmtDate(value) is None:
value = ''
placeholder = self.getZMILangStr(fmt_str)
Expand Down
2 changes: 1 addition & 1 deletion Products/zms/_textformatmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def renderText( self, format, key, text, REQUEST, id=None, clazz=None):
if format is not None:
textformat = self.getTextFormat( format, REQUEST)
if textformat is not None and len( text) > 0:
text = textformat.renderText( text, REQUEST, id, clazz)
text = textformat.renderText( self, text, id, clazz)
# Custom hook.
try:
name = 'renderCustomText'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Script (Python) "manage_attrChange"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=cselected=None,aselected=None,searchstr=None,replacestr=None,mode=None,lang='ger'
##title=*** DO NOT DELETE OR MODIFY ***
##
## Script (Python) "manage_attrChange"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=cselected=None,aselected=None,searchstr=None,replacestr=None,mode=None,lang='ger'
##title=*** DO NOT DELETE OR MODIFY ***
##
request = container.REQUEST
RESPONSE = request.RESPONSE
zms = context.content
Expand All @@ -15,7 +15,6 @@
# aselected = request.get('aselected',None)
# mode = request.get('mode',None)
# request.set('lang',request.get('lang','eng'))
request.set('manage_lang', request.get('manage_lang', request.get('lang','eng')))
request.set('ZMI_TIME', DateTime().timeTime())
request.set('quickrun', int(request.get('quickrun', 0)))

Expand Down Expand Up @@ -281,4 +280,4 @@ def renderHtml():

print(html)
RESPONSE.setHeader('Content-Type','text/html;charset=utf-8')
return printed
return printed
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ def manage_repository_gitconfig(self, request=None):
git_url = self.getConfProperty('ZMSRepository.git.server.url','git@github.com:myname/myproject.git')
if request.get('lang',None) is None:
request['lang'] = 'ger'
if request.get('manage_lang',None) is None:
request['manage_lang'] = 'ger'
RESPONSE = request.RESPONSE
btn = request.form.get('btn')
came_from = request.get('came_from',request['HTTP_REFERER'])
if came_from.find('?') > 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ def manage_repository_gitstatus( self ):
git_branch = self.getConfProperty('ZMSRepository.git.server.branch','main')
if request.get('lang',None) is None:
request['lang'] = 'ger'
if request.get('manage_lang',None) is None:
request['manage_lang'] = 'ger'
RESPONSE = request.RESPONSE
btn = request.form.get('btn')
came_from = request.get('came_from',request['HTTP_REFERER'])
if came_from.find('?') > 0:
Expand Down
13 changes: 8 additions & 5 deletions Products/zms/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,18 @@ def triggerEvent(context, *args, **kwargs):


security.declarePublic('isManagementInterface')
def isManagementInterface(REQUEST):
def isManagementInterface(self):
"""
Returns true if current context is management-interface, false else.
@rtype: C{Bool}
"""
return REQUEST is not None and \
REQUEST.get('URL', '').find('/manage') >= 0 and \
isPreviewRequest(REQUEST)

request = self.REQUEST
if not 'is_zmi' in request:
permissions = set(sum([list(x[1]) for x in self.__ac_permissions__],[]))
current = request.get('URL', '').split('/')[-1]
request.set('is_zmi', request.get('AUTHENTICATED_USER') and \
(current.startswith('manage_') or current in permissions))
return request.get('is_zmi')


security.declarePublic('isPreviewRequest')
Expand Down
1 change: 1 addition & 0 deletions Products/zms/zms.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class ZMS(
'manage_customizeDesign', 'manage_customizeDesignForm',
)
__authorPermissions__ = (
'preview_html', 'preview_top_html',
'manage_addZMSModule',
'manage_deleteObjs', 'manage_undoObjs',
'manage_moveObjUp', 'manage_moveObjDown', 'manage_moveObjToPos',
Expand Down
1 change: 1 addition & 0 deletions Products/zms/zmscustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def manage_options(self):
'manage', 'manage_main', 'manage_container', 'manage_workspace', 'manage_menu',
)
__authorPermissions__ = (
'preview_html', 'preview_top_html',
'manage_addZMSModule',
'manage_changeRecordSet',
'manage_properties', 'manage_changeProperties', 'manage_changeTempBlobjProperty',
Expand Down
Loading

0 comments on commit e321739

Please sign in to comment.