admin has forms
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-07-28 01:00:54) dev
|
Version 2.00.0 (2012-07-28 02:08:47) dev
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ def change_password():
|
|||||||
redirect(URL('site'))
|
redirect(URL('site'))
|
||||||
return dict(form=form)
|
return dict(form=form)
|
||||||
|
|
||||||
|
|
||||||
def site():
|
def site():
|
||||||
""" Site handler """
|
""" Site handler """
|
||||||
|
|
||||||
@@ -175,12 +176,32 @@ def site():
|
|||||||
# Shortcut to make the elif statements more legible
|
# Shortcut to make the elif statements more legible
|
||||||
file_or_appurl = 'file' in request.vars or 'appurl' in request.vars
|
file_or_appurl = 'file' in request.vars or 'appurl' in request.vars
|
||||||
|
|
||||||
|
class IS_VALID_APPNAME(object):
|
||||||
|
def __call__(self,value):
|
||||||
|
if not re.compile('[\w_]+').match(value):
|
||||||
|
return (value,T('Invalid application name'))
|
||||||
|
if not request.vars.overwrite and \
|
||||||
|
os.path.exists(os.path.join(apath(r=request),value)):
|
||||||
|
return (value,T('Application exists already'))
|
||||||
|
return (value,None)
|
||||||
|
|
||||||
|
is_appname = IS_VALID_APPNAME()
|
||||||
|
form_create = SQLFORM.factory(Field('name',requires=is_appname),
|
||||||
|
table_name='appcreate')
|
||||||
|
form_update = SQLFORM.factory(Field('name',requires=is_appname),
|
||||||
|
Field('file','upload',uploadfield=False),
|
||||||
|
Field('url'),
|
||||||
|
Field('overwrite','boolean'),
|
||||||
|
table_name='appupdate')
|
||||||
|
form_create.process()
|
||||||
|
form_update.process()
|
||||||
|
|
||||||
if DEMO_MODE:
|
if DEMO_MODE:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif request.vars.filename and not 'file' in request.vars:
|
elif form_create.accepted:
|
||||||
# create a new application
|
# create a new application
|
||||||
appname = cleanpath(request.vars.filename).replace('.', '_')
|
appname = cleanpath(form_create.vars.name)
|
||||||
if app_create(appname, request):
|
if app_create(appname, request):
|
||||||
if MULTI_USER_MODE:
|
if MULTI_USER_MODE:
|
||||||
db.app.insert(name=appname,owner=auth.user.id)
|
db.app.insert(name=appname,owner=auth.user.id)
|
||||||
@@ -189,65 +210,57 @@ def site():
|
|||||||
redirect(URL('design',args=appname))
|
redirect(URL('design',args=appname))
|
||||||
else:
|
else:
|
||||||
session.flash = \
|
session.flash = \
|
||||||
T('unable to create application "%s" (it may exist already)', request.vars.filename)
|
T('unable to create application "%s" (it may exist already)',
|
||||||
|
form_create.vars.name)
|
||||||
redirect(URL(r=request))
|
redirect(URL(r=request))
|
||||||
|
|
||||||
elif file_or_appurl and not request.vars.filename:
|
elif form_update.accepted:
|
||||||
# can't do anything without an app name
|
if (form_update.vars.url or '').endswith('.git'):
|
||||||
msg = 'you must specify a name for the uploaded application'
|
if not have_git:
|
||||||
response.flash = T(msg)
|
session.flash = GIT_MISSING
|
||||||
|
target = os.path.join(apath(r=request),form_update.vars.name)
|
||||||
elif (request.vars.appurl or '').endswith('.git') and request.vars.filename:
|
|
||||||
if not have_git:
|
|
||||||
session.flash = GIT_MISSING
|
|
||||||
elif request.vars.filename:
|
|
||||||
target = os.path.join(apath(r=request),request.vars.filename)
|
|
||||||
if os.path.exists(target):
|
|
||||||
session.flash = 'Application by that name already exists.'
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
new_repo = Repo.clone_from(request.vars.appurl,target)
|
|
||||||
session.flash = T('new application "%s" imported',request.vars.filename)
|
|
||||||
except GitCommandError, err:
|
|
||||||
session.flash = T('Invalid git repository specified.')
|
|
||||||
else:
|
|
||||||
session.flash = 'Application Name required for git import.'
|
|
||||||
redirect(URL(r=request))
|
|
||||||
|
|
||||||
elif file_or_appurl and request.vars.filename:
|
|
||||||
# fetch an application via URL or file upload
|
|
||||||
f = None
|
|
||||||
if request.vars.appurl:
|
|
||||||
try:
|
try:
|
||||||
f = urllib.urlopen(request.vars.appurl)
|
new_repo = Repo.clone_from(form_update.vars.url,target)
|
||||||
except Exception, e:
|
session.flash = T('new application "%s" imported',
|
||||||
session.flash = DIV(T('Unable to download app because:'),PRE(str(e)))
|
form_update.vars.name)
|
||||||
redirect(URL(r=request))
|
except GitCommandError, err:
|
||||||
fname = request.vars.appurl
|
session.flash = T('Invalid git repository specified.')
|
||||||
elif request.vars.file:
|
redirect(URL(r=request))
|
||||||
f = request.vars.file.file
|
|
||||||
fname = request.vars.file.filename
|
|
||||||
|
|
||||||
if f:
|
elif form_update.vars.url:
|
||||||
appname = cleanpath(request.vars.filename).replace('.', '_')
|
# fetch an application via URL or file upload
|
||||||
installed = app_install(appname, f, request, fname,
|
if form_update.vars.url:
|
||||||
overwrite=request.vars.overwrite_check)
|
try:
|
||||||
if f and installed:
|
form_update.vars.file = \
|
||||||
msg = 'application %(appname)s installed with md5sum: %(digest)s'
|
urllib.urlopen(form_update.vars.url)
|
||||||
if MULTI_USER_MODE:
|
except Exception, e:
|
||||||
db.app.insert(name=appname,owner=auth.user.id)
|
session.flash = \
|
||||||
log_progress(appname)
|
DIV(T('Unable to download app because:'),PRE(str(e)))
|
||||||
session.flash = T(msg, dict(appname=appname,
|
redirect(URL(r=request))
|
||||||
digest=md5_hash(installed)))
|
fname = form_update.vars.url
|
||||||
elif f and request.vars.overwrite_check:
|
|
||||||
msg = 'unable to install application "%(appname)s"'
|
elif form_update.accepted and form_update.vars.file:
|
||||||
session.flash = T(msg, dict(appname=request.vars.filename))
|
fname = form_update.vars.file.filename
|
||||||
|
appname = cleanpath(form_update.vars.name)
|
||||||
|
installed = app_install(appname, form_update.vars.file.file,
|
||||||
|
request, fname,
|
||||||
|
overwrite=form_update.vars.overwrite)
|
||||||
|
if f and installed:
|
||||||
|
msg = 'application %(appname)s installed with md5sum: %(digest)s'
|
||||||
|
if MULTI_USER_MODE:
|
||||||
|
db.app.insert(name=appname,owner=auth.user.id)
|
||||||
|
log_progress(appname)
|
||||||
|
session.flash = T(msg, dict(appname=appname,
|
||||||
|
digest=md5_hash(installed)))
|
||||||
|
elif f and form_update.vars.overwrite:
|
||||||
|
msg = 'unable to install application "%(appname)s"'
|
||||||
|
session.flash = T(msg, dict(appname=form_update.vars.name))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
msg = 'unable to install application "%(appname)s"'
|
msg = 'unable to install application "%(appname)s"'
|
||||||
session.flash = T(msg, dict(appname=request.vars.filename))
|
session.flash = T(msg, dict(appname=form_update.vars.name))
|
||||||
|
|
||||||
redirect(URL(r=request))
|
redirect(URL(r=request))
|
||||||
|
|
||||||
regex = re.compile('^\w+$')
|
regex = re.compile('^\w+$')
|
||||||
|
|
||||||
@@ -261,7 +274,8 @@ def site():
|
|||||||
|
|
||||||
apps = sorted(apps,lambda a,b:cmp(a.upper(),b.upper()))
|
apps = sorted(apps,lambda a,b:cmp(a.upper(),b.upper()))
|
||||||
|
|
||||||
return dict(app=None, apps=apps, myversion=myversion)
|
return dict(app=None, apps=apps, myversion=myversion,
|
||||||
|
form_create=form_create, form_update=form_update)
|
||||||
|
|
||||||
|
|
||||||
def report_progress(app):
|
def report_progress(app):
|
||||||
|
|||||||
@@ -70,12 +70,12 @@
|
|||||||
{{else:}}
|
{{else:}}
|
||||||
<p id="check_version">
|
<p id="check_version">
|
||||||
{{=button("javascript:ajax('"+URL('check_version')+"',[],'check_version')", T('Check for upgrades'))}}
|
{{=button("javascript:ajax('"+URL('check_version')+"',[],'check_version')", T('Check for upgrades'))}}
|
||||||
{{pass}}
|
{{=button(URL('default','reload_routes'), T('Reload routes'))}}
|
||||||
</p>
|
</p>
|
||||||
<div class="formfield">
|
{{pass}}
|
||||||
|
<p>
|
||||||
{{=T("Running on %s", request.env.server_software)}}
|
{{=T("Running on %s", request.env.server_software)}}
|
||||||
</div>
|
</p>
|
||||||
<p>{{=button(URL('default','reload_routes'), T('Reload routes'))}}</p>
|
|
||||||
</div>
|
</div>
|
||||||
{{pass}}
|
{{pass}}
|
||||||
<!-- APP WIZARD -->
|
<!-- APP WIZARD -->
|
||||||
@@ -87,64 +87,42 @@
|
|||||||
<!-- SCAFFOLD APP -->
|
<!-- SCAFFOLD APP -->
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3>{{=T("New simple application")}}</h3>
|
<h3>{{=T("New simple application")}}</h3>
|
||||||
<form action="" enctype="multipart/form-data" method="post">
|
{{=form_create.custom.begin}}
|
||||||
<div class="formfield">
|
<table><tr><td>
|
||||||
{{=LABEL(T("Application name:"), _for="scaffold_filename")}}
|
{{=LABEL(T("Application name:"))}}
|
||||||
<input name="filename" type="text" id="scaffold_filename" />
|
</td><td>
|
||||||
<button type="submit" class="button">{{=T('Create')}}</button>
|
{{=form_create.custom.widget.name}}
|
||||||
</div>
|
</td><td>
|
||||||
<div class="hidden"></div>
|
<button type="submit">{{=T('Create')}}</button>
|
||||||
</form>
|
</td></tr></table>
|
||||||
|
{{=form_create.custom.end}}
|
||||||
</div>
|
</div>
|
||||||
<!-- UPLOAD PACKAGE -->
|
<!-- UPLOAD PACKAGE -->
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3>{{=T("Upload and install packed application")}}</h3>
|
<h3>{{=T("Upload and install packed application")}}</h3>
|
||||||
<form action="" enctype="multipart/form-data" method="post">
|
{{=form_update.custom.begin}}
|
||||||
<div class="formfield">
|
<table><tr><td>
|
||||||
<table>
|
{{=LABEL(T("Application name:"))}}
|
||||||
<tr>
|
</td><td>
|
||||||
<td>
|
{{=form_update.custom.widget.name}}
|
||||||
{{=LABEL(T("Application name:"), _form='upload_filename')}}
|
</td></tr><tr><td>
|
||||||
</td>
|
{{=LABEL(T("Upload a package:"))}}
|
||||||
<td>
|
</td><td>
|
||||||
<input id="appname" name="filename" type="text" id="upload_filename" />
|
{{=form_update.custom.widget.file}}
|
||||||
</td>
|
</td></tr><tr><td>
|
||||||
</tr>
|
{{=LABEL('Or ',T("Get from URL:"))}}
|
||||||
<tr>
|
</td><td>
|
||||||
<td>
|
{{=form_update.custom.widget.url}}
|
||||||
{{=LABEL(T("Upload a package:"), _for='upload_file')}}
|
</td></tr><tr><td>
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input id="file" name="file" type="file" id="upload_file" />
|
|
||||||
<b>OR</b>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
{{=LABEL(T("Get from URL:"), _for='upload_url')}}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input id="appurl" name="appurl" type="text" id="upload_url"/><br/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
({{=T('can be a git repo')}})
|
({{=T('can be a git repo')}})
|
||||||
</td>
|
</td><td>
|
||||||
<td>
|
{{=form_update.custom.widget.overwrite}}
|
||||||
<input type="checkbox" name="overwrite_check" id="upload_overwrite" />
|
{{=LABEL(T("Overwrite installed app"))}}
|
||||||
{{=LABEL(T("Overwrite installed app"), _for='upload_overwrite')}}
|
</td></tr><tr><td>
|
||||||
</td>
|
</td><td>
|
||||||
</tr>
|
<button type="submit">{{=T('Install')}}</button>
|
||||||
<tr>
|
</td></tr></table>
|
||||||
<td></td>
|
{{=form_update.custom.end}}
|
||||||
<td>
|
|
||||||
<button type="submit">{{=T('Install')}}</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- DEPLOY ON GAE -->
|
<!-- DEPLOY ON GAE -->
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|||||||
Reference in New Issue
Block a user