Example #1
0
def post_install(rebuild_website=False):
	if rebuild_website:
		render.clear_cache()

	init_singles()
	frappe.db.commit()
	frappe.clear_cache()
Example #2
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 frappe.db.get_value("DocType", reference_doctype, "issingle"):
		return

	try:
		# use sql, so that we do not mess with the timestamp
		frappe.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(frappe.local, 'request', None):
			# missing column and in request, add column and update after commit
			frappe.local._comments = (getattr(frappe.local, "_comments", [])
				+ [(reference_doctype, reference_name, _comments)])
		else:
			raise ImplicitCommitError

	else:
		if not frappe.flags.in_patch:
			reference_doc = frappe.get_doc(reference_doctype, reference_name)
			if getattr(reference_doc, "route", None):
				clear_cache(reference_doc.route)
Example #3
0
def move(name, up_or_down):
	ret = None
	if not frappe.has_permission("Website Route"):
		raise frappe.PermissionError

	sitemap = frappe.get_doc("Website Route", name)
	if up_or_down=="up":
		if sitemap.idx > 0:
			prev = frappe.get_doc("Website Route", {
				"parent_website_route": sitemap.parent_website_route,
				"idx": sitemap.idx - 1
			})
			if prev.name:
				prev.idx = prev.idx + 1
				prev.save()

				sitemap.idx = sitemap.idx - 1
				sitemap.save()
				ret = "ok"

	else:
		nexts = frappe.get_doc("Website Route", {
			"parent_website_route": sitemap.parent_website_route,
			"idx": sitemap.idx + 1
		})
		if nexts.name:
			nexts.idx = nexts.idx - 1
			nexts.save()

			sitemap.idx = sitemap.idx + 1
			sitemap.save()
			ret = "ok"

	clear_cache()
	return ret
Example #4
0
def build_website(verbose=False):
	from frappe.website import render, statics
	frappe.connect()
	render.clear_cache()
	statics.sync(verbose=verbose).start(True)
	frappe.db.commit()
	frappe.destroy()
