Пример #1
0
def get_messages(language, start=0, page_length=100, search_text=''):
    from frappe.frappeclient import FrappeClient
    translator = FrappeClient(get_translator_url())
    translated_dict = translator.post_api(
        'translator.api.get_strings_for_translation', params=locals())

    return translated_dict
Пример #2
0
def placeOrder(test):
    client = FrappeClient("http://0.0.0.0:8001", "*****@*****.**",
                          "qwerty0987")
    print "======================CALL THIS================================"
    args = {"item_code": "1314", "qty": test}
    tags2 = client.post_api("erpnext.shopping_cart.cart.place_order", args)
    print tags2
Пример #3
0
def cartPost(test):
    client = FrappeClient("http://0.0.0.0:8001", "*****@*****.**",
                          "qwerty0987")
    print "8=================POST TO CART TRIGGER=====================D"
    args = {"item_code": "1314", "qty": test}
    tags = client.post_api("erpnext.shopping_cart.cart.update_cart", args)
    print tags
    # placeOrder()
    print "8=================END TO CART TRIGGER=====================D"
Пример #4
0
def create_translations(translation_map, language):
	from frappe.frappeclient import FrappeClient

	translation_map = json.loads(translation_map)
	translation_map_to_send = frappe._dict({})
	# first create / update local user translations
	for source_id, translation_dict in translation_map.items():
		translation_dict = frappe._dict(translation_dict)
		existing_doc_name = frappe.db.get_all(
			"Translation",
			{
				"source_text": translation_dict.source_text,
				"context": translation_dict.context or "",
				"language": language,
			},
		)
		translation_map_to_send[source_id] = translation_dict
		if existing_doc_name:
			frappe.db.set_value(
				"Translation",
				existing_doc_name[0].name,
				{
					"translated_text": translation_dict.translated_text,
					"contributed": 1,
					"contribution_status": "Pending",
				},
			)
			translation_map_to_send[source_id].name = existing_doc_name[0].name
		else:
			doc = frappe.get_doc(
				{
					"doctype": "Translation",
					"source_text": translation_dict.source_text,
					"contributed": 1,
					"contribution_status": "Pending",
					"translated_text": translation_dict.translated_text,
					"context": translation_dict.context,
					"language": language,
				}
			)
			doc.insert()
			translation_map_to_send[source_id].name = doc.name

	params = {
		"language": language,
		"contributor_email": frappe.session.user,
		"contributor_name": frappe.utils.get_fullname(frappe.session.user),
		"translation_map": json.dumps(translation_map_to_send),
	}

	translator = FrappeClient(get_translator_url())
	added_translations = translator.post_api("translator.api.add_translations", params=params)

	for local_docname, remote_docname in added_translations.items():
		frappe.db.set_value("Translation", local_docname, "contribution_docname", remote_docname)
Пример #5
0
def create_translations(translation_map, language):
    from frappe.frappeclient import FrappeClient

    translation_map = json.loads(translation_map)
    translation_map_to_send = frappe._dict({})
    # first create / update local user translations
    for source_id, translation_dict in translation_map.items():
        translation_dict = frappe._dict(translation_dict)
        existing_doc_name = frappe.db.get_all(
            'Translation', {
                'source_text': translation_dict.source_text,
                'context': translation_dict.context or '',
                'language': language,
            })
        translation_map_to_send[source_id] = translation_dict
        if existing_doc_name:
            frappe.db.set_value(
                'Translation', existing_doc_name[0].name, {
                    'translated_text': translation_dict.translated_text,
                    'contributed': 1,
                    'contribution_status': 'Pending'
                })
            translation_map_to_send[source_id].name = existing_doc_name[0].name
        else:
            doc = frappe.get_doc({
                'doctype': 'Translation',
                'source_text': translation_dict.source_text,
                'contributed': 1,
                'contribution_status': 'Pending',
                'translated_text': translation_dict.translated_text,
                'context': translation_dict.context,
                'language': language
            })
            doc.insert()
            translation_map_to_send[source_id].name = doc.name

    params = {
        'language': language,
        'contributor_email': frappe.session.user,
        'contributor_name': frappe.utils.get_fullname(frappe.session.user),
        'translation_map': json.dumps(translation_map_to_send)
    }

    translator = FrappeClient(get_translator_url())
    added_translations = translator.post_api('translator.api.add_translations',
                                             params=params)

    for local_docname, remote_docname in added_translations.items():
        frappe.db.set_value('Translation', local_docname,
                            'contribution_docname', remote_docname)
Пример #6
0
 def create_event_consumer(self):
     """register event consumer on the producer site"""
     if self.is_producer_online():
         producer_site = FrappeClient(self.producer_url, verify=False)
         response = producer_site.post_api(
             'frappe.event_streaming.doctype.event_consumer.event_consumer.register_consumer',
             params={'data': json.dumps(self.get_request_data())})
         if response:
             response = json.loads(response)
             self.api_key = response['api_key']
             self.api_secret = response['api_secret']
             self.last_update = response['last_update']
         else:
             frappe.throw(
                 _('Failed to create an Event Consumer or an Event Consumer for the current site is already registered.'
                   ))
Пример #7
0
	def create_event_consumer(self):
		"""register event consumer on the producer site"""
		if self.is_producer_online():
			producer_site = FrappeClient(
				url=self.producer_url, api_key=self.api_key, api_secret=self.get_password("api_secret")
			)

			response = producer_site.post_api(
				"frappe.event_streaming.doctype.event_consumer.event_consumer.register_consumer",
				params={"data": json.dumps(self.get_request_data())},
			)
			if response:
				response = json.loads(response)
				self.set_last_update(response["last_update"])
			else:
				frappe.throw(
					_(
						"Failed to create an Event Consumer or an Event Consumer for the current site is already registered."
					)
				)
Пример #8
0
def get_source_additional_info(source, language=''):
	from frappe.frappeclient import FrappeClient
	translator = FrappeClient(get_translator_url())
	return translator.post_api('translator.api.get_source_additional_info', params=locals())