예제 #1
0
    def test_insert_child_table(self):
        frappe.db.sql('delete from tabEvent')
        phrases = [
            'Hydrus is a small constellation in the deep southern sky. ',
            'It was first depicted on a celestial atlas by Johann Bayer in his 1603 Uranometria. ',
            'The French explorer and astronomer Nicolas Louis de Lacaille charted the brighter stars and gave their Bayer designations in 1756. ',
            'Its name means "male water snake", as opposed to Hydra, a much larger constellation that represents a female water snake. ',
            'It remains below the horizon for most Northern Hemisphere observers.',
            'The brightest star is the 2.8-magnitude Beta Hydri, also the closest reasonably bright star to the south celestial pole. ',
            'Pulsating between magnitude 3.26 and 3.33, Gamma Hydri is a variable red giant some 60 times the diameter of our Sun. ',
            'Lying near it is VW Hydri, one of the brightest dwarf novae in the heavens. ',
            'Four star systems have been found to have exoplanets to date, most notably HD 10180, which could bear up to nine planetary companions.'
        ]

        for text in phrases:
            doc = frappe.get_doc({
                'doctype': 'Event',
                'subject': text,
                "event_type": "Public",
                'starts_on': frappe.utils.now_datetime()
            })
            doc.insert()

        global_search.sync_global_search()
        frappe.db.commit()
예제 #2
0
 def commit(self):
     """Commit current transaction. Calls SQL `COMMIT`."""
     self.sql("commit")
     frappe.local.rollback_observers = []
     self.flush_realtime_log()
     if frappe.flags.update_global_search:
         sync_global_search()
예제 #3
0
파일: utils.py 프로젝트: yered1/frappe
def rebuild_global_search(context, static_pages=False):
	'''Setup help table in the current site (called after migrate)'''
	from frappe.utils.global_search import (get_doctypes_with_global_search, rebuild_for_doctype,
		get_routes_to_index, add_route_to_global_search, sync_global_search)

	for site in context.sites:
		try:
			frappe.init(site)
			frappe.connect()

			if static_pages:
				routes = get_routes_to_index()
				for i, route in enumerate(routes):
					add_route_to_global_search(route)
					frappe.local.request = None
					update_progress_bar('Rebuilding Global Search', i, len(routes))
				sync_global_search()
			else:
				doctypes = get_doctypes_with_global_search()
				for i, doctype in enumerate(doctypes):
					rebuild_for_doctype(doctype)
					update_progress_bar('Rebuilding Global Search', i, len(doctypes))

		finally:
			frappe.destroy()
예제 #4
0
	def test_web_page_index(self):
		global_search.update_global_search_for_all_web_pages()
		global_search.sync_global_search()
		frappe.db.commit()
		results = global_search.web_search('unsubscribe')
		self.assertTrue('Unsubscribe' in results[0].content)
		results = global_search.web_search(text='unsubscribe',
					scope="manufacturing\" UNION ALL SELECT 1,2,3,4,doctype from __global_search")
		self.assertTrue(results == [])
예제 #5
0
	def enqueue_global_search(self):
		if frappe.flags.update_global_search:
			try:
				frappe.enqueue('frappe.utils.global_search.sync_global_search',
					now=frappe.flags.in_test or frappe.flags.in_install or frappe.flags.in_migrate,
					flags=frappe.flags.update_global_search)
			except redis.exceptions.ConnectionError:
				sync_global_search()

			frappe.flags.update_global_search = []
예제 #6
0
	def test_update_doc(self):
		self.insert_test_events()
		test_subject = "testing global search"
		event = frappe.get_doc("Event", frappe.get_all("Event")[0].name)
		event.subject = test_subject
		event.save()
		frappe.db.commit()
		global_search.sync_global_search()
		results = global_search.search("testing global search")

		self.assertTrue("testing global search" in results[0].content)
예제 #7
0
	def test_update_doc(self):
		self.insert_test_events()
		test_subject = 'testing global search'
		event = frappe.get_doc('Event', frappe.get_all('Event')[0].name)
		event.subject = test_subject
		event.save()
		frappe.db.commit()
		global_search.sync_global_search()
		results = global_search.search('testing global search')

		self.assertTrue('testing global search' in results[0].content)
예제 #8
0
    def test_update_doc(self):
        self.insert_test_events()
        test_subject = 'testing global search'
        event = frappe.get_doc('Event', frappe.get_all('Event')[0].name)
        event.subject = test_subject
        event.save()
        frappe.db.commit()
        global_search.sync_global_search()
        results = global_search.search('testing global search')

        self.assertTrue('testing global search' in results[0].content)
