Exemplo n.º 1
0
    def on_update(self):
        """Update database schema, make controller templates if `custom` is not set and clear cache."""
        from frappe.model.db_schema import updatedb
        updatedb(self.name, self)

        self.change_modified_of_parent()
        make_module_and_roles(self)

        self.update_fields_to_fetch()

        from frappe import conf
        if not self.custom and not (
                frappe.flags.in_import
                or frappe.flags.in_test) and conf.get('developer_mode'):
            self.export_doc()
            self.make_controller_template()

            if self.has_web_view:
                self.set_base_class_for_controller()

        # update index
        if not self.custom:
            self.run_module_method("on_doctype_update")
            if self.flags.in_insert:
                self.run_module_method("after_doctype_insert")

        delete_notification_count_for(doctype=self.name)
        frappe.clear_cache(doctype=self.name)

        if not frappe.flags.in_install and hasattr(self, 'before_update'):
            self.sync_global_search()
Exemplo n.º 2
0
def get_list(arg=None):
	"""get list of messages"""
	frappe.form_dict['limit_start'] = int(frappe.form_dict['limit_start'])
	frappe.form_dict['limit_page_length'] = int(frappe.form_dict['limit_page_length'])
	frappe.form_dict['user'] = frappe.session['user']

	# set all messages as read
	frappe.db.begin()
	frappe.db.sql("""UPDATE `tabComment`
	set docstatus = 1 where comment_doctype in ('My Company', 'Message')
	and comment_docname = %s
	""", frappe.session.user)

	delete_notification_count_for("Messages")

	frappe.db.commit()

	if frappe.form_dict['contact'] == frappe.session['user']:
		# return messages
		return frappe.db.sql("""select * from `tabComment`
		where (owner=%(contact)s
			or comment_docname=%(user)s
			or (owner=comment_docname and ifnull(parenttype, "")!="Assignment"))
		and comment_doctype ='Message'
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1)
	else:
		return frappe.db.sql("""select * from `tabComment`
		where (owner=%(contact)s and comment_docname=%(user)s)
		or (owner=%(user)s and comment_docname=%(contact)s)
		or (owner=%(contact)s and comment_docname=%(contact)s)
		and comment_doctype ='Message'
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1)
Exemplo n.º 3
0
def clear_doctype_cache(doctype=None):
    clear_controller_cache(doctype)
    cache = frappe.cache()

    if getattr(frappe.local, "meta_cache") and (doctype
                                                in frappe.local.meta_cache):
        del frappe.local.meta_cache[doctype]

    for key in ("is_table", "doctype_modules", "document_cache"):
        cache.delete_value(key)

    frappe.local.document_cache = {}

    def clear_single(dt):
        for name in doctype_cache_keys:
            cache.hdel(name, dt)

    if doctype:
        clear_single(doctype)

        # clear all parent doctypes

        for dt in frappe.db.get_all(
                "DocField", "parent",
                dict(fieldtype=["in", frappe.model.table_fields],
                     options=doctype)):
            clear_single(dt.parent)

        # clear all notifications
        delete_notification_count_for(doctype)

    else:
        # clear all
        for name in doctype_cache_keys:
            cache.delete_value(name)
