Commit 6dbd1544 authored by Anand Doshi's avatar Anand Doshi
Browse files

Merge branch 'develop'

parents 473d1e41 2c501801
No related merge requests found
Showing with 71 additions and 36 deletions
+71 -36
......@@ -1052,7 +1052,9 @@ def publish_realtime(*args, **kwargs):
:param room: Room in which to publish update (default entire site)
:param user: Transmit to user
:param doctype: Transmit to doctype, docname
:param docname: Transmit to doctype, docname"""
:param docname: Transmit to doctype, docname
:param after_commit: (default False) will emit after current transaction is committed
"""
import frappe.async
return frappe.async.publish_realtime(*args, **kwargs)
......
from __future__ import unicode_literals
__version__ = "6.17.4"
__version__ = "6.17.5"
......@@ -97,7 +97,7 @@ def is_file_old(file_path):
return ((time.time() - os.stat(file_path).st_mtime) > TASK_LOG_MAX_AGE)
def publish_realtime(event=None, message=None, room=None, user=None, doctype=None, docname=None, now=False):
def publish_realtime(event=None, message=None, room=None, user=None, doctype=None, docname=None, after_commit=False):
"""Publish real-time updates
:param event: Event name, like `task_progress` etc. that will be handled by the client (default is `task_progress` if within task or `global`)
......@@ -105,23 +105,24 @@ def publish_realtime(event=None, message=None, room=None, user=None, doctype=Non
:param room: Room in which to publish update (default entire site)
:param user: Transmit to user
:param doctype: Transmit to doctype, docname
:param docname: Transmit to doctype, docname"""
:param docname: Transmit to doctype, docname
:param after_commit: (default False) will emit after current transaction is committed"""
if message is None:
message = {}
if event is None:
if frappe.local.task_id:
if getattr(frappe.local, "task_id", None):
event = "task_progress"
else:
event = "global"
if not room:
if frappe.local.task_id:
if getattr(frappe.local, "task_id", None):
room = get_task_progress_room()
if not "task_id" in message:
message["task_id"] = frappe.local.task_id
now = True
after_commit = False
elif user:
room = get_user_room(user)
elif doctype and docname:
......@@ -129,10 +130,10 @@ def publish_realtime(event=None, message=None, room=None, user=None, doctype=Non
else:
room = get_site_room()
if now:
emit_via_redis(event, message, room)
else:
if after_commit:
frappe.local.realtime_log.append([event, message, room])
else:
emit_via_redis(event, message, room)
def emit_via_redis(event, message, room):
"""Publish real-time updates via redis
......@@ -159,7 +160,7 @@ def put_log(line_no, line, task_id=None):
"lines": {line_no: line}
},
"task_id": task_id
}, room=task_progress_room, now=True)
}, room=task_progress_room)
r.hset(task_log_key, line_no, line)
r.expire(task_log_key, 3600)
......
......@@ -218,6 +218,7 @@ def migrate(context, rebuild_website=False):
clear_notifications()
finally:
frappe.publish_realtime("version-update")
frappe.destroy()
if rebuild_website:
......@@ -225,6 +226,7 @@ def migrate(context, rebuild_website=False):
else:
call_command(sync_www, context)
def prepare_for_update():
from frappe.sessions import clear_global_cache
clear_global_cache()
......
......@@ -46,13 +46,15 @@ class Comment(Document):
if self.comment_docname == frappe.session.user:
message = self.as_dict()
message['broadcast'] = True
frappe.publish_realtime('new_message', message)
frappe.publish_realtime('new_message', message, after_commit=True)
else:
# comment_docname contains the user who is addressed in the messages' page comment
frappe.publish_realtime('new_message', self.as_dict(), user=self.comment_docname)
frappe.publish_realtime('new_message', self.as_dict(),
user=self.comment_docname, after_commit=True)
else:
frappe.publish_realtime('new_comment', self.as_dict(), doctype= self.comment_doctype,
docname = self.comment_docname)
frappe.publish_realtime('new_comment', self.as_dict(),
doctype= self.comment_doctype, docname = self.comment_docname,
after_commit=True)
self.notify_mentions()
......
......@@ -30,7 +30,7 @@ frappe.ui.form.on("Communication", "refresh", function(frm) {
frappe.ui.form.on("Communication", "onload", function(frm) {
if(frm.doc.content) {
frm.doc.content = frappe.utils.remove_script_and_style(frm.doc.content);
frm.doc.content = frappe.dom.remove_script_and_style(frm.doc.content);
}
frm.set_query("reference_doctype", function() {
return {
......
......@@ -51,7 +51,7 @@ class Communication(Document):
comment["comment_type"] = comment["communication_medium"]
frappe.publish_realtime('new_comment', comment, doctype = self.reference_doctype,
docname = self.reference_name)
docname = self.reference_name, after_commit=True)
def on_update(self):
"""Update parent status as `Open` or `Replied`."""
......
......@@ -218,7 +218,7 @@ def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False,
# publish task_update
frappe.publish_realtime("data_import_progress", {"progress": [i, total]},
user=frappe.session.user, now=True)
user=frappe.session.user)
try:
doc = get_doc(row_idx)
......
......@@ -74,12 +74,12 @@ def install_app(name):
frappe.throw(_("You cannot install this app"))
frappe.publish_realtime("install_app_progress", {"status": _("Installing App {0}").format(name)},
user=frappe.session.user, now=True)
user=frappe.session.user)
frappe.installer.install_app(name)
frappe.publish_realtime("install_app_progress", {"status": _("{0} Installed").format(name)},
user=frappe.session.user, now=True)
user=frappe.session.user)
def get_app(name):
"""Get app using git clone and install it in bench environment"""
......@@ -89,7 +89,7 @@ def get_app(name):
raise frappe.ValidationError
frappe.publish_realtime("install_app_progress", {"status": _("Downloading App {0}").format(name)},
user=frappe.session.user, now=True)
user=frappe.session.user)
args = [find_executable('bench'), 'get-app', name, app_listing[name]['repo_url']]
......
......@@ -5,7 +5,7 @@ app_publisher = "Frappe Technologies Pvt. Ltd."
app_description = "Full stack web framework with Python, Javascript, MariaDB, Redis, Node"
app_icon = "octicon octicon-circuit-board"
app_version = "6.17.4"
app_version = "6.17.5"
app_color = "orange"
source_link = "https://github.com/frappe/frappe"
app_license = "MIT"
......
......@@ -649,11 +649,11 @@ class Document(BaseDocument):
def notify_update(self):
"""Publish realtime that the current document is modified"""
frappe.publish_realtime("doc_update", {"modified": self.modified, "doctype": self.doctype, "name": self.name},
doctype=self.doctype, docname=self.name)
doctype=self.doctype, docname=self.name, after_commit=True)
if not self.meta.get("read_only") and not self.meta.get("issingle") and \
not self.meta.get("istable"):
frappe.publish_realtime("list_update", {"doctype": self.doctype})
frappe.publish_realtime("list_update", {"doctype": self.doctype}, after_commit=True)
def check_no_back_links_exist(self):
......
......@@ -18,11 +18,15 @@
"website/js/website.js",
"public/js/lib/socket.io.min.js"
],
"js/editor.min.js": [
"public/js/lib/jquery/jquery.hotkeys.js",
"public/js/lib/beautify-html.js",
"public/js/frappe/ui/editor.html",
"public/js/frappe/ui/editor.js"
"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/control.js",
"public/js/frappe/form/link_selector.js",
"public/js/frappe/ui/dialog.js"
],
"css/desk.min.css": [
"public/js/lib/jquery/bootstrap_theme/jquery-ui.selected.css",
......@@ -81,7 +85,6 @@
"public/js/frappe/form/control.js",
"public/js/frappe/form/link_selector.js",
"public/js/frappe/ui/dialog.js",
"public/js/frappe/ui/button.js",
"public/js/frappe/ui/app_icon.js",
"public/js/frappe/model/model.js",
......
......@@ -108,6 +108,7 @@ a.badge-hover:active .badge {
background-color: #D8DFE5;
}
.msgprint {
margin: 15px 0px;
text-align: center;
}
.msgprint pre {
......
......@@ -108,6 +108,7 @@ a.badge-hover:active .badge {
background-color: #D8DFE5;
}
.msgprint {
margin: 15px 0px;
text-align: center;
}
.msgprint pre {
......
......@@ -108,6 +108,7 @@ a.badge-hover:active .badge {
background-color: #D8DFE5;
}
.msgprint {
margin: 15px 0px;
text-align: center;
}
.msgprint pre {
......
......@@ -70,6 +70,14 @@ frappe.Application = Class.extend({
frappe.csrf_token = data.csrf_token;
}
});
frappe.realtime.on("version-update", function() {
var dialog = frappe.msgprint(__("The application has been updated to a new version, please refresh this page"));
dialog.set_primary_action("Refresh", function() {
location.reload(true);
});
dialog.get_close_btn().toggle(false);
});
},
load_bootinfo: function() {
......
......@@ -24,6 +24,18 @@ frappe.dom = {
// execute the script globally
document.getElementsByTagName('head')[0].appendChild(el);
},
remove_script_and_style: function(txt) {
var div = document.createElement('div');
div.innerHTML = txt;
["script", "style", "noscript", "title", "meta", "base", "head"].forEach(function(e, i) {
var elements = div.getElementsByTagName(e);
var i = elements.length;
while (i--) {
elements[i].parentNode.removeChild(elements[i]);
}
});
return div.innerHTML;
},
set_style: function(txt, id) {
if(!txt) return;
......
......@@ -102,9 +102,11 @@ frappe.ui.form.Control = Class.extend({
undefined;
},
set_model_value: function(value) {
if(frappe.model.set_value(this.doctype, this.docname, this.df.fieldname,
value, this.df.fieldtype)) {
this.last_value = value;
if(this.doctype) {
if(frappe.model.set_value(this.doctype, this.docname, this.df.fieldname,
value, this.df.fieldtype)) {
this.last_value = value;
}
}
},
});
......@@ -1384,7 +1386,7 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({
},
_set_input: function(value) {
if(value == null) value = "";
value = frappe.utils.remove_script_and_style(value);
value = frappe.dom.remove_script_and_style(value);
this.editor.set_input(value);
this.md_editor.val(value);
this.last_value = value;
......
......@@ -148,7 +148,7 @@ frappe.ui.form.Comments = Class.extend({
if(c.comment_type=="Email") {
c.comment = c.comment.split("<!-- original-reply -->")[0];
c.comment = frappe.utils.strip_original_content(c.comment);
c.comment = frappe.utils.remove_script_and_style(c.comment);
c.comment = frappe.dom.remove_script_and_style(c.comment);
c.original_comment = c.comment;
c.comment = frappe.utils.toggle_blockquote(c.comment);
......
......@@ -202,7 +202,7 @@ frappe.format = function(value, df, options, doc) {
var formatted = formatter(value, df, options, doc);
if (typeof formatted == "string")
formatted = frappe.utils.remove_script_and_style(formatted);
formatted = frappe.dom.remove_script_and_style(formatted);
return formatted;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment