Browse Source

PEP8 / PyLint on datasources module

Roland Haroutiounian 9 years ago
parent
commit
32fe54e205
2 changed files with 17 additions and 23 deletions
  1. 3
    3
      leobject/datasources/dummy.py
  2. 14
    20
      leobject/datasources/ledatasourcesql.py

+ 3
- 3
leobject/datasources/dummy.py View File

@@ -19,7 +19,7 @@ class DummyDatasource(object):
19 19
     # @param data dict : Dict representing fields and there values
20 20
     # @return True if success
21 21
     def update(self, letype, leclass, filters, rel_filters, data):
22
-        print ("DummyDatasource.update: ", lodel_id, checked_data, filters, relational_filters)
22
+        print ("DummyDatasource.update: ", letype, leclass, filters, rel_filters, data)
23 23
         return True
24 24
 
25 25
     ## @brief create a new LeObject
@@ -38,7 +38,7 @@ class DummyDatasource(object):
38 38
     # @param relational_filters list : relationnal filters list (see @ref leobject_filters )
39 39
     # @return okay bool: True on success, it will raise on failure
40 40
     def delete(self, letype, leclass, filters, relational_filters):
41
-        print("DummyDatasource.delete: ", filters)
41
+        print("DummyDatasource.delete: ", letype, leclass, filters, relational_filters)
42 42
         return True
43 43
 
44 44
     ## @brief search for a collection of objects
@@ -49,5 +49,5 @@ class DummyDatasource(object):
49 49
     # @param relational_filters list : relationnal filters list (see @ref leobject_filters )
50 50
     # @return responses ({string:*}): a list of dict with field:value
51 51
     def get(self, leclass, letype, field_list, filters, relational_filters):
52
-        print("DummyDatasource.get: ", emclass, emtype, field_list, filters, relational_filters)
52
+        print("DummyDatasource.get: ", leclass, letype, field_list, filters, relational_filters)
53 53
         return []

+ 14
- 20
leobject/datasources/ledatasourcesql.py View File

@@ -1,26 +1,23 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-import sqlite3
4 3
 from leobject.datasources.dummy import DummyDatasource
5 4
 from mosql.db import Database, all_to_dicts
6
-from mosql.query import select, insert, update, delete
7
-from leobject import REL_SUB, REL_SUP
8
-
9
-from Lodel.utils.mosql import *
5
+from mosql.query import select, insert, update, delete, join
6
+from leobject.leobject import REL_SUB, REL_SUP
10 7
 
11 8
 ## SQL DataSource for LeObject
12 9
 class LeDataSourceSQL(DummyDatasource):
13 10
 
14 11
     RELATIONS_TABLE_NAME = 'relations'
15
-    RELATIONS_POSITIONS_FIELDS = {REL_SUP:'superior_id', REL_SUB:'subordinate_id'}
12
+    RELATIONS_POSITIONS_FIELDS = {REL_SUP: 'superior_id', REL_SUB: 'subordinate_id'}
16 13
     RELATIONS_NATURE_FIELD = 'nature'
17 14
 
18 15
     MODULE = 'sqlite3'
19 16
 
20 17
     def __init__(self, module=None, *conn_args, **conn_kargs):
21
-        self.module = self.MODULE if module == None else module
18
+        self.module = self.MODULE if module is None else module
22 19
         super(LeDataSourceSQL, self).__init__()
23
-        self.db = Database(self.module, self.conn_args, self.conn_kargs)
20
+        self.connection = Database(self.module, self.conn_args, self.conn_kargs)
24 21
 
25 22
     ## @brief update an existing object's data
26 23
     # @param letype LeType
@@ -39,7 +36,7 @@ class LeDataSourceSQL(DummyDatasource):
39 36
         # Building the query
40 37
         query = update(table=query_table_name, where=where_filters, set=set_data)
41 38
         # Executing the query
42
-        with self.db as cur:
39
+        with self.connection as cur:
43 40
             cur.execute(query)
44 41
         return True
45 42
 
@@ -53,7 +50,7 @@ class LeDataSourceSQL(DummyDatasource):
53 50
         #building the query
54 51
         query = insert(query_table_name, datas)
55 52
         #executing the query
56
-        with self.db as cur:
53
+        with self.connection as cur:
57 54
             cur.execute(query)
58 55
         return True
59 56
 
@@ -67,7 +64,7 @@ class LeDataSourceSQL(DummyDatasource):
67 64
     def delete(self, letype, leclass, filters, relational_filters):
68 65
         query_table_name = leclass.name
69 66
         query = delete(query_table_name, filters)
70
-        with self.db as cur:
67
+        with self.connection as cur:
71 68
             cur.execute(query)
72 69
         return True
73 70
 
@@ -99,11 +96,8 @@ class LeDataSourceSQL(DummyDatasource):
99 96
                 query_table_join_field = "%s.lodel_id" % query_table_name
100 97
                 join_fields[query_table_join_field] = relation_table_join_field
101 98
 
102
-                # Adding to "where" filters
103
-                where_filters['%s.%s' % (self.RELATIONS_TABLE_NAME,self.RELATIONS_NATURE_FIELD_NAME ]
104
-
105 99
                 # Adding "where" filters
106
-                where_filters['%s.%s' % (self.RELATIONS_TABLE_NAME, self.RELATIONS_NATURE_FIELD)] = relational_field
100
+                where_filters['%s.%s' % (self.RELATIONS_TABLE_NAME, self.RELATIONS_NATURE_FIELD)] = relational_nature
107 101
                 where_filters[relational_condition_key] = relational_condition_value
108 102
 
109 103
             # Building the query
@@ -112,7 +106,7 @@ class LeDataSourceSQL(DummyDatasource):
112 106
             query = select(query_table_name, where=where_filters, select=field_list)
113 107
 
114 108
         # Executing the query
115
-        with self.db as cur:
109
+        with self.connection as cur:
116 110
             results = cur.execute(query)
117 111
 
118 112
         # Returning it as a list of dict
@@ -123,9 +117,9 @@ class LeDataSourceSQL(DummyDatasource):
123 117
     # @return dict : Dictionnary with (FIELD, OPERATOR):VALUE style elements
124 118
     def _prepare_filters(self, filters):
125 119
         prepared_filters = {}
126
-        for filter in filters:
127
-            prepared_filter_key = (filter[0], filter[1])
128
-            prepared_filter_value = filter[2]
120
+        for filter_item in filters:
121
+            prepared_filter_key = (filter_item[0], filter_item[1])
122
+            prepared_filter_value = filter_item[2]
129 123
             prepared_filters[prepared_filter_key] = prepared_filter_value
130 124
 
131
-        return prepared_filters
125
+        return prepared_filters

Loading…
Cancel
Save