Exemplo n.º 4
0
def clear_doctype_cache(doctype=None):
	cache = frappe.cache()

	if getattr(frappe.local, 'meta_cache') and (doctype in frappe.local.meta_cache):
		del frappe.local.meta_cache[doctype]

	for key in ('is_table', 'doctype_modules'):
		cache.delete_value(key)

	groups = ["meta", "form_meta", "table_columns", "last_modified",
		"linked_doctypes", 'notifications', 'workflow']

	def clear_single(dt):
		for name in groups:
			cache.hdel(name, dt)

	if doctype:
		clear_single(doctype)

		# clear all parent doctypes
		for dt in frappe.db.sql("""select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype,)):
			clear_single(dt[0])

		# clear all notifications
		delete_notification_count_for(doctype)

	else:
		# clear all
		for name in groups:
			cache.delete_value(name)
Exemplo n.º 5
0
def clear_doctype_cache(doctype=None):
    cache = frappe.cache()

    if getattr(frappe.local, 'meta_cache') and (doctype
                                                in frappe.local.meta_cache):
        del frappe.local.meta_cache[doctype]

    for key in ('is_table', 'doctype_modules'):
        cache.delete_value(key)

    groups = [
        "meta", "form_meta", "table_columns", "last_modified",
        "linked_doctypes", 'notifications', 'workflow'
    ]

    def clear_single(dt):
        for name in groups:
            cache.hdel(name, dt)

    if doctype:
        clear_single(doctype)

        # clear all parent doctypes

        for dt in frappe.db.get_all('DocField', 'parent',
                                    dict(fieldtype='Table', options=doctype)):
            clear_single(dt.parent)

        # clear all notifications
        delete_notification_count_for(doctype)

    else:
        # clear all
        for name in groups:
            cache.delete_value(name)
Exemplo n.º 6
0
def clear_cache(doctype=None):
	cache = frappe.cache()

	cache.delete_value("is_table")
	cache.delete_value("doctype_modules")

	groups = ["meta", "form_meta", "table_columns", "last_modified", "linked_doctypes"]

	def clear_single(dt):
		for name in groups:
			cache.hdel(name, dt)

		# also clear linked_with list cache
		cache.delete_keys("user:*:linked_with:{doctype}:".format(doctype=doctype))

	if doctype:
		clear_single(doctype)

		# clear all parent doctypes
		for dt in frappe.db.sql("""select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype,)):
			clear_single(dt[0])

		# clear all notifications
		from frappe.desk.notifications import delete_notification_count_for
		delete_notification_count_for(doctype)

	else:
		# clear all
		for name in groups:
			cache.delete_value(name)
