@@ -14,7 +14,7 @@ import os, sys, importlib, inspect, json | |||||
from .exceptions import * | from .exceptions import * | ||||
from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template | from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template | ||||
__version__ = '10.0.10' | |||||
__version__ = '10.0.11' | |||||
__title__ = "Frappe Framework" | __title__ = "Frappe Framework" | ||||
local = Local() | local = Local() | ||||
@@ -197,22 +197,26 @@ def _set_amended_name(doc): | |||||
doc.name = am_prefix + '-' + str(am_id) | doc.name = am_prefix + '-' + str(am_id) | ||||
return doc.name | return doc.name | ||||
def append_number_if_name_exists(doctype, name, fieldname='name', separator='-'): | |||||
if frappe.db.exists(doctype, name): | |||||
def append_number_if_name_exists(doctype, value, fieldname='name', separator='-'): | |||||
exists = frappe.db.exists(doctype, | |||||
value if fieldname == 'name' else {fieldname: value}) | |||||
if exists: | |||||
# should be escaped 2 times since | # should be escaped 2 times since | ||||
# python string will parse the first escape | # python string will parse the first escape | ||||
escaped_name = re.escape(re.escape(name)) | |||||
last = frappe.db.sql("""select name from `tab{doctype}` | |||||
where {fieldname} regexp '^{name}{separator}[[:digit:]]+' | |||||
escaped_value = re.escape(re.escape(value)) | |||||
last = frappe.db.sql("""select {fieldname} from `tab{doctype}` | |||||
where {fieldname} regexp '^{value}{separator}[[:digit:]]+' | |||||
order by length({fieldname}) desc, | order by length({fieldname}) desc, | ||||
{fieldname} desc limit 1""".format(doctype=doctype, | {fieldname} desc limit 1""".format(doctype=doctype, | ||||
name=escaped_name, fieldname=fieldname, separator=separator)) | |||||
value=escaped_value, fieldname=fieldname, separator=separator)) | |||||
if last: | if last: | ||||
count = str(cint(last[0][0].rsplit("-", 1)[1]) + 1) | |||||
count = str(cint(last[0][0].rsplit(separator, 1)[1]) + 1) | |||||
else: | else: | ||||
count = "1" | count = "1" | ||||
name = "{0}{1}{2}".format(name, separator, count) | |||||
value = "{0}{1}{2}".format(value, separator, count) | |||||
return name | |||||
return value |
@@ -233,7 +233,7 @@ frappe.Application = Class.extend({ | |||||
refresh_notifications: function() { | refresh_notifications: function() { | ||||
var me = this; | var me = this; | ||||
if(frappe.session_alive) { | |||||
if(frappe.session_alive && frappe.boot && !frappe.boot.in_setup_wizard) { | |||||
return frappe.call({ | return frappe.call({ | ||||
method: "frappe.desk.notifications.get_notifications", | method: "frappe.desk.notifications.get_notifications", | ||||
callback: function(r) { | callback: function(r) { | ||||
@@ -0,0 +1,28 @@ | |||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors | |||||
# MIT License. See license.txt | |||||
from __future__ import unicode_literals | |||||
import unittest | |||||
import frappe | |||||
from frappe.model.naming import append_number_if_name_exists | |||||
class TestNaming(unittest.TestCase): | |||||
def test_append_number_if_name_exists(self): | |||||
''' | |||||
Append number to name based on existing values | |||||
if Bottle exists | |||||
Bottle -> Bottle-1 | |||||
if Bottle-1 exists | |||||
Bottle -> Bottle-2 | |||||
''' | |||||
note = frappe.new_doc('Note') | |||||
note.title = 'Test' | |||||
note.insert() | |||||
title2 = append_number_if_name_exists('Note', 'Test') | |||||
self.assertEquals(title2, 'Test-1') | |||||
title2 = append_number_if_name_exists('Note', 'Test', 'title', '_') | |||||
self.assertEquals(title2, 'Test_1') |
@@ -21,9 +21,10 @@ class WebsiteSlideshow(Document): | |||||
def validate_images(self): | def validate_images(self): | ||||
''' atleast one image file should be public for slideshow ''' | ''' atleast one image file should be public for slideshow ''' | ||||
files = map(lambda row: row.image, self.slideshow_items) | files = map(lambda row: row.image, self.slideshow_items) | ||||
result = frappe.get_all("File", filters={ "file_url":("in", files) }, fields="is_private") | |||||
if any([file.is_private for file in result]): | |||||
frappe.throw(_("All Images attached to Website Slideshow should be public")) | |||||
if files: | |||||
result = frappe.get_all("File", filters={ "file_url":("in", files) }, fields="is_private") | |||||
if any([file.is_private for file in result]): | |||||
frappe.throw(_("All Images attached to Website Slideshow should be public")) | |||||
def get_slideshow(doc): | def get_slideshow(doc): | ||||
if not doc.slideshow: | if not doc.slideshow: | ||||