Esempio n. 1
0
def add_sidebar_data(context):
	from frappe.utils.user import get_fullname_and_avatar
	import frappe.www.list

	if not context.sidebar_items:

		sidebar_items = frappe.cache().hget('portal_menu_items', frappe.session.user)
		if sidebar_items == None:
			sidebar_items = []
			roles = frappe.get_roles()
			portal_settings = frappe.get_doc('Portal Settings', 'Portal Settings')

			def add_items(sidebar_items, menu_field):
				for d in portal_settings.get(menu_field):
					if d.enabled and ((not d.role) or d.role in roles):
						sidebar_items.append(d.as_dict())

			if not portal_settings.hide_standard_menu:
				add_items(sidebar_items, 'menu')

			if portal_settings.custom_menu:
				add_items(sidebar_items, 'custom_menu')

			frappe.cache().hset('portal_menu_items', frappe.session.user, sidebar_items)

		context.sidebar_items = sidebar_items

	info = get_fullname_and_avatar(frappe.session.user)
	context["fullname"] = info.fullname
	context["user_image"] = info.avatar
	context["user"] = info.name
Esempio n. 2
0
    def get_context(self, context):
        context.update(get_fullname_and_avatar(self.owner))
        context.comment_list = get_comment_list(self.doctype, self.name)
        if frappe.session.user == self.owner:
            context.bids = frappe.get_all("Frappe Job Bid",
                                          fields=[
                                              "status, "
                                              "name", "frappe_partner",
                                              "creation",
                                              "frappe_partner_title"
                                          ],
                                          filters={"frappe_job": self.name},
                                          order_by="creation asc")

            if self.status == "Assigned":
                context.bid = [
                    b for b in context.bids if b.status == 'Accepted'
                ][0].name

        elif frappe.session.user != "Guest":
            context.bid = frappe.db.get_value("Frappe Job Bid", {
                "owner": frappe.session.user,
                "frappe_job": self.name
            })

        if self.frappe_partner:
            context.frappe_partner_name, context.frappe_partner_route = \
             frappe.db.get_value("Frappe Partner",
              self.frappe_partner, ["partner_name", "page_name"])
Esempio n. 3
0
def add_sidebar_data(context):
    from frappe.utils.user import get_fullname_and_avatar
    import frappe.www.list

    if not context.sidebar_items:

        sidebar_items = frappe.cache().hget('portal_menu_items',
                                            frappe.session.user)
        if sidebar_items == None:
            sidebar_items = []
            roles = frappe.get_roles()
            portal_settings = frappe.get_doc('Portal Settings',
                                             'Portal Settings')

            def add_items(sidebar_items, menu_field):
                for d in portal_settings.get(menu_field):
                    if d.enabled and ((not d.role) or d.role in roles):
                        sidebar_items.append(d.as_dict())

            if not portal_settings.hide_standard_menu:
                add_items(sidebar_items, 'menu')

            if portal_settings.custom_menu:
                add_items(sidebar_items, 'custom_menu')

            frappe.cache().hset('portal_menu_items', frappe.session.user,
                                sidebar_items)

        context.sidebar_items = sidebar_items

    info = get_fullname_and_avatar(frappe.session.user)
    context["fullname"] = info.fullname
    context["user_image"] = info.avatar
    context["user"] = info.name
Esempio n. 4
0
def add_sidebar_data(context):
	from frappe.utils.user import get_fullname_and_avatar
	import frappe.templates.pages.list

	context.my_account_list = frappe.get_all('Portal Menu Item',
			fields=['title', 'route', 'reference_doctype'], filters={'enabled': 1}, order_by='idx asc')

	for item in context.my_account_list:
		if item.reference_doctype:
			item.count = len(frappe.templates.pages.list.get(item.reference_doctype).get('result'))

	info = get_fullname_and_avatar(frappe.session.user)
	context["fullname"] = info.fullname
	context["user_image"] = info.avatar
Esempio n. 5
0
def get_context(context):
	if frappe.session.user == "Guest":
		frappe.throw(_("You need to be logged in to access this page."), frappe.PermissionError)

	context.my_account_list = frappe.get_all('Portal Menu Item',
		fields=['title', 'route', 'reference_doctype'], filters={'enabled': 1}, order_by='idx asc')

	for item in context.my_account_list:
		if item.reference_doctype:
			item.count = len(frappe.templates.pages.list.get(item.reference_doctype).get('result'))

	info = get_fullname_and_avatar(frappe.session.user)
	context["fullname"] = info.fullname
	context["user_image"] = info.avatar
