@@ -19,36 +19,38 @@ from frappe.exceptions import SiteNotSpecifiedError | |||||
@click.option('--db-type', default='mariadb', type=click.Choice(['mariadb', 'postgres']), help='Optional "postgres" or "mariadb". Default is "mariadb"') | @click.option('--db-type', default='mariadb', type=click.Choice(['mariadb', 'postgres']), help='Optional "postgres" or "mariadb". Default is "mariadb"') | ||||
@click.option('--db-host', help='Database Host') | @click.option('--db-host', help='Database Host') | ||||
@click.option('--db-port', type=int, help='Database Port') | @click.option('--db-port', type=int, help='Database Port') | ||||
@click.option('--mariadb-root-username', default='root', help='Root username for MariaDB') | |||||
@click.option('--mariadb-root-password', help='Root password for MariaDB') | |||||
@click.option('--db-root-username', '--mariadb-root-username', help='Root username for MariaDB or PostgreSQL, Default is "root"') | |||||
@click.option('--db-root-password', '--mariadb-root-password', help='Root password for MariaDB or PostgreSQL') | |||||
@click.option('--no-mariadb-socket', is_flag=True, default=False, help='Set MariaDB host to % and use TCP/IP Socket instead of using the UNIX Socket') | @click.option('--no-mariadb-socket', is_flag=True, default=False, help='Set MariaDB host to % and use TCP/IP Socket instead of using the UNIX Socket') | ||||
@click.option('--admin-password', help='Administrator password for new site', default=None) | @click.option('--admin-password', help='Administrator password for new site', default=None) | ||||
@click.option('--verbose', is_flag=True, default=False, help='Verbose') | @click.option('--verbose', is_flag=True, default=False, help='Verbose') | ||||
@click.option('--force', help='Force restore if site/database already exists', is_flag=True, default=False) | @click.option('--force', help='Force restore if site/database already exists', is_flag=True, default=False) | ||||
@click.option('--source_sql', help='Initiate database with a SQL file') | @click.option('--source_sql', help='Initiate database with a SQL file') | ||||
@click.option('--install-app', multiple=True, help='Install app after installation') | @click.option('--install-app', multiple=True, help='Install app after installation') | ||||
def new_site(site, mariadb_root_username=None, mariadb_root_password=None, admin_password=None, | |||||
verbose=False, install_apps=None, source_sql=None, force=None, no_mariadb_socket=False, | |||||
install_app=None, db_name=None, db_password=None, db_type=None, db_host=None, db_port=None): | |||||
@click.option('--set-default', is_flag=True, default=False, help='Set the new site as default site') | |||||
def new_site(site, db_root_username=None, db_root_password=None, admin_password=None, | |||||
verbose=False, install_apps=None, source_sql=None, force=None, no_mariadb_socket=False, | |||||
install_app=None, db_name=None, db_password=None, db_type=None, db_host=None, db_port=None, | |||||
set_default=False): | |||||
"Create a new site" | "Create a new site" | ||||
from frappe.installer import _new_site | from frappe.installer import _new_site | ||||
frappe.init(site=site, new_site=True) | frappe.init(site=site, new_site=True) | ||||
_new_site(db_name, site, mariadb_root_username=mariadb_root_username, | |||||
mariadb_root_password=mariadb_root_password, admin_password=admin_password, | |||||
verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force, | |||||
no_mariadb_socket=no_mariadb_socket, db_password=db_password, db_type=db_type, db_host=db_host, | |||||
db_port=db_port, new_site=True) | |||||
_new_site(db_name, site, db_root_username=db_root_username, | |||||
db_root_password=db_root_password, admin_password=admin_password, | |||||
verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force, | |||||
no_mariadb_socket=no_mariadb_socket, db_password=db_password, db_type=db_type, db_host=db_host, | |||||
db_port=db_port, new_site=True) | |||||
if len(frappe.utils.get_sites()) == 1: | |||||
if set_default: | |||||
use(site) | use(site) | ||||
@click.command('restore') | @click.command('restore') | ||||
@click.argument('sql-file-path') | @click.argument('sql-file-path') | ||||
@click.option('--mariadb-root-username', default='root', help='Root username for MariaDB') | |||||
@click.option('--mariadb-root-password', help='Root password for MariaDB') | |||||
@click.option('--db-root-username', '--mariadb-root-username', help='Root username for MariaDB or PostgreSQL, Default is "root"') | |||||
@click.option('--db-root-password', '--mariadb-root-password', help='Root password for MariaDB or PostgreSQL') | |||||
@click.option('--db-name', help='Database name for site in case it is a new one') | @click.option('--db-name', help='Database name for site in case it is a new one') | ||||
@click.option('--admin-password', help='Administrator password for new site') | @click.option('--admin-password', help='Administrator password for new site') | ||||
@click.option('--install-app', multiple=True, help='Install app after installation') | @click.option('--install-app', multiple=True, help='Install app after installation') | ||||
@@ -57,7 +59,7 @@ def new_site(site, mariadb_root_username=None, mariadb_root_password=None, admin | |||||
@click.option('--force', is_flag=True, default=False, help='Ignore the validations and downgrade warnings. This action is not recommended') | @click.option('--force', is_flag=True, default=False, help='Ignore the validations and downgrade warnings. This action is not recommended') | ||||
@click.option('--encryption-key', help='Backup encryption key') | @click.option('--encryption-key', help='Backup encryption key') | ||||
@pass_context | @pass_context | ||||
def restore(context, sql_file_path, encryption_key=None, mariadb_root_username=None, mariadb_root_password=None, | |||||
def restore(context, sql_file_path, encryption_key=None, db_root_username=None, db_root_password=None, | |||||
db_name=None, verbose=None, install_app=None, admin_password=None, force=None, with_public_files=None, | db_name=None, verbose=None, install_app=None, admin_password=None, force=None, with_public_files=None, | ||||
with_private_files=None): | with_private_files=None): | ||||
"Restore site database from an sql file" | "Restore site database from an sql file" | ||||
@@ -150,8 +152,8 @@ def restore(context, sql_file_path, encryption_key=None, mariadb_root_username=N | |||||
try: | try: | ||||
_new_site(frappe.conf.db_name, site, mariadb_root_username=mariadb_root_username, | |||||
mariadb_root_password=mariadb_root_password, admin_password=admin_password, | |||||
_new_site(frappe.conf.db_name, site, db_root_username=db_root_username, | |||||
db_root_password=db_root_password, admin_password=admin_password, | |||||
verbose=context.verbose, install_apps=install_app, source_sql=decompressed_file_name, | verbose=context.verbose, install_apps=install_app, source_sql=decompressed_file_name, | ||||
force=True, db_type=frappe.conf.db_type) | force=True, db_type=frappe.conf.db_type) | ||||
@@ -290,16 +292,16 @@ def partial_restore(context, sql_file_path, verbose, encryption_key=None): | |||||
@click.command('reinstall') | @click.command('reinstall') | ||||
@click.option('--admin-password', help='Administrator Password for reinstalled site') | @click.option('--admin-password', help='Administrator Password for reinstalled site') | ||||
@click.option('--mariadb-root-username', help='Root username for MariaDB') | |||||
@click.option('--mariadb-root-password', help='Root password for MariaDB') | |||||
@click.option('--db-root-username', '--mariadb-root-username', help='Root username for MariaDB or PostgreSQL, Default is "root"') | |||||
@click.option('--db-root-password', '--mariadb-root-password', help='Root password for MariaDB or PostgreSQL') | |||||
@click.option('--yes', is_flag=True, default=False, help='Pass --yes to skip confirmation') | @click.option('--yes', is_flag=True, default=False, help='Pass --yes to skip confirmation') | ||||
@pass_context | @pass_context | ||||
def reinstall(context, admin_password=None, mariadb_root_username=None, mariadb_root_password=None, yes=False): | |||||
def reinstall(context, admin_password=None, db_root_username=None, db_root_password=None, yes=False): | |||||
"Reinstall site ie. wipe all data and start over" | "Reinstall site ie. wipe all data and start over" | ||||
site = get_site(context) | site = get_site(context) | ||||
_reinstall(site, admin_password, mariadb_root_username, mariadb_root_password, yes, verbose=context.verbose) | |||||
_reinstall(site, admin_password, db_root_username, db_root_password, yes, verbose=context.verbose) | |||||
def _reinstall(site, admin_password=None, mariadb_root_username=None, mariadb_root_password=None, yes=False, verbose=False): | |||||
def _reinstall(site, admin_password=None, db_root_username=None, db_root_password=None, yes=False, verbose=False): | |||||
from frappe.installer import _new_site | from frappe.installer import _new_site | ||||
if not yes: | if not yes: | ||||
@@ -319,7 +321,7 @@ def _reinstall(site, admin_password=None, mariadb_root_username=None, mariadb_ro | |||||
frappe.init(site=site) | frappe.init(site=site) | ||||
_new_site(frappe.conf.db_name, site, verbose=verbose, force=True, reinstall=True, install_apps=installed, | _new_site(frappe.conf.db_name, site, verbose=verbose, force=True, reinstall=True, install_apps=installed, | ||||
mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, | |||||
db_root_username=db_root_username, db_root_password=db_root_password, | |||||
admin_password=admin_password) | admin_password=admin_password) | ||||
@click.command('install-app') | @click.command('install-app') | ||||
@@ -656,16 +658,16 @@ def uninstall(context, app, dry_run, yes, no_backup, force): | |||||
@click.command('drop-site') | @click.command('drop-site') | ||||
@click.argument('site') | @click.argument('site') | ||||
@click.option('--root-login', default='root') | |||||
@click.option('--root-password') | |||||
@click.option('--db-root-username', '--mariadb-root-username', '--root-login', help='Root username for MariaDB or PostgreSQL, Default is "root"') | |||||
@click.option('--db-root-password', '--mariadb-root-password', '--root-password', help='Root password for MariaDB or PostgreSQL') | |||||
@click.option('--archived-sites-path') | @click.option('--archived-sites-path') | ||||
@click.option('--no-backup', is_flag=True, default=False) | @click.option('--no-backup', is_flag=True, default=False) | ||||
@click.option('--force', help='Force drop-site even if an error is encountered', is_flag=True, default=False) | @click.option('--force', help='Force drop-site even if an error is encountered', is_flag=True, default=False) | ||||
def drop_site(site, root_login='root', root_password=None, archived_sites_path=None, force=False, no_backup=False): | |||||
_drop_site(site, root_login, root_password, archived_sites_path, force, no_backup) | |||||
def drop_site(site, db_root_username='root', db_root_password=None, archived_sites_path=None, force=False, no_backup=False): | |||||
_drop_site(site, db_root_username, db_root_password, archived_sites_path, force, no_backup) | |||||
def _drop_site(site, root_login='root', root_password=None, archived_sites_path=None, force=False, no_backup=False): | |||||
def _drop_site(site, db_root_username=None, db_root_password=None, archived_sites_path=None, force=False, no_backup=False): | |||||
"Remove site from database and filesystem" | "Remove site from database and filesystem" | ||||
from frappe.database import drop_user_and_database | from frappe.database import drop_user_and_database | ||||
from frappe.utils.backups import scheduled_backup | from frappe.utils.backups import scheduled_backup | ||||
@@ -690,7 +692,7 @@ def _drop_site(site, root_login='root', root_password=None, archived_sites_path= | |||||
click.echo("\n".join(messages)) | click.echo("\n".join(messages)) | ||||
sys.exit(1) | sys.exit(1) | ||||
drop_user_and_database(frappe.conf.db_name, root_login, root_password) | |||||
drop_user_and_database(frappe.conf.db_name, db_root_username, db_root_password) | |||||
archived_sites_path = archived_sites_path or os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived', 'sites') | archived_sites_path = archived_sites_path or os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived', 'sites') | ||||
@@ -640,6 +640,7 @@ def run_tests(context, app=None, module=None, doctype=None, test=(), profile=Fal | |||||
skip_test_records=False, skip_before_tests=False, failfast=False, case=None): | skip_test_records=False, skip_before_tests=False, failfast=False, case=None): | ||||
with CodeCoverage(coverage, app): | with CodeCoverage(coverage, app): | ||||
import frappe | |||||
import frappe.test_runner | import frappe.test_runner | ||||
tests = test | tests = test | ||||
site = get_site(context) | site = get_site(context) | ||||
@@ -356,7 +356,7 @@ class TestUser(unittest.TestCase): | |||||
self.assertEqual(update_password(new_password, key=test_user.reset_password_key), "/") | self.assertEqual(update_password(new_password, key=test_user.reset_password_key), "/") | ||||
update_password(old_password, old_password=new_password) | update_password(old_password, old_password=new_password) | ||||
self.assertEqual( | self.assertEqual( | ||||
json.loads(frappe.message_log[0]).get("message"), | |||||
json.loads(frappe.message_log[0]).get("message"), | |||||
"Password reset instructions have been sent to your email" | "Password reset instructions have been sent to your email" | ||||
) | ) | ||||
@@ -2,6 +2,9 @@ | |||||
// For license information, please see license.txt | // For license information, please see license.txt | ||||
frappe.ui.form.on('Client Script', { | frappe.ui.form.on('Client Script', { | ||||
setup(frm) { | |||||
frm.get_field("sample").html(SAMPLE_HTML); | |||||
}, | |||||
refresh(frm) { | refresh(frm) { | ||||
if (frm.doc.dt && frm.doc.script) { | if (frm.doc.dt && frm.doc.script) { | ||||
frm.add_custom_button(__('Go to {0}', [frm.doc.dt]), | frm.add_custom_button(__('Go to {0}', [frm.doc.dt]), | ||||
@@ -97,3 +100,56 @@ frappe.ui.form.on('${doctype}', { | |||||
frm.set_value('script', script + boilerplate); | frm.set_value('script', script + boilerplate); | ||||
} | } | ||||
}); | }); | ||||
const SAMPLE_HTML = `<h3>Client Script Help</h3> | |||||
<p>Client Scripts are executed only on the client-side (i.e. in Forms). Here are some examples to get you started</p> | |||||
<pre><code> | |||||
// fetch local_tax_no on selection of customer | |||||
// cur_frm.add_fetch(link_field, source_fieldname, target_fieldname); | |||||
cur_frm.add_fetch("customer", "local_tax_no', 'local_tax_no'); | |||||
// additional validation on dates | |||||
frappe.ui.form.on('Task', 'validate', function(frm) { | |||||
if (frm.doc.from_date < get_today()) { | |||||
msgprint('You can not select past date in From Date'); | |||||
validated = false; | |||||
} | |||||
}); | |||||
// make a field read-only after saving | |||||
frappe.ui.form.on('Task', { | |||||
refresh: function(frm) { | |||||
// use the __islocal value of doc, to check if the doc is saved or not | |||||
frm.set_df_property('myfield', 'read_only', frm.doc.__islocal ? 0 : 1); | |||||
} | |||||
}); | |||||
// additional permission check | |||||
frappe.ui.form.on('Task', { | |||||
validate: function(frm) { | |||||
if(user=='user1@example.com' && frm.doc.purpose!='Material Receipt') { | |||||
msgprint('You are only allowed Material Receipt'); | |||||
validated = false; | |||||
} | |||||
} | |||||
}); | |||||
// calculate sales incentive | |||||
frappe.ui.form.on('Sales Invoice', { | |||||
validate: function(frm) { | |||||
// calculate incentives for each person on the deal | |||||
total_incentive = 0 | |||||
$.each(frm.doc.sales_team, function(i, d) { | |||||
// calculate incentive | |||||
var incentive_percent = 2; | |||||
if(frm.doc.base_grand_total > 400) incentive_percent = 4; | |||||
// actual incentive | |||||
d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100; | |||||
total_incentive += flt(d.incentives) | |||||
}); | |||||
frm.doc.total_incentive = total_incentive; | |||||
} | |||||
}) | |||||
</code></pre>`; |
@@ -40,8 +40,7 @@ | |||||
{ | { | ||||
"fieldname": "sample", | "fieldname": "sample", | ||||
"fieldtype": "HTML", | "fieldtype": "HTML", | ||||
"label": "Sample", | |||||
"options": "<h3>Client Script Help</h3>\n<p>Client Scripts are executed only on the client-side (i.e. in Forms). Here are some examples to get you started</p>\n<pre><code>\n\n// fetch local_tax_no on selection of customer \n// cur_frm.add_fetch(link_field, source_fieldname, target_fieldname); \ncur_frm.add_fetch('customer', 'local_tax_no', 'local_tax_no');\n\n// additional validation on dates \nfrappe.ui.form.on('Task', 'validate', function(frm) {\n if (frm.doc.from_date < get_today()) {\n msgprint('You can not select past date in From Date');\n validated = false;\n } \n});\n\n// make a field read-only after saving \nfrappe.ui.form.on('Task', {\n refresh: function(frm) {\n // use the __islocal value of doc, to check if the doc is saved or not\n frm.set_df_property('myfield', 'read_only', frm.doc.__islocal ? 0 : 1);\n } \n});\n\n// additional permission check\nfrappe.ui.form.on('Task', {\n validate: function(frm) {\n if(user=='user1@example.com' && frm.doc.purpose!='Material Receipt') {\n msgprint('You are only allowed Material Receipt');\n validated = false;\n }\n } \n});\n\n// calculate sales incentive\nfrappe.ui.form.on('Sales Invoice', {\n validate: function(frm) {\n // calculate incentives for each person on the deal\n total_incentive = 0\n $.each(frm.doc.sales_team, function(i, d) {\n // calculate incentive\n var incentive_percent = 2;\n if(frm.doc.base_grand_total > 400) incentive_percent = 4;\n // actual incentive\n d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100;\n total_incentive += flt(d.incentives)\n });\n frm.doc.total_incentive = total_incentive;\n } \n})\n\n</code></pre>" | |||||
"label": "Sample" | |||||
}, | }, | ||||
{ | { | ||||
"default": "0", | "default": "0", | ||||
@@ -76,7 +75,7 @@ | |||||
"idx": 1, | "idx": 1, | ||||
"index_web_pages_for_search": 1, | "index_web_pages_for_search": 1, | ||||
"links": [], | "links": [], | ||||
"modified": "2021-09-04 12:03:27.029815", | |||||
"modified": "2022-02-18 00:43:33.941466", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Custom", | "module": "Custom", | ||||
"name": "Client Script", | "name": "Client Script", | ||||
@@ -107,5 +106,6 @@ | |||||
], | ], | ||||
"sort_field": "modified", | "sort_field": "modified", | ||||
"sort_order": "ASC", | "sort_order": "ASC", | ||||
"states": [], | |||||
"track_changes": 1 | "track_changes": 1 | ||||
} | } |
@@ -540,6 +540,7 @@ docfield_properties = { | |||||
'in_global_search': 'Check', | 'in_global_search': 'Check', | ||||
'in_preview': 'Check', | 'in_preview': 'Check', | ||||
'bold': 'Check', | 'bold': 'Check', | ||||
'no_copy': 'Check', | |||||
'hidden': 'Check', | 'hidden': 'Check', | ||||
'collapsible': 'Check', | 'collapsible': 'Check', | ||||
'collapsible_depends_on': 'Data', | 'collapsible_depends_on': 'Data', | ||||
@@ -97,13 +97,18 @@ class TestCustomizeForm(unittest.TestCase): | |||||
custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0] | custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0] | ||||
custom_field.reqd = 1 | custom_field.reqd = 1 | ||||
custom_field.no_copy = 1 | |||||
d.run_method("save_customization") | d.run_method("save_customization") | ||||
self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "reqd"), 1) | self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "reqd"), 1) | ||||
self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "no_copy"), 1) | |||||
custom_field = d.get("fields", {"is_custom_field": True})[0] | custom_field = d.get("fields", {"is_custom_field": True})[0] | ||||
custom_field.reqd = 0 | custom_field.reqd = 0 | ||||
custom_field.no_copy = 0 | |||||
d.run_method("save_customization") | d.run_method("save_customization") | ||||
self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "reqd"), 0) | self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "reqd"), 0) | ||||
self.assertEqual(frappe.db.get_value("Custom Field", "Event-test_custom_field", "no_copy"), 0) | |||||
def test_save_customization_new_field(self): | def test_save_customization_new_field(self): | ||||
d = self.get_customize_form("Event") | d = self.get_customize_form("Event") | ||||
@@ -20,6 +20,7 @@ | |||||
"in_global_search", | "in_global_search", | ||||
"in_preview", | "in_preview", | ||||
"bold", | "bold", | ||||
"no_copy", | |||||
"allow_in_quick_entry", | "allow_in_quick_entry", | ||||
"translatable", | "translatable", | ||||
"column_break_7", | "column_break_7", | ||||
@@ -437,13 +438,19 @@ | |||||
"fieldname": "show_dashboard", | "fieldname": "show_dashboard", | ||||
"fieldtype": "Check", | "fieldtype": "Check", | ||||
"label": "Show Dashboard" | "label": "Show Dashboard" | ||||
}, | |||||
{ | |||||
"default": "0", | |||||
"fieldname": "no_copy", | |||||
"fieldtype": "Check", | |||||
"label": "No Copy" | |||||
} | } | ||||
], | ], | ||||
"idx": 1, | "idx": 1, | ||||
"index_web_pages_for_search": 1, | "index_web_pages_for_search": 1, | ||||
"istable": 1, | "istable": 1, | ||||
"links": [], | "links": [], | ||||
"modified": "2022-01-27 21:45:22.349776", | |||||
"modified": "2022-02-08 19:38:16.111199", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Custom", | "module": "Custom", | ||||
"name": "Customize Form Field", | "name": "Customize Form Field", | ||||
@@ -453,4 +460,4 @@ | |||||
"sort_field": "modified", | "sort_field": "modified", | ||||
"sort_order": "ASC", | "sort_order": "ASC", | ||||
"states": [] | "states": [] | ||||
} | |||||
} |
@@ -4,7 +4,7 @@ import frappe | |||||
def setup_database(force, source_sql=None, verbose=False): | def setup_database(force, source_sql=None, verbose=False): | ||||
root_conn = get_root_connection() | |||||
root_conn = get_root_connection(frappe.flags.root_login, frappe.flags.root_password) | |||||
root_conn.commit() | root_conn.commit() | ||||
root_conn.sql("DROP DATABASE IF EXISTS `{0}`".format(frappe.conf.db_name)) | root_conn.sql("DROP DATABASE IF EXISTS `{0}`".format(frappe.conf.db_name)) | ||||
root_conn.sql("DROP USER IF EXISTS {0}".format(frappe.conf.db_name)) | root_conn.sql("DROP USER IF EXISTS {0}".format(frappe.conf.db_name)) | ||||
@@ -70,7 +70,7 @@ def import_db_from_sql(source_sql=None, verbose=False): | |||||
print(f"\nSTDOUT by psql:\n{restore_proc.stdout.decode()}\nImported from Database File: {source_sql}") | print(f"\nSTDOUT by psql:\n{restore_proc.stdout.decode()}\nImported from Database File: {source_sql}") | ||||
def setup_help_database(help_db_name): | def setup_help_database(help_db_name): | ||||
root_conn = get_root_connection() | |||||
root_conn = get_root_connection(frappe.flags.root_login, frappe.flags.root_password) | |||||
root_conn.sql("DROP DATABASE IF EXISTS `{0}`".format(help_db_name)) | root_conn.sql("DROP DATABASE IF EXISTS `{0}`".format(help_db_name)) | ||||
root_conn.sql("DROP USER IF EXISTS {0}".format(help_db_name)) | root_conn.sql("DROP USER IF EXISTS {0}".format(help_db_name)) | ||||
root_conn.sql("CREATE DATABASE `{0}`".format(help_db_name)) | root_conn.sql("CREATE DATABASE `{0}`".format(help_db_name)) | ||||
@@ -392,7 +392,7 @@ def make_records(records, debug=False): | |||||
doc.flags.ignore_mandatory = True | doc.flags.ignore_mandatory = True | ||||
try: | try: | ||||
doc.insert(ignore_permissions=True, ignore_if_duplicate=True) | |||||
doc.insert(ignore_permissions=True) | |||||
frappe.db.commit() | frappe.db.commit() | ||||
except frappe.DuplicateEntryError as e: | except frappe.DuplicateEntryError as e: | ||||
@@ -20,11 +20,13 @@ class TestDomain(unittest.TestCase): | |||||
mail_domain = frappe.get_doc("Email Domain", "test.com") | mail_domain = frappe.get_doc("Email Domain", "test.com") | ||||
mail_account = frappe.get_doc("Email Account", "Test") | mail_account = frappe.get_doc("Email Account", "Test") | ||||
# Initially, incoming_port is different in domain and account | |||||
self.assertNotEqual(mail_account.incoming_port, mail_domain.incoming_port) | |||||
# Ensure a different port | |||||
mail_account.incoming_port = int(mail_domain.incoming_port) + 5 | |||||
mail_account.save() | |||||
# Trigger update of accounts using this domain | # Trigger update of accounts using this domain | ||||
mail_domain.on_update() | mail_domain.on_update() | ||||
mail_account = frappe.get_doc("Email Account", "Test") | |||||
mail_account.reload() | |||||
# After update, incoming_port in account should match the domain | # After update, incoming_port in account should match the domain | ||||
self.assertEqual(mail_account.incoming_port, mail_domain.incoming_port) | self.assertEqual(mail_account.incoming_port, mail_domain.incoming_port) | ||||
@@ -14,8 +14,8 @@ from frappe.defaults import _clear_cache | |||||
def _new_site( | def _new_site( | ||||
db_name, | db_name, | ||||
site, | site, | ||||
mariadb_root_username=None, | |||||
mariadb_root_password=None, | |||||
db_root_username=None, | |||||
db_root_password=None, | |||||
admin_password=None, | admin_password=None, | ||||
verbose=False, | verbose=False, | ||||
install_apps=None, | install_apps=None, | ||||
@@ -60,8 +60,8 @@ def _new_site( | |||||
installing = touch_file(get_site_path("locks", "installing.lock")) | installing = touch_file(get_site_path("locks", "installing.lock")) | ||||
install_db( | install_db( | ||||
root_login=mariadb_root_username, | |||||
root_password=mariadb_root_password, | |||||
root_login=db_root_username, | |||||
root_password=db_root_password, | |||||
db_name=db_name, | db_name=db_name, | ||||
admin_password=admin_password, | admin_password=admin_password, | ||||
verbose=verbose, | verbose=verbose, | ||||
@@ -92,7 +92,7 @@ def _new_site( | |||||
print("*** Scheduler is", scheduler_status, "***") | print("*** Scheduler is", scheduler_status, "***") | ||||
def install_db(root_login="root", root_password=None, db_name=None, source_sql=None, | |||||
def install_db(root_login=None, root_password=None, db_name=None, source_sql=None, | |||||
admin_password=None, verbose=True, force=0, site_config=None, reinstall=False, | admin_password=None, verbose=True, force=0, site_config=None, reinstall=False, | ||||
db_password=None, db_type=None, db_host=None, db_port=None, no_mariadb_socket=False): | db_password=None, db_type=None, db_host=None, db_port=None, no_mariadb_socket=False): | ||||
import frappe.database | import frappe.database | ||||
@@ -101,6 +101,11 @@ def install_db(root_login="root", root_password=None, db_name=None, source_sql=N | |||||
if not db_type: | if not db_type: | ||||
db_type = frappe.conf.db_type or 'mariadb' | db_type = frappe.conf.db_type or 'mariadb' | ||||
if not root_login and db_type == 'mariadb': | |||||
root_login='root' | |||||
elif not root_login and db_type == 'postgres': | |||||
root_login='postgres' | |||||
make_conf(db_name, site_config=site_config, db_password=db_password, db_type=db_type, db_host=db_host, db_port=db_port) | make_conf(db_name, site_config=site_config, db_password=db_password, db_type=db_type, db_host=db_host, db_port=db_port) | ||||
frappe.flags.in_install_db = True | frappe.flags.in_install_db = True | ||||
@@ -38,6 +38,7 @@ | |||||
"local_ca_certs_file", | "local_ca_certs_file", | ||||
"ldap_custom_settings_section", | "ldap_custom_settings_section", | ||||
"ldap_group_objectclass", | "ldap_group_objectclass", | ||||
"ldap_custom_group_search", | |||||
"column_break_33", | "column_break_33", | ||||
"ldap_group_member_attribute", | "ldap_group_member_attribute", | ||||
"ldap_group_mappings_section", | "ldap_group_mappings_section", | ||||
@@ -247,6 +248,12 @@ | |||||
"fieldtype": "Data", | "fieldtype": "Data", | ||||
"label": "Group Object Class" | "label": "Group Object Class" | ||||
}, | }, | ||||
{ | |||||
"description": "string value, i.e. {0} or uid={0},ou=users,dc=example,dc=com", | |||||
"fieldname": "ldap_custom_group_search", | |||||
"fieldtype": "Data", | |||||
"label": "Custom Group Search" | |||||
}, | |||||
{ | { | ||||
"description": "Requires any valid fdn path. i.e. ou=users,dc=example,dc=com", | "description": "Requires any valid fdn path. i.e. ou=users,dc=example,dc=com", | ||||
"fieldname": "ldap_search_path_user", | "fieldname": "ldap_search_path_user", | ||||
@@ -49,6 +49,10 @@ class LDAPSettings(Document): | |||||
frappe.throw(_("Custom LDAP Directoy Selected, please ensure 'LDAP Group Member attribute' and 'Group Object Class' are entered"), | frappe.throw(_("Custom LDAP Directoy Selected, please ensure 'LDAP Group Member attribute' and 'Group Object Class' are entered"), | ||||
title=_("Misconfigured")) | title=_("Misconfigured")) | ||||
if self.ldap_custom_group_search and "{0}" not in self.ldap_custom_group_search: | |||||
frappe.throw(_("Custom Group Search if filled needs to contain the user placeholder {0}, eg uid={0},ou=users,dc=example,dc=com"), | |||||
title=_("Misconfigured")) | |||||
else: | else: | ||||
frappe.throw(_("LDAP Search String must be enclosed in '()' and needs to contian the user placeholder {0}, eg sAMAccountName={0}")) | frappe.throw(_("LDAP Search String must be enclosed in '()' and needs to contian the user placeholder {0}, eg sAMAccountName={0}")) | ||||
@@ -209,7 +213,8 @@ class LDAPSettings(Document): | |||||
ldap_object_class = self.ldap_group_objectclass | ldap_object_class = self.ldap_group_objectclass | ||||
ldap_group_members_attribute = self.ldap_group_member_attribute | ldap_group_members_attribute = self.ldap_group_member_attribute | ||||
user_search_str = getattr(user, self.ldap_username_field).value | |||||
ldap_custom_group_search = self.ldap_custom_group_search or "{0}" | |||||
user_search_str = ldap_custom_group_search.format(getattr(user, self.ldap_username_field).value) | |||||
else: | else: | ||||
# NOTE: depreciate this else path | # NOTE: depreciate this else path | ||||
@@ -1,6 +1,7 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | ||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
from typing import Optional | |||||
import frappe | import frappe | ||||
from frappe import _ | from frappe import _ | ||||
from frappe.utils import now_datetime, cint, cstr | from frappe.utils import now_datetime, cint, cstr | ||||
@@ -283,7 +284,7 @@ def get_default_naming_series(doctype): | |||||
return None | return None | ||||
def validate_name(doctype, name, case=None, merge=False): | |||||
def validate_name(doctype: str, name: str, case: Optional[str] = None): | |||||
if not name: | if not name: | ||||
frappe.throw(_("No Name Specified for {0}").format(doctype)) | frappe.throw(_("No Name Specified for {0}").format(doctype)) | ||||
if name.startswith("New "+doctype): | if name.startswith("New "+doctype): | ||||
@@ -1,48 +1,80 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
from typing import TYPE_CHECKING, Dict, List, Optional | |||||
import frappe | import frappe | ||||
from frappe import _, bold | from frappe import _, bold | ||||
from frappe.model.dynamic_links import get_dynamic_link_map | from frappe.model.dynamic_links import get_dynamic_link_map | ||||
from frappe.model.naming import validate_name | from frappe.model.naming import validate_name | ||||
from frappe.model.utils.user_settings import sync_user_settings, update_user_settings_data | from frappe.model.utils.user_settings import sync_user_settings, update_user_settings_data | ||||
from frappe.query_builder import Field | |||||
from frappe.utils import cint | from frappe.utils import cint | ||||
from frappe.utils.password import rename_password | from frappe.utils.password import rename_password | ||||
from frappe.query_builder import Field | |||||
if TYPE_CHECKING: | |||||
from frappe.model.meta import Meta | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def update_document_title(doctype, docname, title_field=None, old_title=None, new_title=None, new_name=None, merge=False): | |||||
def update_document_title( | |||||
*, | |||||
doctype: str, | |||||
docname: str, | |||||
title: Optional[str] = None, | |||||
name: Optional[str] = None, | |||||
merge: bool = False, | |||||
**kwargs | |||||
) -> str: | |||||
""" | """ | ||||
Update title from header in form view | Update title from header in form view | ||||
""" | """ | ||||
if docname and new_name and not docname == new_name: | |||||
docname = rename_doc(doctype=doctype, old=docname, new=new_name, merge=merge) | |||||
if old_title and new_title and not old_title == new_title: | |||||
# to maintain backwards API compatibility | |||||
updated_title = kwargs.get("new_title") or title | |||||
updated_name = kwargs.get("new_name") or name | |||||
# TODO: omit this after runtime type checking (ref: https://github.com/frappe/frappe/pull/14927) | |||||
for obj in [docname, updated_title, updated_name]: | |||||
if not isinstance(obj, (str, type(None))): | |||||
frappe.throw(f"{obj=} must be of type str or None") | |||||
doc = frappe.get_doc(doctype, docname) | |||||
doc.check_permission(permtype="write") | |||||
title_field = doc.meta.get_title_field() | |||||
title_updated = (title_field != "name") and (updated_title != doc.get(title_field)) | |||||
name_updated = updated_name != doc.name | |||||
if name_updated: | |||||
docname = rename_doc(doctype=doctype, old=docname, new=updated_name, merge=merge) | |||||
if title_updated: | |||||
try: | try: | ||||
frappe.db.set_value(doctype, docname, title_field, new_title) | |||||
frappe.msgprint(_('Saved'), alert=True, indicator='green') | |||||
frappe.db.set_value(doctype, docname, title_field, updated_title) | |||||
frappe.msgprint(_("Saved"), alert=True, indicator="green") | |||||
except Exception as e: | except Exception as e: | ||||
if frappe.db.is_duplicate_entry(e): | if frappe.db.is_duplicate_entry(e): | ||||
frappe.throw( | frappe.throw( | ||||
_("{0} {1} already exists").format(doctype, frappe.bold(docname)), | _("{0} {1} already exists").format(doctype, frappe.bold(docname)), | ||||
title=_("Duplicate Name"), | title=_("Duplicate Name"), | ||||
exc=frappe.DuplicateEntryError | |||||
exc=frappe.DuplicateEntryError, | |||||
) | ) | ||||
raise | |||||
return docname | return docname | ||||
def rename_doc( | def rename_doc( | ||||
doctype, | |||||
old, | |||||
new, | |||||
force=False, | |||||
merge=False, | |||||
ignore_permissions=False, | |||||
ignore_if_exists=False, | |||||
show_alert=True, | |||||
rebuild_search=True | |||||
): | |||||
doctype: str, | |||||
old: str, | |||||
new: str, | |||||
force: bool = False, | |||||
merge: bool = False, | |||||
ignore_permissions: bool = False, | |||||
ignore_if_exists: bool = False, | |||||
show_alert: bool = True, | |||||
rebuild_search: bool = True, | |||||
) -> str: | |||||
"""Rename a doc(dt, old) to doc(dt, new) and update all linked fields of type "Link".""" | """Rename a doc(dt, old) to doc(dt, new) and update all linked fields of type "Link".""" | ||||
if not frappe.db.exists(doctype, old): | if not frappe.db.exists(doctype, old): | ||||
return | return | ||||
@@ -79,7 +111,7 @@ def rename_doc( | |||||
update_user_settings(old, new, link_fields) | update_user_settings(old, new, link_fields) | ||||
if doctype=='DocType': | if doctype=='DocType': | ||||
rename_doctype(doctype, old, new, force) | |||||
rename_doctype(doctype, old, new) | |||||
update_customizations(old, new) | update_customizations(old, new) | ||||
update_attachments(doctype, old, new) | update_attachments(doctype, old, new) | ||||
@@ -121,7 +153,7 @@ def rename_doc( | |||||
return new | return new | ||||
def update_assignments(old, new, doctype): | |||||
def update_assignments(old: str, new: str, doctype: str) -> None: | |||||
old_assignments = frappe.parse_json(frappe.db.get_value(doctype, old, '_assign')) or [] | old_assignments = frappe.parse_json(frappe.db.get_value(doctype, old, '_assign')) or [] | ||||
new_assignments = frappe.parse_json(frappe.db.get_value(doctype, new, '_assign')) or [] | new_assignments = frappe.parse_json(frappe.db.get_value(doctype, new, '_assign')) or [] | ||||
common_assignments = list(set(old_assignments).intersection(new_assignments)) | common_assignments = list(set(old_assignments).intersection(new_assignments)) | ||||
@@ -143,7 +175,7 @@ def update_assignments(old, new, doctype): | |||||
unique_assignments = list(set(old_assignments + new_assignments)) | unique_assignments = list(set(old_assignments + new_assignments)) | ||||
frappe.db.set_value(doctype, new, '_assign', frappe.as_json(unique_assignments, indent=0)) | frappe.db.set_value(doctype, new, '_assign', frappe.as_json(unique_assignments, indent=0)) | ||||
def update_user_settings(old, new, link_fields): | |||||
def update_user_settings(old: str, new: str, link_fields: List[Dict]) -> None: | |||||
''' | ''' | ||||
Update the user settings of all the linked doctypes while renaming. | Update the user settings of all the linked doctypes while renaming. | ||||
''' | ''' | ||||
@@ -178,7 +210,7 @@ def update_user_settings(old, new, link_fields): | |||||
def update_customizations(old: str, new: str) -> None: | def update_customizations(old: str, new: str) -> None: | ||||
frappe.db.set_value("Custom DocPerm", {"parent": old}, "parent", new, update_modified=False) | frappe.db.set_value("Custom DocPerm", {"parent": old}, "parent", new, update_modified=False) | ||||
def update_attachments(doctype, old, new): | |||||
def update_attachments(doctype: str, old: str, new: str) -> None: | |||||
try: | try: | ||||
if old != "File Data" and doctype != "DocType": | if old != "File Data" and doctype != "DocType": | ||||
frappe.db.sql("""update `tabFile` set attached_to_name=%s | frappe.db.sql("""update `tabFile` set attached_to_name=%s | ||||
@@ -187,11 +219,11 @@ def update_attachments(doctype, old, new): | |||||
if not frappe.db.is_column_missing(e): | if not frappe.db.is_column_missing(e): | ||||
raise | raise | ||||
def rename_versions(doctype, old, new): | |||||
def rename_versions(doctype: str, old: str, new: str) -> None: | |||||
frappe.db.sql("""UPDATE `tabVersion` SET `docname`=%s WHERE `ref_doctype`=%s AND `docname`=%s""", | frappe.db.sql("""UPDATE `tabVersion` SET `docname`=%s WHERE `ref_doctype`=%s AND `docname`=%s""", | ||||
(new, doctype, old)) | (new, doctype, old)) | ||||
def rename_eps_records(doctype, old, new): | |||||
def rename_eps_records(doctype: str, old: str, new: str) -> None: | |||||
epl = frappe.qb.DocType("Energy Point Log") | epl = frappe.qb.DocType("Energy Point Log") | ||||
(frappe.qb.update(epl) | (frappe.qb.update(epl) | ||||
.set(epl.reference_name, new) | .set(epl.reference_name, new) | ||||
@@ -201,20 +233,20 @@ def rename_eps_records(doctype, old, new): | |||||
) | ) | ||||
).run() | ).run() | ||||
def rename_parent_and_child(doctype, old, new, meta): | |||||
def rename_parent_and_child(doctype: str, old: str, new: str, meta: "Meta") -> None: | |||||
# rename the doc | # rename the doc | ||||
frappe.db.sql("UPDATE `tab{0}` SET `name`={1} WHERE `name`={1}".format(doctype, '%s'), (new, old)) | frappe.db.sql("UPDATE `tab{0}` SET `name`={1} WHERE `name`={1}".format(doctype, '%s'), (new, old)) | ||||
update_autoname_field(doctype, new, meta) | update_autoname_field(doctype, new, meta) | ||||
update_child_docs(old, new, meta) | update_child_docs(old, new, meta) | ||||
def update_autoname_field(doctype, new, meta): | |||||
def update_autoname_field(doctype: str, new: str, meta: "Meta") -> None: | |||||
# update the value of the autoname field on rename of the docname | # update the value of the autoname field on rename of the docname | ||||
if meta.get('autoname'): | if meta.get('autoname'): | ||||
field = meta.get('autoname').split(':') | field = meta.get('autoname').split(':') | ||||
if field and field[0] == "field": | if field and field[0] == "field": | ||||
frappe.db.sql("UPDATE `tab{0}` SET `{1}`={2} WHERE `name`={2}".format(doctype, field[1], '%s'), (new, new)) | frappe.db.sql("UPDATE `tab{0}` SET `{1}`={2} WHERE `name`={2}".format(doctype, field[1], '%s'), (new, new)) | ||||
def validate_rename(doctype, new, meta, merge, force, ignore_permissions): | |||||
def validate_rename(doctype: str, new: str, meta: "Meta", merge: bool, force: bool, ignore_permissions: bool) -> str: | |||||
# using for update so that it gets locked and someone else cannot edit it while this rename is going on! | # using for update so that it gets locked and someone else cannot edit it while this rename is going on! | ||||
exists = ( | exists = ( | ||||
frappe.qb.from_(doctype) | frappe.qb.from_(doctype) | ||||
@@ -226,27 +258,27 @@ def validate_rename(doctype, new, meta, merge, force, ignore_permissions): | |||||
exists = exists[0] if exists else None | exists = exists[0] if exists else None | ||||
if merge and not exists: | if merge and not exists: | ||||
frappe.msgprint(_("{0} {1} does not exist, select a new target to merge").format(doctype, new), raise_exception=1) | |||||
frappe.throw(_("{0} {1} does not exist, select a new target to merge").format(doctype, new)) | |||||
if exists and exists != new: | if exists and exists != new: | ||||
# for fixing case, accents | # for fixing case, accents | ||||
exists = None | exists = None | ||||
if (not merge) and exists: | if (not merge) and exists: | ||||
frappe.msgprint(_("Another {0} with name {1} exists, select another name").format(doctype, new), raise_exception=1) | |||||
frappe.throw(_("Another {0} with name {1} exists, select another name").format(doctype, new)) | |||||
if not (ignore_permissions or frappe.permissions.has_permission(doctype, "write", raise_exception=False)): | if not (ignore_permissions or frappe.permissions.has_permission(doctype, "write", raise_exception=False)): | ||||
frappe.msgprint(_("You need write permission to rename"), raise_exception=1) | |||||
frappe.throw(_("You need write permission to rename")) | |||||
if not (force or ignore_permissions) and not meta.allow_rename: | if not (force or ignore_permissions) and not meta.allow_rename: | ||||
frappe.msgprint(_("{0} not allowed to be renamed").format(_(doctype)), raise_exception=1) | |||||
frappe.throw(_("{0} not allowed to be renamed").format(_(doctype))) | |||||
# validate naming like it's done in doc.py | # validate naming like it's done in doc.py | ||||
new = validate_name(doctype, new, merge=merge) | |||||
new = validate_name(doctype, new) | |||||
return new | return new | ||||
def rename_doctype(doctype, old, new, force=False): | |||||
def rename_doctype(doctype: str, old: str, new: str) -> None: | |||||
# change options for fieldtype Table, Table MultiSelect and Link | # change options for fieldtype Table, Table MultiSelect and Link | ||||
fields_with_options = ("Link",) + frappe.model.table_fields | fields_with_options = ("Link",) + frappe.model.table_fields | ||||
@@ -261,13 +293,13 @@ def rename_doctype(doctype, old, new, force=False): | |||||
# change parenttype for fieldtype Table | # change parenttype for fieldtype Table | ||||
update_parenttype_values(old, new) | update_parenttype_values(old, new) | ||||
def update_child_docs(old, new, meta): | |||||
def update_child_docs(old: str, new: str, meta: "Meta") -> None: | |||||
# update "parent" | # update "parent" | ||||
for df in meta.get_table_fields(): | for df in meta.get_table_fields(): | ||||
frappe.db.sql("update `tab%s` set parent=%s where parent=%s" \ | frappe.db.sql("update `tab%s` set parent=%s where parent=%s" \ | ||||
% (df.options, '%s', '%s'), (new, old)) | % (df.options, '%s', '%s'), (new, old)) | ||||
def update_link_field_values(link_fields, old, new, doctype): | |||||
def update_link_field_values(link_fields: List[Dict], old: str, new: str, doctype: str) -> None: | |||||
for field in link_fields: | for field in link_fields: | ||||
if field['issingle']: | if field['issingle']: | ||||
try: | try: | ||||
@@ -302,7 +334,7 @@ def update_link_field_values(link_fields, old, new, doctype): | |||||
if doctype=='DocType' and field['parent'] == old: | if doctype=='DocType' and field['parent'] == old: | ||||
field['parent'] = new | field['parent'] = new | ||||
def get_link_fields(doctype): | |||||
def get_link_fields(doctype: str) -> List[Dict]: | |||||
# get link fields from tabDocField | # get link fields from tabDocField | ||||
if not frappe.flags.link_fields: | if not frappe.flags.link_fields: | ||||
frappe.flags.link_fields = {} | frappe.flags.link_fields = {} | ||||
@@ -345,7 +377,7 @@ def get_link_fields(doctype): | |||||
return frappe.flags.link_fields[doctype] | return frappe.flags.link_fields[doctype] | ||||
def update_options_for_fieldtype(fieldtype, old, new): | |||||
def update_options_for_fieldtype(fieldtype: str, old: str, new: str) -> None: | |||||
if frappe.conf.developer_mode: | if frappe.conf.developer_mode: | ||||
for name in frappe.get_all("DocField", filters={"options": old}, pluck="parent"): | for name in frappe.get_all("DocField", filters={"options": old}, pluck="parent"): | ||||
doctype = frappe.get_doc("DocType", name) | doctype = frappe.get_doc("DocType", name) | ||||
@@ -366,7 +398,7 @@ def update_options_for_fieldtype(fieldtype, old, new): | |||||
frappe.db.sql("""update `tabProperty Setter` set value=%s | frappe.db.sql("""update `tabProperty Setter` set value=%s | ||||
where property='options' and value=%s""", (new, old)) | where property='options' and value=%s""", (new, old)) | ||||
def get_select_fields(old, new): | |||||
def get_select_fields(old: str, new: str) -> List[Dict]: | |||||
""" | """ | ||||
get select type fields where doctype's name is hardcoded as | get select type fields where doctype's name is hardcoded as | ||||
new line separated list | new line separated list | ||||
@@ -410,7 +442,7 @@ def get_select_fields(old, new): | |||||
return select_fields | return select_fields | ||||
def update_select_field_values(old, new): | |||||
def update_select_field_values(old: str, new: str): | |||||
frappe.db.sql(""" | frappe.db.sql(""" | ||||
update `tabDocField` set options=replace(options, %s, %s) | update `tabDocField` set options=replace(options, %s, %s) | ||||
where | where | ||||
@@ -433,7 +465,7 @@ def update_select_field_values(old, new): | |||||
(value like {0} or value like {1})""" | (value like {0} or value like {1})""" | ||||
.format(frappe.db.escape('%' + '\n' + old + '%'), frappe.db.escape('%' + old + '\n' + '%')), (old, new, new)) | .format(frappe.db.escape('%' + '\n' + old + '%'), frappe.db.escape('%' + old + '\n' + '%')), (old, new, new)) | ||||
def update_parenttype_values(old, new): | |||||
def update_parenttype_values(old: str, new: str): | |||||
child_doctypes = frappe.db.get_all('DocField', | child_doctypes = frappe.db.get_all('DocField', | ||||
fields=['options', 'fieldname'], | fields=['options', 'fieldname'], | ||||
filters={ | filters={ | ||||
@@ -469,7 +501,7 @@ def update_parenttype_values(old, new): | |||||
for doctype in child_doctypes: | for doctype in child_doctypes: | ||||
frappe.db.sql(f"update `tab{doctype}` set parenttype=%s where parenttype=%s", (new, old)) | frappe.db.sql(f"update `tab{doctype}` set parenttype=%s where parenttype=%s", (new, old)) | ||||
def rename_dynamic_links(doctype, old, new): | |||||
def rename_dynamic_links(doctype: str, old: str, new: str): | |||||
for df in get_dynamic_link_map().get(doctype, []): | for df in get_dynamic_link_map().get(doctype, []): | ||||
# dynamic link in single, just one value to check | # dynamic link in single, just one value to check | ||||
if frappe.get_meta(df.parent).issingle: | if frappe.get_meta(df.parent).issingle: | ||||
@@ -485,7 +517,7 @@ def rename_dynamic_links(doctype, old, new): | |||||
where {options}=%s and {fieldname}=%s""".format(parent = parent, | where {options}=%s and {fieldname}=%s""".format(parent = parent, | ||||
fieldname=df.fieldname, options=df.options), (new, doctype, old)) | fieldname=df.fieldname, options=df.options), (new, doctype, old)) | ||||
def bulk_rename(doctype, rows=None, via_console = False): | |||||
def bulk_rename(doctype: str, rows: Optional[List[List]] = None, via_console: bool = False) -> Optional[List[str]]: | |||||
"""Bulk rename documents | """Bulk rename documents | ||||
:param doctype: DocType to be renamed | :param doctype: DocType to be renamed | ||||
@@ -523,7 +555,7 @@ def bulk_rename(doctype, rows=None, via_console = False): | |||||
if not via_console: | if not via_console: | ||||
return rename_log | return rename_log | ||||
def update_linked_doctypes(doctype, docname, linked_to, value, ignore_doctypes=None): | |||||
def update_linked_doctypes(doctype: str, docname: str, linked_to: str, value: str, ignore_doctypes: Optional[List] = None) -> None: | |||||
from frappe.model.utils.rename_doc import update_linked_doctypes | from frappe.model.utils.rename_doc import update_linked_doctypes | ||||
show_deprecation_warning("update_linked_doctypes") | show_deprecation_warning("update_linked_doctypes") | ||||
@@ -536,7 +568,7 @@ def update_linked_doctypes(doctype, docname, linked_to, value, ignore_doctypes=N | |||||
) | ) | ||||
def get_fetch_fields(doctype, linked_to, ignore_doctypes=None): | |||||
def get_fetch_fields(doctype: str, linked_to: str, ignore_doctypes: Optional[List] = None) -> List[Dict]: | |||||
from frappe.model.utils.rename_doc import get_fetch_fields | from frappe.model.utils.rename_doc import get_fetch_fields | ||||
show_deprecation_warning("get_fetch_fields") | show_deprecation_warning("get_fetch_fields") | ||||
@@ -544,7 +576,7 @@ def get_fetch_fields(doctype, linked_to, ignore_doctypes=None): | |||||
doctype=doctype, linked_to=linked_to, ignore_doctypes=ignore_doctypes | doctype=doctype, linked_to=linked_to, ignore_doctypes=ignore_doctypes | ||||
) | ) | ||||
def show_deprecation_warning(funct): | |||||
def show_deprecation_warning(funct: str) -> None: | |||||
from click import secho | from click import secho | ||||
message = ( | message = ( | ||||
f"Function frappe.model.rename_doc.{funct} has been deprecated and " | f"Function frappe.model.rename_doc.{funct} has been deprecated and " | ||||
@@ -1,10 +1,14 @@ | |||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# License: MIT. See LICENSE | |||||
from itertools import product | from itertools import product | ||||
from typing import Dict, List, Optional | |||||
import frappe | import frappe | ||||
from frappe.model.rename_doc import get_link_fields | from frappe.model.rename_doc import get_link_fields | ||||
def update_linked_doctypes(doctype, docname, linked_to, value, ignore_doctypes=None): | |||||
def update_linked_doctypes(doctype: str, docname: str, linked_to: str, value: str, ignore_doctypes: Optional[List] = None): | |||||
""" | """ | ||||
linked_doctype_info_list = list formed by get_fetch_fields() function | linked_doctype_info_list = list formed by get_fetch_fields() function | ||||
docname = Master DocType's name in which modification are made | docname = Master DocType's name in which modification are made | ||||
@@ -24,7 +28,7 @@ def update_linked_doctypes(doctype, docname, linked_to, value, ignore_doctypes=N | |||||
) | ) | ||||
def get_fetch_fields(doctype, linked_to, ignore_doctypes=None): | |||||
def get_fetch_fields(doctype: str, linked_to: str, ignore_doctypes: Optional[List] = None) -> List[Dict]: | |||||
""" | """ | ||||
doctype = Master DocType in which the changes are being made | doctype = Master DocType in which the changes are being made | ||||
linked_to = DocType name of the field thats being updated in Master | linked_to = DocType name of the field thats being updated in Master | ||||
@@ -1102,13 +1102,13 @@ frappe.ui.form.Form = class FrappeForm { | |||||
let list_view = frappe.get_list_view(this.doctype); | let list_view = frappe.get_list_view(this.doctype); | ||||
if (list_view) { | if (list_view) { | ||||
filters = list_view.get_filters_for_args(); | filters = list_view.get_filters_for_args(); | ||||
sort_field = list_view.sort_field; | |||||
sort_field = list_view.sort_by; | |||||
sort_order = list_view.sort_order; | sort_order = list_view.sort_order; | ||||
} else { | } else { | ||||
let list_settings = frappe.get_user_settings(this.doctype)['List']; | let list_settings = frappe.get_user_settings(this.doctype)['List']; | ||||
if (list_settings) { | if (list_settings) { | ||||
filters = list_settings.filters; | filters = list_settings.filters; | ||||
sort_field = list_settings.sort_field; | |||||
sort_field = list_settings.sort_by; | |||||
sort_order = list_settings.sort_order; | sort_order = list_settings.sort_order; | ||||
} | } | ||||
} | } | ||||
@@ -101,10 +101,8 @@ frappe.ui.form.Toolbar = class Toolbar { | |||||
return frappe.xcall("frappe.model.rename_doc.update_document_title", { | return frappe.xcall("frappe.model.rename_doc.update_document_title", { | ||||
doctype, | doctype, | ||||
docname, | docname, | ||||
new_name, | |||||
title_field, | |||||
old_title: this.frm.doc[title_field], | |||||
new_title, | |||||
name: new_name, | |||||
title: new_title, | |||||
merge | merge | ||||
}).then(new_docname => { | }).then(new_docname => { | ||||
if (new_name != docname) { | if (new_name != docname) { | ||||
@@ -73,7 +73,7 @@ frappe.ui.LinkPreview = class { | |||||
} | } | ||||
this.popover_timeout = setTimeout(() => { | this.popover_timeout = setTimeout(() => { | ||||
if (this.popover) { | |||||
if (this.popover && this.popover.options) { | |||||
let new_content = this.get_popover_html(preview_data); | let new_content = this.get_popover_html(preview_data); | ||||
this.popover.options.content = new_content; | this.popover.options.content = new_content; | ||||
} else { | } else { | ||||
@@ -50,6 +50,10 @@ | |||||
&:last-child { | &:last-child { | ||||
padding-right: 0; | padding-right: 0; | ||||
} | } | ||||
@include media-breakpoint-down(sm) { | |||||
padding: 0; | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -55,9 +55,6 @@ def main(app=None, module=None, doctype=None, verbose=False, tests=(), | |||||
if not frappe.db: | if not frappe.db: | ||||
frappe.connect() | frappe.connect() | ||||
# if not frappe.conf.get("db_name").startswith("test_"): | |||||
# raise Exception, 'db_name must start with "test_"' | |||||
# workaround! since there is no separate test db | # workaround! since there is no separate test db | ||||
frappe.clear_cache() | frappe.clear_cache() | ||||
scheduler_disabled_by_user = frappe.utils.scheduler.is_scheduler_disabled() | scheduler_disabled_by_user = frappe.utils.scheduler.is_scheduler_disabled() | ||||
@@ -72,11 +72,14 @@ class FrappeAPITestCase(unittest.TestCase): | |||||
@property | @property | ||||
def sid(self) -> str: | def sid(self) -> str: | ||||
if not getattr(self, "_sid", None): | if not getattr(self, "_sid", None): | ||||
r = self.post("/api/method/login", { | |||||
"usr": "Administrator", | |||||
"pwd": frappe.conf.admin_password or "admin", | |||||
}) | |||||
self._sid = r.headers[2][1].split(";")[0].lstrip("sid=") | |||||
from frappe.auth import CookieManager, LoginManager | |||||
from frappe.utils import set_request | |||||
set_request(path="/") | |||||
frappe.local.cookie_manager = CookieManager() | |||||
frappe.local.login_manager = LoginManager() | |||||
frappe.local.login_manager.login_as('Administrator') | |||||
self._sid = frappe.session.sid | |||||
return self._sid | return self._sid | ||||
@@ -112,16 +115,6 @@ class TestResourceAPI(FrappeAPITestCase): | |||||
frappe.delete_doc_if_exists(cls.DOCTYPE, name) | frappe.delete_doc_if_exists(cls.DOCTYPE, name) | ||||
frappe.db.commit() | frappe.db.commit() | ||||
def setUp(self): | |||||
# commit to ensure consistency in session (postgres CI randomly fails) | |||||
if frappe.conf.db_type == "postgres": | |||||
frappe.db.commit() | |||||
if self._testMethodName == "test_auth_cycle": | |||||
from frappe.core.doctype.user.user import generate_keys | |||||
generate_keys("Administrator") | |||||
frappe.db.commit() | |||||
def test_unauthorized_call(self): | def test_unauthorized_call(self): | ||||
# test 1: fetch documents without auth | # test 1: fetch documents without auth | ||||
response = requests.get(f"{self.RESOURCE_URL}/{self.DOCTYPE}") | response = requests.get(f"{self.RESOURCE_URL}/{self.DOCTYPE}") | ||||
@@ -226,6 +219,12 @@ class TestResourceAPI(FrappeAPITestCase): | |||||
class TestMethodAPI(FrappeAPITestCase): | class TestMethodAPI(FrappeAPITestCase): | ||||
METHOD_PATH = "/api/method" | METHOD_PATH = "/api/method" | ||||
def setUp(self): | |||||
if self._testMethodName == "test_auth_cycle": | |||||
from frappe.core.doctype.user.user import generate_keys | |||||
generate_keys("Administrator") | |||||
frappe.db.commit() | |||||
def test_version(self): | def test_version(self): | ||||
# test 1: test for /api/method/version | # test 1: test for /api/method/version | ||||
response = self.get(f"{self.METHOD_PATH}/version") | response = self.get(f"{self.METHOD_PATH}/version") | ||||
@@ -1,9 +1,9 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
import unittest, frappe, re, email | import unittest, frappe, re, email | ||||
from frappe.email.doctype.email_account.test_email_account import TestEmailAccount | |||||
from frappe.email.doctype.email_account.test_email_account import TestEmailAccount | |||||
test_dependencies = ['Email Account'] | test_dependencies = ['Email Account'] | ||||
@@ -176,7 +176,6 @@ class TestEmail(unittest.TestCase): | |||||
with open(frappe.get_app_path('frappe', 'tests', 'data', 'email_with_image.txt'), 'r') as raw: | with open(frappe.get_app_path('frappe', 'tests', 'data', 'email_with_image.txt'), 'r') as raw: | ||||
messages = { | messages = { | ||||
# append_to = ToDo | |||||
'"INBOX"': { | '"INBOX"': { | ||||
'latest_messages': [ | 'latest_messages': [ | ||||
raw.read() | raw.read() | ||||
@@ -185,17 +184,20 @@ class TestEmail(unittest.TestCase): | |||||
2: 'UNSEEN' | 2: 'UNSEEN' | ||||
}, | }, | ||||
'uid_list': [2] | 'uid_list': [2] | ||||
} | |||||
} | |||||
} | } | ||||
email_account = frappe.get_doc("Email Account", "_Test Email Account 1") | email_account = frappe.get_doc("Email Account", "_Test Email Account 1") | ||||
changed_flag = False | changed_flag = False | ||||
if not email_account.enable_incoming: | |||||
if not email_account.enable_incoming: | |||||
email_account.enable_incoming = True | email_account.enable_incoming = True | ||||
changed_flag = True | changed_flag = True | ||||
mails = TestEmailAccount.mocked_get_inbound_mails(email_account, messages) | mails = TestEmailAccount.mocked_get_inbound_mails(email_account, messages) | ||||
# mails = email_account.get_inbound_mails(test_mails=[raw.read()]) | |||||
# TODO: fix this flaky test! - 'IndexError: list index out of range' for `.process()` line | |||||
if not mails: | |||||
raise self.skipTest("No inbound mails found / Email Account wasn't patched properly") | |||||
communication = mails[0].process() | communication = mails[0].process() | ||||
self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco1.png[^>]*>''', communication.content)) | self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco1.png[^>]*>''', communication.content)) | ||||
@@ -1,17 +1,30 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# License: MIT. See LICENSE | # License: MIT. See LICENSE | ||||
import unittest, frappe | |||||
import base64 | |||||
import unittest | |||||
import requests | |||||
import frappe | |||||
from frappe.core.doctype.user.user import generate_keys | from frappe.core.doctype.user.user import generate_keys | ||||
from frappe.frappeclient import FrappeClient, FrappeException | |||||
from frappe.frappeclient import AuthError, FrappeClient, FrappeException | |||||
from frappe.utils.data import get_url | from frappe.utils.data import get_url | ||||
import requests | |||||
import base64 | |||||
class TestFrappeClient(unittest.TestCase): | class TestFrappeClient(unittest.TestCase): | ||||
PASSWORD = frappe.conf.admin_password or "admin" | PASSWORD = frappe.conf.admin_password or "admin" | ||||
@classmethod | |||||
def setUpClass(cls) -> None: | |||||
site_url = get_url() | |||||
try: | |||||
FrappeClient(site_url, "Administrator", cls.PASSWORD, verify=False) | |||||
except AuthError: | |||||
raise unittest.SkipTest(f"AuthError raised for {site_url} [usr=Administrator, pwd={cls.PASSWORD}]") | |||||
return super().setUpClass() | |||||
def test_insert_many(self): | def test_insert_many(self): | ||||
server = FrappeClient(get_url(), "Administrator", self.PASSWORD, verify=False) | server = FrappeClient(get_url(), "Administrator", self.PASSWORD, verify=False) | ||||
frappe.db.delete("Note", {"title": ("in", ('Sing','a','song','of','sixpence'))}) | frappe.db.delete("Note", {"title": ("in", ('Sing','a','song','of','sixpence'))}) | ||||
@@ -1,13 +1,40 @@ | |||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# License: MIT. See LICENSE | |||||
import os | import os | ||||
import unittest | import unittest | ||||
from contextlib import contextmanager, redirect_stdout | |||||
from io import StringIO | |||||
from random import choice, sample | |||||
from typing import List | |||||
from unittest.mock import patch | |||||
import frappe | import frappe | ||||
from frappe.utils import add_to_date, now | |||||
from frappe.exceptions import DoesNotExistError | |||||
from random import choice, sample | |||||
from frappe.exceptions import DoesNotExistError, ValidationError | |||||
from frappe.model.base_document import get_controller | from frappe.model.base_document import get_controller | ||||
from frappe.model.rename_doc import bulk_rename, get_fetch_fields, update_document_title, update_linked_doctypes | |||||
from frappe.modules.utils import get_doc_path | from frappe.modules.utils import get_doc_path | ||||
from frappe.utils import add_to_date, now | |||||
@contextmanager | |||||
def patch_db(endpoints: List[str] = None): | |||||
patched_endpoints = [] | |||||
for point in endpoints: | |||||
x = patch(f"frappe.db.{point}", new=lambda: True) | |||||
patched_endpoints.append(x) | |||||
savepoint = "SAVEPOINT_for_test_bulk_rename" | |||||
frappe.db.savepoint(save_point=savepoint) | |||||
try: | |||||
for x in patched_endpoints: | |||||
x.start() | |||||
yield | |||||
finally: | |||||
for x in patched_endpoints: | |||||
x.stop() | |||||
frappe.db.rollback(save_point=savepoint) | |||||
class TestRenameDoc(unittest.TestCase): | class TestRenameDoc(unittest.TestCase): | ||||
@@ -50,6 +77,11 @@ class TestRenameDoc(unittest.TestCase): | |||||
@classmethod | @classmethod | ||||
def tearDownClass(self): | def tearDownClass(self): | ||||
"""Deleting data generated for the tests defined under TestRenameDoc""" | """Deleting data generated for the tests defined under TestRenameDoc""" | ||||
# delete_doc doesnt drop tables | |||||
# this is done to bypass inconsistencies in the db | |||||
frappe.delete_doc_if_exists("DocType", "Renamed Doc") | |||||
frappe.db.sql_ddl("drop table if exists `tabRenamed Doc`") | |||||
# delete the documents created | # delete the documents created | ||||
for docname in self.available_documents: | for docname in self.available_documents: | ||||
frappe.delete_doc(self.test_doctype, docname) | frappe.delete_doc(self.test_doctype, docname) | ||||
@@ -153,7 +185,55 @@ class TestRenameDoc(unittest.TestCase): | |||||
new_name, frappe.rename_doc("Renamed Doc", old_name, new_name, force=True) | new_name, frappe.rename_doc("Renamed Doc", old_name, new_name, force=True) | ||||
) | ) | ||||
# delete_doc doesnt drop tables | |||||
# this is done to bypass inconsistencies in the db | |||||
frappe.delete_doc_if_exists("DocType", "Renamed Doc") | |||||
frappe.db.sql_ddl("drop table if exists `tabRenamed Doc`") | |||||
def test_update_document_title_api(self): | |||||
test_doctype = "Module Def" | |||||
test_doc = frappe.get_doc({ | |||||
"doctype": test_doctype, | |||||
"module_name": f"Test-test_update_document_title_api-{frappe.generate_hash()}", | |||||
"custom": True, | |||||
}) | |||||
test_doc.insert(ignore_mandatory=True) | |||||
dt = test_doc.doctype | |||||
dn = test_doc.name | |||||
new_name = f"{dn}-new" | |||||
# pass invalid types to API | |||||
with self.assertRaises(ValidationError): | |||||
update_document_title(doctype=dt, docname=dn, title={}, name={"hack": "this"}) | |||||
doc_before = frappe.get_doc(test_doctype, dn) | |||||
return_value = update_document_title(doctype=dt, docname=dn, new_name=new_name) | |||||
doc_after = frappe.get_doc(test_doctype, return_value) | |||||
doc_before_dict = doc_before.as_dict(no_nulls=True, no_default_fields=True) | |||||
doc_after_dict = doc_after.as_dict(no_nulls=True, no_default_fields=True) | |||||
doc_before_dict.pop("module_name") | |||||
doc_after_dict.pop("module_name") | |||||
self.assertEqual(new_name, return_value) | |||||
self.assertDictEqual(doc_before_dict, doc_after_dict) | |||||
self.assertEqual(doc_after.module_name, return_value) | |||||
test_doc.delete() | |||||
def test_bulk_rename(self): | |||||
input_data = [[x, f"{x}-new"] for x in self.available_documents] | |||||
with patch_db(["commit", "rollback"]), patch("frappe.enqueue") as enqueue: | |||||
message_log = bulk_rename(self.test_doctype, input_data, via_console=False) | |||||
self.assertEqual(len(message_log), len(self.available_documents)) | |||||
self.assertIsInstance(message_log, list) | |||||
enqueue.assert_called_with( | |||||
'frappe.utils.global_search.rebuild_for_doctype', doctype=self.test_doctype, | |||||
) | |||||
def test_deprecated_utils(self): | |||||
stdout = StringIO() | |||||
with redirect_stdout(stdout), patch_db(["set_value"]): | |||||
get_fetch_fields("User", "ToDo", ["Activity Log"]) | |||||
self.assertTrue("Function frappe.model.rename_doc.get_fetch_fields" in stdout.getvalue()) | |||||
update_linked_doctypes("User", "ToDo", "str", "str") | |||||
self.assertTrue("Function frappe.model.rename_doc.update_linked_doctypes" in stdout.getvalue()) |
@@ -97,13 +97,10 @@ def get_jloader(): | |||||
if not getattr(frappe.local, 'jloader', None): | if not getattr(frappe.local, 'jloader', None): | ||||
from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader | from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader | ||||
if frappe.local.flags.in_setup_help: | |||||
apps = ['frappe'] | |||||
else: | |||||
apps = frappe.get_hooks('template_apps') | |||||
if not apps: | |||||
apps = frappe.local.flags.web_pages_apps or frappe.get_installed_apps(sort=True) | |||||
apps.reverse() | |||||
apps = frappe.get_hooks('template_apps') | |||||
if not apps: | |||||
apps = frappe.local.flags.web_pages_apps or frappe.get_installed_apps(sort=True) | |||||
apps.reverse() | |||||
if "frappe" not in apps: | if "frappe" not in apps: | ||||
apps.append('frappe') | apps.append('frappe') | ||||
@@ -124,15 +121,13 @@ def set_filters(jenv): | |||||
import frappe | import frappe | ||||
from frappe.utils import cint, cstr, flt | from frappe.utils import cint, cstr, flt | ||||
jenv.filters["json"] = frappe.as_json | |||||
jenv.filters["len"] = len | |||||
jenv.filters["int"] = cint | |||||
jenv.filters["str"] = cstr | |||||
jenv.filters["flt"] = flt | |||||
if frappe.flags.in_setup_help: | |||||
return | |||||
jenv.filters.update({ | |||||
"json": frappe.as_json, | |||||
"len": len, | |||||
"int": cint, | |||||
"str": cstr, | |||||
"flt": flt, | |||||
}) | |||||
def get_jinja_hooks(): | def get_jinja_hooks(): | ||||
"""Returns a tuple of (methods, filters) each containing a dict of method name and method definition pair.""" | """Returns a tuple of (methods, filters) each containing a dict of method name and method definition pair.""" | ||||
@@ -139,7 +139,21 @@ def get_safe_globals(): | |||||
get_hooks=get_hooks, | get_hooks=get_hooks, | ||||
enqueue=safe_enqueue, | enqueue=safe_enqueue, | ||||
sanitize_html=frappe.utils.sanitize_html, | sanitize_html=frappe.utils.sanitize_html, | ||||
log_error=frappe.log_error | |||||
log_error=frappe.log_error, | |||||
db = NamespaceDict( | |||||
get_list=frappe.get_list, | |||||
get_all=frappe.get_all, | |||||
get_value=frappe.db.get_value, | |||||
set_value=frappe.db.set_value, | |||||
get_single_value=frappe.db.get_single_value, | |||||
get_default=frappe.db.get_default, | |||||
exists=frappe.db.exists, | |||||
count=frappe.db.count, | |||||
escape=frappe.db.escape, | |||||
sql=read_sql, | |||||
commit=frappe.db.commit, | |||||
rollback=frappe.db.rollback, | |||||
), | |||||
), | ), | ||||
FrappeClient=FrappeClient, | FrappeClient=FrappeClient, | ||||
style=frappe._dict( | style=frappe._dict( | ||||
@@ -155,29 +169,11 @@ def get_safe_globals(): | |||||
dev_server=1 if frappe._dev_server else 0, | dev_server=1 if frappe._dev_server else 0, | ||||
run_script=run_script, | run_script=run_script, | ||||
is_job_queued=is_job_queued, | is_job_queued=is_job_queued, | ||||
get_visible_columns=get_visible_columns, | |||||
) | ) | ||||
add_module_properties(frappe.exceptions, out.frappe, lambda obj: inspect.isclass(obj) and issubclass(obj, Exception)) | add_module_properties(frappe.exceptions, out.frappe, lambda obj: inspect.isclass(obj) and issubclass(obj, Exception)) | ||||
if not frappe.flags.in_setup_help: | |||||
out.get_visible_columns = get_visible_columns | |||||
out.frappe.date_format = date_format | |||||
out.frappe.time_format = time_format | |||||
out.frappe.db = NamespaceDict( | |||||
get_list=frappe.get_list, | |||||
get_all=frappe.get_all, | |||||
get_value=frappe.db.get_value, | |||||
set_value=frappe.db.set_value, | |||||
get_single_value=frappe.db.get_single_value, | |||||
get_default=frappe.db.get_default, | |||||
exists=frappe.db.exists, | |||||
count=frappe.db.count, | |||||
escape=frappe.db.escape, | |||||
sql=read_sql, | |||||
commit=frappe.db.commit, | |||||
rollback=frappe.db.rollback, | |||||
) | |||||
if frappe.response: | if frappe.response: | ||||
out.frappe.response = frappe.response | out.frappe.response = frappe.response | ||||