Esempio n. 1
0
def get_linked_docs(doctype, name, metadata_loaded=None):
	if not metadata_loaded: metadata_loaded = []
	meta = webnotes.get_doctype(doctype, True)
	linkinfo = meta[0].get("__linked_with")
	results = {}
	for dt, link in linkinfo.items():
		link["doctype"] = dt
		linkmeta = webnotes.get_doctype(dt, True)
		if not linkmeta[0].get("issingle"):
			fields = [d.fieldname for d in linkmeta.get({"parent":dt, "in_list_view":1})] \
				+ ["name", "modified"]

			fields = ["`tab{dt}`.`{fn}`".format(dt=dt, fn=sf.strip()) for sf in fields if sf]

			if link.get("child_doctype"):
				ret = webnotes.get_list(doctype=dt, fields=fields, 
					filters=[[link.get('child_doctype'), link.get("fieldname"), '=', name]])
				
			else:
				ret = webnotes.get_list(doctype=dt, fields=fields, 
					filters=[[dt, link.get("fieldname"), '=', name]])
			
			if ret: 
				results[dt] = ret
				
			if not dt in metadata_loaded:
				if not "docs" in webnotes.local.response:
					webnotes.local.response.docs = []
				webnotes.local.response.docs += linkmeta
				
	return results
Esempio n. 2
0
	def test_event_list(self):
		webnotes.set_user("*****@*****.**")
		res = webnotes.get_list("Event", filters=[["Event", "subject", "like", "_Test Event%"]], fields=["name", "subject"])
		self.assertEquals(len(res), 2)
		subjects = [r.subject for r in res]
		self.assertTrue("_Test Event 1" in subjects)
		self.assertTrue("_Test Event 3" in subjects)
		self.assertFalse("_Test Event 2" in subjects)
Esempio n. 3
0
	def test_restriction_in_report(self):
		webnotes.defaults.add_default("Blog Category", "_Test Blog Category 1", "*****@*****.**", 
			"Restriction")
		webnotes.local.reportview_doctypes = {}
		
		names = [d.name for d in webnotes.get_list("Blog Post", fields=["name", "blog_category"])]

		self.assertTrue("_test-blog-post-1" in names)
		self.assertFalse("_test-blog-post" in names)
Esempio n. 4
0
	def test_owner_match_report(self):
		webnotes.conn.sql("""update tabDocPerm set `restricted`=1 where parent='Blog Post' 
			and ifnull(permlevel,0)=0""")
		webnotes.clear_cache(doctype="Blog Post")

		webnotes.set_user("*****@*****.**")

		names = [d.name for d in webnotes.get_list("Blog Post", fields=["name", "owner"])]
		self.assertTrue("_test-blog-post" in names)
		self.assertFalse("_test-blog-post-1" in names)
Esempio n. 5
0
def get_linked_docs(doctype, name, metadata_loaded=None):
    if not metadata_loaded: metadata_loaded = []
    meta = webnotes.get_doctype(doctype, True)
    linkinfo = meta[0].get("__linked_with")
    results = {}
    for dt, link in linkinfo.items():
        link["doctype"] = dt
        linkmeta = webnotes.get_doctype(dt, True)
        if not linkmeta[0].get("issingle"):
            fields = [d.fieldname for d in linkmeta.get({"parent":dt, "in_list_view":1,
             "fieldtype": ["not in", ["Image", "HTML", "Button", "Table"]]})] \
             + ["name", "modified", "docstatus"]

            fields = [
                "`tab{dt}`.`{fn}`".format(dt=dt, fn=sf.strip())
                for sf in fields if sf
            ]

            if link.get("child_doctype"):
                ret = webnotes.get_list(doctype=dt,
                                        fields=fields,
                                        filters=[[
                                            link.get('child_doctype'),
                                            link.get("fieldname"), '=', name
                                        ]])

            else:
                ret = webnotes.get_list(
                    doctype=dt,
                    fields=fields,
                    filters=[[dt, link.get("fieldname"), '=', name]])

            if ret:
                results[dt] = ret

            if not dt in metadata_loaded:
                if not "docs" in webnotes.local.response:
                    webnotes.local.response.docs = []
                webnotes.local.response.docs += linkmeta

    return results
