diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index adb8ccf7b4..94bc040ac5 100644 --- a/frappe/commands/utils.py +++ b/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: diff --git a/frappe/desk/notifications.py b/frappe/desk/notifications.py index 7a5676cca6..f0b0cd62b6 100644 --- a/frappe/desk/notifications.py +++ b/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), diff --git a/frappe/desk/page/setup_wizard/setup_wizard.py b/frappe/desk/page/setup_wizard/setup_wizard.py index ed6b0eacb7..9af3ffd344 100755 --- a/frappe/desk/page/setup_wizard/setup_wizard.py +++ b/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()) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index ed4bcfd3d9..a80feaecf2 100644 --- a/frappe/public/js/frappe/desk.js +++ b/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 diff --git a/frappe/public/js/frappe/ui/dialog.js b/frappe/public/js/frappe/ui/dialog.js index 2815cbbda3..cd76db91d4 100644 --- a/frappe/public/js/frappe/ui/dialog.js +++ b/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" ) diff --git a/frappe/utils/install.py b/frappe/utils/install.py index b84e292397..28813b2904 100644 --- a/frappe/utils/install.py +++ b/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() \ No newline at end of file + }).db_insert()