Browse Source

[fixes] [minor] based on error reports

version-14
Rushabh Mehta 10 years ago
parent
commit
766d4540b9
6 changed files with 42 additions and 10 deletions
  1. +3
    -4
      frappe/core/doctype/custom_field/custom_field.py
  2. +22
    -1
      frappe/core/doctype/custom_field/test_custom_field.py
  3. +3
    -1
      frappe/database.py
  4. +3
    -1
      frappe/model/db_schema.py
  5. +5
    -0
      frappe/tests/test_db.py
  6. +6
    -3
      frappe/utils/data.py

+ 3
- 4
frappe/core/doctype/custom_field/custom_field.py View File

@@ -9,7 +9,6 @@ from frappe import _
from frappe.model.document import Document

class CustomField(Document):

def autoname(self):
self.set_fieldname()
self.name = self.dt + "-" + self.fieldname
@@ -40,9 +39,9 @@ class CustomField(Document):
self.create_property_setter()

# update the schema
if not frappe.flags.in_test:
from frappe.model.db_schema import updatedb
updatedb(self.dt)
# if not frappe.flags.in_test:
from frappe.model.db_schema import updatedb
updatedb(self.dt)

def on_trash(self):
# delete property setter entries


+ 22
- 1
frappe/core/doctype/custom_field/test_custom_field.py View File

@@ -1,10 +1,31 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# See license.txt

from __future__ import unicode_literals

import frappe
import unittest

test_records = frappe.get_test_records('Custom Field')

from frappe.model.db_schema import InvalidColumnName

class TestCustomField(unittest.TestCase):
pass
def test_non_ascii(self):
cf = frappe.get_doc({
"doctype":"Custom Field",
"dt": "ToDo",
"fieldtype": "Data",
"fieldname": "δου"
})

self.assertRaises(InvalidColumnName, cf.insert)

# todo = frappe.get_doc({
# "doctype": "ToDo",
# "description": "test",
# "δου": "greek"
# })
# todo.insert()

+ 3
- 1
frappe/database.py View File

@@ -556,4 +556,6 @@ class Database:
self._conn = None

def escape(self, s):
return unicode(MySQLdb.escape_string((s or "").encode("utf-8")), "utf-8")
if isinstance(s, unicode):
s = (s or "").encode("utf-8")
return unicode(MySQLdb.escape_string(s), "utf-8")

+ 3
- 1
frappe/model/db_schema.py View File

@@ -13,6 +13,8 @@ import frappe
from frappe import _
from frappe.utils import cstr, cint

class InvalidColumnName(frappe.ValidationError): pass

type_map = {
'Currency': ('decimal', '18,6')
,'Int': ('int', '11')
@@ -373,7 +375,7 @@ def validate_column_name(n):
n = n.replace(' ','_').strip().lower()
import re
if re.search("[\W]", n):
frappe.throw(_("Fieldname {0} cannot contain letters, numbers or spaces").format(n))
frappe.throw(_("Fieldname {0} cannot contain letters, numbers or spaces").format(n), InvalidColumnName)
return n




+ 5
- 0
frappe/tests/test_db.py View File

@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

@@ -14,3 +16,6 @@ class TestDB(unittest.TestCase):
self.assertEquals(frappe.db.get_value("User", {"name": ["<=", "Administrator"]}), "Administrator")
self.assertEquals("test1@example.com", frappe.db.get_value("User", {"name": [">", "s"]}))
self.assertEquals("test1@example.com", frappe.db.get_value("User", {"name": [">=", "t"]}))

def test_escape(self):
frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode("utf-8"))

+ 6
- 3
frappe/utils/data.py View File

@@ -165,9 +165,12 @@ def formatdate(string_date=None, format_string=None):

out = frappe.local.user_format or "yyyy-mm-dd"

return out.replace("dd", date.strftime("%d"))\
.replace("mm", date.strftime("%m"))\
.replace("yyyy", date.strftime("%Y"))
try:
return out.replace("dd", date.strftime("%d"))\
.replace("mm", date.strftime("%m"))\
.replace("yyyy", date.strftime("%Y"))
except ValueError, e:
raise frappe.ValidationError, str(e)

def global_date_format(date):
"""returns date as 1 January 2012"""


Loading…
Cancel
Save