Пример #1
0
    def update_user_settings(self):
        # update user settings if new search
        user_settings = json.loads(get_user_settings(self.doctype))

        if hasattr(self, 'user_settings'):
            user_settings.update(self.user_settings)

        if self.save_user_settings_fields:
            user_settings['fields'] = self.user_settings_fields

        update_user_settings(self.doctype, user_settings)
Пример #2
0
	def update_user_settings(self):
		# update user settings if new search
		user_settings = json.loads(get_user_settings(self.doctype))

		if hasattr(self, 'user_settings'):
			user_settings.update(self.user_settings)

		if self.save_user_settings_fields:
			user_settings['fields'] = self.user_settings_fields

		update_user_settings(self.doctype, user_settings)
Пример #3
0
def get_bundle(doctype, user=None):
    if not user:
        user = frappe.session.user
    cache_key = "{}:{}".format(doctype, user)
    bundle_obj = frappe.cache().hget("renovation_doc_bundle", cache_key)
    if not bundle_obj:
        bundle_obj = {"metas": [], "user_settings": get_user_settings(doctype)}

        # update renovation_enabled
        for meta in get_meta_bundle(doctype):
            enabled_fields = get_enabled_fields(meta.name, user)
            meta = frappe._dict(meta.as_dict())
            # renovation-core takes 1 as true since all other db-Check types are 0/1
            meta.treeview = 1 if meta.name in frappe.get_hooks(
                "treeviews") else 0

            fields = []
            _fields = []
            for field in meta.get("fields"):
                if field.get("fieldname") in enabled_fields:
                    fields.append(field)
                else:
                    _fields.append(field)
            meta["fields"] = fields
            meta["_fields"] = _fields
            bundle_obj["metas"].append(meta)

            # Renovation Scripts
            meta["renovation_scripts"] = frappe.get_all(
                "Renovation Script",
                filters={"target_dt": meta.name},
                fields=["name", "code"])

            # reference bundle so that it can be cleared when required
            # a doctype can be referenced in multiple bundles
            mcach_key = "{}:{}".format(meta.name, user)
            ref_bundles = frappe.cache().hget("renovation_doc_ref_bundle",
                                              mcach_key)
            if not ref_bundles:
                ref_bundles = []
            if doctype not in ref_bundles:
                ref_bundles.append(doctype)
                frappe.cache().hset("renovation_doc_ref_bundle", mcach_key,
                                    ref_bundles)

        frappe.cache().hset("renovation_doc_bundle", cache_key, bundle_obj)
    return bundle_obj
Пример #4
0
def getdoctype(doctype, with_parent=False, cached_timestamp=None):
    """load doctype"""

    docs = []
    parent_dt = None

    # with parent (called from report builder)
    if with_parent:
        parent_dt = frappe.model.meta.get_parent_dt(doctype)
        if parent_dt:
            docs = get_meta_bundle(parent_dt)
            frappe.response['parent_dt'] = parent_dt

    if not docs:
        docs = get_meta_bundle(doctype)

    frappe.response['user_settings'] = get_user_settings(parent_dt or doctype)

    if cached_timestamp and docs[0].modified == cached_timestamp:
        return "use_cache"

    frappe.response.docs.extend(docs)
Пример #5
0
def getdoctype(doctype, with_parent=False, cached_timestamp=None):
	"""load doctype"""

	docs = []
	parent_dt = None

	# with parent (called from report builder)
	if with_parent:
		parent_dt = frappe.model.meta.get_parent_dt(doctype)
		if parent_dt:
			docs = get_meta_bundle(parent_dt)
			frappe.response['parent_dt'] = parent_dt

	if not docs:
		docs = get_meta_bundle(doctype)

	frappe.response['user_settings'] = get_user_settings(parent_dt or doctype)

	if cached_timestamp and docs[0].modified==cached_timestamp:
		return "use_cache"

	frappe.response.docs.extend(docs)