Bläddra i källkod

started fresh install and added country_info

version-14
Rushabh Mehta 12 år sedan
förälder
incheckning
338018e78d
16 ändrade filer med 2096 tillägg och 49 borttagningar
  1. +0
    -0
      core/doctype/patch_log/__init__.py
  2. +8
    -0
      core/doctype/patch_log/patch_log.py
  3. +35
    -0
      core/doctype/patch_log/patch_log.txt
  4. +2
    -4
      core/doctype/profile/profile.py
  5. +3
    -1
      public/js/legacy/widgets/form/form.js
  6. +3
    -11
      public/js/wn/ui/field_group.js
  7. +8
    -0
      webnotes/auth.py
  8. +1945
    -0
      webnotes/country_info.json
  9. +20
    -0
      webnotes/country_info.py
  10. +3
    -0
      webnotes/db.py
  11. +31
    -13
      webnotes/install_lib/install.py
  12. +2
    -0
      webnotes/model/doc.py
  13. +2
    -2
      webnotes/model/sync.py
  14. +17
    -11
      webnotes/modules/patch_handler.py
  15. +3
    -3
      webnotes/utils/datautils.py
  16. +14
    -4
      wnf.py

+ 0
- 0
core/doctype/patch_log/__init__.py Visa fil


+ 8
- 0
core/doctype/patch_log/patch_log.py Visa fil

@@ -0,0 +1,8 @@
# For license information, please see license.txt

from __future__ import unicode_literals
import webnotes

class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl

+ 35
- 0
core/doctype/patch_log/patch_log.txt Visa fil

@@ -0,0 +1,35 @@
[
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2013-01-17 11:36:45",
"modified_by": "Administrator",
"modified": "2013-01-17 11:36:45"
},
{
"autoname": "PATCHLOG.#####",
"description": "List of patches executed",
"doctype": "DocType",
"module": "Core",
"document_type": "System",
"name": "__common__"
},
{
"name": "__common__",
"parent": "Patch Log",
"label": "Patch",
"parenttype": "DocType",
"fieldname": "patch",
"fieldtype": "Data",
"doctype": "DocField",
"permlevel": 0,
"parentfield": "fields"
},
{
"name": "Patch Log",
"doctype": "DocType"
},
{
"doctype": "DocField"
}
]

+ 2
- 4
core/doctype/profile/profile.py Visa fil

@@ -131,10 +131,8 @@ class DocType:
def update_new_password(self):
"""update new password if set"""
if self.doc.new_password:
webnotes.conn.sql("""insert into __Auth (user, `password`)
values (%s, password(%s))
on duplicate key update `password`=password(%s)""", (self.doc.name,
self.doc.new_password, self.doc.new_password))
from webnotes.auth import update_password
update_password(self.doc.name, self.doc.new_password)
if not self.is_new:
self.password_reset_mail(self.doc.new_password)


+ 3
- 1
public/js/legacy/widgets/form/form.js Visa fil

