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'))
|
||||
return dict(form=form)
|
||||
|
||||
|
||||
def site():
|
||||
""" Site handler """
|
||||
|
||||
@@ -175,12 +176,32 @@ def site():
|
||||
# Shortcut to make the elif statements more legible
|
||||
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:
|
||||
pass
|
||||
|
||||
elif request.vars.filename and not 'file' in request.vars:
|
||||
elif form_create.accepted:
|
||||
# create a new application
|
||||
appname = cleanpath(request.vars.filename).replace('.', '_')
|
||||
appname = cleanpath(form_create.vars.name)
|
||||
if app_create(appname, request):
|
||||
if MULTI_USER_MODE:
|
||||
db.app.insert(name=appname,owner=auth.user.id)
|
||||
@@ -189,65 +210,57 @@ def site():
|
||||
redirect(URL('design',args=appname))
|
||||
else:
|
||||
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))
|
||||
|
||||
elif file_or_appurl and not request.vars.filename:
|
||||
# can't do anything without an app name
|
||||
msg = 'you must specify a name for the uploaded application'
|
||||
response.flash = T(msg)
|
||||
|
||||
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:
|
||||
elif form_update.accepted:
|
||||
if (form_update.vars.url or '').endswith('.git'):
|
||||
if not have_git:
|
||||
session.flash = GIT_MISSING
|
||||
target = os.path.join(apath(r=request),form_update.vars.name)
|
||||
try:
|
||||
f = urllib.urlopen(request.vars.appurl)
|
||||
except Exception, e:
|
||||
session.flash = DIV(T('Unable to download app because:'),PRE(str(e)))
|
||||
redirect(URL(r=request))
|
||||
fname = request.vars.appurl
|
||||
elif request.vars.file:
|
||||
f = request.vars.file.file
|
||||
fname = request.vars.file.filename
|
||||
new_repo = Repo.clone_from(form_update.vars.url,target)
|
||||
session.flash = T('new application "%s" imported',
|
||||
form_update.vars.name)
|
||||
except GitCommandError, err:
|
||||
session.flash = T('Invalid git repository specified.')
|
||||
redirect(URL(r=request))
|
||||
|
||||
if f:
|
||||
appname = cleanpath(request.vars.filename).replace('.', '_')
|
||||
installed = app_install(appname, f, request, fname,
|
||||
overwrite=request.vars.overwrite_check)
|
||||
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 request.vars.overwrite_check:
|
||||
msg = 'unable to install application "%(appname)s"'
|
||||
session.flash = T(msg, dict(appname=request.vars.filename))
|
||||
elif form_update.vars.url:
|
||||
# fetch an application via URL or file upload
|
||||
if form_update.vars.url:
|
||||
try:
|
||||
form_update.vars.file = \
|
||||
urllib.urlopen(form_update.vars.url)
|
||||
except Exception, e:
|
||||
session.flash = \
|
||||
DIV(T('Unable to download app because:'),PRE(str(e)))
|
||||
redirect(URL(r=request))
|
||||
fname = form_update.vars.url
|
||||
|
||||
elif form_update.accepted and form_update.vars.file:
|
||||
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:
|
||||
msg = 'unable to install application "%(appname)s"'
|
||||
session.flash = T(msg, dict(appname=request.vars.filename))
|
||||
else:
|
||||
msg = 'unable to install application "%(appname)s"'
|
||||
session.flash = T(msg, dict(appname=form_update.vars.name))
|
||||
|
||||
redirect(URL(r=request))
|
||||
redirect(URL(r=request))
|
||||
|
||||
regex = re.compile('^\w+$')
|
||||
|
||||
@@ -261,7 +274,8 @@ def site():
|
||||
|
||||
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):
|
||||
|
||||
@@ -70,12 +70,12 @@
|
||||
{{else:}}
|
||||
<p id="check_version">
|
||||
{{=button("javascript:ajax('"+URL('check_version')+"',[],'check_version')", T('Check for upgrades'))}}
|
||||
{{pass}}
|
||||
{{=button(URL('default','reload_routes'), T('Reload routes'))}}
|
||||
</p>
|
||||
<div class="formfield">
|
||||
{{pass}}
|
||||
<p>
|
||||
{{=T("Running on %s", request.env.server_software)}}
|
||||
</div>
|
||||
<p>{{=button(URL('default','reload_routes'), T('Reload routes'))}}</p>
|
||||
</p>
|
||||
</div>
|
||||
{{pass}}
|
||||
<!-- APP WIZARD -->
|
||||
@@ -87,64 +87,42 @@
|
||||
<!-- SCAFFOLD APP -->
|
||||
<div class="box">
|
||||
<h3>{{=T("New simple application")}}</h3>
|
||||
<form action="" enctype="multipart/form-data" method="post">
|
||||
<div class="formfield">
|
||||
{{=LABEL(T("Application name:"), _for="scaffold_filename")}}
|
||||
<input name="filename" type="text" id="scaffold_filename" />
|
||||
<button type="submit" class="button">{{=T('Create')}}</button>
|
||||
</div>
|
||||
<div class="hidden"></div>
|
||||
</form>
|
||||
{{=form_create.custom.begin}}
|
||||
<table><tr><td>
|
||||
{{=LABEL(T("Application name:"))}}
|
||||
</td><td>
|
||||
{{=form_create.custom.widget.name}}
|
||||
</td><td>
|
||||
<button type="submit">{{=T('Create')}}</button>
|
||||
</td></tr></table>
|
||||
{{=form_create.custom.end}}
|
||||
</div>
|
||||
<!-- UPLOAD PACKAGE -->
|
||||
<div class="box">
|
||||
<h3>{{=T("Upload and install packed application")}}</h3>
|
||||
<form action="" enctype="multipart/form-data" method="post">
|
||||
<div class="formfield">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
{{=LABEL(T("Application name:"), _form='upload_filename')}}
|
||||
</td>
|
||||
<td>
|
||||
<input id="appname" name="filename" type="text" id="upload_filename" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{{=LABEL(T("Upload a package:"), _for='upload_file')}}
|
||||
</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>
|
||||
{{=form_update.custom.begin}}
|
||||
<table><tr><td>
|
||||
{{=LABEL(T("Application name:"))}}
|
||||
</td><td>
|
||||
{{=form_update.custom.widget.name}}
|
||||
</td></tr><tr><td>
|
||||
{{=LABEL(T("Upload a package:"))}}
|
||||
</td><td>
|
||||
{{=form_update.custom.widget.file}}
|
||||
</td></tr><tr><td>
|
||||
{{=LABEL('Or ',T("Get from URL:"))}}
|
||||
</td><td>
|
||||
{{=form_update.custom.widget.url}}
|
||||
</td></tr><tr><td>
|
||||
({{=T('can be a git repo')}})
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" name="overwrite_check" id="upload_overwrite" />
|
||||
{{=LABEL(T("Overwrite installed app"), _for='upload_overwrite')}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<button type="submit">{{=T('Install')}}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</td><td>
|
||||
{{=form_update.custom.widget.overwrite}}
|
||||
{{=LABEL(T("Overwrite installed app"))}}
|
||||
</td></tr><tr><td>
|
||||
</td><td>
|
||||
<button type="submit">{{=T('Install')}}</button>
|
||||
</td></tr></table>
|
||||
{{=form_update.custom.end}}
|
||||
</div>
|
||||
<!-- DEPLOY ON GAE -->
|
||||
<div class="box">
|
||||
|
||||
Reference in New Issue
Block a user