frappe/frappe#478, more changes, removed bean
This commit is contained in:
parent
63eb09f3a3
commit
5d4e39bef6
35 changed files with 142 additions and 143 deletions
|
|
@ -41,17 +41,17 @@ def handle():
|
|||
|
||||
elif call=="resource":
|
||||
if "run_method" in frappe.local.form_dict:
|
||||
bean = frappe.get_doc(doctype, name)
|
||||
doc = frappe.get_doc(doctype, name)
|
||||
|
||||
if frappe.local.request.method=="GET":
|
||||
if not bean.has_permission("read"):
|
||||
if not doc.has_permission("read"):
|
||||
frappe.throw("No Permission", frappe.PermissionError)
|
||||
bean.run_method(frappe.local.form_dict.run_method, **frappe.local.form_dict)
|
||||
doc.run_method(frappe.local.form_dict.run_method, **frappe.local.form_dict)
|
||||
|
||||
if frappe.local.request.method=="POST":
|
||||
if not bean.has_permission("write"):
|
||||
if not doc.has_permission("write"):
|
||||
frappe.throw("No Permission", frappe.PermissionError)
|
||||
bean.run_method(frappe.local.form_dict.run_method, **frappe.local.form_dict)
|
||||
doc.run_method(frappe.local.form_dict.run_method, **frappe.local.form_dict)
|
||||
frappe.db.commit()
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@ def set_value(doctype, name, fieldname, value):
|
|||
|
||||
doc = frappe.db.get_value(doctype, name, ["parenttype", "parent"], as_dict=True)
|
||||
if doc and doc.parent:
|
||||
bean = frappe.get_doc(doc.parenttype, doc.parent)
|
||||
child = bean.getone({"doctype": doctype, "name": name})
|
||||
doc = frappe.get_doc(doc.parenttype, doc.parent)
|
||||
child = doc.getone({"doctype": doctype, "name": name})
|
||||
child.set(fieldname, value)
|
||||
else:
|
||||
bean = frappe.get_doc(doctype, name)
|
||||
bean.set(fieldname, value)
|
||||
doc = frappe.get_doc(doctype, name)
|
||||
doc.set(fieldname, value)
|
||||
|
||||
bean.save()
|
||||
doc.save()
|
||||
|
||||
return bean.as_dict()
|
||||
return doc.as_dict()
|
||||
|
||||
@frappe.whitelist()
|
||||
def insert(doclist):
|
||||
|
|
@ -54,21 +54,21 @@ def insert(doclist):
|
|||
if doclist[0].get("parent") and doclist[0].get("parenttype"):
|
||||
# inserting a child record
|
||||
d = doclist[0]
|
||||
bean = frappe.get_doc(d["parenttype"], d["parent"])
|
||||
bean.append(d)
|
||||
bean.save()
|
||||
doc = frappe.get_doc(d["parenttype"], d["parent"])
|
||||
doc.append(d)
|
||||
doc.save()
|
||||
return [d]
|
||||
else:
|
||||
bean = frappe.get_doc(doclist).insert()
|
||||
return bean.as_dict()
|
||||
doc = frappe.get_doc(doclist).insert()
|
||||
return doc.as_dict()
|
||||
|
||||
@frappe.whitelist()
|
||||
def save(doclist):
|
||||
if isinstance(doclist, basestring):
|
||||
doclist = json.loads(doclist)
|
||||
|
||||
bean = frappe.get_doc(doclist).save()
|
||||
return bean.as_dict()
|
||||
doc = frappe.get_doc(doclist).save()
|
||||
return doc.as_dict()
|
||||
|
||||
@frappe.whitelist()
|
||||
def rename_doc(doctype, old_name, new_name, merge=False):
|
||||
|
|
@ -104,7 +104,7 @@ def set_default(key, value, parent=None):
|
|||
|
||||
@frappe.whitelist()
|
||||
def make_width_property_setter():
|
||||
doc = json.loads(frappe.form_dict.doc)
|
||||
doc = json.loads(frappe.form_dict)
|
||||
if doc["doctype"]=="Property Setter" and doc["property"]=="width":
|
||||
frappe.get_doc(doc).insert(ignore_permissions = True)
|
||||
|
||||
|
|
@ -117,9 +117,9 @@ def bulk_update(docs):
|
|||
ddoc = {key: val for key, val in doc.iteritems() if key not in ['doctype', 'docname']}
|
||||
doctype = doc['doctype']
|
||||
docname = doc['docname']
|
||||
bean = frappe.get_doc(doctype, docname)
|
||||
bean.update(ddoc)
|
||||
bean.save()
|
||||
doc = frappe.get_doc(doctype, docname)
|
||||
doc.update(ddoc)
|
||||
doc.save()
|
||||
except:
|
||||
failed_docs.append({
|
||||
'doc': doc,
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ from frappe.utils import scrub_urls
|
|||
from frappe.model.document import Document
|
||||
|
||||
class Communication(Document):
|
||||
def get_parent_bean(self):
|
||||
def get_parent_doc(self):
|
||||
return frappe.get_doc(self.parenttype, self.parent)
|
||||
|
||||
def update_parent(self):
|
||||
"""update status of parent Lead or Contact based on who is replying"""
|
||||
observer = self.get_parent_bean().get_attr("on_communication")
|
||||
observer = self.get_parent_doc().get_attr("on_communication")
|
||||
if observer:
|
||||
observer()
|
||||
|
||||
|
|
@ -58,8 +58,8 @@ def _make(doctype=None, name=None, content=None, subject=None, sent_or_received
|
|||
if isinstance(sender, (tuple, list)) and len(sender)==2:
|
||||
sender = formataddr(sender)
|
||||
|
||||
comm = frappe.new_bean('Communication')
|
||||
d = comm.doc
|
||||
comm = frappe.new_doc('Communication')
|
||||
d = comm
|
||||
d.subject = subject
|
||||
d.content = content
|
||||
d.sent_or_received = sent_or_received
|
||||
|
|
@ -81,7 +81,7 @@ def _make(doctype=None, name=None, content=None, subject=None, sent_or_received
|
|||
comm.insert()
|
||||
|
||||
if send_email:
|
||||
d = comm.doc
|
||||
d = comm
|
||||
send_comm_email(d, name, sent_via, print_html, attachments, send_me_a_copy)
|
||||
|
||||
@frappe.whitelist()
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class CustomizeForm(Document):
|
|||
if ref_d.get("__custom_field"):
|
||||
# update custom field
|
||||
if self.has_property_changed(ref_d, new_d, prop):
|
||||
# using set_value not bean because validations are called
|
||||
# using set_value not doc because validations are called
|
||||
# in the end anyways
|
||||
frappe.db.set_value("Custom Field", ref_d.name, prop, new_d.get(prop))
|
||||
else:
|
||||
|
|
@ -294,13 +294,13 @@ class CustomizeForm(Document):
|
|||
frappe.db.sql("""
|
||||
DELETE FROM `tabProperty Setter`
|
||||
WHERE doc_type = %(doc_type)s
|
||||
AND property = %(property)s""", d.fields)
|
||||
AND property = %(property)s""", d.as_dict())
|
||||
else:
|
||||
frappe.db.sql("""
|
||||
DELETE FROM `tabProperty Setter`
|
||||
WHERE doc_type = %(doc_type)s
|
||||
AND field_name = %(field_name)s
|
||||
AND property = %(property)s""", d.fields)
|
||||
AND property = %(property)s""", d.as_dict())
|
||||
|
||||
# Save the property setter doc if not marked for deletion i.e. delete=0
|
||||
if not d.delete:
|
||||
|
|
|
|||
|
|
@ -176,23 +176,24 @@ def validate_fields(fields):
|
|||
|
||||
def check_illegal_mandatory(d):
|
||||
if d.fieldtype in ('HTML', 'Button', 'Section Break', 'Column Break') and d.reqd:
|
||||
frappe.msgprint('%(label)s [%(fieldtype)s] cannot be mandatory' % d.fields,
|
||||
print d.fieldname, d.reqd
|
||||
frappe.msgprint('%(parent)s, %(label)s [%(fieldtype)s] cannot be mandatory' % d.as_dict(),
|
||||
raise_exception=1)
|
||||
|
||||
def check_link_table_options(d):
|
||||
if d.fieldtype in ("Link", "Table"):
|
||||
if not d.options:
|
||||
frappe.msgprint("""#%(idx)s %(label)s: Options must be specified for Link and Table type fields""" % d.fields,
|
||||
frappe.msgprint("""#%(idx)s %(label)s: Options must be specified for Link and Table type fields""" % d.as_dict(),
|
||||
raise_exception=1)
|
||||
if d.options=="[Select]":
|
||||
return
|
||||
if d.options != d.parent and not frappe.db.exists("DocType", d.options):
|
||||
frappe.msgprint("""#%(idx)s %(label)s: Options %(options)s must be a valid "DocType" for Link and Table type fields""" % d.fields,
|
||||
frappe.msgprint("""#%(idx)s %(label)s: Options %(options)s must be a valid "DocType" for Link and Table type fields""" % d.as_dict(),
|
||||
raise_exception=1)
|
||||
|
||||
def check_hidden_and_mandatory(d):
|
||||
if d.hidden and d.reqd and not d.default:
|
||||
frappe.msgprint("""#%(idx)s %(label)s: Cannot be hidden and mandatory (reqd) without default""" % d.fields,
|
||||
frappe.msgprint("""#%(idx)s %(label)s: Cannot be hidden and mandatory (reqd) without default""" % d.as_dict(),
|
||||
raise_exception=True)
|
||||
|
||||
def check_min_items_in_list(fields):
|
||||
|
|
|
|||
|
|
@ -59,12 +59,12 @@ def delete_notification_count_for(doctype):
|
|||
def delete_event_notification_count():
|
||||
delete_notification_count_for("Event")
|
||||
|
||||
def clear_doctype_notifications(bean, method=None):
|
||||
def clear_doctype_notifications(doc, method=None):
|
||||
if frappe.flags.in_import:
|
||||
return
|
||||
|
||||
config = get_notification_config()
|
||||
doctype = bean.doctype
|
||||
doctype = doc.doctype
|
||||
|
||||
if doctype in config.for_doctype:
|
||||
delete_notification_count_for(doctype)
|
||||
|
|
|
|||
|
|
@ -48,16 +48,16 @@ def get_args():
|
|||
<pre>%s</pre>""" % repr(frappe.form_dict)
|
||||
}
|
||||
|
||||
bean = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
|
||||
doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
|
||||
for ptype in ("read", "print"):
|
||||
if not frappe.has_permission(bean.doctype, ptype, bean):
|
||||
if not frappe.has_permission(doc.doctype, ptype, doc):
|
||||
return {
|
||||
"body": """<h1>Error</h1>
|
||||
<p>No {ptype} permission</p>""".format(ptype=ptype)
|
||||
}
|
||||
|
||||
return {
|
||||
"body": get_html(bean),
|
||||
"body": get_html(doc),
|
||||
"css": get_print_style(frappe.form_dict.style),
|
||||
"comment": frappe.session.user
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False,
|
|||
continue
|
||||
|
||||
row_idx = i + start_row
|
||||
bean = None
|
||||
doc = None
|
||||
|
||||
doc = get_doc(row_idx)
|
||||
try:
|
||||
|
|
@ -209,8 +209,8 @@ def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False,
|
|||
ret.append('Submitted row (#%d) %s' % (row_idx + 1, getlink(doc.doctype, doc.name)))
|
||||
except Exception, e:
|
||||
error = True
|
||||
if bean:
|
||||
frappe.errprint(bean.as_dict())
|
||||
if doc:
|
||||
frappe.errprint(doc.as_dict())
|
||||
err_msg = frappe.local.message_log and "<br>".join(frappe.local.message_log) or cstr(e)
|
||||
ret.append('Error for row (#%d) %s : %s' % (row_idx + 1,
|
||||
len(row)>1 and row[1] or "", err_msg))
|
||||
|
|
|
|||
|
|
@ -33,10 +33,9 @@ def web_logout():
|
|||
@frappe.whitelist(allow_guest=True)
|
||||
def run_custom_method(doctype, name, custom_method):
|
||||
"""cmd=run_custom_method&doctype={doctype}&name={name}&custom_method={custom_method}"""
|
||||
bean = frappe.get_doc(doctype, name)
|
||||
controller = bean.get_controller()
|
||||
if getattr(controller, custom_method, frappe._dict()).is_whitelisted:
|
||||
frappe.call(getattr(controller, custom_method), **frappe.local.form_dict)
|
||||
doc = frappe.get_doc(doctype, name)
|
||||
if getattr(doc, custom_method, frappe._dict()).is_whitelisted:
|
||||
frappe.call(getattr(doc, custom_method), **frappe.local.form_dict)
|
||||
else:
|
||||
frappe.throw("Not Allowed")
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ def get_meta(doctype, cached=True):
|
|||
|
||||
class Meta(Document):
|
||||
_metaclass = True
|
||||
_fields = {}
|
||||
default_fields = default_fields[1:]
|
||||
special_doctypes = ("DocField", "DocPerm", "Role", "DocType", "Module Def")
|
||||
def __init__(self, doctype):
|
||||
self._fields = {}
|
||||
super(Meta, self).__init__("DocType", doctype)
|
||||
self.process()
|
||||
|
||||
|
|
@ -108,19 +108,19 @@ class Meta(Document):
|
|||
def apply_property_setters(self):
|
||||
for ps in frappe.db.sql("""select * from `tabProperty Setter` where
|
||||
doc_type=%s""", (self.name,), as_dict=1):
|
||||
if ps['doctype_or_field']=='DocType':
|
||||
if ps.get('property_type', None) in ('Int', 'Check'):
|
||||
ps['value'] = cint(ps['value'])
|
||||
if ps.doctype_or_field=='DocType':
|
||||
if ps.property_type in ('Int', 'Check'):
|
||||
ps.value = cint(ps.value)
|
||||
|
||||
self.set(ps["property"], ps["value"])
|
||||
self.set(ps.property, ps.value)
|
||||
else:
|
||||
docfield = self.get("fields", {"fieldname":ps["fieldname"]}, limit=1)[0]
|
||||
docfield = self.get("fields", {"fieldname":ps.field_name}, limit=1)[0]
|
||||
|
||||
if not docfield: continue
|
||||
if ps["property"] in integer_docfield_properties:
|
||||
ps['value'] = cint(ps['value'])
|
||||
if ps.property in integer_docfield_properties:
|
||||
ps.value = cint(ps.value)
|
||||
|
||||
docfield.set(ps["property"], ps["value"])
|
||||
docfield.set(ps.property, ps.value)
|
||||
|
||||
def sort_fields(self):
|
||||
"""sort on basis of previous_field"""
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from frappe.utils import now_datetime, cint
|
|||
|
||||
def set_new_name(doc):
|
||||
if getattr(doc, "_new_name_set", False):
|
||||
# already set by bean
|
||||
# already set by doc
|
||||
return
|
||||
|
||||
doc._new_name_set = True
|
||||
|
|
|
|||
|
|
@ -105,13 +105,13 @@ def has_unrestricted_access(doc, verbose=True):
|
|||
|
||||
def has_controller_permissions(doc):
|
||||
if doc.get("__islocal"):
|
||||
bean = frappe.get_doc([doc])
|
||||
doc = frappe.get_doc([doc])
|
||||
else:
|
||||
bean = frappe.get_doc(doc.doctype, doc.name)
|
||||
doc = frappe.get_doc(doc.doctype, doc.name)
|
||||
|
||||
condition_methods = frappe.get_hooks("has_permission:" + doc.doctype)
|
||||
for method in frappe.get_hooks("has_permission:" + doc.doctype):
|
||||
if not frappe.call(frappe.get_attr(method), doc=doc, bean=bean):
|
||||
if not frappe.call(frappe.get_attr(method), doc=doc, doc=doc):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ sort_by = "published_on"
|
|||
sort_order = "desc"
|
||||
|
||||
def get_context(context):
|
||||
blog_post = context.bean.doc
|
||||
blog_post = context.doc
|
||||
|
||||
# this is for double precaution. usually it wont reach this code if not published
|
||||
if not cint(blog_post.published):
|
||||
|
|
@ -37,7 +37,7 @@ def get_context(context):
|
|||
and comment_docname=%s order by creation""", (blog_post.name,), as_dict=1) or []
|
||||
|
||||
|
||||
return blog_post.fields
|
||||
return blog_post.as_dict()
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def get_blog_list(start=0, by=None, category=None):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ doctype = "Web Page"
|
|||
condition_field = "published"
|
||||
|
||||
def get_context(context):
|
||||
web_page = context.bean
|
||||
web_page = context.doc
|
||||
|
||||
if web_page.slideshow:
|
||||
web_page.update(get_slideshow(web_page))
|
||||
|
|
@ -29,4 +29,4 @@ def get_context(context):
|
|||
|
||||
web_page.update(context)
|
||||
|
||||
return web_page.fields
|
||||
return web_page.as_dict()
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def get_context(context):
|
|||
def get_group_context(group, view, context):
|
||||
cache_key = "website_group_context:{}:{}".format(group, view)
|
||||
|
||||
views = get_views(context.bean.group_type)
|
||||
views = get_views(context.doc.group_type)
|
||||
view = frappe._dict(views.get(view))
|
||||
|
||||
if can_cache(view.no_cache):
|
||||
|
|
@ -50,10 +50,10 @@ def get_group_context(group, view, context):
|
|||
return group_context
|
||||
|
||||
def build_group_context(group, view, views, context):
|
||||
title = "{} - {}".format(context.bean.group_title, view.get("label"))
|
||||
title = "{} - {}".format(context.doc.group_title, view.get("label"))
|
||||
|
||||
group_context = frappe._dict({
|
||||
"group": context.bean.fields,
|
||||
"group": context.doc.as_dict(),
|
||||
"view": view,
|
||||
"views": [v[1] for v in sorted(views.iteritems(), key=lambda (k, v): v.get("idx"))],
|
||||
"title": title,
|
||||
|
|
@ -87,7 +87,7 @@ def build_view_context(context):
|
|||
|
||||
def guess_group_view(context):
|
||||
group = context.docname
|
||||
view = frappe.form_dict.view or get_default_view(context.bean.group_type)
|
||||
view = frappe.form_dict.view or get_default_view(context.doc.group_type)
|
||||
return group, view
|
||||
|
||||
def get_default_view(group_type):
|
||||
|
|
@ -138,8 +138,8 @@ def clear_event_cache():
|
|||
for group in frappe.db.sql_list("""select name from `tabWebsite Group` where group_type='Event'"""):
|
||||
clear_unit_views(website_group=group)
|
||||
|
||||
def clear_cache_on_doc_event(bean, method, *args, **kwargs):
|
||||
clear_cache(path=bean.website_route, website_group=bean.website_group)
|
||||
def clear_cache_on_doc_event(doc, method, *args, **kwargs):
|
||||
clear_cache(path=doc.website_route, website_group=doc.website_group)
|
||||
|
||||
def get_pathname(group):
|
||||
return frappe.db.get_value("Website Route", {"ref_doctype": "Website Group",
|
||||
|
|
|
|||
|
|
@ -57,5 +57,5 @@ def add_comment(args=None):
|
|||
|
||||
template = frappe.get_template("templates/includes/comment.html")
|
||||
|
||||
return template.render({"comment": comment.fields})
|
||||
return template.render({"comment": comment.as_dict()})
|
||||
|
||||
|
|
@ -10,9 +10,9 @@
|
|||
Be sure to update your company history and
|
||||
list of key team members in Website > About Us Settings</p>""" }}
|
||||
|
||||
{% if obj.doclist.get({"doctype":"Company History"}) %}
|
||||
{% if obj.get({"doctype":"Company History"}) %}
|
||||
<h3>{{ obj.doc.company_history_heading or "Company History" }}</h3>
|
||||
{% for d in obj.doclist.get({"doctype":"Company History"}) %}
|
||||
{% for d in obj.get({"doctype":"Company History"}) %}
|
||||
<div class="row">
|
||||
<span class="col-md-2"><h4 style="margin:0px;">{{ d.year }}</h4></span>
|
||||
<span class="col-md-10"><p>{{ d.highlight }}</p></span>
|
||||
|
|
@ -20,9 +20,9 @@
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if obj.doclist.get({"doctype":"About Us Team Member"}) %}
|
||||
{% if obj.get({"doctype":"About Us Team Member"}) %}
|
||||
<h3>{{ obj.doc.team_members_heading or "Team Members" }}</h3>
|
||||
{% for d in obj.doclist.get({"doctype":"About Us Team Member"}) %}
|
||||
{% for d in obj.get({"doctype":"About Us Team Member"}) %}
|
||||
<div class="row" itemscope itemtype="http://schema.org/Person">
|
||||
<span class="col-md-2">
|
||||
<div class="avatar avatar-large">
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ from __future__ import unicode_literals
|
|||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
return { "obj": frappe.get_doc("About Us Settings", "About Us Settings").get_controller() }
|
||||
return { "obj": frappe.get_doc("About Us Settings", "About Us Settings") }
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@ import frappe
|
|||
from frappe.utils import now
|
||||
|
||||
def get_context(context):
|
||||
bean = frappe.get_doc("Contact Us Settings", "Contact Us Settings")
|
||||
doc = frappe.get_doc("Contact Us Settings", "Contact Us Settings")
|
||||
|
||||
query_options = filter(None, bean.query_options.replace(",", "\n").split()) if \
|
||||
bean.query_options else ["Sales", "Support", "General"]
|
||||
query_options = filter(None, doc.query_options.replace(",", "\n").split()) if \
|
||||
doc.query_options else ["Sales", "Support", "General"]
|
||||
|
||||
address = frappe.get_doc("Address", bean.address).doc if bean.address else None
|
||||
address = frappe.get_doc("Address", doc.address) if doc.address else None
|
||||
|
||||
out = {
|
||||
"query_options": query_options
|
||||
}
|
||||
out.update(bean.fields)
|
||||
out.update(doc.as_dict())
|
||||
|
||||
return out
|
||||
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ def get_post_context(context):
|
|||
return frappe.cache().get_value(cache_key, lambda: _get_post_context())
|
||||
|
||||
def get_parent_post_html(post, context):
|
||||
user = frappe.get_doc("User", post.owner).doc
|
||||
user = frappe.get_doc("User", post.owner)
|
||||
for fieldname in ("first_name", "last_name", "user_image", "location"):
|
||||
post.set(fieldname, user.get(fieldname))
|
||||
|
||||
return frappe.get_template("templates/includes/inline_post.html")\
|
||||
.render({"post": post.fields, "view": context.view})
|
||||
.render({"post": post.as_dict(), "view": context.view})
|
||||
|
||||
def get_child_posts_html(post, context):
|
||||
posts = frappe.db.sql("""select p.*, pr.user_image, pr.first_name, pr.last_name
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def add_sitemap_permission(group, user):
|
|||
})
|
||||
permission.insert(ignore_permissions=True)
|
||||
|
||||
user = permission.fields
|
||||
user = permission.as_dict()
|
||||
user.update(frappe.db.get_value("User", user.user,
|
||||
["name", "first_name", "last_name", "user_image", "location"], as_dict=True))
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ def make_test_objects(doctype, test_records, verbose=None):
|
|||
if frappe.local.test_objects.get(d.doctype):
|
||||
# do not create test records, if already exists
|
||||
return []
|
||||
|
||||
if d.meta.get_field("naming_series"):
|
||||
if not d.naming_series:
|
||||
d.naming_series = "_T-" + d.doctype + "-"
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ class TestDocument(unittest.TestCase):
|
|||
self.assertEquals(d.doctype, "DocType")
|
||||
self.assertEquals(d.name, "User")
|
||||
self.assertEquals(d.allow_rename, 1)
|
||||
self.assertTrue(isinstance(d.fields, list))
|
||||
self.assertTrue(isinstance(d.as_dict(), list))
|
||||
self.assertTrue(isinstance(d.permissions, list))
|
||||
self.assertTrue(filter(lambda d: d.fieldname=="email", d.fields))
|
||||
self.assertTrue(filter(lambda d: d.fieldname=="email", d.as_dict()))
|
||||
|
||||
def test_load_single(self):
|
||||
d = frappe.get_doc("Website Settings", "Website Settings")
|
||||
|
|
|
|||
|
|
@ -128,27 +128,27 @@ def import_doc(d, doctype, overwrite, row_idx, submit=False, ignore_links=False)
|
|||
"""import main (non child) document"""
|
||||
if d.get("name") and frappe.db.exists(doctype, d['name']):
|
||||
if overwrite:
|
||||
bean = frappe.get_doc(doctype, d['name'])
|
||||
bean.ignore_links = ignore_links
|
||||
bean.update(d)
|
||||
doc = frappe.get_doc(doctype, d['name'])
|
||||
doc.ignore_links = ignore_links
|
||||
doc.update(d)
|
||||
if d.get("docstatus") == 1:
|
||||
bean.update_after_submit()
|
||||
doc.update_after_submit()
|
||||
else:
|
||||
bean.save()
|
||||
doc.save()
|
||||
return 'Updated row (#%d) %s' % (row_idx + 1, getlink(doctype, d['name']))
|
||||
else:
|
||||
return 'Ignored row (#%d) %s (exists)' % (row_idx + 1,
|
||||
getlink(doctype, d['name']))
|
||||
else:
|
||||
bean = frappe.get_doc([d])
|
||||
bean.ignore_links = ignore_links
|
||||
bean.insert()
|
||||
doc = frappe.get_doc([d])
|
||||
doc.ignore_links = ignore_links
|
||||
doc.insert()
|
||||
|
||||
if submit:
|
||||
bean.submit()
|
||||
doc.submit()
|
||||
|
||||
return 'Inserted row (#%d) %s' % (row_idx + 1, getlink(doctype,
|
||||
bean.get('name')))
|
||||
doc.get('name')))
|
||||
|
||||
def getlink(doctype, name):
|
||||
return '<a href="#Form/%(doctype)s/%(name)s">%(name)s</a>' % locals()
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ def save_url(file_url, dt, dn):
|
|||
f.insert();
|
||||
except frappe.DuplicateEntryError:
|
||||
return frappe.get_doc("File Data", f.duplicate_entry)
|
||||
return f.doc
|
||||
return f
|
||||
|
||||
def get_uploaded_content():
|
||||
# should not be unicode when reading a file, hence using frappe.form
|
||||
|
|
@ -153,7 +153,7 @@ def save_file(fname, content, dt, dn, decode=False):
|
|||
except frappe.DuplicateEntryError:
|
||||
return frappe.get_doc("File Data", f.duplicate_entry)
|
||||
|
||||
return f.doc
|
||||
return f
|
||||
|
||||
def get_file_versions(files_path, main, extn):
|
||||
out = []
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ def add_role(user, role):
|
|||
|
||||
def add_system_manager(email, first_name=None, last_name=None):
|
||||
# add user
|
||||
user = frappe.new_bean("User")
|
||||
user = frappe.new_doc("User")
|
||||
user.update({
|
||||
"name": email,
|
||||
"email": email,
|
||||
|
|
|
|||
|
|
@ -23,12 +23,10 @@ def get_signature(params, nonce, secret=None):
|
|||
signature.update(params)
|
||||
return signature.hexdigest()
|
||||
|
||||
def verify_using_bean(bean, signature, cmd):
|
||||
controller = bean.get_controller()
|
||||
params = controller.get_signature_params()
|
||||
return signature == get_signature(params, controller.get_nonce())
|
||||
def verify_using_doc(doc, signature, cmd):
|
||||
params = doc.get_signature_params()
|
||||
return signature == get_signature(params, doc.get_nonce())
|
||||
|
||||
def get_url_using_bean(bean, cmd):
|
||||
controller = bean.get_controller()
|
||||
params = controller.get_signature_params()
|
||||
return get_url(cmd, params, controller.get_nonce())
|
||||
def get_url_using_doc(doc, cmd):
|
||||
params = doc.get_signature_params()
|
||||
return get_url(cmd, params, doc.get_nonce())
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ def get_context(path):
|
|||
return context
|
||||
|
||||
def build_context(sitemap_options):
|
||||
"""get_context method of bean or module is supposed to render content templates and push it into context"""
|
||||
"""get_context method of doc or module is supposed to render content templates and push it into context"""
|
||||
context = frappe._dict(sitemap_options)
|
||||
context.update(get_website_settings())
|
||||
|
||||
# provide bean
|
||||
# provide doc
|
||||
if context.doctype and context.docname:
|
||||
context.bean = frappe.get_doc(context.doctype, context.docname)
|
||||
context.doc = frappe.get_doc(context.doctype, context.docname)
|
||||
|
||||
if context.controller:
|
||||
module = frappe.get_module(context.controller)
|
||||
|
|
@ -61,8 +61,8 @@ def build_context(sitemap_options):
|
|||
if context.get("base_template_path") != context.get("template_path") and not context.get("rendered"):
|
||||
context.data = render_blocks(context)
|
||||
|
||||
# remove bean, as it is not pickle friendly and its purpose is over
|
||||
if context.bean:
|
||||
del context["bean"]
|
||||
# remove doc, as it is not pickle friendly and its purpose is over
|
||||
if context.doc:
|
||||
del context["doc"]
|
||||
|
||||
return context
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class TestBlogPost(unittest.TestCase):
|
|||
post = frappe.get_doc("Blog Post", "_test-blog-post")
|
||||
self.assertTrue(post.has_permission("read"))
|
||||
|
||||
def test_restriction_in_bean(self):
|
||||
def test_restriction_in_doc(self):
|
||||
frappe.defaults.add_default("Blog Category", "_Test Blog Category 1", "test1@example.com",
|
||||
"Restriction")
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class TestBlogPost(unittest.TestCase):
|
|||
and ifnull(permlevel,0)=0""")
|
||||
frappe.clear_cache(doctype="Blog Post")
|
||||
|
||||
def test_owner_match_bean(self):
|
||||
def test_owner_match_doc(self):
|
||||
self.add_restricted_on_blogger()
|
||||
|
||||
frappe.set_user("test2@example.com")
|
||||
|
|
@ -111,12 +111,12 @@ class TestBlogPost(unittest.TestCase):
|
|||
frappe.set_user("test2@example.com")
|
||||
|
||||
# user can only access restricted blog post
|
||||
bean = frappe.get_doc("Blog Post", "_test-blog-post")
|
||||
self.assertTrue(bean.has_permission("read"))
|
||||
doc = frappe.get_doc("Blog Post", "_test-blog-post")
|
||||
self.assertTrue(doc.has_permission("read"))
|
||||
|
||||
# and not this one
|
||||
bean = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
self.assertFalse(bean.has_permission("read"))
|
||||
doc = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
self.assertFalse(doc.has_permission("read"))
|
||||
|
||||
def test_not_allowed_to_remove_self(self):
|
||||
self.add_restriction_to_user2()
|
||||
|
|
@ -132,21 +132,21 @@ class TestBlogPost(unittest.TestCase):
|
|||
self.add_restricted_on_blogger()
|
||||
|
||||
frappe.set_user("test2@example.com")
|
||||
bean = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
self.assertFalse(bean.has_permission("read"))
|
||||
doc = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
self.assertFalse(doc.has_permission("read"))
|
||||
|
||||
frappe.set_user("test1@example.com")
|
||||
add("test2@example.com", "Blog Post", "_test-blog-post-1")
|
||||
|
||||
frappe.set_user("test2@example.com")
|
||||
bean = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
doc = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
|
||||
self.assertTrue(bean.has_permission("read"))
|
||||
self.assertTrue(doc.has_permission("read"))
|
||||
|
||||
def test_set_only_once(self):
|
||||
blog_post = frappe.get_meta("Blog Post")
|
||||
blog_post.get_field("title").set_only_once = 1
|
||||
bean = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
bean.title = "New"
|
||||
self.assertRaises(frappe.CannotChangeConstantError, bean.save)
|
||||
doc = frappe.get_doc("Blog Post", "_test-blog-post-1")
|
||||
doc.title = "New"
|
||||
self.assertRaises(frappe.CannotChangeConstantError, doc.save)
|
||||
blog_post.get_field("title").set_only_once = 0
|
||||
|
|
@ -54,7 +54,7 @@ class Post(Document):
|
|||
def send_email_on_reply(self):
|
||||
owner_fullname = get_fullname(self.owner)
|
||||
|
||||
parent_post = frappe.get_doc("Post", self.parent_post).doc
|
||||
parent_post = frappe.get_doc("Post", self.parent_post)
|
||||
|
||||
message = self.get_reply_email_message(self.name, owner_fullname)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ class WebsiteSlideshow(Document):
|
|||
from frappe.website.render import clear_cache
|
||||
clear_cache()
|
||||
|
||||
def get_slideshow(bean):
|
||||
slideshow = frappe.get_doc("Website Slideshow", bean.slideshow)
|
||||
def get_slideshow(doc):
|
||||
slideshow = frappe.get_doc("Website Slideshow", doc.slideshow)
|
||||
|
||||
return {
|
||||
"slides": slideshow.get({"doctype":"Website Slideshow Item"}),
|
||||
|
|
|
|||
|
|
@ -135,13 +135,13 @@ class sync(object):
|
|||
|
||||
|
||||
# update timestamp
|
||||
route_bean = frappe.get_doc("Website Route", {"ref_doctype": "Web Page",
|
||||
route_doc = frappe.get_doc("Website Route", {"ref_doctype": "Web Page",
|
||||
"docname": page.name})
|
||||
route_bean.static_file_timestamp = cint(os.path.getmtime(fpath))
|
||||
route_bean.save()
|
||||
route_doc.static_file_timestamp = cint(os.path.getmtime(fpath))
|
||||
route_doc.save()
|
||||
|
||||
self.updated += 1
|
||||
print route_bean.name + " inserted"
|
||||
print route_doc.name + " inserted"
|
||||
self.synced.append(route)
|
||||
|
||||
def update_web_page(self, route_details, fpath, priority, parent_website_route):
|
||||
|
|
@ -153,11 +153,11 @@ class sync(object):
|
|||
page.idx = priority
|
||||
page.save()
|
||||
|
||||
route_bean = frappe.get_doc("Website Route", route_details.name)
|
||||
route_bean.static_file_timestamp = cint(os.path.getmtime(fpath))
|
||||
route_bean.save()
|
||||
route_doc = frappe.get_doc("Website Route", route_details.name)
|
||||
route_doc.static_file_timestamp = cint(os.path.getmtime(fpath))
|
||||
route_doc.save()
|
||||
|
||||
print route_bean.name + " updated"
|
||||
print route_doc.name + " updated"
|
||||
self.updated += 1
|
||||
|
||||
self.synced.append(route_details.name)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ def get_cal_events(m_st, m_end):
|
|||
doclist, rl = [], []
|
||||
for r in res1 + res2 + res3 + res4:
|
||||
if not r in rl:
|
||||
doclist += frappe.model.get('Event', r[0])
|
||||
doclist += frappe.get_doc('Event', r[0])
|
||||
rl.append(r)
|
||||
|
||||
return doclist
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ def getdoctype(doctype, with_parent=False, cached_timestamp=None):
|
|||
|
||||
def get_meta_bundle(doctype):
|
||||
bundle = [frappe.widgets.form.meta.get_meta(doctype)]
|
||||
for df in bundle[0].fields:
|
||||
for df in bundle[0].as_dict():
|
||||
if df.fieldtype=="Table":
|
||||
bundle.append(frappe.widgets.form.meta.get_meta(df.options))
|
||||
return bundle
|
||||
|
|
|
|||
|
|
@ -13,15 +13,15 @@ from frappe.utils import flt, cint
|
|||
import frappe.widgets.reportview
|
||||
|
||||
def get_report_doc(report_name):
|
||||
bean = frappe.get_doc("Report", report_name)
|
||||
if not bean.has_permission("read"):
|
||||
doc = frappe.get_doc("Report", report_name)
|
||||
if not doc.has_permission("read"):
|
||||
raise frappe.PermissionError("You don't have access to: {report}".format(report=report_name))
|
||||
|
||||
if not frappe.has_permission(bean.ref_doctype, "report"):
|
||||
if not frappe.has_permission(doc.ref_doctype, "report"):
|
||||
raise frappe.PermissionError("You don't have access to get a report on: {doctype}".format(
|
||||
doctype=bean.ref_doctype))
|
||||
doctype=doc.ref_doctype))
|
||||
|
||||
return bean.doc
|
||||
return doc
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_script(report_name):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue