Bläddra i källkod

[Bug] fixed install failure due to psycopg2 (#4566)

version-14
Ameya Shenoy 7 år sedan
committed by Faris Ansari
förälder
incheckning
7f9ec35391
3 ändrade filer med 3 tillägg och 50 borttagningar
  1. +0
    -43
      frappe/data_migration/doctype/data_migration_connector/connectors/postgres.py
  2. +2
    -2
      frappe/data_migration/doctype/data_migration_connector/data_migration_connector.json
  3. +1
    -5
      frappe/data_migration/doctype/data_migration_connector/data_migration_connector.py

+ 0
- 43
frappe/data_migration/doctype/data_migration_connector/connectors/postgres.py Visa fil

@@ -1,43 +0,0 @@
from __future__ import unicode_literals
import frappe, psycopg2
from .base import BaseConnection

class PostGresConnection(BaseConnection):
def __init__(self, properties):
self.__dict__.update(properties)
self._connector = psycopg2.connect("host='{0}' dbname='{1}' user='{2}' password='{3}'".format(self.hostname,
self.database_name, self.username, self.password))
self.cursor = self._connector.cursor()

def get_objects(self, object_type, condition, selection):
if not condition:
condition = ''
else:
condition = ' WHERE ' + condition
self.cursor.execute('SELECT {0} FROM {1}{2}'.format(selection, object_type, condition))
raw_data = self.cursor.fetchall()
data = []
for r in raw_data:
row_dict = frappe._dict({})
for i, value in enumerate(r):
row_dict[self.cursor.description[i][0]] = value
data.append(row_dict)

return data

def get_join_objects(self, object_type, field, primary_key):
"""
field.formula 's first line will be list of tables that needs to be linked to fetch an item
The subsequent lines that follows will contain one to one mapping across tables keys
"""
condition = ""
key_mapping = field.formula.split('\n')
obj_type = key_mapping[0]
selection = field.source_fieldname

for d in key_mapping[1:]:
condition += d + ' AND '

condition += str(object_type) + ".id=" + str(primary_key)

return self.get_objects(obj_type, condition, selection)

+ 2
- 2
frappe/data_migration/doctype/data_migration_connector/data_migration_connector.json Visa fil

@@ -62,7 +62,7 @@
"label": "Connector Type",
"length": 0,
"no_copy": 0,
"options": "\nFrappe\nPostgres\nCustom",
"options": "\nFrappe\nCustom",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -268,7 +268,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-10-26 12:03:40.646348",
"modified": "2017-12-01 13:38:55.992499",
"modified_by": "Administrator",
"module": "Data Migration",
"name": "Data Migration Connector",


+ 1
- 5
frappe/data_migration/doctype/data_migration_connector/data_migration_connector.py Visa fil

@@ -8,7 +8,6 @@ from frappe.model.document import Document
from frappe import _
from frappe.modules.export_file import create_init_py
from .connectors.base import BaseConnection
from .connectors.postgres import PostGresConnection
from .connectors.frappe_connection import FrappeConnection

class DataMigrationConnector(Document):
@@ -27,10 +26,7 @@ class DataMigrationConnector(Document):
_class = get_connection_class(self.python_module)
return _class(self)
else:
if self.connector_type == 'Frappe':
self.connection = FrappeConnection(self)
elif self.connector_type == 'PostGres':
self.connection = PostGresConnection(self.as_dict())
self.connection = FrappeConnection(self)

return self.connection



Laddar…
Avbryt
Spara