Skip to content

Commit

Permalink
Re-implements the 'Install_Type' stage completely. It also fixes a
Browse files Browse the repository at this point in the history
number of problem with the 'Phase' base class (that prevented its
'goto_next_stage' event from propagating correctly).

git-svn-id: svn://cherokee-project.com/wizards2@6787 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Aug 5, 2011
1 parent 15a3beb commit 6b8144e
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 96 deletions.
237 changes: 145 additions & 92 deletions Wizard2_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,65 @@
# Phase's base
#

class Phase (CTK.Container):
OLD = """
class Phase_OLD (CTK.Box):
def __init__ (self, title):
CTK.Container.__init__ (self)
CTK.Box.__init__ (self)
self.title = title
self.cont = CTK.Container()
self.cont = CTK.Box()
def __iadd__ (self, w):
self.cont += w
return self
def Render (self):
box = CTK.Container()
box = CTK.Box()
box += CTK.RawHTML ('<h2>%s</h2>' %(_(self.title)))
box += self.cont
return box.Render()
def __call__ (self):
if hasattr (self, '__build_GUI__'):
self.cont = CTK.Container()
self.cont = CTK.Box()
self.__build_GUI__()
return self.Render().toStr()
"""

class Phase (CTK.Box):
def __init__ (self, title):
CTK.Box.__init__ (self)
self.title = title
self.built = False

def Render (self):
if not self.built:
self.built = True
self += CTK.RawHTML ('<h2>%s</h2>' %(_(self.title)))
if hasattr (self, '__build_GUI__'):
self.__build_GUI__()

return CTK.Box.Render (self)

def __call__ (self):
return self.Render().toStr()


# self.title_added = False



# def Render (self):
# if not self.title_added:
# self += CTK.RawHTML ('<h2>%s</h2>' %(_(self.title)))
# self.title_added = True

# return CTK.Box.Render (self)

def __callOLD__ (self):
if hasattr (self, '__build_GUI__'):
self.Empty()
self += CTK.RawHTML ('<h2>%s</h2>' %(_(self.title)))
self.__build_GUI__()

return self.Render().toStr()
Expand Down Expand Up @@ -120,14 +160,16 @@ def Render (self):
class Phase_Welcome (Phase_Next):
def __init__ (self, wizard, install_type):
Phase_Next.__init__ (self, "Welcome to the %s Wizard"%(wizard))
self += CTK.RawHTML ('Welcome!')

# Clean up previous wizard info
del (CTK.cfg[CFG_PREFIX])

# Set installation type
CTK.cfg['%s!type'%(CFG_PREFIX)] = install_type

def __build_GUI__ (self):
self += CTK.RawHTML ('Welcome!')


#
# Enter Virtual Server
Expand Down Expand Up @@ -214,111 +256,119 @@ def __build_GUI__ (self):
('local_directory', N_('Already Installed Software')),
]

INSTALL_TYPE_ON_CHANGE_JS = """
$('.stage_install_type_block').hide();
class Stage_Install_Type (Phase_PrevNext):
def __init__ (self):
Phase_PrevNext.__init__ (self, _("Software Retrival Method"))

def __build_GUI__ (self):
# Refresh
refresh = CTK.Refreshable({'id': 'wizard2-stage-install-type-refresh'})
refresh.register (lambda: self.Refresh_Content (refresh, self).Render())

# Radio buttons
radios = CTK.RadioGroupCfg ('%s!install_type'%(CFG_PREFIX), INSTALL_OPTIONS, {'checked': INSTALL_OPTIONS[0][0]})

# Submitter
submit = CTK.Submitter (URL_STAGE_INSTALL_APPLY)
submit.bind ('submit_success', refresh.JS_to_refresh())
submit += radios

# GUI Layout
self += submit
self += refresh
self.bind ('goto_next_stage', CTK.DruidContent__JS_to_goto_next (self.id))

var val = $('#%s input[type=\"radio\"]:checked').val();
if (val == 'download_auto') { %s }
else if (val == 'download_URL') { %s }
else if (val == 'local_directory') { %s }
"""

class Stage_Install_Type (Phase_PrevNext):
class Apply:
def __call__ (self):
type_key = '%s!install_type'%(CFG_PREFIX)
url_key = '%s!download_url'%(CFG_PREFIX)
dir_key = '%s!app_dir' %(CFG_PREFIX)
tipe = CTK.post.get_val ('%s!install_type'%(CFG_PREFIX))

tipe_cfg = CTK.cfg.get_val(type_key)
tipe_post = CTK.post.get_val(type_key)
if tipe == 'download_auto':
CTK.cfg['%s!app_fetch'%(CFG_PREFIX)] = 'auto'
elif CTK.cfg.get_val('%s!app_fetch'%(CFG_PREFIX)) == 'auto':
del (CTK.cfg['%s!app_fetch'%(CFG_PREFIX)])