@@ -896,7 +896,6 @@ var validated;
_f.Frm.prototype.save = function(save_action, callback, btn) {
$(document.activeElement).blur();
var me = this;
var doclist = new wn.model.DocList(this.doctype, this.docname);
// validate
if(save_action!="Cancel") {
@@ -906,6 +905,9 @@ _f.Frm.prototype.save = function(save_action, callback, btn) {
return;
}
}

var doclist = new wn.model.DocList(this.doctype, this.docname);

doclist.save(save_action || "Save", function(r) {
if(!r.exc) {
me.refresh();


+ 3
- 11
public/js/wn/ui/field_group.js Visa fil

@@ -31,13 +31,7 @@ wn.ui.FieldGroup = Class.extend({
},
first_button: false,
make_fields: function() {
if(!window.make_field) {
// called in website, load some libs
wn.require('css/fields.css');
wn.require('js/fields.js');
}

$(this.parent).css({padding:'11px'});
$(this.parent).css({padding:'25px'});
this.fields_dict = {}; // reset
for(var i=0; i< this.fields.length; i++) {
var df = this.fields[i];
@@ -68,7 +62,8 @@ wn.ui.FieldGroup = Class.extend({
})
},
get_input: function(fieldname) {
return $(this.fields_dict[fieldname].input);
var field = this.fields_dict[fieldname];
return $(field.txt ? field.txt : field.input);
},
get_values: function() {
var ret = {};
@@ -114,7 +109,4 @@ wn.ui.FieldGroup = Class.extend({
}
}
},
get_input: function(fieldname) {
return $(this.fields_dict[fieldname].input);
}
});

+ 8
- 0
webnotes/auth.py Visa fil

@@ -232,3 +232,11 @@ class CookieManager:
webnotes.cookies[b'remember_me'] = 1
for k in webnotes.cookies.keys():
webnotes.cookies[k][b'expires'] = expires.encode('utf-8')


def update_password(user, password):
webnotes.conn.sql("""insert into __Auth (user, `password`)
values (%s, password(%s))
on duplicate key update `password`=password(%s)""", (user,
password, password))

+ 1945
- 0
webnotes/country_info.json
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 20
- 0
webnotes/country_info.py Visa fil

@@ -0,0 +1,20 @@
# all country info
from __future__ import unicode_literals

import os, json, webnotes

def get_country_info(country=None):
data = get_all()
data = webnotes._dict(data.get(country, {}))
if not 'date_format' in data:
data.date_format = "dd-mm-yyyy"
return data

@webnotes.whitelist()
def get_all():
with open(os.path.join(os.path.dirname(__file__), "country_info.json"), "r") as local_info:
all_data = json.loads(local_info.read())
return all_data


+ 3
- 0
webnotes/db.py Visa fil

@@ -358,6 +358,9 @@ class Database:
def field_exists(self, dt, fn):
return self.sql("select name from tabDocField where fieldname=%s and parent=%s", (dt, fn))

def table_exists(self, tablename):
return tablename in [d[0] for d in self.sql("show tables")]

def exists(self, dt, dn=None):
if isinstance(dt, basestring):
try:


+ 31
- 13
webnotes/install_lib/install.py Visa fil

@@ -34,10 +34,11 @@ from webnotes.model.sync import sync_for

class Installer:
def __init__(self, root_login, root_password=None):

if root_login and not root_password:
root_password = 'test123' #getpass.getpass("MySQL root password: ")
if root_login:
if not root_password:
root_password = getattr(conf, "root_password", None)
if not root_password:
root_password = getpass.getpass("MySQL root password: ")
self.root_password = root_password
@@ -89,10 +90,8 @@ class Installer:
print "Installing app..."
self.install_app()

self.framework_cleanups(hasattr(conf, 'admin_password') \
and conf.admin_password or password)
if verbose: print "Ran framework startups on %s" % target
# update admin password
self.update_admin_password(password)
return target
def install_app(self):
@@ -107,12 +106,13 @@ class Installer:
sync_for("app", force=True, sync_everything=True)
print "Completing App Import..."
install.post_import()
print "Updating patches..."
self.set_all_patches_as_completed()

def framework_cleanups(self, password):
# set the basic passwords
def update_admin_password(self, password):
from webnotes.auth import update_password
webnotes.conn.begin()
webnotes.conn.sql("""update __Auth set password = password(%s)
where user='Administrator'""", (password,))
update_password("Administrator", getattr(conf, "admin_password", password))
webnotes.conn.commit()
def import_core_docs(self):
@@ -139,6 +139,24 @@ class Installer:
'parenttype':'Profile', 'parentfield':'userroles'}
]
webnotes.conn.begin()
for d in install_docs:
doc = webnotes.doc(fielddata=d)
doc.insert()
doc.insert()
webnotes.conn.commit()
def set_all_patches_as_completed(self):
try:
from patches.patch_list import patch_list
except ImportError, e:
print "No patches to update."
return
webnotes.conn.begin()
for patch in patch_list:
webnotes.doc({
"doctype": "Patch Log",
"patch": patch
}).insert()
webnotes.conn.commit()

+ 2
- 0
webnotes/model/doc.py Visa fil

@@ -420,6 +420,7 @@ class Document:
def insert(self):
self.fields['__islocal'] = 1
self.save()
return self
def update_parentinfo(self):
"""update parent type and parent field, if not explicitly specified"""
@@ -484,6 +485,7 @@ class Document:
* if local is set, it does not save the record
* if doclist is passed, it append the record to the doclist
"""
from webnotes.model.doc import Document
d = Document()
d.parent = self.name
d.parenttype = self.doctype


+ 2
- 2
webnotes/model/sync.py Visa fil

@@ -9,8 +9,8 @@ import conf
from webnotes.modules import reload_doc

def sync_all(force=0):
sync_from("lib", force)
sync_from("app", force)
sync_for("lib", force)
sync_for("app", force)
webnotes.clear_cache()

def sync_for(folder, force=0, sync_everything = False):


+ 17
- 11
webnotes/modules/patch_handler.py Visa fil

@@ -35,21 +35,21 @@ import webnotes

def run_all(patch_list=None):
"""run all pending patches"""
executed = [p[0] for p in webnotes.conn.sql("""select patch from __PatchLog""")]
if webnotes.conn.table_exists("__PatchLog"):
executed = [p[0] for p in webnotes.conn.sql("""select patch from `__PatchLog`""")]
else:
executed = [p[0] for p in webnotes.conn.sql("""select patch from `tabPatch Log`""")]
import patches.patch_list
for patch in (patch_list or patches.patch_list.patch_list):
pn = patch['patch_module'] + '.' + patch['patch_file']
if pn not in executed:
if not run_single(patchmodule = pn):
return log(pn + ': failed: STOPPED')
if patch not in executed:
if not run_single(patchmodule = patch):
return log(patch + ': failed: STOPPED')

def reload_doc(args):
"""relaod a doc args {module, doctype, docname}"""
import webnotes.modules
run_single(method = webnotes.modules.reload_doc, methodargs = args)

def run_single(patchmodule=None, method=None, methodargs=None, force=False):
"""run a single patch"""
import conf
# don't write txt files
@@ -97,13 +97,19 @@ def add_to_patch_log(tb):
patchlog.write('\n\n' + tb)
def update_patch_log(patchmodule):
"""update patch_file in patch log"""
webnotes.conn.sql("""INSERT INTO `__PatchLog` VALUES (%s, now())""", \
patchmodule)
"""update patch_file in patch log"""
if webnotes.conn.table_exists("__PatchLog"):
webnotes.conn.sql("""INSERT INTO `__PatchLog` VALUES (%s, now())""", \
patchmodule)
else:
webnotes.doc({"doctype": "Patch Log", "patch": patchmodule}).insert()

def executed(patchmodule):
"""return True if is executed"""
done = webnotes.conn.sql("""select patch from __PatchLog where patch=%s""", patchmodule)
if webnotes.conn.table_exists("__PatchLog"):
done = webnotes.conn.sql("""select patch from __PatchLog where patch=%s""", patchmodule)
else:
done = webnotes.conn.get_value("Patch Log", {"patch": patchmodule})
if done:
print "Patch %s executed in %s" % (patchmodule, webnotes.conn.cur_db_name)
return done


+ 3
- 3
webnotes/utils/datautils.py Visa fil

@@ -37,12 +37,12 @@ def read_csv_content_from_attached_file(doc):
from webnotes.utils.file_manager import get_file
fid = doc.file_list.split(",")[1]
fname, fcontent = get_file(fid)
return read_csv_content(fcontent)
return read_csv_content(fcontent, webnotes.form_dict.get('ignore_encoding_errors'))
except Exception, e:
webnotes.msgprint("""Unable to open attached file. Please try again.""")
raise Exception

def read_csv_content(fcontent):
def read_csv_content(fcontent, ignore_encoding=False):
import csv
from webnotes.utils import cstr
rows = []
@@ -54,7 +54,7 @@ def read_csv_content(fcontent):
for row in csvrows:
newrow = []
for val in row:
if webnotes.form_dict.get('ignore_encoding_errors'):
if ignore_encoding:
newrow.append(cstr(val.strip()))
else:
try:


+ 14
- 4
wnf.py Visa fil

@@ -133,7 +133,11 @@ def setup_options():

# install
parser.add_option('--install', nargs=2, metavar = "NEW_DB_NAME SOURCE_PATH",
help="install db")

parser.add_option('--install_fresh', nargs=1, metavar = "NEW_DB_NAME",
help="install fresh db")

# update
parser.add_option("--update", help="Pull, run latest patches and sync all",
nargs=2, metavar="ORIGIN BRANCH")
@@ -312,7 +316,7 @@ def run():
webnotes.connect(options.db_name, options.password)
else:
webnotes.connect(options.db_name)
elif not any([options.install, options.pull]):
elif not any([options.install, options.pull, options.install_fresh]):
webnotes.connect(conf.db_name)

if options.pull:
@@ -365,9 +369,15 @@ def run():
elif options.install:
from webnotes.install_lib.install import Installer
inst = Installer('root')
inst.import_from_db(options.install[0], source_path=options.install[1], \
password='admin', verbose = 1)
inst.import_from_db(options.install[0], source_path=options.install[1],
verbose = 1)

elif options.install_fresh:
from webnotes.install_lib.install import Installer
inst = Installer('root')
inst.import_from_db(options.install_fresh, source_path="lib/conf/Framework.sql",
verbose = 1)

elif options.diff_ref_file is not None:
import webnotes.modules.diff
webnotes.modules.diff.diff_ref_file()


Laddar…
Avbryt
Spara