瀏覽代碼

Add make_records()

version-14
Prateeksha Singh 6 年之前
父節點
當前提交
0ccb159c6f
共有 6 個檔案被更改,包括 100 行新增5 行删除
  1. +14
    -1
      frappe/commands/utils.py
  2. +1
    -1
      frappe/desk/notifications.py
  3. +68
    -0
      frappe/desk/page/setup_wizard/setup_wizard.py
  4. +5
    -0
      frappe/public/js/frappe/desk.js
  5. +8
    -0
      frappe/public/js/frappe/ui/dialog.js
  6. +4
    -3
      frappe/utils/install.py

+ 14
- 1
frappe/commands/utils.py 查看文件

@@ -9,6 +9,8 @@ from frappe.commands import pass_context, get_site
from frappe.utils import update_progress_bar, get_bench_path
from frappe.utils.response import json_handler
from coverage import Coverage
import cProfile, pstats
from six import StringIO

@click.command('build')
@click.option('--app', help='Build assets for app')
@@ -98,8 +100,9 @@ def reset_perms(context):
@click.argument('method')
@click.option('--args')
@click.option('--kwargs')
@click.option('--profile', is_flag=True, default=False)
@pass_context
def execute(context, method, args=None, kwargs=None):
def execute(context, method, args=None, kwargs=None, profile=False):
"Execute a function"
for site in context.sites:
try:
@@ -119,8 +122,18 @@ def execute(context, method, args=None, kwargs=None):
else:
kwargs = {}

if profile:
pr = cProfile.Profile()
pr.enable()

ret = frappe.get_attr(method)(*args, **kwargs)

if profile:
pr.disable()
s = StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumulative').print_stats(.5)
print(s.getvalue())

if frappe.db:
frappe.db.commit()
finally:


+ 1
- 1
frappe/desk/notifications.py 查看文件

@@ -28,7 +28,7 @@ def get_notifications():
notification_count[name] = count

return {
"open_count_doctype": get_notifications_for_doctypes(config, notification_count),
"open_count_doctype": {},
"open_count_module": get_notifications_for_modules(config, notification_count),
"open_count_other": get_notifications_for_other(config, notification_count),
"targets": get_notifications_for_targets(config, notification_percent),


+ 68
- 0
frappe/desk/page/setup_wizard/setup_wizard.py 查看文件

@@ -349,3 +349,71 @@ def enable_twofactor_all_roles():
all_role.two_factor_auth = True
all_role.save(ignore_permissions=True)

def make_records(records, debug=False):
from frappe import _dict
from frappe.modules import scrub
from time import time

root_time_start = time()

# LOG every success and failure
for record in records:

doctype = record.get("doctype")
condition = record.get('__condition')

if condition and not condition():
continue

doc = frappe.new_doc(doctype)
doc.update(record)

# ignore mandatory for root
parent_link_field = ("parent_" + scrub(doc.doctype))
if doc.meta.get_field(parent_link_field) and not doc.get(parent_link_field):
doc.flags.ignore_mandatory = True

try:
if debug:
time_start = time()

doc.insert(ignore_permissions=True)

exec_time_str = ""
if debug:
time_end = time()
exec_time_str = ": {0} sec".format(round(time_end - time_start, 2))

print("Inserted {0} {1}".format(doctype, doc.name) + exec_time_str)

except frappe.DuplicateEntryError as e:
print("Failed to insert duplicate {0} {1}".format(doctype, doc.name))

# pass DuplicateEntryError and continue
if e.args and e.args[0]==doc.doctype and e.args[1]==doc.name:
# make sure DuplicateEntryError is for the exact same doc and not a related doc
pass
else:
raise

except Exception as e:
print("Failed to insert {0} {1}".format(doctype, doc.name))

exception = record.get('__exception')
if exception:
config = _dict(exception)
if type(e) == config.exception:
config.handler()
else:
show_document_insert_error()
else:
show_document_insert_error()

finally:
root_time_end = time()
total_time = round(root_time_end - root_time_start, 2)
print("Completion: {0} sec".format(total_time))

def show_document_insert_error():
print("Document Insert Error")
print(frappe.get_traceback())

+ 5
- 0
frappe/public/js/frappe/desk.js 查看文件

@@ -80,6 +80,11 @@ frappe.Application = Class.extend({

this.show_update_available();

if(frappe.ui.startup_setup_dialog) {
frappe.ui.startup_setup_dialog.pre_show();
frappe.ui.startup_setup_dialog.show();
}

// listen to csrf_update
frappe.realtime.on("csrf_generated", function(data) {
// handles the case when a user logs in again from another tab


+ 8
- 0
frappe/public/js/frappe/ui/dialog.js 查看文件

@@ -20,6 +20,14 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup {
make() {
this.$wrapper = frappe.get_modal("", "");

if(this.static) {
this.$wrapper.modal({
backdrop: 'static',
keyboard: false
});
this.get_close_btn().hide();
}

this.wrapper = this.$wrapper.find('.modal-dialog')
.get(0);
if ( this.size == "small" )


+ 4
- 3
frappe/utils/install.py 查看文件

@@ -36,8 +36,9 @@ def after_install():
# update admin password
update_password("Administrator", get_admin_password())

# setup wizard now in frappe
frappe.db.set_default('desktop:home_page', 'setup-wizard')
# setup_conf = frappe._dict(frappe.local.conf.setup)
# if setup_conf and not setup_conf.skip_setup_wizard:
# frappe.db.set_default('desktop:home_page', 'setup-wizard')

# clear test log
with open(frappe.get_site_path('.test_log'), 'w') as f:
@@ -157,4 +158,4 @@ def add_country_and_currency(name, country):
"smallest_currency_fraction_value": country.smallest_currency_fraction_value,
"number_format": country.number_format,
"docstatus": 0
}).db_insert()
}).db_insert()

Loading…
取消
儲存