@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class BulkEmail(Document): | |||||
pass |
@@ -5,9 +5,9 @@ from __future__ import unicode_literals | |||||
import frappe, json | import frappe, json | ||||
from frappe.website.render import clear_cache | from frappe.website.render import clear_cache | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Comment(Document): | |||||
def validate(self): | def validate(self): | ||||
if frappe.db.sql("""select count(*) from tabComment where comment_doctype=%s | if frappe.db.sql("""select count(*) from tabComment where comment_doctype=%s | ||||
@@ -12,11 +12,9 @@ from frappe.utils.email_lib.email_body import get_email | |||||
from frappe.utils.email_lib.smtp import send | from frappe.utils.email_lib.smtp import send | ||||
from frappe.utils import scrub_urls | from frappe.utils import scrub_urls | ||||
class DocType(): | |||||
def __init__(self, doc, doclist=None): | |||||
self.doc = doc | |||||
self.doclist = doclist | |||||
from frappe.model.document import Document | |||||
class Communication(Document): | |||||
def get_parent_bean(self): | def get_parent_bean(self): | ||||
return frappe.bean(self.doc.parenttype, self.doc.parent) | return frappe.bean(self.doc.parenttype, self.doc.parent) | ||||
@@ -7,10 +7,9 @@ import frappe | |||||
from frappe import form, msgprint | from frappe import form, msgprint | ||||
import frappe.defaults | import frappe.defaults | ||||
class DocType: | |||||
def __init__(self, doc, doclist): | |||||
self.doc = doc | |||||
self.doclist = doclist | |||||
from frappe.model.document import Document | |||||
class ControlPanel(Document): | |||||
def on_update(self): | def on_update(self): | ||||
# clear cache on save | # clear cache on save | ||||
@@ -6,9 +6,9 @@ import frappe | |||||
from frappe.utils import cint, cstr | from frappe.utils import cint, cstr | ||||
from frappe import _ | from frappe import _ | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class CustomField(Document): | |||||
def autoname(self): | def autoname(self): | ||||
self.set_fieldname() | self.set_fieldname() | ||||
@@ -4,9 +4,9 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
from frappe.utils import cstr | from frappe.utils import cstr | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class CustomScript(Document): | |||||
def autoname(self): | def autoname(self): | ||||
self.doc.name = self.doc.dt + "-" + self.doc.script_type | self.doc.name = self.doc.dt + "-" + self.doc.script_type | ||||
@@ -9,7 +9,9 @@ from __future__ import unicode_literals | |||||
import frappe, json | import frappe, json | ||||
from frappe.utils import cstr | from frappe.utils import cstr | ||||
class DocType: | |||||
from frappe.model.document import Document | |||||
class CustomizeForm(Document): | |||||
def __init__(self, doc, doclist=[]): | def __init__(self, doc, doclist=[]): | ||||
self.doc, self.doclist = doc, doclist | self.doc, self.doclist = doc, doclist | ||||
self.doctype_properties = [ | self.doctype_properties = [ | ||||
@@ -57,12 +59,10 @@ class DocType: | |||||
self.clear() | self.clear() | ||||
if self.doc.doc_type: | if self.doc.doc_type: | ||||
from frappe.model.doc import addchild | |||||
for d in self.get_ref_doclist(): | for d in self.get_ref_doclist(): | ||||
if d.doctype=='DocField': | if d.doctype=='DocField': | ||||
new = addchild(self.doc, 'fields', 'Customize Form Field', | |||||
self.doclist) | |||||
new = self.doc.append('fields', {}) | |||||
self.set( | self.set( | ||||
{ | { | ||||
'list': self.docfield_properties, | 'list': self.docfield_properties, | ||||
@@ -94,7 +94,7 @@ class DocType: | |||||
Clear fields in the doc | Clear fields in the doc | ||||
""" | """ | ||||
# Clear table before adding new doctype's fields | # Clear table before adding new doctype's fields | ||||
self.doclist = self.doc.clear_table(self.doclist, 'fields') | |||||
self.set('fields', []) | |||||
self.set({ 'list': self.doctype_properties, 'value': None }) | self.set({ 'list': self.doctype_properties, 'value': None }) | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class CustomizeFormField(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class DefaultHomePage(Document): | |||||
pass |
@@ -4,9 +4,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Defaultvalue(Document): | |||||
def on_doctype_update(): | def on_doctype_update(): | ||||
if not frappe.db.sql("""show index from `tabDefaultValue` | if not frappe.db.sql("""show index from `tabDefaultValue` | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class DocField(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class DocPerm(Document): | |||||
pass |
@@ -134,7 +134,7 @@ class DocType(Document): | |||||
with open(pypath, 'w') as pyfile: | with open(pypath, 'w') as pyfile: | ||||
with open(os.path.join(get_module_path("core"), "doctype", "doctype", | with open(os.path.join(get_module_path("core"), "doctype", "doctype", | ||||
"doctype_template.py"), 'r') as srcfile: | "doctype_template.py"), 'r') as srcfile: | ||||
pyfile.write(srcfile.read().format(app_publisher=app_publisher)) | |||||
pyfile.write(srcfile.read().format(app_publisher=app_publisher, classname=self.name.replace(" ", ""))) | |||||
def make_amendable(self): | def make_amendable(self): | ||||
""" | """ | ||||
@@ -3,7 +3,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
from frappe.model.document import Document | |||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
class {classname}(Document): | |||||
pass |
@@ -14,14 +14,6 @@ class Event(Document): | |||||
def validate(self): | def validate(self): | ||||
if self.starts_on and self.ends_on and self.starts_on > self.ends_on: | if self.starts_on and self.ends_on and self.starts_on > self.ends_on: | ||||
frappe.msgprint(frappe._("Event End must be after Start"), raise_exception=True) | frappe.msgprint(frappe._("Event End must be after Start"), raise_exception=True) | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
def validate(self): | |||||
if self.doc.starts_on and self.doc.ends_on and self.doc.starts_on > self.doc.ends_on: | |||||
frappe.msgprint(frappe._("Event End must be after Start"), raise_exception=True) | |||||
def get_permission_query_conditions(): | def get_permission_query_conditions(): | ||||
return """(tabEvent.event_type='Public' or tabEvent.owner='%(user)s' | return """(tabEvent.event_type='Public' or tabEvent.owner='%(user)s' | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class EventRole(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class EventUser(Document): | |||||
pass |
@@ -10,11 +10,9 @@ naming for same name files: file.gif, file-1.gif, file-2.gif etc | |||||
import frappe, frappe.utils, os | import frappe, frappe.utils, os | ||||
from frappe import conf | from frappe import conf | ||||
from frappe.model.document import Document | |||||
class DocType(): | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
class FileData(Document): | |||||
def before_insert(self): | def before_insert(self): | ||||
frappe.local.rollback_observers.append(self) | frappe.local.rollback_observers.append(self) | ||||
@@ -5,10 +5,9 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, doc, doclist=[]): | |||||
self.doc = doc | |||||
self.doclist = doclist | |||||
from frappe.model.document import Document | |||||
class LetterHead(Document): | |||||
def validate(self): | def validate(self): | ||||
self.set_as_default() | self.set_as_default() | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class ModuleDef(Document): | |||||
pass |
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class NotificationCount(Document): | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def get_notifications(): | def get_notifications(): | ||||
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class OutgoingEmailSettings(Document): | |||||
def validate(self): | def validate(self): | ||||
self.doc.encode() | self.doc.encode() | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class PageRole(Document): | |||||
pass |
@@ -6,6 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class PatchLog(Document): | |||||
pass |
@@ -8,7 +8,9 @@ from frappe.modules import get_doc_path | |||||
standard_format = "templates/print_formats/standard.html" | standard_format = "templates/print_formats/standard.html" | ||||
class DocType: | |||||
from frappe.model.document import Document | |||||
class PrintFormat(Document): | |||||
def __init__(self, d, dl): | def __init__(self, d, dl): | ||||
self.doc, self.doclist = d,dl | self.doc, self.doclist = d,dl | ||||
@@ -4,9 +4,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class PropertySetter(Document): | |||||
def autoname(self): | def autoname(self): | ||||
self.doc.name = self.doc.doc_type + "-" \ | self.doc.name = self.doc.doc_type + "-" \ | ||||
@@ -5,7 +5,9 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
from frappe import conf, _ | from frappe import conf, _ | ||||
class DocType: | |||||
from frappe.model.document import Document | |||||
class Report(Document): | |||||
def __init__(self, doc, doclist): | def __init__(self, doc, doclist): | ||||
self.doc, self.doclist = doc, doclist | self.doc, self.doclist = doc, doclist | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Role(Document): | |||||
pass |
@@ -6,6 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class SchedulerLog(Document): | |||||
pass |
@@ -6,6 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class SocialLoginKeys(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Tag(Document): | |||||
pass |
@@ -4,9 +4,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Todo(Document): | |||||
def validate(self): | def validate(self): | ||||
if self.doc.is_new(): | if self.doc.is_new(): | ||||
@@ -9,10 +9,9 @@ from frappe.auth import _update_password | |||||
STANDARD_USERS = ("Guest", "Administrator") | STANDARD_USERS = ("Guest", "Administrator") | ||||
class DocType: | |||||
def __init__(self, doc, doclist): | |||||
self.doc = doc | |||||
self.doclist = doclist | |||||
from frappe.model.document import Document | |||||
class User(Document): | |||||
def autoname(self): | def autoname(self): | ||||
"""set name as email id""" | """set name as email id""" | ||||
@@ -49,7 +48,7 @@ class DocType: | |||||
def add_system_manager_role(self): | def add_system_manager_role(self): | ||||
# if adding system manager, do nothing | # if adding system manager, do nothing | ||||
if not cint(self.doc.enabled) or ("System Manager" in [user_role.role for user_role in | if not cint(self.doc.enabled) or ("System Manager" in [user_role.role for user_role in | ||||
self.doclist.get({"parentfield": "user_roles"})]): | |||||
self.get("user_roles")]): | |||||
return | return | ||||
if self.doc.user_type == "System User" and not self.get_other_system_managers(): | if self.doc.user_type == "System User" and not self.get_other_system_managers(): | ||||
@@ -5,9 +5,9 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
from frappe.utils import cint | from frappe.utils import cint | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Userrole(Document): | |||||
def validate(self): | def validate(self): | ||||
if cint(self.doc.fields.get("__islocal")) and frappe.db.exists("UserRole", { | if cint(self.doc.fields.get("__islocal")) and frappe.db.exists("UserRole", { | ||||
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe, json | import frappe, json | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Version(Document): | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def restore(version): | def restore(version): | ||||
@@ -4,9 +4,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Workflow(Document): | |||||
def validate(self): | def validate(self): | ||||
self.set_active() | self.set_active() | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WorkflowAction(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WorkflowDocumentState(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WorkflowState(Document): | |||||
pass |
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WorkflowTransition(Document): | |||||
pass |
@@ -34,9 +34,9 @@ def copytables(srctype, src, srcfield, tartype, tar, tarfield, srcfields, tarfie | |||||
if not tarfields: | if not tarfields: | ||||
tarfields = srcfields | tarfields = srcfields | ||||
l = [] | l = [] | ||||
data = frappe.model.doc.getchildren(src.name, srctype, srcfield) | |||||
data = src.get(srcfield) | |||||
for d in data: | for d in data: | ||||
newrow = frappe.model.doc.addchild(tar, tarfield, tartype) | |||||
newrow = tar.append(tarfield) | |||||
newrow.idx = d.idx | newrow.idx = d.idx | ||||
for i in range(len(srcfields)): | for i in range(len(srcfields)): | ||||
@@ -33,9 +33,15 @@ class BaseDocument(object): | |||||
def get(self, key=None, filters=None, limit=None, default=None): | def get(self, key=None, filters=None, limit=None, default=None): | ||||
if key: | if key: | ||||
if filters: | if filters: | ||||
return _filter(self.__dict__.get(key), filters, limit=limit) | |||||
value = _filter(self.__dict__.get(key), filters, limit=limit) | |||||
else: | else: | ||||
return self.__dict__.get(key, default) | |||||
value = self.__dict__.get(key, default) | |||||
if value is None and key in self.get_table_fields(): | |||||
self.set(key, []) | |||||
value = self.__dict__.get(key) | |||||
return value | |||||
else: | else: | ||||
return self.__dict__ | return self.__dict__ | ||||
@@ -48,11 +54,15 @@ class BaseDocument(object): | |||||
self.__dict__[key] = value | self.__dict__[key] = value | ||||
def append(self, key, value): | |||||
def append(self, key, value=None): | |||||
if value==None: | |||||
value={} | |||||
if isinstance(value, dict): | if isinstance(value, dict): | ||||
if not self.get(key): | if not self.get(key): | ||||
self.__dict__[key] = [] | self.__dict__[key] = [] | ||||
self.get(key).append(self._init_child(value, key)) | |||||
value = self._init_child(value, key) | |||||
self.get(key).append(value) | |||||
return value | |||||
else: | else: | ||||
raise ValueError | raise ValueError | ||||
@@ -51,7 +51,6 @@ class Bean: | |||||
""" | """ | ||||
Load doclist from dt | Load doclist from dt | ||||
""" | """ | ||||
from frappe.model.doc import getchildren | |||||
if not dt: dt = self.doc.doctype | if not dt: dt = self.doc.doctype | ||||
if not dn: dn = self.doc.name | if not dn: dn = self.doc.name | ||||
@@ -63,8 +62,6 @@ class Bean: | |||||
# load chilren | # load chilren | ||||
doclist = frappe.doclist([doc,]) | doclist = frappe.doclist([doc,]) | ||||
for t in tablefields: | |||||
doclist += getchildren(doc.name, t[0], t[1], dt) | |||||
self.set_doclist(doclist) | self.set_doclist(doclist) | ||||
@@ -432,7 +429,7 @@ class Bean: | |||||
if df.doctype=="DocField" and df.reqd and df.parent==doc.doctype and df.fieldname!="naming_series": | if df.doctype=="DocField" and df.reqd and df.parent==doc.doctype and df.fieldname!="naming_series": | ||||
msg = "" | msg = "" | ||||
if df.fieldtype == "Table": | if df.fieldtype == "Table": | ||||
if not self.doclist.get({"parentfield": df.fieldname}): | |||||
if not self.get(df.fieldname): | |||||
msg = _("Error") + ": " + _("Data missing in table") + ": " + _(df.label) | msg = _("Error") + ": " + _("Data missing in table") + ": " + _(df.label) | ||||
elif doc.fields.get(df.fieldname) is None: | elif doc.fields.get(df.fieldname) is None: | ||||
@@ -56,7 +56,7 @@ class DocListController(Document): | |||||
msgprint(msg, raise_exception=raise_exception or True) | msgprint(msg, raise_exception=raise_exception or True) | ||||
def validate_table_has_rows(self, parentfield, raise_exception=None): | def validate_table_has_rows(self, parentfield, raise_exception=None): | ||||
if not self.doclist.get({"parentfield": parentfield}): | |||||
if not self.get(parentfield): | |||||
label = self.meta.get_label(parentfield) | label = self.meta.get_label(parentfield) | ||||
msgprint(_("Error") + ": " + _(label) + " " + _("cannot be empty"), | msgprint(_("Error") + ": " + _(label) + " " + _("cannot be empty"), | ||||
raise_exception=raise_exception or EmptyTableError) | raise_exception=raise_exception or EmptyTableError) | ||||
@@ -545,29 +545,6 @@ class Document: | |||||
self.fields['__unsaved'] = 1 | self.fields['__unsaved'] = 1 | ||||
return frappe.doclist(doclist) | return frappe.doclist(doclist) | ||||
def addchild(self, fieldname, childtype = '', doclist=None): | |||||
""" | |||||
Returns a child record of the give `childtype`. | |||||
* if local is set, it does not save the record | |||||
* if doclist is passed, it append the record to the doclist | |||||
""" | |||||
from frappe.model.doc import Document | |||||
d = Document() | |||||
d.parent = self.name | |||||
d.parenttype = self.doctype | |||||
d.parentfield = fieldname | |||||
d.doctype = childtype | |||||
d.docstatus = 0; | |||||
d.name = '' | |||||
d.owner = frappe.session['user'] | |||||
d.fields['__islocal'] = 1 # for Client to identify unsaved doc | |||||
if doclist != None: | |||||
doclist.append(d) | |||||
return d | |||||
def get_values(self): | def get_values(self): | ||||
"""get non-null fields dict withouth standard fields""" | """get non-null fields dict withouth standard fields""" | ||||
@@ -581,21 +558,7 @@ class Document: | |||||
def get_db_value(self, key): | def get_db_value(self, key): | ||||
return frappe.db.get_value(self.doctype, self.name, key) | return frappe.db.get_value(self.doctype, self.name, key) | ||||
def addchild(parent, fieldname, childtype = '', doclist=None): | |||||
""" | |||||
Create a child record to the parent doc. | |||||
Example:: | |||||
c = Document('Contact','ABC') | |||||
d = addchild(c, 'contact_updates', 'Contact Update') | |||||
d.last_updated = 'Phone call' | |||||
d.save(1) | |||||
""" | |||||
return parent.addchild(fieldname, childtype, doclist) | |||||
def make_autoname(key, doctype=''): | def make_autoname(key, doctype=''): | ||||
""" | """ | ||||
Creates an autoname from the given key: | Creates an autoname from the given key: | ||||
@@ -132,12 +132,26 @@ class Document(BaseDocument): | |||||
self.db_update() | self.db_update() | ||||
# children | # children | ||||
child_map = {} | |||||
ignore_children_type = self.get("_ignore_children_type", []) | ignore_children_type = self.get("_ignore_children_type", []) | ||||
for d in self.get_all_children(): | for d in self.get_all_children(): | ||||
if d.doctype not in _ignore_children_type: | |||||
d.parent = self.name | |||||
d.db_update() | |||||
d.parent = self.name # rename if reqd | |||||
d.parenttype = self.doctype | |||||
d.db_update() | |||||
child_map.setdefault(d.doctype, []).append(d.name) | |||||
for df in self.get_table_fields(): | |||||
if df.options not in ignore_children_type: | |||||
cnames = child_map.get(df.options) or [] | |||||
if cnames: | |||||
frappe.db.sql("""delete from `tab%s` where parent=%s and parenttype=%s and | |||||
name not in (%s)""" % (df.options, '%s', '%s', ','.join(['%s'] * len(cnames))), | |||||
tuple([self.name, self.doctype] + cnames)) | |||||
else: | |||||
frappe.db.sql("""delete from `tab%s` where parent=%s and parenttype=%s""" \ | |||||
% (df.options, '%s', '%s'), (self.name, self.doctype)) | |||||
self.run_post_save_methods() | self.run_post_save_methods() | ||||
def update_single(self, d): | def update_single(self, d): | ||||
@@ -14,6 +14,7 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
from frappe import msgprint, _ | from frappe import msgprint, _ | ||||
from frappe.model.document import Document | |||||
class NestedSetRecursionError(frappe.ValidationError): pass | class NestedSetRecursionError(frappe.ValidationError): pass | ||||
class NestedSetMultipleRootsError(frappe.ValidationError): pass | class NestedSetMultipleRootsError(frappe.ValidationError): pass | ||||
@@ -188,7 +189,7 @@ def validate_loop(doctype, name, lft, rgt): | |||||
"%s", "%s"), (lft, rgt)): | "%s", "%s"), (lft, rgt)): | ||||
frappe.throw("""Item cannot be added to its own descendents.""", NestedSetRecursionError) | frappe.throw("""Item cannot be added to its own descendents.""", NestedSetRecursionError) | ||||
class DocTypeNestedSet(object): | |||||
class DocTypeNestedSet(Document): | |||||
def on_update(self): | def on_update(self): | ||||
update_nsm(self) | update_nsm(self) | ||||
self.validate_ledger() | self.validate_ledger() | ||||
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class AboutUsSettings(Document): | |||||
def on_update(self): | def on_update(self): | ||||
from frappe.website.render import clear_cache | from frappe.website.render import clear_cache | ||||
@@ -6,6 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class AboutUsTeamMember(Document): | |||||
pass |
@@ -6,9 +6,7 @@ import frappe | |||||
from frappe.website.website_generator import WebsiteGenerator | from frappe.website.website_generator import WebsiteGenerator | ||||
from frappe.website.render import clear_cache | from frappe.website.render import clear_cache | ||||
class DocType(WebsiteGenerator): | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
class BlogCategory(WebsiteGenerator): | |||||
def autoname(self): | def autoname(self): | ||||
# to override autoname of WebsiteGenerator | # to override autoname of WebsiteGenerator | ||||
@@ -10,9 +10,7 @@ from frappe.website.render import clear_cache | |||||
from frappe import _ | from frappe import _ | ||||
from frappe.utils import today | from frappe.utils import today | ||||
class DocType(WebsiteGenerator): | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
class BlogPost(WebsiteGenerator): | |||||
self.save_versions = True | self.save_versions = True | ||||
def get_page_title(self): | def get_page_title(self): | ||||
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class BlogSettings(Document): | |||||
def on_update(self): | def on_update(self): | ||||
from frappe.website.render import clear_cache | from frappe.website.render import clear_cache | ||||
@@ -7,9 +7,9 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
from frappe import _ | from frappe import _ | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Blogger(Document): | |||||
def on_update(self): | def on_update(self): | ||||
"if user is set, then update all older blogs" | "if user is set, then update all older blogs" | ||||
@@ -6,6 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class CompanyHistory(Document): | |||||
pass |
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class ContactUsSettings(Document): | |||||
def on_update(self): | def on_update(self): | ||||
from frappe.website.render import clear_cache | from frappe.website.render import clear_cache |
@@ -10,9 +10,9 @@ from frappe.utils import get_fullname | |||||
from frappe.utils.email_lib.bulk import send | from frappe.utils.email_lib.bulk import send | ||||
from frappe.utils.email_lib import sendmail | from frappe.utils.email_lib import sendmail | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class Post(Document): | |||||
def validate(self): | def validate(self): | ||||
if not self.doc.parent_post and not self.doc.title: | if not self.doc.parent_post and not self.doc.title: | ||||
@@ -7,9 +7,9 @@ import frappe | |||||
from frappe.utils import cint, cstr | from frappe.utils import cint, cstr | ||||
from frappe import _ | from frappe import _ | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class StyleSettings(Document): | |||||
def validate(self): | def validate(self): | ||||
"""make custom css""" | """make custom css""" | ||||
@@ -4,6 +4,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class TopBarItem(Document): | |||||
pass |
@@ -5,9 +5,9 @@ from __future__ import unicode_literals | |||||
import frappe | import frappe | ||||
from frappe.website.permissions import get_access | from frappe.website.permissions import get_access | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class UserVote(Document): | |||||
def validate(self): | def validate(self): | ||||
# if new | # if new | ||||
@@ -7,9 +7,7 @@ from frappe.website.website_generator import WebsiteGenerator | |||||
from frappe.templates.generators.website_group import clear_cache | from frappe.templates.generators.website_group import clear_cache | ||||
from frappe.model.doc import make_autoname | from frappe.model.doc import make_autoname | ||||
class DocType(WebsiteGenerator): | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
class WebsiteGroup(WebsiteGenerator): | |||||
def get_page_title(self): | def get_page_title(self): | ||||
return self.doc.group_title | return self.doc.group_title | ||||
@@ -10,9 +10,7 @@ from frappe.utils.nestedset import DocTypeNestedSet | |||||
sitemap_fields = ("page_name", "ref_doctype", "docname", "page_or_generator", "idx", | sitemap_fields = ("page_name", "ref_doctype", "docname", "page_or_generator", "idx", | ||||
"lastmod", "parent_website_route", "public_read", "public_write", "page_title") | "lastmod", "parent_website_route", "public_read", "public_write", "page_title") | ||||
class DocType(DocTypeNestedSet): | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
class WebsiteRoute(DocTypeNestedSet): | |||||
self.nsm_parent_field = "parent_website_route" | self.nsm_parent_field = "parent_website_route" | ||||
def autoname(self): | def autoname(self): | ||||
@@ -6,9 +6,9 @@ import frappe | |||||
from frappe.website.permissions import remove_empty_permissions, clear_permissions | from frappe.website.permissions import remove_empty_permissions, clear_permissions | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WebsiteRoutePermission(Document): | |||||
def on_update(self): | def on_update(self): | ||||
remove_empty_permissions() | remove_empty_permissions() | ||||
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WebsiteScript(Document): | |||||
def on_update(self): | def on_update(self): | ||||
"""clear cache""" | """clear cache""" | ||||
@@ -8,7 +8,7 @@ from frappe.utils import get_request_site_address, encode | |||||
from frappe.model.controller import DocListController | from frappe.model.controller import DocListController | ||||
from urllib import quote | from urllib import quote | ||||
class DocType(DocListController): | |||||
class WebsiteSettings(DocListController): | |||||
def validate(self): | def validate(self): | ||||
self.validate_top_bar_items() | self.validate_top_bar_items() | ||||
self.validate_footer_items() | self.validate_footer_items() | ||||
@@ -21,7 +21,7 @@ class DocType(DocListController): | |||||
def validate_top_bar_items(self): | def validate_top_bar_items(self): | ||||
"""validate url in top bar items""" | """validate url in top bar items""" | ||||
for top_bar_item in self.doclist.get({"parentfield": "top_bar_items"}): | |||||
for top_bar_item in self.get("top_bar_items"): | |||||
if top_bar_item.parent_label: | if top_bar_item.parent_label: | ||||
parent_label_item = self.doclist.get({"parentfield": "top_bar_items", | parent_label_item = self.doclist.get({"parentfield": "top_bar_items", | ||||
"label": top_bar_item.parent_label}) | "label": top_bar_item.parent_label}) | ||||
@@ -38,7 +38,7 @@ class DocType(DocListController): | |||||
def validate_footer_items(self): | def validate_footer_items(self): | ||||
"""clear parent label in footer""" | """clear parent label in footer""" | ||||
for footer_item in self.doclist.get({"parentfield": "footer_items"}): | |||||
for footer_item in self.get("footer_items"): | |||||
footer_item.parent_label = None | footer_item.parent_label = None | ||||
def on_update(self): | def on_update(self): | ||||
@@ -6,9 +6,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WebsiteSlideshow(Document): | |||||
def on_update(self): | def on_update(self): | ||||
# a slide show can be in use and any change in it should get reflected | # a slide show can be in use and any change in it should get reflected | ||||
@@ -6,6 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | import frappe | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WebsiteSlideshowItem(Document): | |||||
pass |
@@ -11,9 +11,9 @@ from frappe import _ | |||||
from frappe.website.doctype.website_route.website_route import add_to_sitemap, update_sitemap, cleanup_sitemap | from frappe.website.doctype.website_route.website_route import add_to_sitemap, update_sitemap, cleanup_sitemap | ||||
from frappe.utils.nestedset import rebuild_tree | from frappe.utils.nestedset import rebuild_tree | ||||
class DocType: | |||||
def __init__(self, d, dl): | |||||
self.doc, self.doclist = d, dl | |||||
from frappe.model.document import Document | |||||
class WebsiteTemplate(Document): | |||||
def after_insert(self): | def after_insert(self): | ||||
if self.doc.page_or_generator == "Page": | if self.doc.page_or_generator == "Page": | ||||