Example #5
0
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:

	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)'''
	clear_global_cache()

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

	# syncs statics
	render.clear_cache()
	if rebuild_website:
		statics.sync(verbose=verbose).start(True)
	else:
		statics.sync_statics()

	frappe.db.commit()

	clear_notifications()

	frappe.publish_realtime("version-update")
Example #6
0
def invalidate_cache_for(bean, trigger, item_group=None):
	if not item_group:
		item_group = bean.doc.name
	
	for i in get_parent_item_groups(item_group):
		if i.page_name:
			clear_cache(i.page_name)
Example #7
0
def invalidate_cache_for(doc, item_group=None):
	if not item_group:
		item_group = doc.name

	for i in get_parent_item_groups(item_group):
		if i.page_name:
			clear_cache(i.page_name)
Example #8
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 = frappe.get_site_path('touched_tables.json')
	if os.path.exists(touched_tables_file):
		os.remove(touched_tables_file)

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

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

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

		frappe.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 frappe.get_installed_apps():
			for fn in frappe.get_hooks('after_migrate', app_name=app):
				frappe.get_attr(fn)()

		frappe.db.commit()

		clear_notifications()

		frappe.publish_realtime("version-update")
		frappe.flags.in_migrate = False
	finally:
		with open(touched_tables_file, 'w') as f:
			json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4)
		frappe.flags.touched_tables.clear()
Example #9
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 = frappe.db.get_value("Item Group", d.get('name'))
		if item_group_name:
			clear_cache(frappe.db.get_value('Item Group', item_group_name, 'route'))
Example #10
0
	def update_comments_in_parent(self, _comments):
		# use sql, so that we do not mess with the timestamp
		frappe.db.sql("""update `tab%s` set `_comments`=%s where name=%s""" % (self.comment_doctype,
			"%s", "%s"), (json.dumps(_comments), self.comment_docname))

		comment_doc = frappe.get_doc(self.comment_doctype, self.comment_docname)
		if getattr(comment_doc, "get_route", None):
			clear_cache(comment_doc.get_route())
Example #11
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):
		d = frappe.get_doc("Item Group", d.name)
		if d.route:
			clear_cache(d.route)
Example #12
0
def add_comment(args=None):
    """
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

    if not args:
        args = frappe.local.form_dict
    args["doctype"] = "Comment"

    page_name = args.get("page_name")
    if "page_name" in args:
        del args["page_name"]
    if "cmd" in args:
        del args["cmd"]

    comment = frappe.get_doc(args)
    comment.ignore_permissions = True
    comment.insert()

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

    # notify commentors
    commentors = [
        d[0]
        for d in frappe.db.sql(
            """select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""",
            (comment.comment_doctype, comment.comment_docname),
        )
    ]

    owner = frappe.db.get_value(comment.comment_doctype, comment.comment_docname, "owner")
    recipients = commentors if owner == "Administrator" else list(set(commentors + [owner]))

    from frappe.utils.email_lib.bulk import send

    send(
        recipients=recipients,
        doctype="Comment",
        email_field="comment_by",
        subject=_("New comment on {0} {1}").format(comment.comment_doctype, comment.comment_docname),
        message=_("{0} by {1}").format(markdown2.markdown(args.get("comment")), comment.comment_by_fullname),
        ref_doctype=comment.comment_doctype,
        ref_docname=comment.comment_docname,
    )

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

    return template.render({"comment": comment.as_dict()})
Example #13
0
	def on_update(self):
		# make js and css
		# clear web cache (for menus!)

		from frappe.website.render import clear_cache
		clear_cache()

		# clears role based home pages
		frappe.clear_cache()
Example #14
0
	def after_rename(self, olddn, newdn, merge):
		super(Item, self).after_rename(olddn, newdn, merge)
		if self.page_name:
			invalidate_cache_for_item(self)
			clear_cache(self.page_name)

		frappe.db.set_value("Item", newdn, "item_code", newdn)
		if merge:
			self.set_last_purchase_rate(newdn)
			self.recalculate_bin_qty(newdn)
Example #15
0
def after_install(rebuild_website=False):
	version = frappe.utils.cint(frappe.__version__.split(".", 1)[0])
	if version >= 5:
		return
	if rebuild_website:
		render.clear_cache()
		statics.sync().start()

	init_singles()
	frappe.db.commit()
	frappe.clear_cache()
Example #16
0
	def update_comments_in_parent(self, _comments):
		# use sql, so that we do not mess with the timestamp
		frappe.db.sql("""update `tab%s` set `_comments`=%s where name=%s""" % (self.comment_doctype,
			"%s", "%s"), (json.dumps(_comments), self.comment_docname))

		# clear parent cache if route exists:
		route = frappe.db.get_value("Website Route", {"ref_doctype": self.comment_doctype,
			"docname": self.comment_docname})

		if route:
			clear_cache(route)
def build_website(context):
	"Sync statics and clear cache"
	from frappe.website import render, statics
	for site in context.sites:
		try:
			frappe.init(site=site)
			frappe.connect()
			render.clear_cache()
			statics.sync(verbose=context.verbose).start(True)
			frappe.db.commit()
		finally:
			frappe.destroy()
Example #18
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

	if not args:
		args = frappe.local.form_dict
	args['doctype'] = "Comment"

	page_name = args.get("page_name")
	if "page_name" in args:
		del args["page_name"]
	if "cmd" in args:
		del args["cmd"]

	comment = frappe.get_doc(args)
	comment.comment_type = "Comment"
	comment.flags.ignore_permissions = True
	comment.insert()

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

	# notify commentors
	commentors = [d[0] for d in frappe.db.sql("""select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""", (comment.comment_doctype, comment.comment_docname))]

	owner = frappe.db.get_value(comment.comment_doctype, comment.comment_docname, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

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

	from frappe.email.bulk import send

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

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

	return template.render({"comment": comment.as_dict()})
Example #19
0
def add_to_installed_apps(app_name, rebuild_website=True):
	installed_apps = frappe.get_installed_apps()
	if not app_name in installed_apps:
		installed_apps.append(app_name)
		frappe.db.set_global("installed_apps", json.dumps(installed_apps))
		frappe.db.commit()

		if rebuild_website:
			render.clear_cache()
			statics.sync().start()

		frappe.db.commit()

		frappe.clear_cache()
Example #20
0
	def update_comments_in_parent(self, _comments):
		"""Updates `_comments` property in parent Document with given dict.

		:param _comments: Dict of comments."""
		if not self.comment_doctype or frappe.db.get_value("DocType", self.comment_doctype, "issingle"):
			return

		# use sql, so that we do not mess with the timestamp
		frappe.db.sql("""update `tab%s` set `_comments`=%s where name=%s""" % (self.comment_doctype,
			"%s", "%s"), (json.dumps(_comments), self.comment_docname))

		comment_doc = frappe.get_doc(self.comment_doctype, self.comment_docname)
		if getattr(comment_doc, "get_route", None):
			clear_cache(comment_doc.get_route())
Example #21
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'reference_doctype': '',
			'reference_name': '',
			'route': '',
		}
	"""

	if not args:
		args = frappe.local.form_dict

	route = args.get("route")

	doc = frappe.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 frappe.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 = frappe.db.get_value(doc.doctype, doc.name, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

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

	from frappe.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 = frappe.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
Example #22
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
	'''
	frappe.flags.in_migrate = True
	clear_global_cache()

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

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

	frappe.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 frappe.get_installed_apps():
		for fn in frappe.get_hooks('after_migrate', app_name=app):
			frappe.get_attr(fn)()

	frappe.db.commit()

	clear_notifications()

	frappe.publish_realtime("version-update")
	frappe.flags.in_migrate = False