Exemplo n.º 7
0
def get_list(arg=None):
	"""get list of messages"""
	frappe.form_dict['limit_start'] = int(frappe.form_dict['limit_start'])
	frappe.form_dict['limit_page_length'] = int(frappe.form_dict['limit_page_length'])
	frappe.form_dict['user'] = frappe.session['user']

	# set all messages as read
	frappe.db.begin()
	frappe.db.sql("""UPDATE `tabComment`
	set docstatus = 1 where comment_doctype in ('My Company', 'Message')
	and comment_docname = %s
	""", frappe.session.user)

	delete_notification_count_for("Messages")

	frappe.db.commit()

	if frappe.form_dict['contact'] == frappe.session['user']:
		# return messages
		return frappe.db.sql("""select * from `tabComment`
		where (owner=%(contact)s
			or comment_docname=%(user)s
			or (owner=comment_docname and ifnull(parenttype, "")!="Assignment")
			or owner=comment_docname)
		and comment_doctype ='Message'
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1)
	else:
		return frappe.db.sql("""select * from `tabComment`
		where ((owner=%(contact)s and comment_docname=%(user)s)
		or (owner=%(user)s and comment_docname=%(contact)s)
		or (owner=%(contact)s and comment_docname=%(contact)s))
		and comment_doctype ='Message'
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1)
Exemplo n.º 8
0
def clear_cache(doctype=None):
    cache = frappe.cache()

    for key in ('is_table', 'doctype_modules'):
        cache.delete_value(key)

    groups = [
        "meta", "form_meta", "table_columns", "last_modified",
        "linked_doctypes", 'email_alerts'
    ]

    def clear_single(dt):
        for name in groups:
            cache.hdel(name, dt)

    if doctype:
        clear_single(doctype)

        # clear all parent doctypes
        for dt in frappe.db.sql(
                """select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype, )):
            clear_single(dt[0])

        # clear all notifications
        from frappe.desk.notifications import delete_notification_count_for
        delete_notification_count_for(doctype)

    else:
        # clear all
        for name in groups:
            cache.delete_value(name)
Exemplo n.º 9
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		from frappe.model.db_schema import updatedb
		updatedb(self.name, self)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		self.update_fields_to_fetch()

		from frappe import conf
		if not self.custom and not (frappe.flags.in_import or frappe.flags.in_test) and conf.get('developer_mode'):
			self.export_doc()
			self.make_controller_template()

			if self.has_web_view:
				self.set_base_class_for_controller()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)

		if not frappe.flags.in_install and hasattr(self, 'before_update'):
			self.sync_global_search()

		# clear from local cache
		if self.name in frappe.local.meta_cache:
			del frappe.local.meta_cache[self.name]
Exemplo n.º 10
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
	"""post message"""

	comment_type = None
	if contact == 'Bot':
		contact = frappe.session.user
		comment_type = 'Bot'

	d = frappe.new_doc('Communication')
	d.communication_type = 'Notification' if parenttype else 'Chat'
	d.subject = subject
	d.content = txt
	d.reference_doctype = 'User'
	d.reference_name = contact
	d.sender = frappe.session.user

	if comment_type:
		d.comment_type = comment_type

	d.insert(ignore_permissions=True)

	delete_notification_count_for("Chat")

	if notify and cint(notify):
		_notify(contact, txt, subject)

	return d
Exemplo n.º 11
0
def clear_doctype_cache(doctype=None):
    cache = frappe.cache()

    if getattr(frappe.local, 'meta_cache') and (doctype
                                                in frappe.local.meta_cache):
        del frappe.local.meta_cache[doctype]

    for key in ('is_table', 'doctype_modules'):
        cache.delete_value(key)

    def clear_single(dt):
        for name in doctype_cache_keys:
            cache.hdel(name, dt)

    if doctype:
        clear_single(doctype)

        # clear all parent doctypes

        for dt in frappe.db.get_all(
                'DocField', 'parent',
                dict(fieldtype=['in', frappe.model.table_fields],
                     options=doctype)):
            clear_single(dt.parent)

        # clear all notifications
        delete_notification_count_for(doctype)

    else:
        # clear all
        for name in doctype_cache_keys:
            cache.delete_value(name)

    # Clear all document's cache. To clear documents of a specific DocType document_cache should be restructured
    clear_document_cache()
Exemplo n.º 12
0
def clear_doctype_cache(doctype):
	frappe.clear_cache(doctype=doctype)
	delete_notification_count_for(doctype)
	for user in frappe.db.sql_list("""select distinct tabUserRole.parent from tabUserRole, tabDocPerm
		where tabDocPerm.parent = %s
		and tabDocPerm.role = tabUserRole.role""", doctype):
		frappe.clear_cache(user=user)
Exemplo n.º 13
0
def clear_cache(doctype=None):
    prefixes = ["meta", "form_meta", "table_columns"]

    def clear_single(dt):
        for p in prefixes:
            frappe.cache().delete_value(p + ":" + dt)

    if doctype:
        clear_single(doctype)

        # clear all parent doctypes
        for dt in frappe.db.sql(
                """select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype, )):
            clear_single(dt[0])

        # clear all notifications
        from frappe.desk.notifications import delete_notification_count_for
        delete_notification_count_for(doctype)

    else:
        # clear all
        for p in prefixes:
            frappe.cache().delete_keys(p + ":")

    frappe.cache().delete_value("is_table")
Exemplo n.º 14
0
def reset_perms(doctype):
    """Reset permissions for given doctype."""
    from frappe.desk.notifications import delete_notification_count_for
    delete_notification_count_for(doctype)

    frappe.db.sql("""delete from `tabCustom DocPerm` where parent=%s""",
                  doctype)
