Quellcode durchsuchen

Fieldname validation, fixes frappe/erpnext#2608

version-14
Anand Doshi vor 10 Jahren
Ursprung
Commit
2e53a15bda
4 geänderte Dateien mit 22 neuen und 13 gelöschten Zeilen
  1. +4
    -3
      frappe/__init__.py
  2. +2
    -1
      frappe/custom/doctype/custom_field/custom_field.json
  3. +12
    -5
      frappe/desk/notifications.py
  4. +4
    -4
      frappe/model/db_schema.py

+ 4
- 3
frappe/__init__.py Datei anzeigen

@@ -202,21 +202,22 @@ def msgprint(msg, small=0, raise_exception=0, as_table=False):
:param raise_exception: [optional] Raise given exception and show message.
:param as_table: [optional] If `msg` is a list of lists, render as HTML table.
"""
from utils import cstr, encode

def _raise_exception():
if raise_exception:
if flags.rollback_on_exception:
db.rollback()
import inspect
if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception):
raise raise_exception, msg
raise raise_exception, encode(msg)
else:
raise ValidationError, msg
raise ValidationError, encode(msg)

if flags.mute_messages:
_raise_exception()
return

from utils import cstr
if as_table and type(msg) in (list, tuple):
msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(['<tr>'+''.join(['<td>%s</td>' % c for c in r])+'</tr>' for r in msg]) + '</table>'



+ 2
- 1
frappe/custom/doctype/custom_field/custom_field.json Datei anzeigen

@@ -50,6 +50,7 @@
"search_index": 0
},
{
"default": "Data",
"fieldname": "fieldtype",
"fieldtype": "Select",
"in_filter": 1,
@@ -275,7 +276,7 @@
],
"icon": "icon-glass",
"idx": 1,
"modified": "2015-02-05 05:11:36.425019",
"modified": "2015-02-25 03:39:23.573928",
"modified_by": "Administrator",
"module": "Custom",
"name": "Custom Field",


+ 12
- 5
frappe/desk/notifications.py Datei anzeigen

@@ -26,13 +26,20 @@ def get_notifications():
if d in notification_count:
open_count_doctype[d] = notification_count[d]
else:
result = frappe.get_list(d, fields=["count(*)"],
filters=condition, as_list=True)[0][0]
try:
result = frappe.get_list(d, fields=["count(*)"],
filters=condition, as_list=True)[0][0]

open_count_doctype[d] = result
except Exception, e:
# OperationalError: (1412, 'Table definition has changed, please retry transaction')
if e.args[0]!=1412:
raise

cache.set_value("notification_count:" + frappe.session.user + ":" + d,
result)
else:
open_count_doctype[d] = result

cache.set_value("notification_count:" + frappe.session.user + ":" + d,
result)

for m in config.for_module:
if m in notification_count:


+ 4
- 4
frappe/model/db_schema.py Datei anzeigen

@@ -402,12 +402,12 @@ class DbManager:

def validate_column_name(n):
n = n.replace(' ','_').strip().lower()
if re.search("[\W]", n, re.UNICODE):
frappe.throw(_("Fieldname {0} cannot contain letters, numbers or spaces").format(n), InvalidColumnName)
special_characters = re.findall("[\W]", n, re.UNICODE)
if special_characters:
special_characters = ", ".join('"{0}"'.format(c) for c in special_characters)
frappe.throw(_("Fieldname {0} cannot have special characters like {1}").format(cstr(n), special_characters), InvalidColumnName)
return n



def remove_all_foreign_keys():
frappe.db.sql("set foreign_key_checks = 0")
frappe.db.commit()


Laden…
Abbrechen
Speichern