Просмотр исходного кода

Merge pull request #12455 from Alchez/dev-import-file-error

fix: error while using data import and importing docs (develop)
version-14
Leela vadlamudi 4 лет назад
committed by GitHub
Родитель
Сommit
a2e791eaa0
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
5 измененных файлов: 36 добавлений и 48 удалений
  1. +2
    -2
      frappe/__init__.py
  2. +1
    -1
      frappe/commands/utils.py
  3. +14
    -31
      frappe/core/doctype/data_import/data_import.py
  4. +11
    -8
      frappe/core/doctype/data_import_legacy/data_import_legacy.py
  5. +8
    -6
      frappe/utils/fixtures.py

+ 2
- 2
frappe/__init__.py Просмотреть файл

@@ -1202,10 +1202,10 @@ def make_property_setter(args, ignore_validate=False, validate_fields_for_doctyp
ps.validate_fieldtype_change() ps.validate_fieldtype_change()
ps.insert() ps.insert()


def import_doc(path, ignore_links=False, ignore_insert=False, insert=False):
def import_doc(path):
"""Import a file using Data Import.""" """Import a file using Data Import."""
from frappe.core.doctype.data_import.data_import import import_doc from frappe.core.doctype.data_import.data_import import import_doc
import_doc(path, ignore_links=ignore_links, ignore_insert=ignore_insert, insert=insert)
import_doc(path)


def copy_doc(doc, ignore_no_copy=True): def copy_doc(doc, ignore_no_copy=True):
""" No_copy fields also get copied.""" """ No_copy fields also get copied."""


+ 1
- 1
frappe/commands/utils.py Просмотреть файл

@@ -293,7 +293,7 @@ def import_doc(context, path, force=False):
try: try:
frappe.init(site=site) frappe.init(site=site)
frappe.connect() frappe.connect()
import_doc(path, overwrite=context.force)
import_doc(path)
finally: finally:
frappe.destroy() frappe.destroy()
if not context.sites: if not context.sites:


+ 14
- 31
frappe/core/doctype/data_import/data_import.py Просмотреть файл

@@ -2,16 +2,16 @@
# Copyright (c) 2019, Frappe Technologies and contributors # Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt # For license information, please see license.txt


from __future__ import unicode_literals
import os import os
import frappe
from frappe.model.document import Document


from frappe.core.doctype.data_import.importer import Importer
import frappe
from frappe import _
from frappe.core.doctype.data_import.exporter import Exporter from frappe.core.doctype.data_import.exporter import Exporter
from frappe.core.doctype.data_import.importer import Importer
from frappe.model.document import Document
from frappe.modules.import_file import import_file_by_path
from frappe.utils.background_jobs import enqueue from frappe.utils.background_jobs import enqueue
from frappe.utils.csvutils import validate_google_sheets_url from frappe.utils.csvutils import validate_google_sheets_url
from frappe import _




class DataImport(Document): class DataImport(Document):
@@ -173,15 +173,7 @@ def import_file(
############## ##############




def import_doc(
path,
overwrite=False,
ignore_links=False,
ignore_insert=False,
insert=False,
submit=False,
pre_process=None,
):
def import_doc(path, pre_process=None):
if os.path.isdir(path): if os.path.isdir(path):
files = [os.path.join(path, f) for f in os.listdir(path)] files = [os.path.join(path, f) for f in os.listdir(path)]
else: else:
@@ -190,30 +182,21 @@ def import_doc(
for f in files: for f in files:
if f.endswith(".json"): if f.endswith(".json"):
frappe.flags.mute_emails = True frappe.flags.mute_emails = True
frappe.modules.import_file.import_file_by_path(
f, data_import=True, force=True, pre_process=pre_process, reset_permissions=True
)
frappe.flags.mute_emails = False
frappe.db.commit()
elif f.endswith(".csv"):
import_file_by_path( import_file_by_path(
f, f,
ignore_links=ignore_links,
overwrite=overwrite,
submit=submit,
data_import=True,
force=True,
pre_process=pre_process, pre_process=pre_process,
reset_permissions=True
) )
frappe.flags.mute_emails = False
frappe.db.commit()
elif f.endswith(".csv"):
validate_csv_import_file(f)
frappe.db.commit() frappe.db.commit()




def import_file_by_path(
path,
ignore_links=False,
overwrite=False,
submit=False,
pre_process=None,
no_email=True,
):
def validate_csv_import_file(path):
if path.endswith(".csv"): if path.endswith(".csv"):
print() print()
print("This method is deprecated.") print("This method is deprecated.")


+ 11
- 8
frappe/core/doctype/data_import_legacy/data_import_legacy.py Просмотреть файл

@@ -2,20 +2,22 @@
# Copyright (c) 2017, Frappe Technologies and contributors # Copyright (c) 2017, Frappe Technologies and contributors
# For license information, please see license.txt # For license information, please see license.txt


from __future__ import unicode_literals
import frappe, os
from frappe import _
import os
import frappe
import frappe.modules.import_file import frappe.modules.import_file
from frappe.model.document import Document
from frappe.utils.data import format_datetime
from frappe import _
from frappe.core.doctype.data_import_legacy.importer import upload from frappe.core.doctype.data_import_legacy.importer import upload
from frappe.model.document import Document
from frappe.modules.import_file import import_file_by_path as _import_file_by_path
from frappe.utils.background_jobs import enqueue from frappe.utils.background_jobs import enqueue
from frappe.utils.data import format_datetime




class DataImportLegacy(Document): class DataImportLegacy(Document):
def autoname(self): def autoname(self):
if not self.name: if not self.name:
self.name = "Import on " +format_datetime(self.creation)
self.name = "Import on " + format_datetime(self.creation)


def validate(self): def validate(self):
if not self.import_file: if not self.import_file:
@@ -33,6 +35,7 @@ class DataImportLegacy(Document):
def get_importable_doctypes(): def get_importable_doctypes():
return frappe.cache().hget("can_import", frappe.session.user) return frappe.cache().hget("can_import", frappe.session.user)



@frappe.whitelist() @frappe.whitelist()
def import_data(data_import): def import_data(data_import):
frappe.db.set_value("Data Import Legacy", data_import, "import_status", "In Progress", update_modified=False) frappe.db.set_value("Data Import Legacy", data_import, "import_status", "In Progress", update_modified=False)
@@ -57,7 +60,7 @@ def import_doc(path, overwrite=False, ignore_links=False, ignore_insert=False,
for f in files: for f in files:
if f.endswith(".json"): if f.endswith(".json"):
frappe.flags.mute_emails = True frappe.flags.mute_emails = True
frappe.modules.import_file.import_file_by_path(f, data_import=True, force=True, pre_process=pre_process, reset_permissions=True)
_import_file_by_path(f, data_import=True, force=True, pre_process=pre_process, reset_permissions=True)
frappe.flags.mute_emails = False frappe.flags.mute_emails = False
frappe.db.commit() frappe.db.commit()
elif f.endswith(".csv"): elif f.endswith(".csv"):
@@ -69,7 +72,7 @@ def import_file_by_path(path, ignore_links=False, overwrite=False, submit=False,
from frappe.utils.csvutils import read_csv_content from frappe.utils.csvutils import read_csv_content
print("Importing " + path) print("Importing " + path)
with open(path, "r") as infile: with open(path, "r") as infile:
upload(rows = read_csv_content(infile.read()), ignore_links=ignore_links, no_email=no_email, overwrite=overwrite,
upload(rows=read_csv_content(infile.read()), ignore_links=ignore_links, no_email=no_email, overwrite=overwrite,
submit_after_import=submit, pre_process=pre_process) submit_after_import=submit, pre_process=pre_process)






+ 8
- 6
frappe/utils/fixtures.py Просмотреть файл

@@ -1,10 +1,11 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt # MIT License. See license.txt


from __future__ import unicode_literals, print_function
import os

import frappe
from frappe.core.doctype.data_import.data_import import export_json, import_doc


import frappe, os
from frappe.core.doctype.data_import.data_import import import_doc, export_json


def sync_fixtures(app=None): def sync_fixtures(app=None):
"""Import, overwrite fixtures from `[app]/fixtures`""" """Import, overwrite fixtures from `[app]/fixtures`"""
@@ -20,8 +21,7 @@ def sync_fixtures(app=None):
fixture_files = sorted(os.listdir(frappe.get_app_path(app, "fixtures"))) fixture_files = sorted(os.listdir(frappe.get_app_path(app, "fixtures")))
for fname in fixture_files: for fname in fixture_files:
if fname.endswith(".json") or fname.endswith(".csv"): if fname.endswith(".json") or fname.endswith(".csv"):
import_doc(frappe.get_app_path(app, "fixtures", fname),
ignore_links=True, overwrite=True)
import_doc(frappe.get_app_path(app, "fixtures", fname))


import_custom_scripts(app) import_custom_scripts(app)


@@ -29,6 +29,7 @@ def sync_fixtures(app=None):


frappe.db.commit() frappe.db.commit()



def import_custom_scripts(app): def import_custom_scripts(app):
"""Import custom scripts from `[app]/fixtures/custom_scripts`""" """Import custom scripts from `[app]/fixtures/custom_scripts`"""
if os.path.exists(frappe.get_app_path(app, "fixtures", "custom_scripts")): if os.path.exists(frappe.get_app_path(app, "fixtures", "custom_scripts")):
@@ -44,11 +45,12 @@ def import_custom_scripts(app):
custom_script.save() custom_script.save()
else: else:
frappe.get_doc({ frappe.get_doc({
"doctype":"Client Script",
"doctype": "Client Script",
"dt": doctype, "dt": doctype,
"script": script "script": script
}).insert() }).insert()



def export_fixtures(app=None): def export_fixtures(app=None):
"""Export fixtures as JSON to `[app]/fixtures`""" """Export fixtures as JSON to `[app]/fixtures`"""
if app: if app:


Загрузка…
Отмена
Сохранить