Exemplo n.º 15
0
def clear_cache(doctype=None):
	cache = frappe.cache()

	cache.delete_value("is_table")
	cache.delete_value("doctype_modules")

	groups = ["meta", "form_meta", "table_columns", "last_modified", "linked_doctypes"]

	def clear_single(dt):
		for name in groups:
			cache.hdel(name, dt)

		# also clear linked_with list cache
		cache.delete_keys("user:*:linked_with:{doctype}:".format(doctype=doctype))

	if doctype:
		clear_single(doctype)

		# clear all parent doctypes
		for dt in frappe.db.sql("""select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype,)):
			clear_single(dt[0])

		# clear all notifications
		from frappe.desk.notifications import delete_notification_count_for
		delete_notification_count_for(doctype)

	else:
		# clear all
		for name in groups:
			cache.delete_value(name)
Exemplo n.º 16
0
def clear_cache(doctype=None):
	cache = frappe.cache()

	if getattr(frappe.local, 'meta_cache') and (doctype in frappe.local.meta_cache):
		del frappe.local.meta_cache[doctype]

	for key in ('is_table', 'doctype_modules'):
		cache.delete_value(key)

	groups = ["meta", "form_meta", "table_columns", "last_modified",
		"linked_doctypes", 'email_alerts']

	def clear_single(dt):
		for name in groups:
			cache.hdel(name, dt)

	if doctype:
		clear_single(doctype)

		# clear all parent doctypes
		for dt in frappe.db.sql("""select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype,)):
			clear_single(dt[0])

		# clear all notifications
		from frappe.desk.notifications import delete_notification_count_for
		delete_notification_count_for(doctype)

	else:
		# clear all
		for name in groups:
			cache.delete_value(name)
Exemplo n.º 17
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
	"""post message"""

	comment_type = None
	if contact == 'Bot':
		contact = frappe.session.user
		comment_type = 'Bot'

	d = frappe.new_doc('Communication')
	d.communication_type = 'Notification' if parenttype else 'Chat'
	d.subject = subject
	d.content = txt
	d.reference_doctype = 'User'
	d.reference_name = contact
	d.sender = frappe.session.user

	if comment_type:
		d.comment_type = comment_type

	d.insert(ignore_permissions=True)

	delete_notification_count_for("Chat")

	if notify and cint(notify):
		_notify(contact, txt, subject)

	return d
Exemplo n.º 18
0
def clear_cache(doctype=None):
	frappe.cache().delete_value("is_table")
	frappe.cache().delete_value("doctype_modules")

	groups = ["meta", "form_meta", "table_columns", "last_modified"]

	def clear_single(dt):
		for name in groups:
			frappe.cache().hdel(name, dt)

	if doctype:
		clear_single(doctype)

		# clear all parent doctypes
		for dt in frappe.db.sql("""select parent from tabDocField
			where fieldtype="Table" and options=%s""", (doctype,)):
			clear_single(dt[0])

		# clear all notifications
		from frappe.desk.notifications import delete_notification_count_for
		delete_notification_count_for(doctype)

	else:
		# clear all
		for name in groups:
			frappe.cache().delete_value(name)
Exemplo n.º 19
0
def get_list(arg=None):
    """get list of messages"""
    frappe.form_dict['start'] = int(frappe.form_dict['start'])
    frappe.form_dict['page_length'] = int(frappe.form_dict['page_length'])
    frappe.form_dict['user'] = frappe.session['user']

    # set all messages as read
    frappe.db.sql(
        """UPDATE `tabCommunication` set seen = 1
		where
			communication_type in ('Chat', 'Notification')
			and seen = 0
			and reference_doctype = 'User'
			and reference_name = %s""", frappe.session.user)

    delete_notification_count_for("Chat")

    frappe.local.flags.commit = True

    fields = '''name, owner, modified, content, communication_type,
		comment_type, reference_doctype, reference_name'''

    if frappe.form_dict.contact == 'Bot':
        return frappe.db.sql("""select {0} from `tabCommunication`
			where
				comment_type = 'Bot'
				and reference_doctype = 'User'
				and reference_name = %(user)s
			order by creation desc
			limit %(start)s, %(page_length)s""".format(fields),
                             frappe.local.form_dict,
                             as_dict=1)

    if frappe.form_dict.contact == frappe.session.user:
        # return messages
        return frappe.db.sql("""select {0} from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and comment_type != 'Bot'
				and reference_doctype ='User'
				and (owner=%(contact)s
					or reference_name=%(user)s
					or owner=reference_name)
			order by creation desc
			limit %(start)s, %(page_length)s""".format(fields),
                             frappe.local.form_dict,
                             as_dict=1)
    else:
        return frappe.db.sql("""select {0} from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and comment_type != 'Bot'
				and reference_doctype ='User'
				and ((owner=%(contact)s and reference_name=%(user)s)
					or (owner=%(user)s and reference_name=%(contact)s))
			order by creation desc
			limit %(start)s, %(page_length)s""".format(fields),
                             frappe.local.form_dict,
                             as_dict=1)
