[import/export] [minor] cleanup
This commit is contained in:
parent
1aac1f91dc
commit
d74a13a4f1
3 changed files with 32 additions and 28 deletions
21
README.md
21
README.md
|
|
@ -10,27 +10,24 @@ To start a new project, in the application root:
|
|||
|
||||
Install:
|
||||
|
||||
1. Install webnotes and treemapper
|
||||
1. Go to the project folder
|
||||
1. Install webnotes and your app:
|
||||
|
||||
$ git clone git@github.com:webnotes/wnframework lib
|
||||
$ git clone git@github.com:webnotes/[your app] app
|
||||
$ lib/wnf.py --make_conf
|
||||
$ lib/wnf.py --reinstall
|
||||
$ lib/wnf.py --build
|
||||
|
||||
1. Setup Apache Conf
|
||||
1. Setup Apache Conf from `conf/apache.conf`
|
||||
- Allow cgi to handle `.py` files
|
||||
- Rewrite to make clean urls
|
||||
- Note: the document root is the `public` folder in your project folder
|
||||
|
||||
1. Give ownership of the project folder to apache user (`www-data` or `apache`) to make .pyc files and upload files.
|
||||
|
||||
enjoy!
|
||||
|
||||
|
||||
#### Export
|
||||
|
||||
Before pushing, export install fixtures
|
||||
|
||||
$ lib/wnf.py --export_doclist "Website Settings" - app/startup/website_settings.json
|
||||
$ lib/wnf.py --export_doclist "Style Settings" - app/startup/style_settings.json
|
||||
$ lib/wnf.py --export_csv "Tree Species" app/startup/Tree_Species.csv
|
||||
$ lib/wnf.py --export_csv "Tree Family" app/startup/Tree_Family.csv
|
||||
|
||||
## wnf.py
|
||||
|
||||
`$ lib/wnf.py --help` for more info
|
||||
|
|
|
|||
|
|
@ -478,3 +478,22 @@ def import_file_by_path(path):
|
|||
print "Importing " + path
|
||||
with open(path, "r") as infile:
|
||||
upload(rows = read_csv_content(infile.read()))
|
||||
|
||||
def export_csv(doctype, path):
|
||||
with open(path, "w") as csvfile:
|
||||
get_template(doctype=doctype, all_doctypes="Yes", with_data="Yes")
|
||||
csvfile.write(webnotes.response.result)
|
||||
|
||||
def export_json(doctype, name, path):
|
||||
from webnotes.handler import json_handler
|
||||
if not name or name=="-":
|
||||
name = doctype
|
||||
with open(path, "w") as outfile:
|
||||
doclist = [d.fields for d in webnotes.bean(doctype, name).doclist]
|
||||
for d in doclist:
|
||||
if d.get("parent"):
|
||||
del d["parent"]
|
||||
del d["name"]
|
||||
d["__islocal"] = 1
|
||||
outfile.write(json.dumps(doclist, default=json_handler, indent=1, sort_keys=True))
|
||||
|
||||
20
wnf.py
20
wnf.py
|
|
@ -523,24 +523,12 @@ def run():
|
|||
write_static()
|
||||
|
||||
elif options.export_doclist:
|
||||
import json
|
||||
from webnotes.handler import json_handler
|
||||
args = list(options.export_doclist)
|
||||
if args[1]=="-": args[1] = args[0]
|
||||
with open(args[2], "w") as outfile:
|
||||
doclist = [d.fields for d in webnotes.bean(args[0], args[1]).doclist]
|
||||
for d in doclist:
|
||||
if d.get("parent"):
|
||||
del d["parent"]
|
||||
del d["name"]
|
||||
d["__islocal"] = 1
|
||||
outfile.write(json.dumps(doclist, default=json_handler, indent=1, sort_keys=True))
|
||||
from core.page.data_import_tool.data_import_tool import export_json
|
||||
export_json(*list(options.export_doclist))
|
||||
|
||||
elif options.export_csv:
|
||||
from core.page.data_import_tool.data_import_tool import get_template
|
||||
with open(options.export_csv[1], "w") as csvfile:
|
||||
get_template(doctype=options.export_csv[0], all_doctypes="Yes", with_data="Yes")
|
||||
csvfile.write(webnotes.response.result)
|
||||
from core.page.data_import_tool.data_import_tool import export_csv
|
||||
export_csv(*options.export_csv)
|
||||
|
||||
elif options.import_doclist:
|
||||
import json
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue