コード例 #1
0
def save_file(fname,
              content,
              dt,
              dn,
              folder=None,
              decode=False,
              is_private=0,
              df=None):
    if decode:
        if isinstance(content, text_type):
            content = content.encode("utf-8")

        if b"," in content:
            content = content.split(b",")[1]
        content = base64.b64decode(content)

    file_size = check_max_file_size(content)
    content_hash = get_content_hash(content)
    content_type = mimetypes.guess_type(fname)[0]
    fname = get_file_name(fname, content_hash[-6:])
    file_data = get_file_data_from_hash(content_hash, is_private=is_private)
    if not file_data:
        call_hook_method("before_write_file", file_size=file_size)

        write_file_method = get_hook_method('write_file',
                                            fallback=save_file_on_filesystem)
        file_data = write_file_method(fname,
                                      content,
                                      content_type=content_type,
                                      is_private=is_private)
        file_data = copy(file_data)

    file_data.update({
        "doctype": "File",
        "attached_to_doctype": dt,
        "attached_to_name": dn,
        "attached_to_field": df,
        "folder": folder,
        "file_size": file_size,
        "content_hash": content_hash,
        "is_private": is_private
    })

    f = dataent.get_doc(file_data)
    f.flags.ignore_permissions = True
    try:
        f.insert()
    except dataent.DuplicateEntryError:
        return dataent.get_doc("File", f.duplicate_entry)

    return f
コード例 #2
0
ファイル: braintree_settings.py プロジェクト: dataent/dataent
 def on_update(self):
     create_payment_gateway('Braintree-' + self.gateway_name,
                            settings='Braintree Settings',
                            controller=self.gateway_name)
     call_hook_method('payment_gateway_enabled',
                      gateway='Braintree-' + self.gateway_name)
コード例 #3
0
	def validate(self):
		create_payment_gateway("PayPal")
		call_hook_method('payment_gateway_enabled', gateway="PayPal")
		if not self.flags.ignore_mandatory:
			self.validate_paypal_credentails()
コード例 #4
0
def handle_subscription_notification(doctype, docname):
	call_hook_method("handle_subscription_notification", doctype=doctype, docname=docname)
コード例 #5
0
ファイル: stripe_settings.py プロジェクト: dataent/dataent
	def on_update(self):
		create_payment_gateway('Stripe-' + self.gateway_name, settings='Stripe Settings', controller=self.gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='Stripe-' + self.gateway_name)
		if not self.flags.ignore_mandatory:
			self.validate_stripe_credentails()
コード例 #6
0
ファイル: gocardless_settings.py プロジェクト: dataent/epaas
 def on_update(self):
     create_payment_gateway('GoCardless-' + self.gateway_name,
                            settings='GoCardLess Settings',
                            controller=self.gateway_name)
     call_hook_method('payment_gateway_enabled',
                      gateway='GoCardless-' + self.gateway_name)