示例#1
0
    def __init__(self, arg1, arg2=None):
        self.doctype = self.name = None
        if arg1 and isinstance(arg1, basestring):
            if not arg2:
                # single
                self.doctype = self.name = arg1
            else:
                self.doctype = arg1
                if isinstance(arg2, dict):
                    # filter
                    self.name = frappe.db.get_value(arg1, arg2, "name")
                    if self.name is None:
                        raise frappe.DoesNotExistError, (arg1, arg2)
                else:
                    self.name = arg2

            self.load_from_db()

        elif isinstance(arg1, dict):
            super(Document, self).__init__(arg1)
            self.init_valid_columns()

        else:
            # incorrect arguments. let's not proceed.
            raise frappe.DataError("Document({0}, {1})".format(arg1, arg2))
示例#2
0
    def __init__(self, arg1, arg2=None):
        self.doctype = self.name = None

        if arg1 and isinstance(arg1, basestring):
            if not arg2:
                # single
                self.doctype = self.name = arg1
            else:
                self.doctype = arg1
                if isinstance(arg2, dict):
                    # filter
                    self.name = frappe.db.get_value(arg1, arg2, "name")
                    if self.name is None:
                        frappe.throw(
                            _("{0} {1} not found").format(_(arg1), arg2),
                            frappe.DoesNotExistError)
                else:
                    self.name = arg2

            self.load_from_db()

        elif isinstance(arg1, dict):
            super(Document, self).__init__(arg1)
            self.init_valid_columns()

        else:
            # incorrect arguments. let's not proceed.
            raise frappe.DataError("Document({0}, {1})".format(arg1, arg2))

        if hasattr(self, "__setup__"):
            self.__setup__()

        self.dont_update_if_missing = []
示例#3
0
文件: bean.py 项目: fogueri/frappe
    def make_controller(self):
        if not self.doc.doctype:
            raise frappe.DataError("Bean doctype not specified")
        if self.obj:
            # update doclist before running any method
            self.obj.doclist = self.doclist
            return self.obj

        self.obj = frappe.get_obj(doc=self.doc, doclist=self.doclist)
        self.obj.bean = self
        self.controller = self.obj
        return self.obj
示例#4
0
    def __init__(self, arg1, arg2=None):
        """Constructor.

		:param arg1: DocType name as string or document **dict**
		:param arg2: Document name, if `arg1` is DocType name.

		If DocType name and document name are passed, the object will load
		all values (including child documents) from the database.
		"""
        self.doctype = self.name = None

        if arg1 and isinstance(arg1, basestring):
            if not arg2:
                # single
                self.doctype = self.name = arg1
            else:
                self.doctype = arg1
                if isinstance(arg2, dict):
                    # filter
                    self.name = frappe.db.get_value(arg1, arg2, "name")
                    if self.name is None:
                        frappe.throw(
                            _("{0} {1} not found").format(_(arg1), arg2),
                            frappe.DoesNotExistError)
                else:
                    self.name = arg2

            self.load_from_db()

        elif isinstance(arg1, dict):
            super(Document, self).__init__(arg1)
            self.init_valid_columns()

        else:
            # incorrect arguments. let's not proceed.
            raise frappe.DataError("Document({0}, {1})".format(arg1, arg2))

        if hasattr(self, "__setup__"):
            self.__setup__()

        self.dont_update_if_missing = []