Exemplo n.º 20
0
def reset_perms(doctype):
	"""Reset permissions for given doctype."""
	from frappe.desk.notifications import delete_notification_count_for
	delete_notification_count_for(doctype)

	frappe.db.sql("""delete from tabDocPerm where parent=%s""", doctype)
	frappe.reload_doc(frappe.db.get_value("DocType", doctype, "module"),
		"DocType", doctype, force=True)
def clear_doctype_cache(doctype):
    frappe.clear_cache(doctype=doctype)
    delete_notification_count_for(doctype)
    for user in frappe.db.sql_list(
            """select distinct tabUserRole.parent from tabUserRole, tabDocPerm
		where tabDocPerm.parent = %s
		and tabDocPerm.role = tabUserRole.role""", doctype):
        frappe.clear_cache(user=user)
Exemplo n.º 22
0
def reset_perms(doctype):
    """Reset permissions for given doctype."""
    from frappe.desk.notifications import delete_notification_count_for
    delete_notification_count_for(doctype)

    frappe.db.sql("""delete from tabDocPerm where parent=%s""", doctype)
    frappe.reload_doc(frappe.db.get_value("DocType", doctype, "module"),
                      "DocType",
                      doctype,
                      force=True)
Exemplo n.º 23
0
def get_list(arg=None):
	"""get list of messages"""
	frappe.form_dict['start'] = int(frappe.form_dict['start'])
	frappe.form_dict['page_length'] = int(frappe.form_dict['page_length'])
	frappe.form_dict['user'] = frappe.session['user']

	# set all messages as read
	frappe.db.sql("""UPDATE `tabCommunication` set seen = 1
		where
			communication_type in ('Chat', 'Notification')
			and seen = 0
			and reference_doctype = 'User'
			and reference_name = %s""", frappe.session.user)

	delete_notification_count_for("Chat")

	frappe.local.flags.commit = True

	fields = '''name, owner, modified, content, communication_type,
		comment_type, reference_doctype, reference_name'''

	if frappe.form_dict.contact == 'Bot':
		return frappe.db.sql("""select {0} from `tabCommunication`
			where
				comment_type = 'Bot'
				and reference_doctype = 'User'
				and reference_name = %(user)s
			order by creation desc
			limit %(start)s, %(page_length)s""".format(fields),
			frappe.local.form_dict, as_dict=1)

	if frappe.form_dict.contact == frappe.session.user:
		# return messages
		return frappe.db.sql("""select {0} from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and comment_type != 'Bot'
				and reference_doctype ='User'
				and (owner=%(contact)s
					or reference_name=%(user)s
					or owner=reference_name)
			order by creation desc
			limit %(start)s, %(page_length)s""".format(fields),
			frappe.local.form_dict, as_dict=1)
	else:
		return frappe.db.sql("""select {0} from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and comment_type != 'Bot'
				and reference_doctype ='User'
				and ((owner=%(contact)s and reference_name=%(user)s)
					or (owner=%(user)s and reference_name=%(contact)s))
			order by creation desc
			limit %(start)s, %(page_length)s""".format(fields),
			frappe.local.form_dict, as_dict=1)
Exemplo n.º 24
0
def clear_permissions_cache(doctype):
	frappe.clear_cache(doctype=doctype)
	delete_notification_count_for(doctype)
	for user in frappe.db.sql_list("""select
			distinct `tabHas Role`.parent
		from
			`tabHas Role`,
		tabDocPerm
			where tabDocPerm.parent = %s
			and tabDocPerm.role = `tabHas Role`.role""", doctype):
		frappe.clear_cache(user=user)
Exemplo n.º 25
0
def clear_permissions_cache(doctype):
	frappe.clear_cache(doctype=doctype)
	delete_notification_count_for(doctype)
	for user in frappe.db.sql_list("""select
			distinct `tabHas Role`.parent
		from
			`tabHas Role`,
		tabDocPerm
			where tabDocPerm.parent = %s
			and tabDocPerm.role = `tabHas Role`.role""", doctype):
		frappe.clear_cache(user=user)