Example #23
0
def update_parent(name, new_parent):
	if not frappe.has_permission("Website Route"):
		raise frappe.PermissionError

	sitemap = frappe.get_doc("Website Route", name)

	if sitemap.ref_doctype:
		generator = frappe.get_doc(sitemap.ref_doctype, sitemap.docname)
		if not generator.meta.get_field("parent_website_route"):
			frappe.throw(_("Not allowed to move"))
		generator.parent_website_route = new_parent
		generator.save()
	else:
		frappe.msgprint(_("Template Pages cannot be moved"))

	clear_cache()
	def update_routes_of_descendants(self, old_route = None):
		if not self.is_new() and self.meta.get_field("parent_website_route"):
			if not old_route:
				old_route = frappe.get_doc(self.doctype, self.name).get_route()

			if old_route and old_route != self.get_route():
				# clear cache of old routes
				old_routes = frappe.get_all(self.doctype, filters={"parent_website_route": ("like", old_route + "%")})

				if old_routes:
					for like_old_route in old_routes:
						clear_cache(frappe.get_doc(self.doctype, like_old_route.name).get_route())

					frappe.db.sql("""update `tab{0}` set
						parent_website_route = replace(parent_website_route, %s, %s),
						modified = %s,
						modified_by = %s
						where parent_website_route like %s""".format(self.doctype),
						(old_route, self.get_route(), now(), frappe.session.user, old_route + "%"))
Example #25
0
	def after_rename(self, old_name, new_name, merge):
		if self.route:
			invalidate_cache_for_item(self)
			clear_cache(self.route)

		frappe.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 frappe.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 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)

					frappe.db.set_value(dt, d.name, "item_wise_tax_detail",
						json.dumps(item_wise_tax_detail), update_modified=False)
