diff --git a/.eslintrc b/.eslintrc index f94193e00e..4ea7f0edff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -54,6 +54,7 @@ "Taggle": true, "Gantt": true, "Slick": true, + "Webcam": true, "PhotoSwipe": true, "PhotoSwipeUI_Default": true, "fluxify": true, diff --git a/.github/logo.png b/.github/logo.png new file mode 100644 index 0000000000..258408edfa Binary files /dev/null and b/.github/logo.png differ diff --git a/.gitignore b/.gitignore index 75bee9a091..436a08414e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ locale dist/ build/ frappe/docs/current +.vscode +node_modules \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..fe7159848b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.linting.pylintEnabled": false +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..956e51befb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2016-2017 Frappé Technologies Pvt. Ltd. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..f30645229e --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +clean: + python setup.py clean \ No newline at end of file diff --git a/README.md b/README.md index 9621b58b46..b8427fc055 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,33 @@ -## Frappé Framework - -[![Build Status](https://travis-ci.org/frappe/frappe.png)](https://travis-ci.org/frappe/frappe) +
+ +

+ + frappé + +

+

+ a web framework with "batteries included" +

+
+ it's pronounced - fra-pay +
+
+ +
+ + + + + + +
Full-stack web application framework that uses Python and MariaDB on the server side and a tightly integrated client side library. Built for [ERPNext](https://erpnext.com) +### Table of Contents +* [Installation](#installation) +* [License](#license) + ### Installation [Install via Frappé Bench](https://github.com/frappe/bench) @@ -20,5 +44,4 @@ For details and documentation, see the website [https://frappe.io](https://frappe.io) ### License - -MIT License +This repository has been released under the [MIT License](LICENSE). diff --git a/frappe/__init__.py b/frappe/__init__.py index e18619f247..2f80353147 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -602,7 +602,7 @@ def set_value(doctype, docname, fieldname, value=None): import frappe.client return frappe.client.set_value(doctype, docname, fieldname, value) -def get_doc(arg1, arg2=None): +def get_doc(*args, **kwargs): """Return a `frappe.model.document.Document` object of the given type and name. :param arg1: DocType name as string **or** document JSON. @@ -619,7 +619,7 @@ def get_doc(arg1, arg2=None): """ import frappe.model.document - return frappe.model.document.get_doc(arg1, arg2) + return frappe.model.document.get_doc(*args, **kwargs) def get_last_doc(doctype): """Get last created document of this type.""" diff --git a/frappe/build.js b/frappe/build.js index 45ab9bc9cf..9a4f0c2fc9 100644 --- a/frappe/build.js +++ b/frappe/build.js @@ -123,10 +123,9 @@ function pack(output_path, inputs, minify) { } function babelify(content, path, minify) { - let presets = ['es2015', 'es2016']; - // if(minify) { - // presets.push('babili'); // new babel minifier - // } + let presets = ['env']; + // Minification doesn't work when loading Frappe Desk + // Avoid for now, trace the error and come back. try { return babel.transform(content, { presets: presets, diff --git a/frappe/build.py b/frappe/build.py index 2a201fee6f..e0ce46f923 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals, print_function from frappe.utils.minify import JavascriptMinify import subprocess +import warnings from six import iteritems, text_type @@ -25,12 +26,12 @@ def setup(): except ImportError: pass app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules] -def bundle(no_compress, make_copy=False, verbose=False): +def bundle(no_compress, make_copy=False, restore=False, verbose=False): """concat / minify js files""" # build js files setup() - make_asset_dirs(make_copy=make_copy) + make_asset_dirs(make_copy=make_copy, restore=restore) # new nodejs build system command = 'node --use_strict ../apps/frappe/frappe/build.js --build' @@ -60,7 +61,8 @@ def watch(no_compress): # time.sleep(3) -def make_asset_dirs(make_copy=False): +def make_asset_dirs(make_copy=False, restore=False): + # don't even think of making assets_path absolute - rm -rf ahead. assets_path = os.path.join(frappe.local.sites_path, "assets") for dir_path in [ os.path.join(assets_path, 'js'), @@ -80,11 +82,28 @@ def make_asset_dirs(make_copy=False): for source, target in symlinks: source = os.path.abspath(source) - if not os.path.exists(target) and os.path.exists(source): - if make_copy: - shutil.copytree(source, target) + if os.path.exists(source): + if restore: + if os.path.exists(target): + if os.path.islink(target): + os.unlink(target) + else: + shutil.rmtree(target) + shutil.copytree(source, target) + elif make_copy: + if os.path.exists(target): + warnings.warn('Target {target} already exists.'.format(target = target)) + else: + shutil.copytree(source, target) else: + if os.path.exists(target): + if os.path.islink(target): + os.unlink(target) + else: + shutil.rmtree(target) os.symlink(source, target) + else: + warnings.warn('Source {source} does not exists.'.format(source = source)) def build(no_compress=False, verbose=False): assets_path = os.path.join(frappe.local.sites_path, "assets") diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 710327b5fe..9b4d40dcd5 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -8,13 +8,14 @@ from frappe.utils import update_progress_bar @click.command('build') @click.option('--make-copy', is_flag=True, default=False, help='Copy the files instead of symlinking') +@click.option('--restore', is_flag=True, default=False, help='Copy the files instead of symlinking with force') @click.option('--verbose', is_flag=True, default=False, help='Verbose') -def build(make_copy=False, verbose=False): +def build(make_copy=False, restore = False, verbose=False): "Minify + concatenate JS and CSS files, build translations" import frappe.build import frappe frappe.init('') - frappe.build.bundle(False, make_copy=make_copy, verbose=verbose) + frappe.build.bundle(False, make_copy=make_copy, restore = restore, verbose=verbose) @click.command('watch') def watch(): diff --git a/frappe/contacts/doctype/address/address.json b/frappe/contacts/doctype/address/address.json index c3b655cec5..d663957580 100644 --- a/frappe/contacts/doctype/address/address.json +++ b/frappe/contacts/doctype/address/address.json @@ -353,7 +353,8 @@ "label": "Email Address", "length": 0, "no_copy": 0, - "permlevel": 0, + "options": "Email", + "permlevel": 0, "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index ac25b97c73..d259b60cbd 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -25,7 +25,7 @@ class Communication(Document): """create email flag queue""" if self.communication_type == "Communication" and self.communication_medium == "Email" \ and self.sent_or_received == "Received" and self.uid and self.uid != -1: - + email_flag_queue = frappe.db.get_value("Email Flag Queue", { "communication": self.name, "is_completed": 0}) @@ -69,7 +69,7 @@ class Communication(Document): def after_insert(self): if not (self.reference_doctype and self.reference_name): return - + if self.reference_doctype == "Communication" and self.sent_or_received == "Sent": frappe.db.set_value("Communication", self.reference_name, "status", "Replied") @@ -94,9 +94,10 @@ class Communication(Document): def on_update(self): """Update parent status as `Open` or `Replied`.""" - update_parent_status(self) - update_comment_in_doc(self) - self.bot_reply() + if self.comment_type != 'Updated': + update_parent_status(self) + update_comment_in_doc(self) + self.bot_reply() def on_trash(self): if (not self.flags.ignore_permissions @@ -264,7 +265,7 @@ def has_permission(doc, ptype, user): if (doc.reference_doctype == "Communication" and doc.reference_name == doc.name) \ or (doc.timeline_doctype == "Communication" and doc.timeline_name == doc.name): return - + if doc.reference_doctype and doc.reference_name: if frappe.has_permission(doc.reference_doctype, ptype="read", doc=doc.reference_name): return True @@ -277,7 +278,9 @@ def get_permission_query_conditions_for_communication(user): if not user: user = frappe.session.user - if "Super Email User" in frappe.get_roles(user): + roles = frappe.get_roles(user) + + if "Super Email User" in roles or "System Manager" in roles: return None else: accounts = frappe.get_all("User Email", filters={ "parent": user }, diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py index 166aa4d84d..c17ac1f5c8 100755 --- a/frappe/core/doctype/communication/email.py +++ b/frappe/core/doctype/communication/email.py @@ -166,9 +166,6 @@ def _notify(doc, print_html=None, print_format=None, attachments=None, def update_parent_status(doc): """Update status of parent document based on who is replying.""" - if doc.communication_type != "Communication": - return - parent = doc.get_parent_doc() if not parent: return diff --git a/frappe/core/page/desktop/desktop.js b/frappe/core/page/desktop/desktop.js index 8b4c062ab6..d18f7dd55c 100644 --- a/frappe/core/page/desktop/desktop.js +++ b/frappe/core/page/desktop/desktop.js @@ -112,13 +112,17 @@ $.extend(frappe.desktop, { }, setup_module_click: function() { + frappe.desktop.wiggling = false; + if(frappe.list_desktop) { frappe.desktop.wrapper.on("click", ".desktop-list-item", function() { frappe.desktop.open_module($(this)); }); } else { frappe.desktop.wrapper.on("click", ".app-icon", function() { - frappe.desktop.open_module($(this).parent()); + if ( !frappe.desktop.wiggling ) { + frappe.desktop.open_module($(this).parent()); + } }); } frappe.desktop.wrapper.on("click", ".circle", function() { @@ -127,6 +131,116 @@ $.extend(frappe.desktop, { frappe.ui.notifications.show_open_count_list(doctype); } }); + + frappe.desktop.setup_wiggle(); + }, + + setup_wiggle: () => { + // Wiggle, Wiggle, Wiggle. + const DURATION_LONG_PRESS = 1000; + // lesser the antidode, more the wiggle (like your drunk uncle) + // 75 seems good to replicate the iOS feels. + const WIGGLE_ANTIDODE = 75; + + var timer_id = 0; + const $cases = frappe.desktop.wrapper.find('.case-wrapper'); + const $icons = frappe.desktop.wrapper.find('.app-icon'); + const $notis = $(frappe.desktop.wrapper.find('.circle').toArray().filter((object) => { + // This hack is so bad, I should punch myself. + // Seriously, punch yourself. + const text = $(object).find('.circle-text').html(); + + return text; + })); + + const clearWiggle = () => { + const $closes = $cases.find('.module-remove'); + $closes.hide(); + $notis.show(); + + $icons.trigger('stopRumble'); + + frappe.desktop.wiggling = false; + }; + + // initiate wiggling. + $icons.jrumble({ + speed: WIGGLE_ANTIDODE // seems neat enough to match the iOS way + }); + + frappe.desktop.wrapper.on('mousedown', '.app-icon', () => { + timer_id = setTimeout(() => { + frappe.desktop.wiggling = true; + // hide all notifications. + $notis.hide(); + + $cases.each((i) => { + const $case = $($cases[i]); + const template = + ` +
+
+ + × + +
+
+ `; + + $case.append(template); + const $close = $case.find('.module-remove'); + const name = $case.attr('title'); + $close.click(() => { + // good enough to create dynamic dialogs? + const dialog = new frappe.ui.Dialog({ + title: __(`Hide ${name}?`) + }); + dialog.set_primary_action(__('Hide'), () => { + frappe.call({ + method: 'frappe.desk.doctype.desktop_icon.desktop_icon.hide', + args: { name: name }, + freeze: true, + callback: (response) => + { + if ( response.message ) { + location.reload(); + } + } + }) + + dialog.hide(); + + clearWiggle(); + }); + // Hacks, Hacks and Hacks. + var $cancel = dialog.get_close_btn(); + $cancel.click(() => { + clearWiggle(); + }); + $cancel.html(__(`Cancel`)); + + dialog.show(); + }); + }); + + $icons.trigger('startRumble'); + }, DURATION_LONG_PRESS); + }); + frappe.desktop.wrapper.on('mouseup mouseleave', '.app-icon', () => { + clearTimeout(timer_id); + }); + + // also stop wiggling if clicked elsewhere. + $('body').click((event) => { + if ( frappe.desktop.wiggling ) { + const $target = $(event.target); + // our target shouldn't be .app-icons or .close + const $parent = $target.parents('.case-wrapper'); + if ( $parent.length == 0 ) + clearWiggle(); + } + }); + // end wiggle }, open_module: function(parent) { diff --git a/frappe/defaults.py b/frappe/defaults.py index b4a9d5cfab..9fbc55a0d0 100644 --- a/frappe/defaults.py +++ b/frappe/defaults.py @@ -92,7 +92,19 @@ def set_default(key, value, parent, parenttype="__default"): :param value: Default value. :param parent: Usually, **User** to whom the default belongs. :param parenttype: [optional] default is `__default`.""" - frappe.db.sql("""delete from `tabDefaultValue` where defkey=%s and parent=%s""", (key, parent)) + if frappe.db.sql(''' + select + defkey + from + tabDefaultValue + where + defkey=%s and parent=%s + for update''', (key, parent)): + frappe.db.sql(""" + delete from + `tabDefaultValue` + where + defkey=%s and parent=%s""", (key, parent)) if value != None: add_default(key, value, parent) diff --git a/frappe/desk/doctype/desktop_icon/desktop_icon.py b/frappe/desk/doctype/desktop_icon/desktop_icon.py index 0787af88f7..91de421e8f 100644 --- a/frappe/desk/doctype/desktop_icon/desktop_icon.py +++ b/frappe/desk/doctype/desktop_icon/desktop_icon.py @@ -404,3 +404,16 @@ palette = ( ('#4F8EA8', 1), ('#428B46', 1) ) + +@frappe.whitelist() +def hide(name, user = None): + if not user: + user = frappe.session.user + + try: + set_hidden(name, user, hidden = 1) + clear_desktop_icons_cache() + except Exception: + return False + + return True \ No newline at end of file diff --git a/frappe/desk/doctype/todo/test_todo.js b/frappe/desk/doctype/todo/test_todo.js new file mode 100644 index 0000000000..de508991cf --- /dev/null +++ b/frappe/desk/doctype/todo/test_todo.js @@ -0,0 +1,23 @@ +/* eslint-disable */ +// rename this file from _test_[name] to test_[name] to activate +// and remove above this line + +QUnit.test("test: ToDo", function (assert) { + let done = assert.async(); + + // number of asserts + assert.expect(1); + + frappe.run_serially([ + // insert a new ToDo + () => frappe.tests.make('ToDo', [ + // values to be set + {key: 'value'} + ]), + () => { + assert.equal(cur_frm.doc.key, 'value'); + }, + () => done() + ]); + +}); diff --git a/frappe/desk/doctype/todo/todo.json b/frappe/desk/doctype/todo/todo.json index 9f1b4ae452..ca70fd1006 100644 --- a/frappe/desk/doctype/todo/todo.json +++ b/frappe/desk/doctype/todo/todo.json @@ -112,20 +112,18 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "color", - "fieldtype": "Color", + "fieldname": "column_break_2", + "fieldtype": "Column Break", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, "in_global_search": 0, - "in_list_view": 1, + "in_list_view": 0, "in_standard_filter": 0, - "label": "Color", "length": 0, "no_copy": 0, "permlevel": 0, - "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, @@ -142,18 +140,20 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "column_break_2", - "fieldtype": "Column Break", + "fieldname": "color", + "fieldtype": "Color", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, "in_global_search": 0, - "in_list_view": 0, + "in_list_view": 1, "in_standard_filter": 0, + "label": "Color", "length": 0, "no_copy": 0, "permlevel": 0, + "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, @@ -544,7 +544,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-09-05 12:54:58.044162", + "modified": "2017-09-30 13:57:29.398598", "modified_by": "Administrator", "module": "Desk", "name": "ToDo", diff --git a/frappe/desk/reportview.py b/frappe/desk/reportview.py index cacfa25e9a..09afea8b3d 100644 --- a/frappe/desk/reportview.py +++ b/frappe/desk/reportview.py @@ -259,7 +259,7 @@ def get_stats(stats, doctype, filters=[]): stats[tag] = scrub_user_tags(tagcount) stats[tag].append([_("No Tags"), frappe.get_list(doctype, fields=[tag, "count(*)"], - filters=filters +["({0} = ',' or {0} is null)".format(tag)], as_list=True)[0][1]]) + filters=filters +["({0} = ',' or {0} = '' or {0} is null)".format(tag)], as_list=True)[0][1]]) else: stats[tag] = tagcount @@ -269,7 +269,6 @@ def get_stats(stats, doctype, filters=[]): except MySQLdb.OperationalError: # raised when _user_tags column is added on the fly pass - return stats @frappe.whitelist() diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index a36d461c60..7dbb71fd3f 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -273,7 +273,6 @@ class EmailAccount(Document): "uid_reindexed": uid_reindexed } communication = self.insert_communication(msg, args=args) - #self.notify_update() except SentEmailInInbox: frappe.db.rollback() diff --git a/frappe/email/doctype/email_alert/email_alert.js b/frappe/email/doctype/email_alert/email_alert.js index 1ab87a9947..3f7423bc1b 100755 --- a/frappe/email/doctype/email_alert/email_alert.js +++ b/frappe/email/doctype/email_alert/email_alert.js @@ -6,13 +6,24 @@ frappe.email_alert = { } frappe.model.with_doctype(frm.doc.document_type, function() { - var get_select_options = function(df) { + let get_select_options = function(df) { return {value: df.fieldname, label: df.fieldname + " (" + __(df.label) + ")"}; } - var fields = frappe.get_doc("DocType", frm.doc.document_type).fields; + let get_date_change_options = function() { + let date_options = $.map(fields, function(d) { + return (d.fieldtype=="Date" || d.fieldtype=="Datetime")? + get_select_options(d) : null; + }); + // append creation and modified date to Date Change field + return date_options.concat([ + { value: "creation", label: `creation (${__('Created On')})` }, + { value: "modified", label: `modified (${__('Last Modified Date')})` } + ]); + } - var options = $.map(fields, + let fields = frappe.get_doc("DocType", frm.doc.document_type).fields; + let options = $.map(fields, function(d) { return in_list(frappe.model.no_value_type, d.fieldtype) ? null : get_select_options(d); }); @@ -21,11 +32,9 @@ frappe.email_alert = { frm.set_df_property("set_property_after_alert", "options", [""].concat(options)); // set date changed options - frm.set_df_property("date_changed", "options", $.map(fields, - function(d) { return (d.fieldtype=="Date" || d.fieldtype=="Datetime") ? - get_select_options(d) : null; })); + frm.set_df_property("date_changed", "options", get_date_change_options()); - var email_fields = $.map(fields, + let email_fields = $.map(fields, function(d) { return (d.options == "Email" || (d.options=='User' && d.fieldtype=='Link')) ? get_select_options(d) : null; }); diff --git a/frappe/hooks.py b/frappe/hooks.py index 9bdd8352a6..707b2fac37 100755 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -11,7 +11,7 @@ app_color = "orange" source_link = "https://github.com/frappe/frappe" app_license = "MIT" -develop_version = '8.x.x-beta' +develop_version = '9.x.x-develop' app_email = "info@frappe.io" diff --git a/frappe/model/document.py b/frappe/model/document.py index e71911e1a9..56a14cff8c 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -20,13 +20,13 @@ from frappe.integrations.doctype.webhook import run_webhooks # once_only validation # methods -def get_doc(arg1, arg2=None): +def get_doc(*args, **kwargs): """returns a frappe.model.Document object. :param arg1: Document dict or DocType name. :param arg2: [optional] document name. - There are two ways to call `get_doc` + There are multiple ways to call `get_doc` # will fetch the latest user object (with child table) from the database user = get_doc("User", "test@example.com") @@ -39,23 +39,39 @@ def get_doc(arg1, arg2=None): {"role": "System Manager"} ] }) + + # create new object with keyword arguments + user = get_doc(doctype='User', email_id='test@example.com') """ - if isinstance(arg1, BaseDocument): - return arg1 - elif isinstance(arg1, string_types): - doctype = arg1 - else: - doctype = arg1.get("doctype") + if args: + if isinstance(args[0], BaseDocument): + # already a document + return args[0] + elif isinstance(args[0], string_types): + doctype = args[0] + + elif isinstance(args[0], dict): + # passed a dict + kwargs = args[0] + + else: + raise ValueError('First non keyword argument must be a string or dict') + + if kwargs: + if 'doctype' in kwargs: + doctype = kwargs['doctype'] + else: + raise ValueError('"doctype" is a required key') controller = get_controller(doctype) if controller: - return controller(arg1, arg2) + return controller(*args, **kwargs) - raise ImportError(arg1) + raise ImportError(doctype) class Document(BaseDocument): """All controllers inherit from `Document`.""" - def __init__(self, arg1, arg2=None): + def __init__(self, *args, **kwargs): """Constructor. :param arg1: DocType name as string or document **dict** @@ -68,29 +84,37 @@ class Document(BaseDocument): self._default_new_docs = {} self.flags = frappe._dict() - if arg1 and isinstance(arg1, string_types): - if not arg2: + if args and args[0] and isinstance(args[0], string_types): + # first arugment is doctype + if len(args)==1: # single - self.doctype = self.name = arg1 + self.doctype = self.name = args[0] else: - self.doctype = arg1 - if isinstance(arg2, dict): + self.doctype = args[0] + if isinstance(args[1], dict): # filter - self.name = frappe.db.get_value(arg1, arg2, "name") + self.name = frappe.db.get_value(args[0], args[1], "name") if self.name is None: - frappe.throw(_("{0} {1} not found").format(_(arg1), arg2), frappe.DoesNotExistError) + frappe.throw(_("{0} {1} not found").format(_(args[0]), args[1]), + frappe.DoesNotExistError) else: - self.name = arg2 + self.name = args[1] self.load_from_db() + return + + if args and args[0] and isinstance(args[0], dict): + # first argument is a dict + kwargs = args[0] - elif isinstance(arg1, dict): - super(Document, self).__init__(arg1) + if kwargs: + # init base document + super(Document, self).__init__(kwargs) self.init_valid_columns() else: # incorrect arguments. let's not proceed. - raise frappe.DataError("Document({0}, {1})".format(arg1, arg2)) + raise ValueError('Illegal arguments') def reload(self): """Reload document from database""" @@ -631,7 +655,7 @@ class Document(BaseDocument): name=self.name)) def _validate_links(self): - if self.flags.ignore_links: + if self.flags.ignore_links or self._action == "cancel": return invalid_links, cancelled_links = self.get_invalid_links() diff --git a/frappe/patches/v6_20x/remove_roles_from_website_user.py b/frappe/patches/v6_20x/remove_roles_from_website_user.py index 347491898f..499ad5ddf4 100644 --- a/frappe/patches/v6_20x/remove_roles_from_website_user.py +++ b/frappe/patches/v6_20x/remove_roles_from_website_user.py @@ -1,6 +1,8 @@ import frappe def execute(): + frappe.reload_doc("core", "doctype", "user_email") + frappe.reload_doc("core", "doctype", "user") for user_name in frappe.get_all('User', filters={'user_type': 'Website User'}): user = frappe.get_doc('User', user_name) if user.roles: diff --git a/frappe/public/build.json b/frappe/public/build.json index 913adfe735..8d10760cf1 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -23,6 +23,7 @@ "public/js/frappe/misc/rating_icons.html" ], "js/control.min.js": [ + "public/js/frappe/ui/capture.js", "public/js/frappe/form/controls/base_control.js", "public/js/frappe/form/controls/base_input.js", "public/js/frappe/form/controls/data.js", @@ -55,12 +56,15 @@ "js/dialog.min.js": [ "public/js/frappe/dom.js", "public/js/frappe/ui/modal.html", + "public/js/frappe/form/formatters.js", "public/js/frappe/form/layout.js", "public/js/frappe/ui/field_group.js", "public/js/frappe/form/link_selector.js", "public/js/frappe/form/multi_select_dialog.js", "public/js/frappe/ui/dialog.js", + "public/js/frappe/ui/capture.js", + "public/js/frappe/form/controls/base_control.js", "public/js/frappe/form/controls/base_input.js", "public/js/frappe/form/controls/data.js", @@ -130,7 +134,9 @@ "public/js/lib/jSignature.min.js", "public/js/frappe/translate.js", "public/js/lib/datepicker/datepicker.min.js", - "public/js/lib/datepicker/locale-all.js" + "public/js/lib/datepicker/locale-all.js", + "public/js/lib/jquery.jrumble.min.js", + "public/js/lib/webcam.min.js" ], "js/desk.min.js": [ "public/js/frappe/class.js", @@ -168,6 +174,7 @@ "public/js/frappe/form/link_selector.js", "public/js/frappe/form/multi_select_dialog.js", "public/js/frappe/ui/dialog.js", + "public/js/frappe/ui/capture.js", "public/js/frappe/ui/app_icon.js", "public/js/frappe/model/model.js", diff --git a/frappe/public/css/report-rtl.css b/frappe/public/css/report-rtl.css index cc87b52bbf..26709a55e3 100644 --- a/frappe/public/css/report-rtl.css +++ b/frappe/public/css/report-rtl.css @@ -1,3 +1,11 @@ .grid-report { direction: ltr; } + +.chart_area{ + direction: ltr; +} + +.grid-report .show-zero{ + direction: rtl ; +} diff --git a/frappe/public/js/frappe/form/controls/color.js b/frappe/public/js/frappe/form/controls/color.js index d13c22d19d..6e8880a72a 100644 --- a/frappe/public/js/frappe/form/controls/color.js +++ b/frappe/public/js/frappe/form/controls/color.js @@ -36,9 +36,11 @@ frappe.ui.form.ControlColor = frappe.ui.form.ControlData.extend({ set_formatted_input: function(value) { this._super(value); - if(!value) value = '#ffffff'; + if (!value) value = '#FFFFFF'; + const contrast = frappe.ui.color.get_contrast_color(value); + this.$input.css({ - "background-color": value + "background-color": value, "color": contrast }); }, bind_events: function () { diff --git a/frappe/public/js/frappe/form/controls/text_editor.js b/frappe/public/js/frappe/form/controls/text_editor.js index 00af468754..cd478f9f48 100644 --- a/frappe/public/js/frappe/form/controls/text_editor.js +++ b/frappe/public/js/frappe/form/controls/text_editor.js @@ -6,6 +6,28 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ this.setup_drag_drop(); this.setup_image_dialog(); this.setting_count = 0; + + $(document).on('form-refresh', () => { + // reset last keystroke when a new form is loaded + this.last_keystroke_on = null; + }) + }, + render_camera_button: (context) => { + var ui = $.summernote.ui; + var button = ui.button({ + contents: '', + tooltip: 'Camera', + click: () => { + const capture = new frappe.ui.Capture(); + capture.open(); + + capture.click((data) => { + context.invoke('editor.insertImage', data); + }); + } + }); + + return button.render(); }, make_editor: function() { var me = this; @@ -25,9 +47,12 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ ['color', ['color']], ['para', ['ul', 'ol', 'paragraph', 'hr']], //['height', ['height']], - ['media', ['link', 'picture', 'video', 'table']], + ['media', ['link', 'picture', 'camera', 'video', 'table']], ['misc', ['fullscreen', 'codeview']] ], + buttons: { + camera: this.render_camera_button, + }, keyMap: { pc: { 'CTRL+ENTER': '' @@ -54,7 +79,7 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ me.parse_validate_and_set_in_model(value); }, onKeydown: function(e) { - me._last_change_on = new Date(); + me.last_keystroke_on = new Date(); var key = frappe.ui.keys.get_key(e); // prevent 'New DocType (Ctrl + B)' shortcut in editor if(['ctrl+b', 'meta+b'].indexOf(key) !== -1) { @@ -80,6 +105,7 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ 'outdent': 'fa fa-outdent', 'arrowsAlt': 'fa fa-arrows-alt', 'bold': 'fa fa-bold', + 'camera': 'fa fa-camera', 'caret': 'caret', 'circle': 'fa fa-circle', 'close': 'fa fa-close', @@ -184,20 +210,30 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ if(this.setting_count > 2) { // we don't understand how the internal triggers work, - // so if someone is setting the value third time, then quit + // so if someone is setting the value third time in 500ms, + // then quit return; } this.setting_count += 1; - let time_since_last_keystroke = moment() - moment(this._last_change_on); + let time_since_last_keystroke = moment() - moment(this.last_keystroke_on); - if(!this._last_change_on || (time_since_last_keystroke > 3000)) { + if(!this.last_keystroke_on || (time_since_last_keystroke > 3000)) { + // if 3 seconds have passed since the last keystroke and + // we have not set any value in the last 1 second, do this setTimeout(() => this.setting_count = 0, 500); this.editor.summernote('code', value || ''); + this.last_keystroke_on = null; } else { + // user is probably still in the middle of typing + // so lets not mess up the html by re-updating it + // keep checking every second if our 3 second barrier + // has been completed, so that we can refresh the html this._setting_value = setInterval(() => { if(time_since_last_keystroke > 3000) { + // 3 seconds done! lets refresh + // safe to update if(this.last_value !== this.get_input_value()) { // if not already in sync, reset this.editor.summernote('code', this.last_value || ''); @@ -205,6 +241,9 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ clearInterval(this._setting_value); this._setting_value = null; this.setting_count = 0; + + // clear timestamp of last keystroke + this.last_keystroke_on = null; } }, 1000); } diff --git a/frappe/public/js/frappe/socketio_client.js b/frappe/public/js/frappe/socketio_client.js index 1512f487e6..c7dd77594f 100644 --- a/frappe/public/js/frappe/socketio_client.js +++ b/frappe/public/js/frappe/socketio_client.js @@ -73,7 +73,7 @@ frappe.socketio = { frappe.socketio.doc_subscribe(frm.doctype, frm.docname); }); - $(document).on("form_refresh", function(e, frm) { + $(document).on("form-refresh", function(e, frm) { if (frm.is_new()) { return; } diff --git a/frappe/public/js/frappe/ui/capture.js b/frappe/public/js/frappe/ui/capture.js new file mode 100644 index 0000000000..f555243975 --- /dev/null +++ b/frappe/public/js/frappe/ui/capture.js @@ -0,0 +1,94 @@ +frappe.ui.Capture = class +{ + constructor (options = { }) + { + this.options = Object.assign({}, frappe.ui.Capture.DEFAULT_OPTIONS, options); + this.dialog = new frappe.ui.Dialog(); + this.template = + ` +
+
+
+
+
+ +
+
+
+ + + +
+
+ + +
+
+
+ `; + $(this.dialog.body).append(this.template); + + this.$btnBarSnap = $(this.dialog.body).find('#frappe-capture-btn-toolbar-snap'); + this.$btnBarKnap = $(this.dialog.body).find('#frappe-capture-btn-toolbar-knap'); + this.$btnBarKnap.hide(); + + Webcam.set(this.options); + } + + open ( ) + { + this.dialog.show(); + + Webcam.attach('#frappe-capture'); + } + + freeze ( ) + { + this.$btnBarSnap.hide(); + this.$btnBarKnap.show(); + + Webcam.freeze(); + } + + unfreeze ( ) + { + this.$btnBarSnap.show(); + this.$btnBarKnap.hide(); + + Webcam.unfreeze(); + } + + click (callback) + { + $(this.dialog.body).find('#frappe-capture-btn-snap').click(() => { + this.freeze(); + + $(this.dialog.body).find('#frappe-capture-btn-discard').click(() => { + this.unfreeze(); + }); + + $(this.dialog.body).find('#frappe-capture-btn-accept').click(() => { + Webcam.snap((data) => { + callback(data); + }); + + this.hide(); + }); + }); + } + + hide ( ) + { + Webcam.reset(); + + $(this.dialog.$wrapper).remove(); + } +}; +frappe.ui.Capture.DEFAULT_OPTIONS = +{ + width: 480, height: 320, flip_horiz: true +}; \ No newline at end of file diff --git a/frappe/public/js/frappe/upload.js b/frappe/public/js/frappe/upload.js index 0a1225d2a5..bb727aa415 100644 --- a/frappe/public/js/frappe/upload.js +++ b/frappe/public/js/frappe/upload.js @@ -12,7 +12,13 @@ frappe.upload = { // whether to show public/private checkbox or not opts.show_private = !("is_private" in opts); - + + // make private by default + if (!("options" in opts) || ("options" in opts && + (!opts.options.toLowerCase()=="public" && !opts.options.toLowerCase()=="image"))) { + opts.is_private = 1; + } + var d = null; // create new dialog if no parent given if(!opts.parent) { @@ -237,7 +243,6 @@ frappe.upload = { if (args.file_size) { frappe.upload.validate_max_file_size(args.file_size); } - if(opts.on_attach) { opts.on_attach(args) } else { @@ -252,7 +257,7 @@ frappe.upload = { frappe.upload.upload_to_server(fileobj, args, opts); }, __("Private or Public?")); } else { - if ("is_private" in opts) { + if (!("is_private" in args) && "is_private" in opts) { args["is_private"] = opts.is_private; } diff --git a/frappe/public/js/legacy/clientscriptAPI.js b/frappe/public/js/legacy/clientscriptAPI.js index 30173328fa..c7590c5ae5 100644 --- a/frappe/public/js/legacy/clientscriptAPI.js +++ b/frappe/public/js/legacy/clientscriptAPI.js @@ -238,7 +238,7 @@ _f.Frm.prototype.set_query = function(fieldname, opt1, opt2) { } _f.Frm.prototype.set_value_if_missing = function(field, value) { - this.set_value(field, value, true); + return this.set_value(field, value, true); } _f.Frm.prototype.clear_table = function(fieldname) { diff --git a/frappe/public/js/legacy/form.js b/frappe/public/js/legacy/form.js index 83c3ffe96f..413e1e594a 100644 --- a/frappe/public/js/legacy/form.js +++ b/frappe/public/js/legacy/form.js @@ -497,7 +497,7 @@ _f.Frm.prototype.render_form = function(is_a_different_doc) { // trigger global trigger // to use this - $(document).trigger('form_refresh', [this]); + $(document).trigger('form-refresh', [this]); // fields this.refresh_fields(); diff --git a/frappe/public/js/lib/jquery.jrumble.min.js b/frappe/public/js/lib/jquery.jrumble.min.js new file mode 100644 index 0000000000..71de6ffb7c --- /dev/null +++ b/frappe/public/js/lib/jquery.jrumble.min.js @@ -0,0 +1,2 @@ +/* jRumble v1.3 - http://jackrugile.com/jrumble - MIT License */ +(function(f){f.fn.jrumble=function(g){var a=f.extend({x:2,y:2,rotation:1,speed:15,opacity:false,opacityMin:0.5},g);return this.each(function(){var b=f(this),h=a.x*2,i=a.y*2,k=a.rotation*2,g=a.speed===0?1:a.speed,m=a.opacity,n=a.opacityMin,l,j,o=function(){var e=Math.floor(Math.random()*(h+1))-h/2,a=Math.floor(Math.random()*(i+1))-i/2,c=Math.floor(Math.random()*(k+1))-k/2,d=m?Math.random()+n:1,e=e===0&&h!==0?Math.random()<0.5?1:-1:e,a=a===0&&i!==0?Math.random()<0.5?1:-1:a;b.css("display")==="inline"&&(l=true,b.css("display","inline-block"));b.css({position:"relative",left:e+"px",top:a+"px","-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity="+d*100+")",filter:"alpha(opacity="+d*100+")","-moz-opacity":d,"-khtml-opacity":d,opacity:d,"-webkit-transform":"rotate("+c+"deg)","-moz-transform":"rotate("+c+"deg)","-ms-transform":"rotate("+c+"deg)","-o-transform":"rotate("+c+"deg)",transform:"rotate("+c+"deg)"})},p={left:0,top:0,"-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)",filter:"alpha(opacity=100)","-moz-opacity":1,"-khtml-opacity":1,opacity:1,"-webkit-transform":"rotate(0deg)","-moz-transform":"rotate(0deg)","-ms-transform":"rotate(0deg)","-o-transform":"rotate(0deg)",transform:"rotate(0deg)"};b.bind({startRumble:function(a){a.stopPropagation();clearInterval(j);j=setInterval(o,g)},stopRumble:function(a){a.stopPropagation();clearInterval(j);l&&b.css("display","inline");b.css(p)}})})}})(jQuery); \ No newline at end of file diff --git a/frappe/public/js/lib/webcam.min.js b/frappe/public/js/lib/webcam.min.js new file mode 100644 index 0000000000..3325ccfd05 --- /dev/null +++ b/frappe/public/js/lib/webcam.min.js @@ -0,0 +1,2 @@ +// WebcamJS v1.0.22 - http://github.com/jhuckaby/webcamjs - MIT Licensed +(function(e){var t;function a(){var e=Error.apply(this,arguments);e.name=this.name="FlashError";this.stack=e.stack;this.message=e.message}function i(){var e=Error.apply(this,arguments);e.name=this.name="WebcamError";this.stack=e.stack;this.message=e.message}IntermediateInheritor=function(){};IntermediateInheritor.prototype=Error.prototype;a.prototype=new IntermediateInheritor;i.prototype=new IntermediateInheritor;var Webcam={version:"1.0.22",protocol:location.protocol.match(/https/i)?"https":"http",loaded:false,live:false,userMedia:true,iOS:/iPad|iPhone|iPod/.test(navigator.userAgent)&&!e.MSStream,params:{width:0,height:0,dest_width:0,dest_height:0,image_format:"jpeg",jpeg_quality:90,enable_flash:true,force_flash:false,flip_horiz:false,fps:30,upload_name:"webcam",constraints:null,swfURL:"",flashNotDetectedText:"ERROR: No Adobe Flash Player detected. Webcam.js relies on Flash for browsers that do not support getUserMedia (like yours).",noInterfaceFoundText:"No supported webcam interface found.",unfreeze_snap:true,iosPlaceholderText:"Click here to open camera.",user_callback:null,user_canvas:null},errors:{FlashError:a,WebcamError:i},hooks:{},init:function(){var t=this;this.mediaDevices=navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices:navigator.mozGetUserMedia||navigator.webkitGetUserMedia?{getUserMedia:function(e){return new Promise(function(t,a){(navigator.mozGetUserMedia||navigator.webkitGetUserMedia).call(navigator,e,t,a)})}}:null;e.URL=e.URL||e.webkitURL||e.mozURL||e.msURL;this.userMedia=this.userMedia&&!!this.mediaDevices&&!!e.URL;if(navigator.userAgent.match(/Firefox\D+(\d+)/)){if(parseInt(RegExp.$1,10)<21)this.userMedia=null}if(this.userMedia){e.addEventListener("beforeunload",function(e){t.reset()})}},exifOrientation:function(e){var t=new DataView(e);if(t.getUint8(0)!=255||t.getUint8(1)!=216){console.log("Not a valid JPEG file");return 0}var a=2;var i=null;while(a8){console.log("Invalid EXIF orientation value ("+p+")");return 0}return p}}}else{a+=2+t.getUint16(a+2)}}return 0},fixOrientation:function(e,t,a){var i=new Image;i.addEventListener("load",function(e){var s=document.createElement("canvas");var r=s.getContext("2d");if(t<5){s.width=i.width;s.height=i.height}else{s.width=i.height;s.height=i.width}switch(t){case 2:r.transform(-1,0,0,1,i.width,0);break;case 3:r.transform(-1,0,0,-1,i.width,i.height);break;case 4:r.transform(1,0,0,-1,0,i.height);break;case 5:r.transform(0,1,1,0,0,0);break;case 6:r.transform(0,1,-1,0,i.height,0);break;case 7:r.transform(0,-1,-1,0,i.height,i.width);break;case 8:r.transform(0,-1,1,0,0,i.width);break}r.drawImage(i,0,0);a.src=s.toDataURL()},false);i.src=e},attach:function(a){if(typeof a=="string"){a=document.getElementById(a)||document.querySelector(a)}if(!a){return this.dispatch("error",new i("Could not locate DOM element to attach to."))}this.container=a;a.innerHTML="";var s=document.createElement("div");a.appendChild(s);this.peg=s;if(!this.params.width)this.params.width=a.offsetWidth;if(!this.params.height)this.params.height=a.offsetHeight;if(!this.params.width||!this.params.height){return this.dispatch("error",new i("No width and/or height for webcam. Please call set() first, or attach to a visible element."))}if(!this.params.dest_width)this.params.dest_width=this.params.width;if(!this.params.dest_height)this.params.dest_height=this.params.height;this.userMedia=t===undefined?this.userMedia:t;if(this.params.force_flash){t=this.userMedia;this.userMedia=null}if(typeof this.params.fps!=="number")this.params.fps=30;var r=this.params.width/this.params.dest_width;var o=this.params.height/this.params.dest_height;if(this.userMedia){var n=document.createElement("video");n.setAttribute("autoplay","autoplay");n.style.width=""+this.params.dest_width+"px";n.style.height=""+this.params.dest_height+"px";if(r!=1||o!=1){a.style.overflow="hidden";n.style.webkitTransformOrigin="0px 0px";n.style.mozTransformOrigin="0px 0px";n.style.msTransformOrigin="0px 0px";n.style.oTransformOrigin="0px 0px";n.style.transformOrigin="0px 0px";n.style.webkitTransform="scaleX("+r+") scaleY("+o+")";n.style.mozTransform="scaleX("+r+") scaleY("+o+")";n.style.msTransform="scaleX("+r+") scaleY("+o+")";n.style.oTransform="scaleX("+r+") scaleY("+o+")";n.style.transform="scaleX("+r+") scaleY("+o+")"}a.appendChild(n);this.video=n;var h=this;this.mediaDevices.getUserMedia({audio:false,video:this.params.constraints||{mandatory:{minWidth:this.params.dest_width,minHeight:this.params.dest_height}}}).then(function(t){n.onloadedmetadata=function(e){h.stream=t;h.loaded=true;h.live=true;h.dispatch("load");h.dispatch("live");h.flip()};n.src=e.URL.createObjectURL(t)||t}).catch(function(e){if(h.params.enable_flash&&h.detectFlash()){setTimeout(function(){h.params.force_flash=1;h.attach(a)},1)}else{h.dispatch("error",e)}})}else if(this.iOS){var l=document.createElement("div");l.id=this.container.id+"-ios_div";l.className="webcamjs-ios-placeholder";l.style.width=""+this.params.width+"px";l.style.height=""+this.params.height+"px";l.style.textAlign="center";l.style.display="table-cell";l.style.verticalAlign="middle";l.style.backgroundRepeat="no-repeat";l.style.backgroundSize="contain";l.style.backgroundPosition="center";var c=document.createElement("span");c.className="webcamjs-ios-text";c.innerHTML=this.params.iosPlaceholderText;l.appendChild(c);var d=document.createElement("img");d.id=this.container.id+"-ios_img";d.style.width=""+this.params.dest_width+"px";d.style.height=""+this.params.dest_height+"px";d.style.display="none";l.appendChild(d);var f=document.createElement("input");f.id=this.container.id+"-ios_input";f.setAttribute("type","file");f.setAttribute("accept","image/*");f.setAttribute("capture","camera");var h=this;var m=this.params;f.addEventListener("change",function(e){if(e.target.files.length>0&&e.target.files[0].type.indexOf("image/")==0){var t=URL.createObjectURL(e.target.files[0]);var a=new Image;a.addEventListener("load",function(e){var t=document.createElement("canvas");t.width=m.dest_width;t.height=m.dest_height;var i=t.getContext("2d");ratio=Math.min(a.width/m.dest_width,a.height/m.dest_height);var s=m.dest_width*ratio;var r=m.dest_height*ratio;var o=(a.width-s)/2;var n=(a.height-r)/2;i.drawImage(a,o,n,s,r,0,0,m.dest_width,m.dest_height);var h=t.toDataURL();d.src=h;l.style.backgroundImage="url('"+h+"')"},false);var i=new FileReader;i.addEventListener("load",function(e){var i=h.exifOrientation(e.target.result);if(i>1){h.fixOrientation(t,i,a)}else{a.src=t}},false);var s=new XMLHttpRequest;s.open("GET",t,true);s.responseType="blob";s.onload=function(e){if(this.status==200||this.status===0){i.readAsArrayBuffer(this.response)}};s.send()}},false);f.style.display="none";a.appendChild(f);l.addEventListener("click",function(e){if(m.user_callback){h.snap(m.user_callback,m.user_canvas)}else{f.style.display="block";f.focus();f.click();f.style.display="none"}},false);a.appendChild(l);this.loaded=true;this.live=true}else if(this.params.enable_flash&&this.detectFlash()){e.Webcam=Webcam;var l=document.createElement("div");l.innerHTML=this.getSWFHTML();a.appendChild(l)}else{this.dispatch("error",new i(this.params.noInterfaceFoundText))}if(this.params.crop_width&&this.params.crop_height){var p=Math.floor(this.params.crop_width*r);var u=Math.floor(this.params.crop_height*o);a.style.width=""+p+"px";a.style.height=""+u+"px";a.style.overflow="hidden";a.scrollLeft=Math.floor(this.params.width/2-p/2);a.scrollTop=Math.floor(this.params.height/2-u/2)}else{a.style.width=""+this.params.width+"px";a.style.height=""+this.params.height+"px"}},reset:function(){if(this.preview_active)this.unfreeze();this.unflip();if(this.userMedia){if(this.stream){if(this.stream.getVideoTracks){var e=this.stream.getVideoTracks();if(e&&e[0]&&e[0].stop)e[0].stop()}else if(this.stream.stop){this.stream.stop()}}delete this.stream;delete this.video}if(this.userMedia!==true&&this.loaded&&!this.iOS){var t=this.getMovie();if(t&&t._releaseCamera)t._releaseCamera()}if(this.container){this.container.innerHTML="";delete this.container}this.loaded=false;this.live=false},set:function(){if(arguments.length==1){for(var e in arguments[0]){this.params[e]=arguments[0][e]}}else{this.params[arguments[0]]=arguments[1]}},on:function(e,t){e=e.replace(/^on/i,"").toLowerCase();if(!this.hooks[e])this.hooks[e]=[];this.hooks[e].push(t)},off:function(e,t){e=e.replace(/^on/i,"").toLowerCase();if(this.hooks[e]){if(t){var a=this.hooks[e].indexOf(t);if(a>-1)this.hooks[e].splice(a,1)}else{this.hooks[e]=[]}}},dispatch:function(){var t=arguments[0].replace(/^on/i,"").toLowerCase();var s=Array.prototype.slice.call(arguments,1);if(this.hooks[t]&&this.hooks[t].length){for(var r=0,o=this.hooks[t].length;rERROR: the Webcam.js Flash fallback does not work from local disk. Please run it from a web server.'}if(!this.detectFlash()){this.dispatch("error",new a("Adobe Flash Player not found. Please install from get.adobe.com/flashplayer and try again."));return'

'+this.params.flashNotDetectedText+"

"}if(!i){var s="";var r=document.getElementsByTagName("script");for(var o=0,n=r.length;o';return t},getMovie:function(){if(!this.loaded)return this.dispatch("error",new a("Flash Movie is not loaded yet"));var e=document.getElementById("webcam_movie_obj");if(!e||!e._snap)e=document.getElementById("webcam_movie_embed");if(!e)this.dispatch("error",new a("Cannot locate Flash movie in DOM"));return e},freeze:function(){var e=this;var t=this.params;if(this.preview_active)this.unfreeze();var a=this.params.width/this.params.dest_width;var i=this.params.height/this.params.dest_height;this.unflip();var s=t.crop_width||t.dest_width;var r=t.crop_height||t.dest_height;var o=document.createElement("canvas");o.width=s;o.height=r;var n=o.getContext("2d");this.preview_canvas=o;this.preview_context=n;if(a!=1||i!=1){o.style.webkitTransformOrigin="0px 0px";o.style.mozTransformOrigin="0px 0px";o.style.msTransformOrigin="0px 0px";o.style.oTransformOrigin="0px 0px";o.style.transformOrigin="0px 0px";o.style.webkitTransform="scaleX("+a+") scaleY("+i+")";o.style.mozTransform="scaleX("+a+") scaleY("+i+")";o.style.msTransform="scaleX("+a+") scaleY("+i+")";o.style.oTransform="scaleX("+a+") scaleY("+i+")";o.style.transform="scaleX("+a+") scaleY("+i+")"}this.snap(function(){o.style.position="relative";o.style.left=""+e.container.scrollLeft+"px";o.style.top=""+e.container.scrollTop+"px";e.container.insertBefore(o,e.peg);e.container.style.overflow="hidden";e.preview_active=true},o)},unfreeze:function(){if(this.preview_active){this.container.removeChild(this.preview_canvas);delete this.preview_context;delete this.preview_canvas;this.preview_active=false;this.flip()}},flip:function(){if(this.params.flip_horiz){var e=this.container.style;e.webkitTransform="scaleX(-1)";e.mozTransform="scaleX(-1)";e.msTransform="scaleX(-1)";e.oTransform="scaleX(-1)";e.transform="scaleX(-1)";e.filter="FlipH";e.msFilter="FlipH"}},unflip:function(){if(this.params.flip_horiz){var e=this.container.style;e.webkitTransform="scaleX(1)";e.mozTransform="scaleX(1)";e.msTransform="scaleX(1)";e.oTransform="scaleX(1)";e.transform="scaleX(1)";e.filter="";e.msFilter=""}},savePreview:function(e,t){var a=this.params;var i=this.preview_canvas;var s=this.preview_context;if(t){var r=t.getContext("2d");r.drawImage(i,0,0)}e(t?null:i.toDataURL("image/"+a.image_format,a.jpeg_quality/100),i,s);if(this.params.unfreeze_snap)this.unfreeze()},snap:function(e,t){if(!e)e=this.params.user_callback;if(!t)t=this.params.user_canvas;var a=this;var s=this.params;if(!this.loaded)return this.dispatch("error",new i("Webcam is not loaded yet"));if(!e)return this.dispatch("error",new i("Please provide a callback function or canvas to snap()"));if(this.preview_active){this.savePreview(e,t);return null}var r=document.createElement("canvas");r.width=this.params.dest_width;r.height=this.params.dest_height;var o=r.getContext("2d");if(this.params.flip_horiz){o.translate(s.dest_width,0);o.scale(-1,1)}var n=function(){if(this.src&&this.width&&this.height){o.drawImage(this,0,0,s.dest_width,s.dest_height)}if(s.crop_width&&s.crop_height){var a=document.createElement("canvas");a.width=s.crop_width;a.height=s.crop_height;var i=a.getContext("2d");i.drawImage(r,Math.floor(s.dest_width/2-s.crop_width/2),Math.floor(s.dest_height/2-s.crop_height/2),s.crop_width,s.crop_height,0,0,s.crop_width,s.crop_height);o=i;r=a}if(t){var n=t.getContext("2d");n.drawImage(r,0,0)}e(t?null:r.toDataURL("image/"+s.image_format,s.jpeg_quality/100),r,o)};if(this.userMedia){o.drawImage(this.video,0,0,this.params.dest_width,this.params.dest_height);n()}else if(this.iOS){var h=document.getElementById(this.container.id+"-ios_div");var l=document.getElementById(this.container.id+"-ios_img");var c=document.getElementById(this.container.id+"-ios_input");iFunc=function(e){n.call(l);l.removeEventListener("load",iFunc);h.style.backgroundImage="none";l.removeAttribute("src");c.value=null};if(!c.value){l.addEventListener("load",iFunc);c.style.display="block";c.focus();c.click();c.style.display="none"}else{iFunc(null)}}else{var d=this.getMovie()._snap();var l=new Image;l.onload=n;l.src="data:image/"+this.params.image_format+";base64,"+d}return null},configure:function(e){if(!e)e="camera";this.getMovie()._configure(e)},flashNotify:function(e,t){switch(e){case"flashLoadComplete":this.loaded=true;this.dispatch("load");break;case"cameraLive":this.live=true;this.dispatch("live");break;case"error":this.dispatch("error",new a(t));break;default:break}},b64ToUint6:function(e){return e>64&&e<91?e-65:e>96&&e<123?e-71:e>47&&e<58?e+4:e===43?62:e===47?63:0},base64DecToArr:function(e,t){var a=e.replace(/[^A-Za-z0-9\+\/]/g,""),i=a.length,s=t?Math.ceil((i*3+1>>2)/t)*t:i*3+1>>2,r=new Uint8Array(s);for(var o,n,h=0,l=0,c=0;c>>(16>>>o&24)&255}h=0}}return r},upload:function(e,t,a){var i=this.params.upload_name||"webcam";var s="";if(e.match(/^data\:image\/(\w+)/))s=RegExp.$1;else throw"Cannot locate image format in Data URI";var r=e.replace(/^data\:image\/\w+\;base64\,/,"");var o=new XMLHttpRequest;o.open("POST",t,true);if(o.upload&&o.upload.addEventListener){o.upload.addEventListener("progress",function(e){if(e.lengthComputable){var t=e.loaded/e.total;Webcam.dispatch("uploadProgress",t,e)}},false)}var n=this;o.onload=function(){if(a)a.apply(n,[o.status,o.responseText,o.statusText]);Webcam.dispatch("uploadComplete",o.status,o.responseText,o.statusText)};var h=new Blob([this.base64DecToArr(r)],{type:"image/"+s});var l=new FormData;l.append(i,h,i+"."+s.replace(/e/,""));o.send(l)}};Webcam.init();if(typeof define==="function"&&define.amd){define(function(){return Webcam})}else if(typeof module==="object"&&module.exports){module.exports=Webcam}else{e.Webcam=Webcam}})(window); \ No newline at end of file diff --git a/frappe/test_runner.py b/frappe/test_runner.py index 7723d0c7c6..dd1fa8ac39 100644 --- a/frappe/test_runner.py +++ b/frappe/test_runner.py @@ -309,9 +309,10 @@ def make_test_objects(doctype, test_records=None, verbose=None, reset=False): else: d.set_new_name() - if d.name in (frappe.local.test_objects.get(d.doctype) or []) and not reset: + if frappe.db.exists(d.doctype, d.name) and not reset: + frappe.db.rollback() # do not create test records, if already exists - return [] + continue # submit if docstatus is set to 1 for test record docstatus = d.docstatus @@ -336,7 +337,7 @@ def make_test_objects(doctype, test_records=None, verbose=None, reset=False): records.append(d.name) - frappe.db.commit() + frappe.db.commit() return records diff --git a/license.txt b/license.txt deleted file mode 100644 index a76f4ef0ba..0000000000 --- a/license.txt +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Frappe Technologies Pvt. Ltd. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index 10ad3df7ea..836c0957ef 100644 --- a/package.json +++ b/package.json @@ -14,20 +14,20 @@ }, "homepage": "https://frappe.io", "dependencies": { - "babel-core": "^6.24.1", - "babel-preset-babili": "0.0.12", - "babel-preset-es2015": "^6.24.1", - "babel-preset-es2016": "^6.24.1", - "babel-preset-es2017": "^6.24.1", - "chokidar": "^1.7.0", - "chromedriver": "^2.30.1", "cookie": "^0.3.1", "express": "^4.15.3", - "less": "^2.7.2", - "nightwatch": "^0.9.16", "redis": "^2.7.1", "socket.io": "^2.0.1", "superagent": "^3.5.2", - "touch": "^3.1.0" + "touch": "^3.1.0" + }, + "devDependencies": { + "babel-core": "^6.26.0", + "babel-preset-env": "^1.6.0", + "babel-preset-minify": "^0.2.0", + "chokidar": "^1.7.0", + "chromedriver": "^2.32.3", + "less": "^2.7.2", + "nightwatch": "^0.9.16" } } diff --git a/requirements.txt b/requirements.txt index b5c564eede..0216f85690 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ httplib2 jinja2 markdown2 markupsafe -mysqlclient==1.3.10 +-e git+https://github.com/frappe/mysqlclient-python.git@1.3.12#egg=mysqlclient python-geoip python-geoip-geolite2 python-dateutil diff --git a/setup.py b/setup.py index bbcf6cfb37..466449e956 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# imports - standard imports +import os, shutil +from distutils.command.clean import clean as Clean + from setuptools import setup, find_packages from pip.req import parse_requirements import re, ast @@ -11,6 +15,31 @@ with open('frappe/__init__.py', 'rb') as f: requirements = parse_requirements("requirements.txt", session="") +class CleanCommand(Clean): + def run(self): + Clean.run(self) + + basedir = os.path.abspath(os.path.dirname(__file__)) + + for relpath in ['build', '.cache', '.coverage', 'dist', 'frappe.egg-info']: + abspath = os.path.join(basedir, relpath) + if os.path.exists(abspath): + if os.path.isfile(abspath): + os.remove(abspath) + else: + shutil.rmtree(abspath) + + for dirpath, dirnames, filenames in os.walk(basedir): + for filename in filenames: + _, extension = os.path.splitext(filename) + if extension in ['.pyc']: + abspath = os.path.join(dirpath, filename) + os.remove(abspath) + for dirname in dirnames: + if dirname in ['__pycache__']: + abspath = os.path.join(dirpath, dirname) + shutil.rmtree(abspath) + setup( name='frappe', version=version, @@ -21,5 +50,9 @@ setup( zip_safe=False, include_package_data=True, install_requires=[str(ir.req) for ir in requirements], - dependency_links=[str(ir._link) for ir in requirements if ir._link] -) + dependency_links=[str(ir._link) for ir in requirements if ir._link], + cmdclass = \ + { + 'clean': CleanCommand + } +) \ No newline at end of file