-
-
Notifications
You must be signed in to change notification settings - Fork 727
web2py install instructions
Hello community,
After few months I'm happy to announce that the new version of SQL WWW Developer is possible to integrate into web2py without the need to patch web2py nor www sql designer code.
Process of integration into web2py is following:
-
Download web2py and unpack
-
create application named designer for example (no hard-coding of names needed anymore)
-
change dir to <application_name>/static/
-
Download and unpack wwwsqldesigner-x.x.x.zip and rename folder to designer ( that is needed if you don't want to change default.py code)
-
cd designer/js/ and edit it so it looks like this snipper bellow
var CONFIG = {
AVAILABLE_DBS: ["mysql", "sqlite", "web2py", "mssql", "postgresql", "oracle", "sqlalchemy", "vfp9", "cubrid"],
DEFAULT_DB: "web2py",
AVAILABLE_LOCALES: ["ar", "cs", "de", "el", "en", "eo", "es", "fr", "hu", "it", "ja", "nl", "pl", "pt_BR", "ro", "ru", "sv", "zh"],
DEFAULT_LOCALE: "en",
AVAILABLE_BACKENDS: ["php-mysql", "php-blank", "php-file", "php-sqlite", "php-mysql+file", "php-postgresql", "php-pdo", "perl-file", "php-cubrid", "asp-file", "web2py"],
DEFAULT_BACKEND: ["web2py"],
RELATION_THICKNESS: 2,
RELATION_SPACING: 15,
RELATION_COLORS: ["#000", "#800", "#080", "#008", "#088", "#808", "#088"],
STATIC_PATH: "",
XHR_PATH: "../../default/",
/*
* The key below needs to be set individually by you if you want to use the Dropbox load/save feature.
* To do that, first # with Dropbox (may require a specific developer / SDK sign-up), go to
* https://www.dropbox.com/developers/apps and use "Create app" to add a new "Dropbox API app".
* Limit the app to its own folder. Call it, for instance, "wwwsqldesigner".
* Under "OAuth 2", "Redirect URIs", add the URL to the "dropbox-oauth-receiver.html" file on your server.
* E.g, if you install wwwsqldesigner on your local web server under "http://localhost/sqldesigner/", then add
* http://localhost/sqldesigner/dropbox-oauth-receiver.html as a Redirection URI.
* Copy the shown "App key" and paste it here below instead of the null value:
*/
DROPBOX_KEY: null // such as: "d6stdscwewhl6sa"
}
- edit ( from web gui or from console ) models/db.py and add table definition:
db.define_table("tbldata",
Field("tblname", "string", default="tabela"),
Field("changed", "datetime", default=request.now),
Field("xmldata", "blob"))
- replace controllers/default.py with code below ( default.py) - adding backend for web2py and redirection to static/designer/index.html
# coding: utf8
#########################################################################
## This is a samples controller
## - index is the default action of any application
## - user is required for authentication and authorization
## - download is for downloading files uploaded in the db (does streaming)
## - call exposes all registered services (none by default)
#########################################################################
def index():
redirect(URL(r=request,c='static',f='designer/index.html',vars=request.vars))
def user():
return dict(form=auth())
def download():
return response.download(request,db)
def call():
session.forget()
return service()
def backend():
import re
if request.vars.action == "save": # api is URL?action=save&keyword=schemaname
if re.compile('[^0-9a-zA-Z]').findall(request.vars.keyword):
raise HTTP(503, 'NOT SAVED! use [0-9a-zA-Z] for project names only... ')
name = db(db.tbldata.tblname == request.vars.keyword).select(db.tbldata.tblname)
if len(name) != 0:
db(db.tbldata.tblname==request.vars.keyword).update(
tblname=request.vars.keyword,
changed=request.now,
xmldata=request.body.read()
)
else:
db.tbldata.insert(tblname=request.vars.keyword,
changed=request.now,
xmldata=request.body.read()
)
raise HTTP(201, "Model has been saved...")
#request.body.read()
elif request.vars.action == "list": # api is URL?action=list
rows = db().select(db.tbldata.ALL)
names = ""
for row in rows:
if names == "":
names = row.tblname
continue
names = names + "\n" + row.tblname
response.headers['Content-Type'] = 'text/plain'
return names
elif request.vars.action == "load": # api is URL?action=load&keyword=schemaname
row = db(db.tbldata.tblname == request.get_vars.keyword).select(db.tbldata.xmldata)
if len(row) != 0 :
response.headers['Content-Type'] = 'application/xml'
#return row[0].xmldata # without cast it errors out with Blob does not have items attribute????
return "%s" % row[0].xmldata # when casted to string it works on GAE....
else:
raise HTTP(404,T('Model Not found...'))
elif request.vars.action == "import": # api is URL?action=import&database=somedatabasename
raise HTTP(501,T("Not implemented"))
-
Go to
http://<YOUR_IP>/<appname>/
and enjoy creating tables visually -
Buy beer or some cocktail to me when in Belgrade, Serbia :) (and to Ondrej as he created this great tool)
- data types fixes (removal of timestamp),
- many XSL fixes;
- relations are working now as they should - no need to remove anything from "relations" line if you are lazy it should just work :),
- tables without relation will be first on list of created tables as needed by web2py - when this is not a case web2py will error out.
- password fields will not be mapped to select box by design!!
- some defaults are mapped correctly - still watch out for single quotes!
BY Boris Manojlovic