예제 #9
0
    def test_delete_doc(self):
        self.insert_test_events()

        event_name = frappe.get_all('Event')[0].name
        event = frappe.get_doc('Event', event_name)
        test_subject = event.subject
        results = global_search.search(test_subject)
        self.assertEqual(len(results), 1)

        frappe.delete_doc('Event', event_name)
        global_search.sync_global_search()

        results = global_search.search(test_subject)
        self.assertEqual(len(results), 0)
예제 #10
0
	def test_delete_doc(self):
		self.insert_test_events()

		event_name = frappe.get_all('Event')[0].name
		event = frappe.get_doc('Event', event_name)
		test_subject = event.subject
		results = global_search.search(test_subject)
		self.assertEqual(len(results), 1)

		frappe.delete_doc('Event', event_name)
		global_search.sync_global_search()

		results = global_search.search(test_subject)
		self.assertEqual(len(results), 0)
예제 #11
0
def sync_global_search():
    '''Sync page content in global search'''
    from frappe.website.render import render_page
    from frappe.utils.global_search import sync_global_search
    from bs4 import BeautifulSoup

    if frappe.flags.update_global_search:
        sync_global_search()
    frappe.flags.update_global_search = []
    frappe.session.user = '******'
    frappe.local.no_cache = True

    frappe.db.sql(
        'delete from __global_search where doctype="Static Web Page"')

    for app in frappe.get_installed_apps(frappe_last=True):
        app_path = frappe.get_app_path(app)

        folders = frappe.local.flags.web_pages_folders or ('www',
                                                           'templates/pages')

        for start in folders:
            for basepath, folders, files in os.walk(
                    os.path.join(app_path, start)):
                for f in files:
                    if f.endswith('.html') or f.endswith('.md'):
                        path = os.path.join(basepath, f.rsplit('.', 1)[0])
                        try:
                            content = render_page(path)
                            soup = BeautifulSoup(content, 'html.parser')
                            text = ''
                            route = os.path.relpath(
                                path, os.path.join(app_path, start))
                            for div in soup.findAll("div",
                                                    {'class': 'page-content'}):
                                text += div.text

                            frappe.flags.update_global_search.append(
                                dict(doctype='Static Web Page',
                                     name=route,
                                     content=frappe.unicode(text),
                                     published=1,
                                     title=soup.title.string,
                                     route=route))

                        except Exception:
                            pass

        sync_global_search()
예제 #12
0
	def insert_test_events(self):
		frappe.db.sql("DELETE FROM `tabEvent`")
		phrases = [
			'"The Sixth Extinction II: Amor Fati" is the second episode of the seventh season of the American science fiction.',
			"After Mulder awakens from his coma, he realizes his duty to prevent alien colonization. ",
			"Carter explored themes of extraterrestrial involvement in ancient mass extinctions in this episode, the third in a trilogy.",
		]

		for text in phrases:
			frappe.get_doc(
				dict(doctype="Event", subject=text, repeat_on="Monthly", starts_on=frappe.utils.now_datetime())
			).insert()

		global_search.sync_global_search()
		frappe.db.commit()
예제 #13
0
	def insert_test_events(self):
		frappe.db.sql('delete from tabEvent')
		phrases = ['"The Sixth Extinction II: Amor Fati" is the second episode of the seventh season of the American science fiction.',
		'After Mulder awakens from his coma, he realizes his duty to prevent alien colonization. ',
		'Carter explored themes of extraterrestrial involvement in ancient mass extinctions in this episode, the third in a trilogy.']

		for text in phrases:
			frappe.get_doc(dict(
				doctype='Event',
				subject=text,
				repeat_on='Every Month',
				starts_on=frappe.utils.now_datetime())).insert()

		global_search.sync_global_search()
		frappe.db.commit()
예제 #14
0
    def test_delete_doc(self):
        self.insert_test_events()

        event_name = frappe.get_all('Event')[0].name
        event = frappe.get_doc('Event', event_name)
        test_subject = event.subject
        results = global_search.search(test_subject)
        self.assertTrue(any(r["name"] == event_name for r in results),
                        msg="Failed to search document by exact name")

        frappe.delete_doc('Event', event_name)
        global_search.sync_global_search()

        results = global_search.search(test_subject)
        self.assertTrue(all(r["name"] != event_name for r in results),
                        msg="Deleted documents appearing in global search.")