Exemplo n.º 26
0
def clear_permissions_cache(doctype):
	frappe.clear_cache(doctype=doctype)
	delete_notification_count_for(doctype)
	for user in frappe.db.sql_list("""
		SELECT
			DISTINCT `tabHas Role`.`parent`
		FROM
			`tabHas Role`,
			`tabDocPerm`
		WHERE `tabDocPerm`.`parent` = %s
		AND `tabDocPerm`.`role` = `tabHas Role`.`role`
		""", doctype):
		frappe.clear_cache(user=user)
Exemplo n.º 27
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		self.delete_duplicate_custom_fields()
		try:
			frappe.db.updatedb(self.name, Meta(self))
		except Exception as e:
			print("\n\nThere was an issue while migrating the DocType: {}\n".format(self.name))
			raise e

		self.change_modified_of_parent()
		make_module_and_roles(self)

		self.update_fields_to_fetch()

		allow_doctype_export = (
			not self.custom
			and not frappe.flags.in_import
			and (
				frappe.conf.developer_mode
				or frappe.flags.allow_doctype_export
			)
		)
		if allow_doctype_export:
			self.export_doc()
			self.make_controller_template()

			if self.has_web_view:
				self.set_base_class_for_controller()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)

		if not frappe.flags.in_install and hasattr(self, 'before_update'):
			self.sync_global_search()

		# clear from local cache
		if self.name in frappe.local.meta_cache:
			del frappe.local.meta_cache[self.name]

		clear_linked_doctype_cache()
Exemplo n.º 28
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
    import frappe
    """post message"""

    d = frappe.new_doc('Comment')
    d.parenttype = parenttype
    d.comment = txt
    d.comment_docname = contact
    d.comment_doctype = 'Message'
    d.insert(ignore_permissions=True)

    delete_notification_count_for("Messages")

    if notify and cint(notify):
        if contact == frappe.session.user:
            _notify([user.name for user in get_enabled_system_users()], txt)
        else:
            _notify(contact, txt, subject)
Exemplo n.º 29
0
def get_list(arg=None):
    """get list of messages"""
    frappe.form_dict['limit_start'] = int(frappe.form_dict['limit_start'])
    frappe.form_dict['limit_page_length'] = int(
        frappe.form_dict['limit_page_length'])
    frappe.form_dict['user'] = frappe.session['user']

    # set all messages as read
    frappe.db.begin()
    frappe.db.sql(
        """UPDATE `tabCommunication` set seen = 1
		where
			communication_type in ('Chat', 'Notification')
			and reference_doctype = 'User'
			and reference_name = %s""", frappe.session.user)

    delete_notification_count_for("Messages")

    frappe.local.flags.commit = True

    if frappe.form_dict['contact'] == frappe.session['user']:
        # return messages
        return frappe.db.sql("""select * from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and reference_doctype ='User'
				and (owner=%(contact)s
					or reference_name=%(user)s
					or owner=reference_name)
			order by creation desc
			limit %(limit_start)s, %(limit_page_length)s""",
                             frappe.local.form_dict,
                             as_dict=1)
    else:
        return frappe.db.sql("""select * from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and reference_doctype ='User'
				and ((owner=%(contact)s and reference_name=%(user)s)
					or (owner=%(contact)s and reference_name=%(contact)s))
			order by creation desc
			limit %(limit_start)s, %(limit_page_length)s""",
                             frappe.local.form_dict,
                             as_dict=1)
Exemplo n.º 30
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
    import frappe

    """post message"""

    d = frappe.new_doc("Comment")
    d.parenttype = parenttype
    d.comment = txt
    d.comment_docname = contact
    d.comment_doctype = "Message"
    d.comment_by_fullname = get_fullname(frappe.session.user)
    d.insert(ignore_permissions=True)

    delete_notification_count_for("Messages")

    if notify and cint(notify):
        if contact == frappe.session.user:
            _notify([user.name for user in get_enabled_system_users()], txt)
        else:
            _notify(contact, txt, subject)
