From c0ef741ce8eea8b08bbb72ca0444ab5d79e81989 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 24 Feb 2017 16:01:30 +0530 Subject: [PATCH] [hot] fix socket js --- frappe/geo/country_info.json | 2 +- frappe/patches.txt | 1 + frappe/public/js/frappe/socketio_client.js | 3 ++- frappe/public/js/legacy/form.js | 4 ++-- frappe/website/context.py | 2 +- frappe/website/website_generator.py | 27 ++++++++++++++-------- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/frappe/geo/country_info.json b/frappe/geo/country_info.json index eda1d7fd11..2676381961 100644 --- a/frappe/geo/country_info.json +++ b/frappe/geo/country_info.json @@ -2325,7 +2325,7 @@ "Asia/Dushanbe" ] }, - "Tanzania, United Republic of": { + "Tanzania": { "code": "tz", "currency": "TZS", "currency_name": "Tanzanian Shilling", diff --git a/frappe/patches.txt b/frappe/patches.txt index 7c0c83ce93..d9df6b4407 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -160,3 +160,4 @@ execute:frappe.db.sql("update tabCommunication set communication_date = creation frappe.patches.v7_2.fix_email_queue_recipient frappe.patches.v7_2.update_feedback_request execute:frappe.rename_doc('Country', 'Macedonia, Republic of', 'Macedonia', ignore_if_exists=True) +execute:frappe.rename_doc('Country', 'Tanzania, United Republic of', 'Tanzania', ignore_if_exists=True) diff --git a/frappe/public/js/frappe/socketio_client.js b/frappe/public/js/frappe/socketio_client.js index cd3010bcbe..749110d00b 100644 --- a/frappe/public/js/frappe/socketio_client.js +++ b/frappe/public/js/frappe/socketio_client.js @@ -137,7 +137,8 @@ frappe.socket = { }, doc_open: function(doctype, docname) { // notify that the user has opened this doc, if not already notified - if(frappe.socket.last_doc[0]!=doctype && frappe.socket.last_doc[0]!=docname) { + if(!frappe.socket.last_doc + || (frappe.socket.last_doc[0]!=doctype && frappe.socket.last_doc[0]!=docname)) { frappe.socket.socket.emit('doc_open', doctype, docname); } frappe.socket.last_doc = [doctype, docname]; diff --git a/frappe/public/js/legacy/form.js b/frappe/public/js/legacy/form.js index 2466af7b7c..509fdba75d 100644 --- a/frappe/public/js/legacy/form.js +++ b/frappe/public/js/legacy/form.js @@ -925,8 +925,8 @@ _f.Frm.prototype.validate_form_action = function(action) { var allowed_for_workflow = false; var perms = frappe.perm.get_perm(this.doc.doctype)[0]; - // Allow submit, write and create permissions for read only documents that are assigned by - // workflows if the user already have those permissions. This is to allow for users to + // Allow submit, write and create permissions for read only documents that are assigned by + // workflows if the user already have those permissions. This is to allow for users to // continue through the workflow states and to allow execution of functions like Duplicate. if (frappe.workflow.is_read_only(this.doctype, this.docname) && (perms["write"] || perms["create"] || perms["submit"])) { diff --git a/frappe/website/context.py b/frappe/website/context.py index e179d56b61..e233234905 100644 --- a/frappe/website/context.py +++ b/frappe/website/context.py @@ -75,7 +75,7 @@ def build_context(context): # provide doc if context.doc: context.update(context.doc.as_dict()) - context.update(context.doc.website) + context.update(context.doc.get_website_properties()) if hasattr(context.doc, "get_context"): ret = context.doc.get_context(context) diff --git a/frappe/website/website_generator.py b/frappe/website/website_generator.py index 29b4291196..4959c247a5 100644 --- a/frappe/website/website_generator.py +++ b/frappe/website/website_generator.py @@ -3,13 +3,10 @@ from __future__ import unicode_literals import frappe -from frappe.utils import quoted from frappe.model.document import Document -from frappe.model.naming import append_number_if_name_exists -from frappe.website.utils import cleanup_page_name, get_home_page +from frappe.website.utils import cleanup_page_name from frappe.website.render import clear_cache from frappe.modules import get_module_name -from frappe.website.router import get_page_context_from_template, get_page_context class WebsiteGenerator(Document): website = frappe._dict( @@ -20,9 +17,16 @@ class WebsiteGenerator(Document): self.route = None super(WebsiteGenerator, self).__init__(*args, **kwargs) + def get_website_properties(self, key=None, default=None): + out = getattr(self, '_website', None) or getattr(self, 'website', None) or {} + if key: + return out.get(key, default) + else: + return out + def autoname(self): if not self.name and self.meta.autoname != "hash": - self.name = self.scrub(self.get(self.website.page_title_field or "title")) + self.name = self.make_route() def onload(self): self.get("__onload").update({ @@ -38,7 +42,7 @@ class WebsiteGenerator(Document): self.route = self.route.strip('/.')[:139] def make_route(self): - return self.scrub(self.get(self.website.page_title_field or "name")) + return self.scrub(self.get(self.get_website_properties('page_title_field', 'title'))) def clear_cache(self): clear_cache(self.route) @@ -55,8 +59,8 @@ class WebsiteGenerator(Document): def is_website_published(self): """Return true if published in website""" - if self.website.condition_field: - return self.get(self.website.condition_field) and True or False + if self.get_website_properties('condition_field'): + return self.get(self.get_website_properties('condition_field')) and True or False else: return True @@ -71,9 +75,12 @@ class WebsiteGenerator(Document): "controller": get_module_name(self.doctype, self.meta.module), }) - route.update(self.website) + print self.get_website_properties() + + route.update(self.get_website_properties()) if not route.page_title: - route.page_title = self.get(self.website.page_title_field or "name") + route.page_title = self.get(self.get_website_properties('page_title'), 'title') \ + or self.get('name') return route