Sort formatting for english lex and add localise to tables columns

This commit is contained in:
Brian Read 2024-05-05 09:31:10 +01:00
parent 145c45f483
commit 228a42ed60
8 changed files with 103 additions and 47 deletions

View File

@ -2,7 +2,7 @@
# Routines to be editted by the developer to provide validation for parameters
# and provison of the control data for table(s)
#
# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-03 17:51
# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-05 09:26
#
use esmith::util;

View File

@ -1,6 +1,6 @@
% layout 'default', title => "Sme server 2 - NFS data share", share_dir => './';
%#
%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-03 17:51
%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-05 09:26
%#
% content_for 'module' => begin
<div id="module" class="module Nfsshare-panel">

View File

@ -1,6 +1,6 @@
package SrvMngr::Controller::Nfsshare;
#
# Generated by version:SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-03 17:51
# Generated by version:SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-05 09:26
#
#----------------------------------------------------------------------
# heading : Network
@ -203,7 +203,7 @@ sub do_update {
sub do_display {
#
# Return after link clicked in table (this is a get) - route is "/<whatever>d"
# Expects ?trt=PANEL&selected="TableRowName" plus any other required
# Expects ?trt=PANEL&selected="TableRownfs_Name" plus any other required
#
#load up all supplied params into prefix_data hash
#call get-selected-PANEL() - returns hash of all relevent parameters

View File

@ -1,5 +1,5 @@
%#
%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-03 17:51
%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-05 09:26
%#
<div id="Nfsshare-PARAMS">
<script>
@ -17,7 +17,7 @@
%= hidden_field 'trt' => $nfs_data->{trt}
%# Inputs etc in here.
<h2>Manage NFS Ibay settings:</h2>
<h2><%=l('nfs_Manage_NFS_Ibay_settings:')%></h2>
<p>
%= l('nfs_These_parameters_will_be_effective')
@ -26,7 +26,7 @@
<p><span class=label>
%=l('nfs_Information_Bay_name'), class => 'label'
</span><span class=data>
%= stash("IbayName"), class => 'data'
%= stash("Ibaynfs_Name"), class => 'data'
</span></p>
<p><span class=label>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-03 17:51
%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-05-05 09:26
%#
<div id="Nfsshare-TABLE">
<script>
@ -17,23 +17,23 @@
%= hidden_field 'trt' => $nfs_data->{trt}
%# Inputs etc in here.
<h2>Manage NFS Ibay settings:</h2>
<h2><%=l('nfs_Manage_NFS_Ibay_settings:')%></h2>
<br /><table class="sme-border TableSort">
<thead>
<tr>
<th class='sme-border'>Name</th>
<th class='sme-border'>Description</th>
<th class='sme-border'>Nfs status</th>
<th class='sme-border'>Action</th>
<th class='sme-border'><%=l('nfs_Name')%></th>
<th class='sme-border'><%=l('nfs_Description')%></th>
<th class='sme-border'><%=l('Nfs_status')%></th>
<th class='sme-border'><%=l('nfs_Action')%></th>
</tr>
</thead>
<tbody>
% my $control_data = $self->stash('ibays');
% foreach my $row (@$control_data) {
<tr>
<td class='sme-border'><%=$c->render_to_string(inline=>$row->{Name})%></td>
<td class='sme-border'><%=$c->render_to_string(inline=>$row->{Description})%></td>
<td class='sme-border'><%=$c->render_to_string(inline=>$row->{nfs_Name})%></td>
<td class='sme-border'><%=$c->render_to_string(inline=>$row->{nfs_Description})%></td>
<td class='sme-border'><%=$c->render_to_string(inline=>$row->{flag})%></td>
<td class='sme-border'><%=$c->render_to_string(inline=>$row->{Modify})%></td>
</tr>

View File

@ -1,23 +1,28 @@
'nfs_Enable_the_NFS_Share' => 'Enable the NFS Share',
'nfs_Hello_TABLE' => 'Hello TABLE',
'nfs_Write_(a)synchronously' => 'Write (a)synchronously',
'nfs_NFS_Client(s)_allowed' => 'NFS Client(s) allowed',
'nfs_Save' => 'Save',
'nfs_Information_Bay_name' => 'Information Bay name',
'nfs_Hello_PARAMS' => 'Hello PARAMS',
'nfs_NFS_data_share' => 'NFS data share',
'nfs_Share_owner_Group' => 'Share owner Group',
'nfs_APPLY' => 'APPLY',
'nfs_Set_the_GID.' => 'Set the GID.',
'nfs_PARAMS_panel_action_was_successfull' => 'PARAMS panel action was successfull',
'nfs_Requests_on_secure_ports' => 'Requests on secure ports',
'nfs_Information_Bay_name' => 'Information Bay name',
'nfs_Squash_the_power_of_users' => 'Squash the power of users',
'nfs_Set_the_UID.' => 'Set the UID.',
'nfs_For_writing_permissions,allowing_the_root' => 'For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).',
'nfs_Enable_the_NFS_Share' => 'Enable the NFS Share',
'nfs_EnableShare_on_local_network' => 'Enableshare on local network',
'nfs_Share_owner_Group' => 'Share owner Group',
'nfs_Browse_the_parent_folders' => 'Browse the parent folders',
'nfs_Hello_PARAMS' => 'Hello PARAMS',
'nfs_Delays_the_disk_writing' => 'Delays the disk writing',
'nfs_These_parameters_will_be_effective' => 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files',
'nfs_TABLE_panel_action_was_successfull' => 'TABLE panel action was successfull',
'nfs_EnableShare_on_local_network' => 'EnableShare on local network',
'nfs_Set_the_uid_and_gid' => 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank',
'nfs_Hello_TABLE' => 'Hello TABLE',
'nfs_NFS_Client(s)_allowed' => 'NFS Client(s) allowed',
'nfs_File_system_permissions' => 'File system permissions',
'nfs_Browse_the_parent_folders' => 'Browse the parent folders',
'nfs_Description' => 'Description',
'nfs_Action' => 'Action',
'nfs_NFS_data_share' => 'NFS data share',
'nfs_Manage_NFS_Ibay_settings:' => 'Manage NFS Ibay settings:',
'nfs_For_writing_permissions,allowing_the_root' => 'For writing permissions, Allowing the root user and using insecure ports, You must configure a list of one IP per line, Being part of the local network(s). ',
'Nfs_status' => 'Status',
'nfs_Requests_on_secure_ports' => 'Requests on secure ports',
'nfs_TABLE_panel_action_was_successfull' => 'TABLE panel action was successfull',
'nfs_Set_the_uid_and_gid' => 'Set the uid and gid if you want all requests appear to be from one user or one group, Otherwise leave blank',
'nfs_APPLY' => 'Apply',
'nfs_Set_the_UID.' => 'Set the UID. ',
'nfs_Name' => 'Name',
'nfs_Set_the_GID.' => 'Set the GID. ',
'nfs_Save' => 'Save',
'nfs_Write_(a)synchronously' => 'Write (a)synchronously',

View File

@ -28,7 +28,7 @@
<Date><![CDATA[
<span class=label>
%=$%=l('${prefix}_${Label}')
%=l('${prefix}_${Label}')
</span><span class=data>
%=date_field '${Name}' =>$$${Name}, pattern=>${regexp | .*}
</span><br>
@ -44,12 +44,12 @@
]]></Textinput>
<SubHeader><![CDATA[
<h2>${value}</h2>]]>
<h2><%=l('${value}')%></h2>]]>
</SubHeader>
<Paragraph><![CDATA[
<p>
%= l('${prefix}_${value}')
%= l('${value}')
</p>
]]></Paragraph>
@ -69,7 +69,7 @@
<url><![CDATA[
<p><span class=label>
%=l('${prefix}_${Label}')
%=l('${Label}')
</span><span class=data>
</span>span></p>
]]>
@ -77,7 +77,7 @@
<tel><![CDATA[
<p><span class=label>
%=l('${prefix}_${Label}')
%=l('${Label}')
</span><span class=data>
</span>span></p>
]]>
@ -85,7 +85,7 @@
<email><![CDATA[
<p><span class=label>
%=l('${prefix}_${Label}')
%=l('${Label}')
</span><span class=data>
</span>span></p>
]]>
@ -93,7 +93,7 @@
<password><![CDATA[
<p><span class=label>
%=l('${prefix}_${Label}')
%=l('${Label}')
</span><span class=data>
</span>span></p>
]]>
@ -103,7 +103,7 @@
<br /><table class="sme-border TableSort">
<thead>
<tr><tal:block tal:repeat="ColHead TopHeadings">
<th class='sme-border'>${ColHead}</th></tal:block>
<th class='sme-border'><%=l('${ColHead}')%></th></tal:block>
</tr>
</thead>
<tbody>

View File

@ -11,7 +11,7 @@ import pkg_resources
from datetime import datetime
import xml.etree.ElementTree as ET
SME2Gen_version = '0.6'
SME2Gen_version = '0.7'
json5_dict: dict = {}
json5_html_list: list = []
@ -181,6 +181,52 @@ def get_db_fields():
def get_table_control_data():
return find_values_with_key(json5_html_list,'TableControl')
def format_text(text):
#
# Turn a piece of text into something a bit better formatted - spaces after full stop and comma and also capitalise sentences
#
# Create a list to hold the formatted sentences
formatted_sentences = []
# Split the text into sentences
sentences = text.split(".")
words = sentences[0].split(" ")
#print(len(sentences))
# Deal with one capitalised word
if sentences[0].isupper() and len(sentences) == 1 and len(words) == 1:
return sentences[0].capitalize()
else:
for sentence in sentences:
#print(sentence)
# and splt into sub phrases, based on comma
formatted_phrases = []
phrases = sentence.split(",")
for phrase in phrases:
#print(phrase)
phrase = phrase.lstrip()
formatted_words = []
words = phrase.split(' ')
for i,word in enumerate(words):
#print(i,word)
# Check if the word is fully uppercase or not the first
word = word.lstrip()
if word.isupper() or i != 0:
formatted_words.append(word)
else:
# Capitalize the word
formatted_words.append(word.capitalize())
# Join the formatted words back together for this phrase
formatted_phrase = ' '.join(formatted_words).lstrip()
formatted_phrases.append(formatted_phrase)
# and sentence
formatted_sentence = ", ".join(formatted_phrases).lstrip()
formatted_sentences.append(formatted_sentence)
# Join the formatted sentences back together
formatted_text = ". ".join(formatted_sentences).lstrip()
return formatted_text
if __name__ == "__main__":
try:
chameleon_version = pkg_resources.get_distribution("Chameleon").version
@ -385,18 +431,22 @@ if __name__ == "__main__":
# Map all spaces to "_" on left hand side
# amd truncate it to max five words
original_str = lex_message
if lex_message.startswith(hl('prefix')):
# Checkif it starts with the prefix (any case|)
if lex_message.lower().startswith(hl('prefix').lower()):
left_str = lex_message
right_str = lex_message[len(hl('prefix'))+1:]
# And take out any "_", map to " "
else:
left_str = hl('prefix')+"_"+lex_message
right_str = lex_message
right_str = right_str.replace("_"," ")
right_str = format_text(right_str)
left_str = left_str.replace(" ","_")
words = left_str.split('_')[:6]
left_str = "_".join(words)
next_lex_str = {"orig":original_str,"left":left_str,"right":right_str}
string_lib.append(next_lex_str)
print(string_lib)
#print(string_lib)
#And write it to lex file
# Now process them one by one into the lexical file
lex_all = "";
@ -406,6 +456,7 @@ if __name__ == "__main__":
with open( lex_file, 'w') as file:
file.write(lex_all)
#and then play the strings back into the partials and the layout file
print("..and feed the lex string names back into other files")
for filename in all_files:
with open(filename, 'r') as file:
file_content = file.read()
@ -414,12 +465,12 @@ if __name__ == "__main__":
original_str = item["orig"]
left_str = item["left"]
right_str = item["right"]
# Replace all occurrences of original string with left string in 'contents'
file_content = file_content.replace(original_str, left_str)
# and write it back
with open(filename, 'w') as file:
file.write(file_content)
print(f"Write out modified:{filename}")