def get_notifications():
    config = get_notification_config()
    can_read = webnotes.user.get_can_read()
    open_count_doctype = {}
    open_count_module = {}

    notification_count = dict(
        webnotes.conn.sql(
            """select for_doctype, open_count 
		from `tabNotification Count` where owner=%s""",
            (webnotes.session.user,),
        )
    )

    for d in config.for_doctype:
        if d in can_read:
            condition = config.for_doctype[d]
            key = condition.keys()[0]

            if d in notification_count:
                open_count_doctype[d] = notification_count[d]
            else:
                result = webnotes.get_list(
                    d, fields=["count(*)"], filters=[[d, key, "=", condition[key]]], as_list=True, limit_page_length=1
                )[0][0]

                webnotes.doc({"doctype": "Notification Count", "for_doctype": d, "open_count": result}).insert()

                open_count_doctype[d] = result

    for m in config.for_module:
        if m in notification_count:
            open_count_module[m] = notification_count[m]
        else:
            open_count_module[m] = webnotes.get_attr(config.for_module[m])()
            webnotes.doc(
                {"doctype": "Notification Count", "for_doctype": m, "open_count": open_count_module[m]}
            ).insert()

    return {"open_count_doctype": open_count_doctype, "open_count_module": open_count_module}
Esempio n. 7
0
def get():
	can_read = webnotes.user.get_can_read()
	open_count_doctype = {}
	open_count_module = {}

	notification_count = dict(webnotes.conn.sql("""select for_doctype, open_count 
		from `tabNotification Count` where owner=%s""", webnotes.session.user))

	for d in for_doctype:
		if d in can_read:
			condition = for_doctype[d]
			key = condition.keys()[0]

					
			if d in notification_count:
				open_count_doctype[d] = notification_count[d]
			else:
				result = webnotes.get_list(d, fields=["count(*)"], 
					filters=[[d, key, "=", condition[key]]], as_list=True, limit_page_length=1)[0][0]

				webnotes.doc({"doctype":"Notification Count", "for_doctype":d, 
					"open_count":result}).insert()
					
				open_count_doctype[d] = result

	for m in for_module:
		if m in notification_count:
			open_count_module[m] = notification_count[m]
		else:
			open_count_module[m] = for_module[m]()
			webnotes.doc({"doctype":"Notification Count", "for_doctype":m, 
				"open_count":open_count_module[m]}).insert()

	return {
		"open_count_doctype": open_count_doctype,
		"open_count_module": open_count_module
	}
Esempio n. 8
0
def get_companies():
	"""get a list of companies based on permission"""
	return [d.name for d in webnotes.get_list("Company", fields=["name"], 
		order_by="name")]
Esempio n. 9
0
    try:
        from startup.open_count import for_doctype, for_module
    except ImportError, e:
        return {}

    can_read = webnotes.user.get_can_read()
    open_count_doctype = {}
    open_count_module = {}

    for d in for_doctype:
        if d in can_read:
            condition = for_doctype[d]
            key = condition.keys()[0]

            result = webnotes.get_list(d,
                                       fields=["count(*)"],
                                       filters=[[d, key, "=", condition[key]]],
                                       as_list=True)[0][0]
            if result:
                open_count_doctype[d] = result

    for m in for_module:
        open_count_module[m] = for_module[m]()

    return {
        "open_count_doctype": open_count_doctype,
        "open_count_module": open_count_module
    }


def get_notification_info_for_boot():
    out = get()
Esempio n. 10
0
def get():
	try:
		from startup.open_count import for_doctype, for_module
	except ImportError, e:
		return {}
	
	can_read = webnotes.user.get_can_read()
	open_count_doctype = {}
	open_count_module = {}

	for d in for_doctype:
		if d in can_read:
			condition = for_doctype[d]
			key = condition.keys()[0]

			result = webnotes.get_list(d, fields=["count(*)"], 
				filters=[[d, key, "=", condition[key]]], as_list=True)[0][0]
			if result:
				open_count_doctype[d] = result

	for m in for_module:
		open_count_module[m] = for_module[m]()

	return {
		"open_count_doctype": open_count_doctype,
		"open_count_module": open_count_module
	}

def get_notification_info_for_boot():
	out = get()
	
	from startup.open_count import for_doctype
Esempio n. 11
0
def get_companies():
    """get a list of companies based on permission"""
    return [
        d.name
        for d in webnotes.get_list("Company", fields=["name"], order_by="name")
    ]