Просмотр исходного кода

docstatus transition check, permissions #478

version-14
Anand Doshi 11 лет назад
Родитель
Сommit
e3ac45d4b0
4 измененных файлов: 31 добавлений и 23 удалений
  1. +1
    -0
      frappe/model/base_document.py
  2. +6
    -2
      frappe/model/document.py
  3. +7
    -0
      frappe/test_runner.py
  4. +17
    -21
      frappe/utils/__init__.py

+ 1
- 0
frappe/model/base_document.py Просмотреть файл

@@ -163,6 +163,7 @@ class BaseDocument(object):
columns = ", ".join(["`"+c+"`" for c in columns]),
values = ", ".join(["%s"] * len(columns))
), d.values())

self.set("__islocal", False)

def db_update(self):


+ 6
- 2
frappe/model/document.py Просмотреть файл

@@ -261,6 +261,8 @@ class Document(BaseDocument):
+ (" (%s, %s). " % (modified, self.modified)) \
+ _("Please refresh to get the latest document."),
raise_exception=frappe.TimestampMismatchError)
else:
self.check_docstatus_transition(0)

def check_docstatus_transition(self, docstatus):
if not self.docstatus:
@@ -292,8 +294,10 @@ class Document(BaseDocument):
raise frappe.ValidationError

def validate_update_after_submit(self):
# check only allowed values are updated
pass
if getattr(self, "ignore_validate_update_after_submit", False):
return

# TODO check only allowed values are updated

def _validate_mandatory(self):
if self.get("ignore_mandatory"):


+ 7
- 0
frappe/test_runner.py Просмотреть файл

@@ -17,12 +17,19 @@ def main(app=None, module=None, doctype=None, verbose=False, tests=()):
if not frappe.db:
frappe.connect()

# workaround! since there is no separate test db
frappe.clear_cache()

if doctype:
ret = run_tests_for_doctype(doctype, verbose=verbose, tests=tests)
elif module:
ret = run_tests_for_module(module, verbose=verbose, tests=tests)
else:
ret = run_all_tests(app, verbose)

# workaround! since there is no separate test db
frappe.clear_cache()

return ret

def run_all_tests(app=None, verbose=False):


+ 17
- 21
frappe/utils/__init__.py Просмотреть файл

@@ -9,6 +9,8 @@ import os
import re
import urllib
import frappe
import datetime
import math

no_value_fields = ['Section Break', 'Column Break', 'HTML', 'Table', 'FlexTable',
'Button', 'Image', 'Graph']
@@ -99,8 +101,6 @@ def getdate(string_date):
"""
Coverts string date (yyyy-mm-dd) to datetime.date object
"""
import datetime

if isinstance(string_date, datetime.date):
return string_date
elif isinstance(string_date, datetime.datetime):
@@ -149,8 +149,7 @@ def time_diff_in_hours(string_ed_date, string_st_date):
return round(float(time_diff(string_ed_date, string_st_date).seconds) / 3600, 6)

def now_datetime():
from datetime import datetime
return convert_utc_to_user_timezone(datetime.utcnow())
return convert_utc_to_user_timezone(datetime.datetime.utcnow())

def get_user_time_zone():
if getattr(frappe.local, "user_time_zone", None) is None:
@@ -194,7 +193,6 @@ def get_first_day(dt, d_years=0, d_months=0):
Returns the first day of the month for the date specified by date object
Also adds `d_years` and `d_months` if specified
"""
import datetime
dt = getdate(dt)

# d_years, d_months are "deltas" to apply to dt
@@ -208,21 +206,23 @@ def get_last_day(dt):
Returns last day of the month using:
`get_first_day(dt, 0, 1) + datetime.timedelta(-1)`
"""
import datetime
return get_first_day(dt, 0, 1) + datetime.timedelta(-1)

def get_datetime(datetime_str):
from datetime import datetime
if isinstance(datetime_str, datetime):
return datetime_str.replace(tzinfo=None)
try:
return datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S.%f')

if datetime_str=='0000-00-00 00:00:00.000000':
return None
except TypeError:
if isinstance(datetime_str, datetime.datetime):
return datetime_str.replace(tzinfo=None)
else:
raise

if len(datetime_str)==26:
return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S.%f')
else:
return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')
except ValueError:
if datetime_str=='0000-00-00 00:00:00.000000':
return None

return datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')

def get_datetime_str(datetime_obj):
if isinstance(datetime_obj, basestring):
@@ -309,7 +309,6 @@ def _round(num, precision=0):
# avoid rounding errors
num = round(num * multiplier if precision else num, 8)

import math
floor = math.floor(num)
decimal_part = num - floor

@@ -336,8 +335,6 @@ def encode(obj, encoding="utf-8"):

def parse_val(v):
"""Converts to simple datatypes from SQL query results"""
import datetime

if isinstance(v, (datetime.date, datetime.datetime)):
v = unicode(v)
elif isinstance(v, datetime.timedelta):
@@ -691,12 +688,11 @@ def pretty_date(iso_datetime):
Ported from PrettyDate by John Resig
"""
if not iso_datetime: return ''
from datetime import datetime
import math

if isinstance(iso_datetime, basestring):
iso_datetime = datetime.strptime(iso_datetime, '%Y-%m-%d %H:%M:%S.%f')
now_dt = datetime.strptime(now(), '%Y-%m-%d %H:%M:%S.%f')
iso_datetime = datetime.datetime.strptime(iso_datetime, '%Y-%m-%d %H:%M:%S.%f')
now_dt = datetime.datetime.strptime(now(), '%Y-%m-%d %H:%M:%S.%f')
dt_diff = now_dt - iso_datetime

# available only in python 2.7+


Загрузка…
Отмена
Сохранить