Move to python venv so that upto date chameleon avaiable

This commit is contained in:
2024-09-14 11:39:26 +01:00
parent 20d5828803
commit 3813f55f68
71 changed files with 1105 additions and 1279 deletions

View File

@@ -0,0 +1,63 @@
#
# Routines to be edited by the developer to provide validation for parameters
# and provison of the control data for table(s)
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-13 19:20
#
use esmith::util;
use esmith::HostsDB;
use esmith::AccountsDB;
use esmith::NetworksDB;
use esmith::HostsDB;
use esmith::DomainsDB;
#The most common ones
our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
# Validation routines - parameters for each panel
sub validate_PARAMS {
my $c = shift;
my $prefix_data = shift; #Data hash as parameter
my $ret = 'ok';
return $ret;
}
# Get control data for tables(s)
# Return hash with values from row in which link clicked on table
sub get_selected_PARAMS {
my $c = shift;
my $selected = shift; #Parameter is name of selected row.
my $is_new_record = shift; #Indicates new record required (defaults)
my %ret = {};
return $ret;
}
#after sucessful modify or create or whatever and submit then perfom (if the params validate)
sub perform_PARAMS {
my $c = shift;
my $prefix_data = shift; #Data hash as parameter
my $ret = 'ok';
return $ret;
}
sub create_link{
# WIP
my ($c,$route, $panel, $index) = shift;
my $link = "$route?trt=$panel&Selected=$index";
return $link;
}
1;

View File

@@ -0,0 +1,243 @@
package SrvMngr::Controller::CreateStarterWebsite;
#
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-13 19:20
#
#----------------------------------------------------------------------
# heading : Miscellaneous
# description : Create Starter Website
# navigation : 2000 400
#
# name : createstarterwebsite, method : get, url : /createstarterwebsite, ctlact : CreateStarterWebsite#main
# name : createstarterwebsiteu, method : post, url : /createstarterwebsiteu, ctlact : CreateStarterWebsite#do_update
# name : createstarterwebsited, method : get, url : /createstarterwebsited, ctlact : CreateStarterWebsite#do_display
#
# routes : end
#
# Documentation: https://wiki.contribs.org/CreateStarterWebsite
#----------------------------------------------------------------------
#
# Scheme of things:
#
# TBA!!
use strict;
use warnings;
use Mojo::Base 'Mojolicious::Controller';
use constant FALSE => 0;
use constant TRUE => 1;
use Locale::gettext;
use SrvMngr::I18N;
use SrvMngr qw(theme_list init_session);
use Data::Dumper;
use esmith::util;
use esmith::HostsDB;
use esmith::AccountsDB;
use esmith::NetworksDB;
use esmith::HostsDB;
use esmith::DomainsDB;
#The most common ones
our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
require '/usr/share/smanager/lib/SrvMngr/Controller/CreateStarterWebsite-Custom.pm'; #The code that is to be added by the developer
sub main {
#
# Initial entry - route is "/<whatever>"
#
#set initial panel
#for initial panel:
#Specifiy panel to enter
#load up _data hash with DB fields
#load up stash with pointer(s) to control fields hash(= get-))
#and a pointer to the prefix_data hash
#render initial panel
my $c = shift;
$c->app->log->info( $c->log_req );
my %csw_data = ();
my $title = $c->l('csw_Create_Starter_Website');
my $modul = '';
$csw_data{'trt'} = 'PARAMS';
#Load any DB entries into the <prefix>_data area so as they are preset in the form
# which DB - this only really works if the initial panel is a PARAMS type panel and not a TABLE
my $db = $cdb; #pickup local or global db or Default to config
# and table control fields
$c->stash(
title => $title,
modul => $modul,
csw_data => \%csw_data
);
$c->render( template => "createstarterwebsite" );
}
# Post request with params - submit from the form
sub do_update {
#
# Return after submit pushed on panel (this is a post) - route is "/<whatever>u"
# parameters in the params hash.
#
#load up all params into prefix_data hash:
#By panel (series of if statements - only one executed):
#call validate-PANEL() - return ret = ok or error message
#if validation not ok:
#render back to current panel with error message in stash
#otherwise:
#By panel (series of if statements - only one executed):
#do whatever is required: call perform-PANEL() - return "ok" or Error Message
#call signal-event for any global actions specified (check it exists - error and continue?)
#if action smeserver-<whatever>-update exists
#signal_event smeserver-<whatever>-update
#call signal-event for any specific actions for thids panel (check it exists first - error and continue)
#set success in stash
#if no "nextpanel" entry:
#set firstpanel
#else
#set nextpanel
#call render
my $c = shift;
$c->app->log->info($c->log_req);
my %csw_data = ();
my $title = $c->l('csw_Create_Starter_Website');
# Accessing all POST parameters
my %params = $c->req->params->to_hash;
# Get number of POST parameters
my $num_params = keys %params;
#Params are available in the hash "params" - copy to the prefix_data hash
while (my ($key, $value) = each %{$c->req->params->to_hash}) {
$csw_data{$key} = $value;
}
# the value of trt will tell you which panel has returned
my $trt = $c->param('trt') || 'PARAMS'; #hidden control on every form.
my $ret = 'ok';
#Validate the parameters in a custom sub one for each panel (although only one of these will be executed)
my $thispanel;
if ($trt eq 'PARAMS'){
#Validate form parameters for panel PARAMS
$ret = $c->validate_PARAMS(\%csw_data);
$thispanel = 'PARAMS';
}
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("createstarterwebsite");
} else {
#Do whatever is needed, including writing values to the DB
if ($trt eq 'PARAMS'){
#do whatever is required ...
$ret = $c->perform_PARAMS(\%csw_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("createstarterwebsite");
} else {
$c->stash( success => $c->l('csw_PARAMS_panel_action_was_successful')); #A bit bland - edit it in the lex file
}
}
# and call any signal-events needed
# Setup shared data and call panel
$c->stash(
title => $title,
csw_data => \%csw_data
);
if ('none' eq 'none') {
$csw_data{'trt'} = 'PARAMS';
} else {
$csw_data{'trt'} = 'none';
}
$c->render("createstarterwebsite");
}
}
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
#
# OR it maybe a post from the main panel to add a new record
#
#load up all supplied params into prefix_data hash
#call get-selected-PANEL() - returns hash of all relevent parameters
#load up returned hash into prefix_data
#render - to called panel
my $c = shift;
$c->app->log->info($c->log_req);
my %csw_data = ();
my $title = $c->l('csw_Create_Starter_Website');
# Accessing all parameters
my %params = $c->req->params->to_hash;
# Get number of parameters
my $num_params = keys %params;
#Tag as Post or Get (ie. create new entry or edit existing one
my $is_new_record = ($c->req->method() eq 'POST');
#Params are available in the hash "params" - copy to the prefix_data hash
while (my ($key, $value) = each %{$c->req->params->to_hash}) {
$csw_data{$key} = $value;
}
# the value of trt will tell you which panel has returned
my $trt = $c->param('trt') || 'PARAMS'; #Indicates where to go now
# Now add in the params from the selected row from the table
my %selectedrow;
if ($trt eq 'PARAMS'){
#Validate form parameters for panel PARAMS
%selectedrow = $c->get_selected_PARAMS($csw_data{'Selected'},$is_new_record);
}
#Copy in the selected row params to the prefix_data hash to pass to the panel
while (my ($key, $value) = each %selectedrow){
$csw_data{$key} = $value;
}
# Where to go now
$csw_data{'trt'} = $trt;
# Data for panel
$c->stash(
title => $title,
csw_data => \%csw_data
);
$c->render("createstarterwebsite");
}
1;