Example #26
0
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:

	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)'''
	frappe.flags.in_migrate = True
	clear_global_cache()

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

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

	# syncs statics
	render.clear_cache()

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

	frappe.db.commit()

	if not frappe.conf.get('global_help_setup'):
		# sync help if not set as global
		frappe.utils.help.sync()

	clear_notifications()

	frappe.publish_realtime("version-update")
	frappe.flags.in_migrate = False
	def clear_cache(self):
		clear_cache(self.get_route())
Example #28
0
	def on_update(self):
		from frappe.website.render import clear_cache
		clear_cache("about")
Example #29
0
	def on_update(self):
		"""clear cache"""
		frappe.clear_cache(user = '******')

		from frappe.website.render import clear_cache
		clear_cache()
Example #30
0
            (json.dumps(_comments), reference_name))

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

    else:
        if not frappe.flags.in_patch:
            reference_doc = frappe.get_doc(reference_doctype, reference_name)
            if getattr(reference_doc, "route", None):
                clear_cache(reference_doc.route)


def add_info_comment(**kwargs):
    kwargs.update({
        "doctype": "Communication",
        "communication_type": "Comment",
        "comment_type": "Info",
        "status": "Closed"
    })
    return frappe.get_doc(kwargs).insert(ignore_permissions=True)


def update_comments_in_parent_after_request():
    """update _comments in parent if _comments column is missing"""
    if hasattr(frappe.local, "_comments"):
Example #31
0
 def clear_cache(self, name=None):
     from frappe.website.render import clear_cache
     clear_cache(name or self.name)
     if self.parent_website_route:
         clear_cache(self.parent_website_route)
Example #32
0
 def after_rename(self, olddn, newdn, merge):
     if getattr(self, "_local"):
         self.update_routes_of_descendants(self._local)
     clear_cache(self.get_route())
Example #33
0
def migrate(verbose=True, rebuild_website=False, skip_failing=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 = frappe.get_site_path('touched_tables.json')
    if os.path.exists(touched_tables_file):
        os.remove(touched_tables_file)

    try:
        frappe.flags.touched_tables = set()
        frappe.flags.in_migrate = True

        clear_global_cache()

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

        # run patches
        frappe.modules.patch_handler.run_all(skip_failing)

        # sync
        frappe.model.sync.sync_all(verbose=verbose)
        frappe.translate.clear_cache()
        sync_jobs()
        sync_fixtures()
        sync_customizations()
        sync_languages()

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

        # syncs statics
        render.clear_cache()

        # add static pages to global search
        global_search.update_global_search_for_all_web_pages()

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

        frappe.db.commit()

        clear_notifications()

        frappe.publish_realtime("version-update")
        frappe.flags.in_migrate = False
    finally:
        with open(touched_tables_file, 'w') as f:
            json.dump(list(frappe.flags.touched_tables),
                      f,
                      sort_keys=True,
                      indent=4)
        frappe.flags.touched_tables.clear()
Example #34
0
def add_comment(comment, comment_email, comment_by, reference_doctype,
                reference_name, route):
    doc = frappe.get_doc(reference_doctype, reference_name)

    if not comment.strip():
        frappe.msgprint(_('The comment cannot be empty'))
        return False

    url_regex = re.compile(
        r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+",
        re.IGNORECASE)
    email_regex = re.compile(
        r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", re.IGNORECASE)

    if url_regex.search(comment) or email_regex.search(comment):
        frappe.msgprint(_('Comments cannot have links or email addresses'))
        return False

    if not comment_email == frappe.session.user:
        comment_email = frappe.session.user

    comments_count = frappe.db.count(
        "Comment", {
            "comment_type": "Comment",
            "comment_email": frappe.session.user,
            "creation": (">", add_to_date(now(), hours=-1))
        })

    if comments_count > 20:
        frappe.msgprint(
            _('Hourly comment limit reached for: {0}').format(
                frappe.bold(frappe.session.user)))
        return False

    comment = doc.add_comment(text=comment,
                              comment_email=comment_email,
                              comment_by=comment_by)

    comment.db_set('published', 1)

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

    content = (
        comment.content +
        "<p><a href='{0}/app/Form/Comment/{1}' style='font-size: 80%'>{2}</a></p>"
        .format(frappe.utils.get_request_site_address(), comment.name,
                _("View Comment")))

    # notify creator
    frappe.sendmail(recipients=frappe.db.get_value('User', doc.owner, 'email')
                    or doc.owner,
                    subject=_('New Comment on {0}: {1}').format(
                        doc.doctype, doc.name),
                    message=content,
                    reference_doctype=doc.doctype,
                    reference_name=doc.name)

    # revert with template if all clear (no backlinks)
    template = frappe.get_template("templates/includes/comments/comment.html")
    return template.render({"comment": comment.as_dict()})
Example #35
0
 def on_update(self):
     super(BlogPost, self).on_update()
     clear_cache("writers")
Example #36
0
	def on_update(self):
		from frappe.website.render import clear_cache
		clear_cache("blog")
		clear_cache("writers")
Example #37
0
 def on_update(self):
     clear_cache(self.get_route())
     if getattr(self, "save_versions", False):
         frappe.add_version(self)
Example #38
0
	def clear_cache(self):
		super(WebsiteGenerator, self).clear_cache()
		clear_cache(self.route)
Example #39
0
    def on_update(self):
        # make js and css
        # clear web cache (for menus!)

        from frappe.website.render import clear_cache
        clear_cache()
Example #40
0
 def on_update(self):
     from frappe.website.render import clear_cache
     clear_cache("contact")
Example #41
0
 def on_update(self):
     from frappe.website.render import clear_cache
     clear_cache("landingrequest")
Example #42
0
 def on_update(self):
     clear_cache("writers")
Example #43
0
 def on_update(self):
     # a slide show can be in use and any change in it should get reflected
     from frappe.website.render import clear_cache
     clear_cache()
Example #44
0
def clear_blog_cache():
    for blog in frappe.db.sql_list("""select page_name from
		`tabBlog Post` where ifnull(published,0)=1"""):
        clear_cache(blog)

    clear_cache("writers")
Example #45
0
 def before_rename(self, oldname, name, merge):
     self._local = self.get_route()
     clear_cache(self.get_route())
Example #46
0
 def on_update(self):
     WebsiteGenerator.on_update(self)
     clear_cache("writers")
Example #47
0
            (json.dumps(_comments), reference_name))

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

        else:
            raise

    else:
        reference_doc = frappe.get_doc(reference_doctype, reference_name)
        if getattr(reference_doc, "get_route", None):
            clear_cache(reference_doc.get_route())


def add_info_comment(**kwargs):
    kwargs.update({
        "doctype": "Communication",
        "communication_type": "Comment",
        "comment_type": "Info"
    })
    return frappe.get_doc(kwargs).insert(ignore_permissions=True)


def update_comments_in_parent_after_request():
    """update _comments in parent if _comments column is missing"""
    if hasattr(frappe.local, "_comments"):
        for (reference_doctype, reference_name,
Example #48
0
def add_comment(args=None):
    """
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'reference_doctype': '',
			'reference_name': '',
			'route': '',
		}
	"""

    if not args:
        args = frappe.local.form_dict

    route = args.get("route")

    doc = frappe.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 frappe.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 = frappe.db.get_value(doc.doctype, doc.name, "owner")
    recipients = list(
        set(commentors if owner == "Administrator" else (commentors +
                                                         [owner])))

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

    from frappe.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 = frappe.get_template("templates/includes/comments/comment.html")

    return template.render({"comment": comment.as_dict()})
Example #49
0
def add_comment(args=None):
    """
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

    if not args:
        args = frappe.local.form_dict
    args['doctype'] = "Comment"

    page_name = args.get("page_name")
    if "page_name" in args:
        del args["page_name"]
    if "cmd" in args:
        del args["cmd"]

    comment = frappe.get_doc(args)
    comment.comment_type = "Comment"
    comment.flags.ignore_permissions = True
    comment.insert()

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

    # notify commentors
    commentors = [
        d[0] for d in frappe.db.sql(
            """select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		unsubscribed=0""", (comment.comment_doctype, comment.comment_docname))
    ]

    owner = frappe.db.get_value(comment.comment_doctype,
                                comment.comment_docname, "owner")
    recipients = list(
        set(commentors if owner == "Administrator" else (commentors +
                                                         [owner])))

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

    from frappe.email.bulk import send

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

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

    return template.render({"comment": comment.as_dict()})
Example #50
0
 def on_update(self):
     from frappe.website.render import clear_cache
     clear_cache("project-progress")
Example #51
0
 def on_update(self):
     from frappe.website.render import clear_cache
     clear_cache("media")
Example #52
0
 def clear_cache(self):
     clear_cache(self.route)
	def on_update(self):
		clear_cache(self.get_route())
		if getattr(self, "save_versions", False):
			frappe.add_version(self)
Example #54
0
 def on_update(self):
     self.update_category()
     clear_cache()
Example #55
0
def migrate(verbose=True, skip_failing=False, skip_search_index=False):
    """Migrate all apps to the current version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync dashboards
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	"""

    service_status = check_connection(redis_services=["redis_cache"])
    if False in service_status.values():
        for service in service_status:
            if not service_status.get(service, True):
                print("{} service is not running.".format(service))
        print("""Cannot run bench migrate without the services running.
If you are running bench in development mode, make sure that bench is running:

$ bench start

Otherwise, check the server logs and ensure that all the required services are running."""
              )
        sys.exit(1)

    touched_tables_file = frappe.get_site_path("touched_tables.json")
    if os.path.exists(touched_tables_file):
        os.remove(touched_tables_file)

    try:
        add_column(doctype="DocType",
                   column_name="migration_hash",
                   fieldtype="Data")
        frappe.flags.touched_tables = set()
        frappe.flags.in_migrate = True

        clear_global_cache()

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

        # run patches
        frappe.modules.patch_handler.run_all(skip_failing)

        # sync
        frappe.model.sync.sync_all(verbose=verbose)
        frappe.translate.clear_cache()
        sync_jobs()
        sync_fixtures()
        sync_dashboards()
        sync_customizations()
        sync_languages()

        frappe.get_doc("Portal Settings", "Portal Settings").sync_menu()

        # syncs statics
        render.clear_cache()

        # updating installed applications data
        frappe.get_single("Installed Applications").update_versions()

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

        # build web_routes index
        if not skip_search_index:
            # Run this last as it updates the current session
            print("Building search index for {}".format(frappe.local.site))
            build_index_for_all_routes()

        frappe.db.commit()

        clear_notifications()

        frappe.publish_realtime("version-update")
        frappe.flags.in_migrate = False
    finally:
        with open(touched_tables_file, "w") as f:
            json.dump(list(frappe.flags.touched_tables),
                      f,
                      sort_keys=True,
                      indent=4)
        frappe.flags.touched_tables.clear()
Example #56
0
def clear_cache():
    clear_website_cache()

    from frappe.website.render import clear_cache
    clear_cache()
Example #57
0
 def clear_cache(self):
     clear_cache(self.get_route())
Example #58
0
	def on_update(self):
		from frappe.website.render import clear_cache
		clear_cache("aboutus")
Example #59
0
	def on_update(self):
		clear_cache()
Example #60
0
 def on_trash(self):
     clear_cache(self.get_route())