Esempio n. 6
0
def add_sidebar_data(context):
    import frappe.www.list
    from frappe.utils.user import get_fullname_and_avatar

    if context.show_sidebar and context.website_sidebar:
        context.sidebar_items = frappe.get_all(
            "Website Sidebar Item",
            filters=dict(parent=context.website_sidebar),
            fields=["title", "route", "`group`"],
            order_by="idx asc",
        )

    if not context.sidebar_items:
        sidebar_items = frappe.cache().hget("portal_menu_items",
                                            frappe.session.user)
        if sidebar_items == None:
            sidebar_items = []
            roles = frappe.get_roles()
            portal_settings = frappe.get_doc("Portal Settings",
                                             "Portal Settings")

            def add_items(sidebar_items, items):
                for d in items:
                    if d.get("enabled") and ((not d.get("role"))
                                             or d.get("role") in roles):
                        sidebar_items.append(
                            d.as_dict() if isinstance(d, Document) else d)

            if not portal_settings.hide_standard_menu:
                add_items(sidebar_items, portal_settings.get("menu"))

            if portal_settings.custom_menu:
                add_items(sidebar_items, portal_settings.get("custom_menu"))

            items_via_hooks = frappe.get_hooks("portal_menu_items")
            if items_via_hooks:
                for i in items_via_hooks:
                    i["enabled"] = 1
                add_items(sidebar_items, items_via_hooks)

            frappe.cache().hset("portal_menu_items", frappe.session.user,
                                sidebar_items)

        context.sidebar_items = sidebar_items

    info = get_fullname_and_avatar(frappe.session.user)
    context["fullname"] = info.fullname
    context["user_image"] = info.avatar
    context["user"] = info.name
Esempio n. 7
0
def get_context(context):
	if frappe.session.user == "Guest":
		frappe.throw(_("You need to be logged in to access this page."), frappe.PermissionError)

	context["my_account_list"] = []

	for element in frappe.get_hooks("my_account_context"):
		if isinstance(element, dict):
			context["my_account_list"].append(element)
		else:
			frappe.get_attr(element)(context)

	info = get_fullname_and_avatar(frappe.session.user)
	context["fullname"] = info.fullname
	context["user_image"] = info.avatar
Esempio n. 8
0
def add_sidebar_data(context):
    from frappe.utils.user import get_fullname_and_avatar
    import frappe.www.list

    if context.show_sidebar and context.website_sidebar:
        context.sidebar_items = frappe.get_all(
            'Website Sidebar Item',
            filters=dict(parent=context.website_sidebar),
            fields=['title', 'route', '`group`'],
            order_by='idx asc')

    if not context.sidebar_items:
        sidebar_items = frappe.cache().hget('portal_menu_items',
                                            frappe.session.user)
        if sidebar_items == None:
            sidebar_items = []
            roles = frappe.get_roles()
            portal_settings = frappe.get_doc('Portal Settings',
                                             'Portal Settings')

            def add_items(sidebar_items, items):
                for d in items:
                    if d.get('enabled') and ((not d.get('role'))
                                             or d.get('role') in roles):
                        sidebar_items.append(
                            d.as_dict() if isinstance(d, Document) else d)

            if not portal_settings.hide_standard_menu:
                add_items(sidebar_items, portal_settings.get('menu'))

            if portal_settings.custom_menu:
                add_items(sidebar_items, portal_settings.get('custom_menu'))

            items_via_hooks = frappe.get_hooks('portal_menu_items')
            if items_via_hooks:
                for i in items_via_hooks:
                    i['enabled'] = 1
                add_items(sidebar_items, items_via_hooks)

            frappe.cache().hset('portal_menu_items', frappe.session.user,
                                sidebar_items)

        context.sidebar_items = sidebar_items

    info = get_fullname_and_avatar(frappe.session.user)
    context["fullname"] = info.fullname
    context["user_image"] = info.avatar
    context["user"] = info.name
Esempio n. 9
0
def get_context(context):
    if frappe.session.user == "Guest":
        frappe.throw(_("You need to be logged in to access this page."),
                     frappe.PermissionError)

    context["my_account_list"] = []

    for element in frappe.get_hooks("my_account_context"):
        if isinstance(element, dict):
            context["my_account_list"].append(element)
        else:
            frappe.get_attr(element)(context)

    info = get_fullname_and_avatar(frappe.session.user)
    context["fullname"] = info.fullname
    context["user_image"] = info.avatar