View File

@@ -0,0 +1,109 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-13 19:20
%#
<div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS">
<script>
window.onload = function() {
SelectInput();
};
</script>
<h2>
%= l('csw_Hello_PARAMS');
</h2>
% my $btn = l('csw_APPLY');
%= form_for "CreateStarterWebsited" => (method => 'POST') => begin
% param 'trt' => $csw_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $csw_data->{trt}
%# Inputs etc in here.
<h2><%=l('csw_Manage_CreateStarterWebsite_settings:')%></h2>
<p>
%= l('To create a simple web page for your company, fill
in the fields below and click onCreate.')
</p>
<p>
%= l('csw_You_can_leave_any_field')
</p>
<p>
%= l('The text that you enter below will be line wrapped
for a nicer appearance in your web page. Leave a blank line
whenever you want to start a new paragraph. If you need
to force a line break without starting a new paragraph (for
example after each line of a mailing address), then type
the four-character sequence')
</p>
<p>
%= l('Do not use this option if you have already customized your web site, since it will
overwrite the 'index.htm' file in your web site directory.')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
</span></p>
<p>
%= l('First header, typically used for short phrases such
as 'Leader in the field of textile manufacturing'')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
</span></p>
<p>
%= l('Text following first header, typically used for a
paragraph of marketing information.')
</p>
<span class=label>
%=l('csw_')
</span><span class=data>
% param 'text1' => $csw_data->{text1} unless param 'text1';
%= text_area 'text1', cols=>40, rows=>10
</span><br>
<p>
%= l('Second header, typically used for short phrases such
as 'For more information' or 'To order our products':')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
</span></p>
<p>
%= l('Text following second header, typically used for contact
or ordering information:')
</p>
<span class=label>
%=l('csw_')
</span><span class=data>
% param 'text2' => $csw_data->{text2} unless param 'text2';
%= text_area 'text2', cols=>40, rows=>10
</span><br>
<p>
%= l('When you create this web page, the file
'index.htm' will be overwritten
in your web site directory.')
</p>
<p>
%= l('csw_Do_you_wish_to_proceed?')
</p>
%# Probably finally by a submit.
%end
</div>

View File

@@ -0,0 +1,50 @@
% layout 'default', title => "Sme server 2 - Create Starter Website", share_dir => './';
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-13 19:20
%#
% content_for 'module' => begin
<div id="module" class="module CreateStarterWebsite-panel">
% if ($config->{debug} == 1) {
<p>
%= dumper $c->current_route
</p>
% }
<h1><%=$title%></h1>
% if ( stash('modul') ) {
%= $c->render_to_string(inline => stash('modul') );
% }
%if ($csw_data->{first}) {
<br><p>
%=$c->render_to_string(inline =>$c->l($csw_data->{first}))
</p>
%} elsif ($csw_data->{success}) {
<div class='sme-border'>
<h2> Operation Status Report</h2><p>
%= $c->l($csw_data->{success});
</p>
</div>
%} elsif ($csw_data->{error}) {
<div class='sme-error'>
<h2> Operation Status Report - error</h2><p>
%= $c->l($csw_data->{error});
</p>
</div>
%}
%#Routing to partials according to trt parameter.
%#This ought to be cascading if/then/elsif, but is easier to just stack the if/then's rather like a case statement'
% if ($csw_data->{trt} eq "PARAMS") {
%= include 'partials/_csw_PARAMS'
%}
</div>
%end

View File

@@ -0,0 +1,8 @@
'csw_APPLY' => 'Apply',
'csw_Do_you_wish_to_proceed?' => 'Do you wish to proceed?',
'csw_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
'csw_Hello_PARAMS' => 'Hello PARAMS',
'csw_' => '',
'csw_You_can_leave_any_field' => 'You can leave any field blank if you do not need it. ',
'csw_Create_Starter_Website' => 'Create Starter Website',