Exemplo n.º 31
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		from frappe.model.db_schema import updatedb
		updatedb(self.name)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		from frappe import conf
		if not self.custom and not (frappe.flags.in_import or frappe.flags.in_test) and conf.get('developer_mode'):
			self.export_doc()
			self.make_controller_template()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)
Exemplo n.º 32
0
def post(txt, contact, parenttype=None, notify=False, subject=None):
	"""post message"""

	d = frappe.new_doc('Communication')
	d.communication_type = 'Notification' if parenttype else 'Chat'
	d.subject = subject
	d.content = txt
	d.reference_doctype = 'User'
	d.reference_name = contact
	d.sender = frappe.session.user
	d.insert(ignore_permissions=True)

	delete_notification_count_for("Messages")

	if notify and cint(notify):
		if contact==frappe.session.user:
			_notify([user.name for user in get_enabled_system_users()], txt)
		else:
			_notify(contact, txt, subject)

	return d
Exemplo n.º 33
0
	def on_update(self):
		"""Update database schema, make controller templates if `custom` is not set and clear cache."""
		from frappe.model.db_schema import updatedb
		updatedb(self.name)

		self.change_modified_of_parent()
		make_module_and_roles(self)

		from frappe import conf
		if not self.custom and not (frappe.flags.in_import or frappe.flags.in_test) and conf.get('developer_mode'):
			self.export_doc()
			self.make_controller_template()

		# update index
		if not self.custom:
			self.run_module_method("on_doctype_update")
			if self.flags.in_insert:
				self.run_module_method("after_doctype_insert")

		delete_notification_count_for(doctype=self.name)
		frappe.clear_cache(doctype=self.name)
Exemplo n.º 34
0
def get_list(arg=None):
	"""get list of messages"""
	frappe.form_dict['limit_start'] = int(frappe.form_dict['limit_start'])
	frappe.form_dict['limit_page_length'] = int(frappe.form_dict['limit_page_length'])
	frappe.form_dict['user'] = frappe.session['user']

	# set all messages as read
	frappe.db.begin()
	frappe.db.sql("""UPDATE `tabCommunication` set seen = 1
		where
			communication_type in ('Chat', 'Notification')
			and reference_doctype = 'User'
			and reference_name = %s""", frappe.session.user)

	delete_notification_count_for("Messages")

	frappe.local.flags.commit = True

	if frappe.form_dict['contact'] == frappe.session['user']:
		# return messages
		return frappe.db.sql("""select * from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and reference_doctype ='User'
				and (owner=%(contact)s
					or reference_name=%(user)s
					or owner=reference_name)
			order by creation desc
			limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1)
	else:
		return frappe.db.sql("""select * from `tabCommunication`
			where
				communication_type in ('Chat', 'Notification')
				and reference_doctype ='User'
				and ((owner=%(contact)s and reference_name=%(user)s)
					or (owner=%(contact)s and reference_name=%(contact)s))
			order by creation desc
			limit %(limit_start)s, %(limit_page_length)s""", frappe.local.form_dict, as_dict=1)
Exemplo n.º 35
0
    def on_update(self):
        """Update database schema, make controller templates if `custom` is not set and clear cache."""
        from frappe.model.db_schema import updatedb
        updatedb(self.name)

        self.change_modified_of_parent()
        make_module_and_roles(self)

        from frappe import conf
        if not (frappe.flags.in_import
                or frappe.flags.in_test) and conf.get('developer_mode') or 0:
            self.export_doc()
            self.make_controller_template()

        # update index
        if not getattr(self, "custom", False):
            from frappe.modules import load_doctype_module
            module = load_doctype_module(self.name, self.module)
            if hasattr(module, "on_doctype_update"):
                module.on_doctype_update()

        delete_notification_count_for(doctype=self.name)
        frappe.clear_cache(doctype=self.name)
Exemplo n.º 36
0
def reset_perms(doctype):
	"""Reset permissions for given doctype."""
	from frappe.desk.notifications import delete_notification_count_for
	delete_notification_count_for(doctype)

	frappe.db.sql("""delete from `tabCustom DocPerm` where parent=%s""", doctype)