Esempio n. 10
0
def add_sidebar_data(context):
	from frappe.utils.user import get_fullname_and_avatar
	import frappe.www.list

	sidebar_items = json.loads(frappe.cache().get('sidebar_items') or '[]')
	if not sidebar_items:
		sidebar_items = frappe.get_all('Portal Menu Item',
			fields=['title', 'route', 'reference_doctype', 'show_always'],
			filters={'enabled': 1}, order_by='idx asc')
		frappe.cache().set('portal_menu_items', json.dumps(sidebar_items))

	if not context.sidebar_items:
		context.sidebar_items = sidebar_items

	info = get_fullname_and_avatar(frappe.session.user)
	context["fullname"] = info.fullname
	context["user_image"] = info.avatar
Esempio n. 11
0
	def get_context(self, context):
		context.update(get_fullname_and_avatar(self.owner))
		context.comment_list = get_comment_list(self.doctype, self.name)
		if frappe.session.user == self.owner:
			context.bids = frappe.get_all("Frappe Job Bid",
				fields=["status, ""name", "frappe_partner", "creation", "frappe_partner_title"],
				filters={"frappe_job": self.name}, order_by="creation asc")

			if self.status == "Assigned":
				context.bid = [b for b in context.bids if b.status=='Accepted'][0].name

		elif frappe.session.user != "Guest":
			context.bid = frappe.db.get_value("Frappe Job Bid",
				{"owner": frappe.session.user, "frappe_job": self.name})

		if self.frappe_partner:
			context.frappe_partner_name, context.frappe_partner_route = \
				frappe.db.get_value("Frappe Partner",
					self.frappe_partner, ["partner_name", "page_name"])
Esempio n. 12
0
def add_sidebar_data(context):
    from frappe.utils.user import get_fullname_and_avatar
    import frappe.www.list

    sidebar_items = json.loads(frappe.cache().get('sidebar_items') or '[]')
    if not sidebar_items:
        sidebar_items = frappe.get_all(
            'Portal Menu Item',
            fields=['title', 'route', 'reference_doctype', 'show_always'],
            filters={'enabled': 1},
            order_by='idx asc')
        frappe.cache().set('portal_menu_items', json.dumps(sidebar_items))

    if not context.sidebar_items:
        context.sidebar_items = sidebar_items

    info = get_fullname_and_avatar(frappe.session.user)
    context["fullname"] = info.fullname
    context["user_image"] = info.avatar
Esempio n. 13
0
def add_sidebar_data(context):
    from frappe.utils.user import get_fullname_and_avatar
    import frappe.templates.pages.list

    context.my_account_list = frappe.get_all(
        'Portal Menu Item',
        fields=['title', 'route', 'reference_doctype'],
        filters={'enabled': 1},
        order_by='idx asc')

    for item in context.my_account_list:
        if item.reference_doctype:
            item.count = len(
                frappe.templates.pages.list.get(
                    item.reference_doctype).get('result'))

    info = get_fullname_and_avatar(frappe.session.user)
    context["fullname"] = info.fullname
    context["user_image"] = info.avatar
Esempio n. 14
0
def add_sidebar_data(context):
	from frappe.utils.user import get_fullname_and_avatar
	import frappe.www.list

	if context.show_sidebar and context.website_sidebar:
		context.sidebar_items = frappe.get_all('Website Sidebar Item',
			filters=dict(parent=context.website_sidebar), fields=['title', 'route', '`group`'],
			order_by='idx asc')

	if not context.sidebar_items:
		sidebar_items = frappe.cache().hget('portal_menu_items', frappe.session.user)
		if sidebar_items == None:
			sidebar_items = []
			roles = frappe.get_roles()
			portal_settings = frappe.get_doc('Portal Settings', 'Portal Settings')

			def add_items(sidebar_items, items):
				for d in items:
					if d.get('enabled') and ((not d.get('role')) or d.get('role') in roles):
						sidebar_items.append(d.as_dict() if isinstance(d, Document) else d)

			if not portal_settings.hide_standard_menu:
				add_items(sidebar_items, portal_settings.get('menu'))

			if portal_settings.custom_menu:
				add_items(sidebar_items, portal_settings.get('custom_menu'))

			items_via_hooks = frappe.get_hooks('portal_menu_items')
			if items_via_hooks:
				for i in items_via_hooks: i['enabled'] = 1
				add_items(sidebar_items, items_via_hooks)

			frappe.cache().hset('portal_menu_items', frappe.session.user, sidebar_items)

		context.sidebar_items = sidebar_items

	info = get_fullname_and_avatar(frappe.session.user)
	context["fullname"] = info.fullname
	context["user_image"] = info.avatar
	context["user"] = info.name
Esempio n. 15
0
 def set_user_info(self):
     from frappe.utils.user import get_fullname_and_avatar
     info = get_fullname_and_avatar(frappe.session.user)
     self.context["fullname"] = info.fullname
     self.context["user_image"] = info.avatar
     self.context["user"] = info.name