# Changed type of install
if tipe_cfg != tipe_post:
if tipe_post == 'download_auto':
CTK.cfg['%s!app_fetch'%(CFG_PREFIX)] = 'auto'
return CTK.cfg_apply_post()
return CTK.cfg_apply_post()

# Download URL
if tipe_cfg == 'download_auto':
CTK.cfg['%s!app_fetch'%(CFG_PREFIX)] = 'auto'
return CTK.cfg_reply_ajax_ok()
class Refresh_Content (CTK.Box):
def __init__ (self, refresh, parent_widget):
CTK.Box.__init__ (self)

# Download URL
elif tipe_cfg == 'download_URL':
url = CTK.post.get_val (url_key)
if not url:
return {'ret': 'unsatisfactory', 'errors': {url_key: _('Cannot be empty')}}
pself = parent_widget
default = INSTALL_OPTIONS[0][0]
method = CTK.cfg.get_val ('%s!install_type'%(CFG_PREFIX), default)

CTK.cfg['%s!app_fetch'%(CFG_PREFIX)] = url
return CTK.cfg_reply_ajax_ok()
if method == 'download_auto':
self += pself.Download_Auto (refresh, pself)
elif method == 'download_URL':
self += pself.Download_URL (refresh)
elif method == 'local_directory':
self += pself.Local_Directory (refresh)
else:
self += CTK.RawHTML ('<h1>%s</h1>' %(_("Unknown method")))

# Local Directory
elif tipe_cfg == 'local_directory':
directory = CTK.post.get_val (dir_key)
if not directory:
return {'ret': 'unsatisfactory', 'errors': {dir_key: _('Cannot be empty')}}
class Download_Auto (CTK.Box):
def __init__ (self, refresh, pself):
CTK.Box.__init__ (self)

CTK.cfg['%s!app_dir'%(CFG_PREFIX)] = directory
return CTK.cfg_reply_ajax_ok()
table = CTK.PropsTable()
table.Add (_('Installation directory'), CTK.TextCfg('%s!app_dir'%(CFG_PREFIX), True, {'optional_string': _('Automatic')}), _(NOTE_APP_DIR))

def __init__ (self):
Phase_PrevNext.__init__ (self, _("Software Retrival Method"))
submit = CTK.Submitter (URL_STAGE_INSTALL_AUTO_APPLY)
submit.bind ('submit_success', table.JS_to_trigger ('goto_next_stage'))
submit += table

def __build_GUI__ (self):
radios = CTK.RadioGroupCfg ('%s!install_type'%(CFG_PREFIX), INSTALL_OPTIONS, {'checked': INSTALL_OPTIONS[0][0]})
self += CTK.RawHTML ("<h3>%s</h3>"%(_('Automatic Download')))
self += submit

submit = CTK.Submitter (URL_STAGE_INSTALL_TYPE_APPLY)
submit += radios
submit.bind ('submit_success', submit.JS_to_trigger ('goto_next_stage'))
class Apply:
def __call__ (self):
return CTK.cfg_apply_post()

# Blocks
prop_blocks = {'class': 'stage_install_type_block'}
prop_blocks_hidden = {'class': 'stage_install_type_block', 'style': 'display: none;'}
class Download_URL (CTK.Box):
def __init__ (self, refresh):
CTK.Box.__init__ (self)

# Automatic
table = CTK.PropsTable()
table.Add (_('Installation directory'), CTK.TextCfg('%s!app_dir'%(CFG_PREFIX), True, {'optional_string': _('Automatic')}), _(NOTE_APP_DIR))
table = CTK.PropsTable()
table.Add (_('URL/Path to package'), CTK.TextCfg('%s!app_fetch'%(CFG_PREFIX)), _(NOTE_DOWNLOAD_URL))
table.Add (_('Installation directory'), CTK.TextCfg('%s!app_dir'%(CFG_PREFIX), True, {'optional_string': _('Automatic')}), _(NOTE_APP_DIR))

automatic = CTK.Box (prop_blocks)
automatic += CTK.RawHTML ("<h3>%s</h3>"%(_('Automatic Download')))
automatic += table
submit = CTK.Submitter (URL_STAGE_INSTALL_URL_APPLY)
submit.bind ('submit_success', table.JS_to_trigger ('goto_next_stage'))
submit += table

# Download_URL block
table = CTK.PropsTable()
table.Add (_('URL/Path to package'), CTK.TextCfg('%s!download_url'%(CFG_PREFIX)), _(NOTE_DOWNLOAD_URL))
table.Add (_('Installation directory'), CTK.TextCfg('%s!app_dir'%(CFG_PREFIX), True, {'optional_string': _('Automatic')}), _(NOTE_APP_DIR))
self += CTK.RawHTML ("<h3>%s</h3>"%(_('Use a specific Package')))
self += submit

download_URL = CTK.Box (prop_blocks_hidden)
download_URL += CTK.RawHTML ("<h3>%s</h3>"%(_('Use a specific Package')))
download_URL += table
class Apply:
def __call__ (self):
key = '%s!app_fetch'%(CFG_PREFIX)
if not CTK.post.get_val(key):
return {'ret': 'unsatisfactory', 'errors': {key: _('Cannot be empty')}}

