Esempio n. 1
0
def update_comments_in_parent(reference_doctype, reference_name, _comments):
    """Updates `_comments` property in parent Document with given dict.

	:param _comments: Dict of comments."""
    if not reference_doctype or dataent.db.get_value(
            "DocType", reference_doctype, "issingle"):
        return

    try:
        # use sql, so that we do not mess with the timestamp
        dataent.db.sql(
            """update `tab%s` set `_comments`=%s where name=%s""" %
            (reference_doctype, "%s", "%s"),
            (json.dumps(_comments), reference_name))

    except Exception as e:
        if e.args[0] == 1054 and getattr(dataent.local, 'request', None):
            # missing column and in request, add column and update after commit
            dataent.local._comments = (
                getattr(dataent.local, "_comments", []) +
                [(reference_doctype, reference_name, _comments)])
        else:
            raise ImplicitCommitError

    else:
        if not dataent.flags.in_patch:
            reference_doc = dataent.get_doc(reference_doctype, reference_name)
            if getattr(reference_doc, "route", None):
                clear_cache(reference_doc.route)
Esempio n. 2
0
    def after_rename(self, old_name, new_name, merge):
        if self.route:
            invalidate_cache_for_item(self)
            clear_cache(self.route)

        dataent.db.set_value("Item", new_name, "item_code", new_name)

        if merge:
            self.set_last_purchase_rate(new_name)
            self.recalculate_bin_qty(new_name)

        for dt in ("Sales Taxes and Charges", "Purchase Taxes and Charges"):
            for d in dataent.db.sql(
                    """select name, item_wise_tax_detail from `tab{0}`
					where ifnull(item_wise_tax_detail, '') != ''""".format(dt),
                    as_dict=1):

                item_wise_tax_detail = json.loads(d.item_wise_tax_detail)
                if isinstance(item_wise_tax_detail,
                              dict) and old_name in item_wise_tax_detail:
                    item_wise_tax_detail[new_name] = item_wise_tax_detail[
                        old_name]
                    item_wise_tax_detail.pop(old_name)

                    dataent.db.set_value(dt,
                                         d.name,
                                         "item_wise_tax_detail",
                                         json.dumps(item_wise_tax_detail),
                                         update_modified=False)
Esempio n. 3
0
def post_install(rebuild_website=False):
    if rebuild_website:
        render.clear_cache()

    init_singles()
    dataent.db.commit()
    dataent.clear_cache()
Esempio n. 4
0
def invalidate_cache_for(doc, item_group=None):
    if not item_group:
        item_group = doc.name

    for d in get_parent_item_groups(item_group):
        item_group_name = dataent.db.get_value("Item Group", d.get('name'))
        if item_group_name:
            clear_cache(
                dataent.db.get_value('Item Group', item_group_name, 'route'))
Esempio n. 5
0
	def clear_cache(self):
		# make js and css
		# clear web cache (for menus!)
		dataent.clear_cache(user='******')

		from dataent.website.render import clear_cache
		clear_cache()

		# clears role based home pages
		dataent.clear_cache()
Esempio n. 6
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'reference_doctype': '',
			'reference_name': '',
			'route': '',
		}
	"""

	if not args:
		args = dataent.local.form_dict

	route = args.get("route")

	doc = dataent.get_doc(args["reference_doctype"], args["reference_name"])
	comment = doc.add_comment("Comment", args["comment"], comment_by=args["comment_by"])
	comment.flags.ignore_permissions = True
	comment.sender_full_name = args["comment_by_fullname"]
	comment.save()

	# since comments are embedded in the page, clear the web cache
	clear_cache(route)

	# notify commentors
	commentors = [d[0] for d in dataent.db.sql("""select sender from `tabCommunication`
		where
			communication_type = 'Comment' and comment_type = 'Comment'
			and reference_doctype=%s
			and reference_name=%s""", (comment.reference_doctype, comment.reference_name))]

	owner = dataent.db.get_value(doc.doctype, doc.name, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

	message = _("{0} by {1}").format(dataent.utils.markdown(args.get("comment")), comment.sender_full_name)
	message += "<p><a href='{0}/{1}' style='font-size: 80%'>{2}</a></p>".format(dataent.utils.get_request_site_address(),
		route, _("View it in your browser"))

	from dataent.email.queue import send

	send(recipients=recipients,
		subject = _("New comment on {0} {1}").format(doc.doctype, doc.name),
		message = message,
		reference_doctype=doc.doctype, reference_name=doc.name)

	template = dataent.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
Esempio n. 7
0
	def on_update(self):
		from dataent.website.render import clear_cache
		clear_cache("blog")
		clear_cache("writers")
Esempio n. 8
0
 def on_update(self):
     from dataent.website.render import clear_cache
     clear_cache("about")
Esempio n. 9
0
	def on_update(self):
		# a slide show can be in use and any change in it should get reflected
		from dataent.website.render import clear_cache
		clear_cache()
Esempio n. 10
0
	def on_update(self):
		clear_cache()
Esempio n. 11
0
def migrate(verbose=True, rebuild_website=False):
    '''Migrate all apps to the latest version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	'''

    touched_tables_file = dataent.get_site_path('touched_tables.json')
    if os.path.exists(touched_tables_file):
        os.remove(touched_tables_file)

    try:
        dataent.flags.touched_tables = set()
        dataent.flags.in_migrate = True
        clear_global_cache()

        #run before_migrate hooks
        for app in dataent.get_installed_apps():
            for fn in dataent.get_hooks('before_migrate', app_name=app):
                dataent.get_attr(fn)()

        # run patches
        dataent.modules.patch_handler.run_all()
        # sync
        dataent.model.sync.sync_all(verbose=verbose)
        dataent.translate.clear_cache()
        sync_fixtures()
        sync_customizations()
        sync_desktop_icons()
        sync_languages()

        dataent.get_doc('Portal Settings', 'Portal Settings').sync_menu()

        # syncs statics
        render.clear_cache()

        # add static pages to global search
        router.sync_global_search()

        #run after_migrate hooks
        for app in dataent.get_installed_apps():
            for fn in dataent.get_hooks('after_migrate', app_name=app):
                dataent.get_attr(fn)()

        dataent.db.commit()

        clear_notifications()

        dataent.publish_realtime("version-update")
        dataent.flags.in_migrate = False
    finally:
        with open(touched_tables_file, 'w') as f:
            json.dump(list(dataent.flags.touched_tables),
                      f,
                      sort_keys=True,
                      indent=4)
        dataent.flags.touched_tables.clear()
Esempio n. 12
0
 def on_update(self):
     self.update_category()
     clear_cache()
Esempio n. 13
0
def clear_cache():
    clear_website_cache()

    from dataent.website.render import clear_cache
    clear_cache()
Esempio n. 14
0
 def clear_cache(self):
     super(WebsiteGenerator, self).clear_cache()
     clear_cache(self.route)
Esempio n. 15
0
	def on_update(self):
		"""clear cache"""
		dataent.clear_cache(user = '******')

		from dataent.website.render import clear_cache
		clear_cache()
Esempio n. 16
0
 def on_update(self):
     clear_cache("writers")
Esempio n. 17
0
def clear_blog_cache():
    for blog in dataent.db.sql_list("""select route from
		`tabBlog Post` where ifnull(published,0)=1"""):
        clear_cache(blog)

    clear_cache("writers")