예제 #15
0
def sync_global_search():
	'''Sync page content in global search'''
	from frappe.website.render import render_page
	from frappe.utils.global_search import sync_global_search
	from bs4 import BeautifulSoup

	if frappe.flags.update_global_search:
		sync_global_search()
	frappe.flags.update_global_search = []
	frappe.session.user = '******'
	frappe.local.no_cache = True

	frappe.db.sql('delete from __global_search where doctype="Static Web Page"')

	for app in frappe.get_installed_apps(frappe_last=True):
		app_path = frappe.get_app_path(app)

		folders = get_start_folders()

		for start in folders:
			for basepath, folders, files in os.walk(os.path.join(app_path, start)):
				for f in files:
					if f.endswith('.html') or f.endswith('.md'):
						path = os.path.join(basepath, f.rsplit('.', 1)[0])
						try:
							content = render_page(path)
							soup = BeautifulSoup(content, 'html.parser')
							text = ''
							route = os.path.relpath(path, os.path.join(app_path, start))
							for div in soup.findAll("div", {'class':'page-content'}):
								text += div.text

							frappe.flags.update_global_search.append(
								dict(doctype='Static Web Page',
									name=route,
									content=text_type(text),
									published=1,
									title=text_type(soup.title.string),
									route=route))

						except Exception:
							pass

		sync_global_search()
예제 #16
0
    def insert_test_events(self):
        frappe.db.sql('DELETE FROM `tabEvent`')
        phrases = [
            '"The Sixth Extinction II: Amor Fati" is the second episode of the seventh season of the American science fiction.',
            'After Mulder awakens from his coma, he realizes his duty to prevent alien colonization. ',
            'Carter explored themes of extraterrestrial involvement in ancient mass extinctions in this episode, the third in a trilogy.'
        ]

        for text in phrases:
            frappe.get_doc(
                dict(doctype='Event',
                     subject=text,
                     repeat_this_event=1,
                     rrule='RRULE:FREQ=MONTHLY;COUNT=30;INTERVAL=1;WKST=MO',
                     event_type="Public",
                     starts_on=frappe.utils.now_datetime())).insert()

        global_search.sync_global_search()
        frappe.db.commit()
예제 #17
0
	def test_insert_child_table(self):
		frappe.db.sql('delete from tabEvent')
		phrases = ['Hydrus is a small constellation in the deep southern sky. ',
		'It was first depicted on a celestial atlas by Johann Bayer in his 1603 Uranometria. ',
		'The French explorer and astronomer Nicolas Louis de Lacaille charted the brighter stars and gave their Bayer designations in 1756. ',
		'Its name means "male water snake", as opposed to Hydra, a much larger constellation that represents a female water snake. ',
		'It remains below the horizon for most Northern Hemisphere observers.',
		'The brightest star is the 2.8-magnitude Beta Hydri, also the closest reasonably bright star to the south celestial pole. ',
		'Pulsating between magnitude 3.26 and 3.33, Gamma Hydri is a variable red giant some 60 times the diameter of our Sun. ',
		'Lying near it is VW Hydri, one of the brightest dwarf novae in the heavens. ',
		'Four star systems have been found to have exoplanets to date, most notably HD 10180, which could bear up to nine planetary companions.']

		for text in phrases:
			doc = frappe.get_doc({
				'doctype':'Event',
				'subject': text,
				'starts_on': frappe.utils.now_datetime()
			})
			doc.insert()

		global_search.sync_global_search()
		frappe.db.commit()
	def commit(self):
		"""Commit current transaction. Calls SQL `COMMIT`."""
		self.sql("commit")
		frappe.local.rollback_observers = []
		self.flush_realtime_log()
		self.enqueue_global_search()
		flush_local_link_count()

	def enqueue_global_search(self):
		if frappe.flags.update_global_search:
			try:
				frappe.enqueue('frappe.utils.global_search.sync_global_search',
					now=frappe.flags.in_test or frappe.flags.in_install or frappe.flags.in_migrate,
					flags=frappe.flags.update_global_search)
			except redis.exceptions.ConnectionError:
				sync_global_search()

			frappe.flags.update_global_search = []

	def flush_realtime_log(self):
		for args in frappe.local.realtime_log:
			frappe.async.emit_via_redis(*args)

		frappe.local.realtime_log = []

	def rollback(self):
		"""`ROLLBACK` current transaction."""
		self.sql("rollback")
		self.begin()
		for obj in frappe.local.rollback_observers:
			if hasattr(obj, "on_rollback"):
예제 #19
0
 def test_web_page_index(self):
     global_search.update_global_search_for_all_web_pages()
     global_search.sync_global_search()
     frappe.db.commit()
     results = global_search.web_search('unsubscribe')
     self.assertTrue('Unsubscribe' in results[0].content)