# Local_Directory block
table = CTK.PropsTable()
table.Add (_('Directory of the application'), CTK.TextCfg('%s!app_dir'%(CFG_PREFIX)), _(NOTE_APP_DIR))
return CTK.cfg_apply_post()

local_directory = CTK.Box (prop_blocks_hidden)
local_directory += CTK.RawHTML ("<h3>%s</h3>"%(_('Already Installed Software')))
local_directory += table
class Local_Directory (CTK.Box):
def __init__ (self, refresh):
CTK.Box.__init__ (self)

# Events handling
js = INSTALL_TYPE_ON_CHANGE_JS %(radios.id,
automatic.JS_to_show(),
download_URL.JS_to_show(),
local_directory.JS_to_show())
radios.bind ('change', js)
table = CTK.PropsTable()
table.Add (_('Directory of the application'), CTK.TextCfg('%s!app_dir'%(CFG_PREFIX)), _(NOTE_APP_DIR))

submit += automatic
submit += download_URL
submit += local_directory
submit = CTK.Submitter (URL_STAGE_INSTALL_LOCAL_APPLY)
submit.bind ('submit_success', table.JS_to_trigger ('goto_next_stage'))
submit += table

box = CTK.Box()
box += submit
box += CTK.RawHTML (js = js)
self += box
self += CTK.RawHTML ("<h3>%s</h3>"%(_('Already Installed Software')))
self += submit

# Next stage
self.bind ('goto_next_stage', CTK.DruidContent__JS_to_goto_next (box.id))
class Apply:
def __call__ (self):
key = '%s!app_dir' %(CFG_PREFIX)
if not CTK.post.get_val(key):
return {'ret': 'unsatisfactory', 'errors': {key: _('Cannot be empty')}}

return CTK.cfg_apply_post()


def validation_download_url (value):
Expand All @@ -335,15 +385,18 @@ def validation_download_url (value):


VALIDATION_INSTALL_TYPE = VALIDATION + [
('%s!download_url'%(CFG_PREFIX), validation_download_url)
('%s!app_fetch'%(CFG_PREFIX), validation_download_url)
]

URL_STAGE_INSTALL_TYPE = "/wizard2/stages/install_type"
URL_STAGE_INSTALL_TYPE_APPLY = "/wizard2/stages/install_type/apply"

CTK.publish ('^%s'%(URL_STAGE_INSTALL_TYPE), Stage_Install_Type)
CTK.publish ('^%s'%(URL_STAGE_INSTALL_TYPE_APPLY), Stage_Install_Type.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
URL_STAGE_INSTALL_APPLY = "/wizard2/stages/install_type/apply"
URL_STAGE_INSTALL_AUTO_APPLY = "/wizard2/stages/install_type/auto/apply"
URL_STAGE_INSTALL_URL_APPLY = "/wizard2/stages/install_type/url/apply"
URL_STAGE_INSTALL_LOCAL_APPLY = "/wizard2/stages/install_type/local_dir/apply"

CTK.publish ('^%s'%(URL_STAGE_INSTALL_APPLY), Stage_Install_Type.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
CTK.publish ('^%s'%(URL_STAGE_INSTALL_AUTO_APPLY), Stage_Install_Type.Download_Auto.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
CTK.publish ('^%s'%(URL_STAGE_INSTALL_URL_APPLY), Stage_Install_Type.Download_URL.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")
CTK.publish ('^%s'%(URL_STAGE_INSTALL_LOCAL_APPLY), Stage_Install_Type.Local_Directory.Apply, validation=VALIDATION_INSTALL_TYPE, method="POST")


#
Expand Down
6 changes: 2 additions & 4 deletions wizards/02-Content Management Systems/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

from util import *

php_tpl = Wizard2.Load_Template ('PHP.py')

CONFIG_VSERVER = """
vserver!%(vserver_num)s!nick = %(vserver_nick)s
vserver!%(vserver_num)s!document_root = %(app_dir)s/wordpress
Expand Down Expand Up @@ -95,9 +97,7 @@
#
# Installer
#

TARBALL = "http://wordpress.org/latest.tar.gz"
php_tpl = Wizard2.Load_Template ('PHP.py')

class Install (php_tpl.Install):
def __init__ (self, params):
Expand All @@ -114,11 +114,9 @@ def Check_Prerequisites (self):
return errors



#
# GUI
#

CTK.publish ('^/wizard/vserver/wordpress$', lambda: Wizard2_GUI.Phase_Welcome ('Wordpress', 'vserver').Render().toStr())
CTK.publish ('^/wizard/vserver/wordpress/2$', Wizard2_GUI.Stage_Install_Type)
CTK.publish ('^/wizard/vserver/wordpress/3$', Wizard2_GUI.Stage_Enter_VServer)
Expand Down

0 comments on commit 6b8144e

Please sign in to comment.