Merge branch 'model-cleanup' of github.com:frappe/frappe into model-cleanup

This commit is contained in:
Rushabh Mehta 2014-04-02 16:00:50 +05:30
commit ae4a7904d7
12 changed files with 29 additions and 24 deletions

View file

@ -210,7 +210,9 @@ def create_folder(path):
def set_user(username):
from frappe.utils.user import User
local.session["user"] = username
local.session.user = username
local.session.sid = username
local.session.data = {}
local.user = User(username)
local.restrictions = None
local.user_perms = {}

View file

@ -21,7 +21,7 @@ def get_bootinfo():
get_user(bootinfo)
# system info
bootinfo['control_panel'] = frappe.get_doc('Control Panel')
bootinfo['control_panel'] = frappe.get_doc('Control Panel').as_dict()
bootinfo['sysdefaults'] = frappe.defaults.get_defaults()
bootinfo['server_date'] = frappe.utils.nowdate()
bootinfo["send_print_in_body_and_attachment"] = frappe.db.get_value("Outgoing Email Settings",

View file

@ -79,8 +79,7 @@ def run(fn, args):
if args.get("profile") and fn!="serve":
pr.disable()
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps = pstats.Stats(pr, stream=s).sort_stats('tottime', 'ncalls')
ps.print_stats()
print s.getvalue()
@ -341,7 +340,7 @@ def latest(verbose=True, rebuild_website_config=True):
print "\n".join(frappe.local.patch_log_list)
# sync
frappe.model.sync.sync_all()
frappe.model.sync.sync_all(verbose=verbose)
# build website config if any changes in templates etc.
if rebuild_website_config:
@ -359,10 +358,10 @@ def latest(verbose=True, rebuild_website_config=True):
frappe.destroy()
@cmd
def sync_all(force=False):
def sync_all(force=False, verbose=True):
import frappe.model.sync
frappe.connect()
frappe.model.sync.sync_all(force=force)
frappe.model.sync.sync_all(force=force, verbose=verbose)
frappe.destroy()
@cmd

View file

@ -1,6 +1,6 @@
{
"autoname": "DL.####",
"creation": "2013-01-29 17:54:08.000000",
"creation": "2013-01-29 17:55:08.000000",
"docstatus": 0,
"doctype": "DocType",
"fields": [
@ -98,7 +98,6 @@
"permlevel": 0
},
{
"default": "no add rows",
"fieldname": "fields",
"fieldtype": "Table",
"label": "Fields",

View file

@ -50,7 +50,7 @@ class CustomizeForm(Document):
'fieldtype': [['Currency', 'Float'], ['Small Text', 'Data'], ['Text', 'Text Editor', 'Code']],
}
def get(self):
def _get(self):
"""
Gets DocFields applied with Property Setter customizations via Customize Form Field
"""
@ -60,8 +60,8 @@ class CustomizeForm(Document):
meta = frappe.get_meta(self.doc_type)
for d in meta.get("fields"):
new = self.append('fields', {})
self.set({ 'list': self.docfield_properties, 'doc' : d, 'doc_to_set': new })
self.set({ 'list': self.doctype_properties, 'doc': d })
self._set({ 'list': self.docfield_properties, 'doc' : d, 'doc_to_set': new })
self._set({ 'list': self.doctype_properties, 'doc': d })
def clear(self):
"""
@ -69,10 +69,10 @@ class CustomizeForm(Document):
"""
# Clear table before adding new doctype's fields
self.set('fields', [])
self.set({ 'list': self.doctype_properties, 'value': None })
self._set({ 'list': self.doctype_properties, 'value': None })
def set(self, args):
def _set(self, args):
"""
Set a list of attributes of a doc to a value
or to attribute values of a doc passed
@ -313,7 +313,7 @@ class CustomizeForm(Document):
frappe.clear_cache(doctype=self.doc_type)
self.get()
self._get()
def remove_forbidden(self, string):
"""

View file

@ -9,7 +9,7 @@ import MySQLdb
import warnings
import frappe
import datetime
from frappe.utils import now
from frappe.utils import now, get_datetime, get_datetime_str
class Database:
"""
@ -44,6 +44,8 @@ class Database:
self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password,
use_unicode=True, charset='utf8')
self._conn.converter[246]=float
self._conn.converter[12]=get_datetime
self._cursor = self._conn.cursor()
if self.user != 'root':
self.use(self.user)

View file

@ -109,7 +109,8 @@ class BaseDocument(object):
doc = self.get_valid_dict()
doc["doctype"] = self.doctype
for df in self.meta.get_table_fields():
doc[df.fieldname] = [d.as_dict() for d in (self.get(df.fieldname) or [])]
children = self.get(df.fieldname) or []
doc[df.fieldname] = [d.as_dict() for d in children]
return doc
def get_table_field_doctype(self, fieldname):

View file

@ -11,9 +11,9 @@ import os, sys
from frappe.modules.import_file import import_file_by_path
from frappe.utils import get_path, cstr
def sync_all(force=0):
def sync_all(force=0, verbose=False):
for app in frappe.get_installed_apps():
sync_for(app, force)
sync_for(app, force, verbose=verbose)
frappe.clear_cache()
def sync_for(app_name, force=0, sync_everything = False, verbose=False):

View file

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe, os, json
from frappe.modules import scrub, get_module_path, scrub_dt_dn
from frappe.utils import get_datetime_str
def import_files(module, dt=None, dn=None, force=False):
if type(module) is list:
@ -36,7 +37,7 @@ def import_file_by_path(path, force=False):
if doc:
if not force:
# check if timestamps match
if doc['modified']==str(frappe.db.get_value(doc['doctype'], doc['name'], 'modified')):
if doc['modified']==get_datetime_str(frappe.db.get_value(doc['doctype'], doc['name'], 'modified')):
return False
original_modified = doc["modified"]

View file

@ -40,11 +40,11 @@ $.extend(frappe.datetime, {
},
now_time: function() {
var d = new Date();
return [double_digit(d.getHours()), double_digit(d.getMinutes()), double_digit(d.getSeconds())].join(":")
return [double_digit(d.getHours()), double_digit(d.getMinutes()), double_digit(d.getSeconds())].join(":") + "." + d.getMilliseconds();
},
get_datetime_as_string: function(d) {
if(!d) return null;
return [d.getFullYear(), double_digit(d.getMonth()+1), double_digit(d.getDate())].join("-") + " "
+ [double_digit(d.getHours()), double_digit(d.getMinutes()), double_digit(d.getSeconds())].join(":");
+ [double_digit(d.getHours()), double_digit(d.getMinutes()), double_digit(d.getSeconds())].join(":") + "." + d.getMilliseconds();
}
});

View file

@ -174,6 +174,7 @@ frappe.datetime = {
var val = d[2]+'-'+d[0]+'-'+d[1];
}
if(time_str.index(".")===-1) time_str += ".0";
if(no_time_str)time_str = '';
return val + time_str;

View file

@ -188,7 +188,7 @@ def today():
def nowtime():
"""return current time in hh:mm"""
return now_datetime().strftime('%H:%M')
return now_datetime().strftime('%H:%M:%S.%f')
def get_first_day(dt, d_years=0, d_months=0):
"""
@ -215,7 +215,7 @@ def get_last_day(dt):
def get_datetime(datetime_str):
from datetime import datetime
if isinstance(datetime_str, datetime):
return datetime_str.replace(microsecond=0, tzinfo=None)
return datetime_str.replace(tzinfo=None)
return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S.%f')