Browse Source

Without is_exist

prieto 7 years ago
parent
commit
b547f75c9f

+ 3
- 6
lodel/leapi/datahandlers/base_classes.py View File

@@ -391,14 +391,11 @@ class Reference(DataHandler):
391 391
             logger.warning('Class of the back_reference given is not an allowed class')
392 392
             return False
393 393
         value = datas[fname]
394
-        if not target_class.is_exist(value):
394
+        target_uidfield = target_class.uid_fieldname()[0]  # multi uid broken here
395
+        obj = target_class.get([(target_uidfield, '=', value)])
396
+        if len(obj) == 0:
395 397
             logger.warning('Object referenced does not exist')
396 398
             return False
397
-        # target_uidfield = target_class.uid_fieldname()[0] #multi uid broken here
398
-        # obj = target_class.get([(target_uidfield, '=', value)])
399
-        # if len(obj) == 0:
400
-        #    logger.warning('Object referenced does not exist')
401
-        #    return False
402 399
         return True
403 400
 
404 401
     # @brief Utility method designed to fetch referenced objects

+ 0
- 9
lodel/leapi/leobject.py View File

@@ -654,12 +654,3 @@ object ! For class %s with uid value = %s" % (cls, uid))
654 654
         elif len(res) == 0:
655 655
             return None
656 656
         return res[0]
657
-
658
-    # @brief Checks if an object exists
659
-    @classmethod
660
-    def is_exist(cls, uid):
661
-        if cls.uid_fieldname() is None:
662
-            raise LodelFatalError(
663
-                "No uid defined for class %s" % cls.__name__)
664
-        from .query import is_exist
665
-        return is_exist(cls, uid)

+ 19
- 33
lodel/leapi/query.py View File

@@ -7,27 +7,15 @@ import warnings
7 7
 
8 8
 from lodel.context import LodelContext
9 9
 LodelContext.expose_modules(globals(), {
10
-    'lodel.leapi.exceptions': ['LeApiError', 'LeApiErrors', 
10
+    'lodel.leapi.exceptions': ['LeApiError', 'LeApiErrors',
11 11
         'LeApiDataCheckError', 'LeApiDataCheckErrors', 'LeApiQueryError',
12 12
         'LeApiQueryErrors'],
13 13
     'lodel.plugin.hooks': ['LodelHook'],
14 14
     'lodel.logger': ['logger']})
15 15
 
16
-##@brief Tool to check if a target_class's object exists and is stored
17
-#@param target_class : class where the object is supposed to be
18
-#@param uid : a unique id in target_class
19
-#@returns true if an object with unique id uid exists in target_class, false if not
20
-def is_exist(target_class, uid):
21
-	from .leobject import LeObject
22
-	if not inspect.isclass(target_class) or not issubclass(target_class, LeObject):
23
-		raise TypeError("target class has to be a child class of LeObject but %s was given"% target_class)
24
-	datasource = target_class._ro_datasource
25
-	return datasource.is_exist(target_class,uid)
26
-
27
-
28 16
 ##@todo check datas when running query
29 17
 class LeQuery(object):
30
-    
18
+
31 19
     ##@brief Hookname prefix
32 20
     _hook_prefix = None
33 21
     ##@brief arguments for the LeObject.check_data_value()
@@ -73,7 +61,7 @@ class LeQuery(object):
73 61
     #@return query result
74 62
     def _query(self, **datas):
75 63
         raise NotImplementedError("Asbtract method")
76
-    
64
+
77 65
     ##@return a dict with query infos
78 66
     def dump_infos(self):
79 67
         return {'target_class': self._target_class}
@@ -118,7 +106,7 @@ class LeFilteredQuery(LeQuery):
118 106
         self.subqueries = None
119 107
         query_filters = [] if query_filters is None else query_filters
120 108
         self.set_query_filter(query_filters)
121
-    
109
+
122 110
     ##@brief Abstract FilteredQuery execution method
123 111
     #
124 112
     # This method takes care to execute subqueries before calling super execute
@@ -439,7 +427,7 @@ field to use for the relational filter"
439 427
     #<pre>contributeur IN (1,2,3,5)</pre> will be transformed into :
440 428
     #<pre>(
441 429
     #       (
442
-    #           contributeur, 
430
+    #           contributeur,
443 431
     #           {
444 432
     #               auteur: 'lodel_id',
445 433
     #               traducteur: 'lodel_id'
@@ -494,7 +482,7 @@ class LeInsertQuery(LeQuery):
494 482
             raise LeApiQueryError("Trying to create an insert query on an \
495 483
 abstract LeObject : %s" % target_class)
496 484
         super().__init__(target_class)
497
-    
485
+
498 486
     ## @brief Implements an insert query operation, with only one insertion
499 487
     # @param datas : datas to be inserted
500 488
     def _query(self, datas):
@@ -536,7 +524,7 @@ class LeUpdateQuery(LeFilteredQuery):
536 524
     #@todo change strategy with instance update. We have to accept datas for
537 525
     #the execute method
538 526
     def __init__(self, target, query_filters=None):
539
-        ##@brief This attr is set only if the target argument is an 
527
+        ##@brief This attr is set only if the target argument is an
540 528
         #instance of a LeObject subclass
541 529
         self.__leobject_instance_datas = None
542 530
         target_class = target
@@ -565,8 +553,8 @@ target to LeUpdateQuery constructor"
565 553
             #Instance update
566 554
             #Building query_filter
567 555
             filters = [(
568
-                uid_name, 
569
-                '=', 
556
+                uid_name,
557
+                '=',
570 558
                 str(self.__leobject_instance_datas[uid_name]))]
571 559
             res = self._rw_datasource.update(
572 560
                 self._target_class, filters, [],
@@ -712,22 +700,22 @@ class LeGetQuery(LeFilteredQuery):
712 700
         l_datas=self._ro_datasource.select(
713 701
             target = self._target_class,
714 702
             field_list = fl,
715
-            filters = self._query_filter[0], 
716
-            relational_filters = self._query_filter[1], 
717
-            order = self._order, 
718
-            group = self._group, 
719
-            limit = self._limit, 
703
+            filters = self._query_filter[0],
704
+            relational_filters = self._query_filter[1],
705
+            order = self._order,
706
+            group = self._group,
707
+            limit = self._limit,
720 708
             offset = self._offset)
721 709
         return l_datas
722 710
 
723 711
     ##@return a dict with query infos
724 712
     def dump_infos(self):
725 713
         ret = super().dump_infos()
726
-        ret.update({  'field_list' : self._field_list, 
727
-                        'order' : self._order, 
728
-                        'group' : self._group, 
729
-                        'limit' : self._limit, 
730
-                        'offset': self._offset, 
714
+        ret.update({  'field_list' : self._field_list,
715
+                        'order' : self._order,
716
+                        'group' : self._group,
717
+                        'limit' : self._limit,
718
+                        'offset': self._offset,
731 719
        })
732 720
         return ret
733 721
 
@@ -742,5 +730,3 @@ offset={offset}"
742 730
                 res %= (n, subq)
743 731
         res += ">"
744 732
         return res
745
-
746
-

+ 19
- 17
lodel/plugins/webui/interface/controllers/admin.py View File

@@ -19,17 +19,17 @@ LIST_SEPARATOR = ','
19 19
 ##@brief These functions are called by the rules defined in ../urls.py
20 20
 ## To administrate the instance of the editorial model
21 21
 
22
-##@brief Controller's function to redirect on the home page of the admin 
22
+##@brief Controller's function to redirect on the home page of the admin
23 23
 # @param request : the request (get or post)
24 24
 # @note the response is given in a html page called in get_response_function
25 25
 def index_admin(request):
26 26
     # We have to be identified to admin the instance
27
-    # temporary, the acl will be more restrictive 
27
+    # temporary, the acl will be more restrictive
28 28
     #if WebUiClient.is_anonymous():
29 29
     #    return get_response('users/signin.html')
30 30
     return get_response('admin/admin.html')
31 31
 
32
-##@brief Controller's function to update an object of the editorial model 
32
+##@brief Controller's function to update an object of the editorial model
33 33
 # @param request : the request (get or post)
34 34
 # @note the response is given in a html page (in templates/admin) called in get_response_function
35 35
 def admin_update(request):
@@ -38,7 +38,7 @@ def admin_update(request):
38 38
     #if WebUiClient.is_anonymous():
39 39
     #    return get_response('users/signin.html')
40 40
     msg=''
41
-    
41
+
42 42
     datas = process_form(request)
43 43
     if not(datas is False):
44 44
         if 'lodel_id' not in datas:
@@ -55,8 +55,8 @@ def admin_update(request):
55 55
         except LeApiDataCheckErrors as e:
56 56
             raise HttpErrors(
57 57
                 title='Form validation errors', errors = e._exceptions)
58
-            
59
-            
58
+
59
+
60 60
 
61 61
     # Display of the form with the object's values to be updated
62 62
     if 'classname' in request.GET:
@@ -72,7 +72,7 @@ def admin_update(request):
72 72
             raise HttpException(400)
73 73
         logger.warning('Composed uids broken here')
74 74
         uid_field = target_leo.uid_fieldname()[0]
75
-    
75
+
76 76
     # We need the uid of the object
77 77
     test_valid = 'lodel_id' in request.GET \
78 78
         and len(request.GET['lodel_id']) == 1
@@ -91,11 +91,14 @@ def admin_update(request):
91 91
     else:
92 92
         # Check if the object actually exists
93 93
         # We get it from the database
94
-        if not target_leo.is_exist(lodel_id):
94
+        query_filters = list()
95
+        query_filters.append((uid_field,'=',lodel_id))
96
+        obj = target_leo.get(query_filters)
97
+        if len(obj) == 0:
95 98
             raise HttpException(404)
96 99
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
97 100
 
98
-##@brief Controller's function to create an object of the editorial model 
101
+##@brief Controller's function to create an object of the editorial model
99 102
 # @param request : the request (get or post)
100 103
 # @note the response is given in a html page (in templates/admin) called in get_response_function
101 104
 def admin_create(request):
@@ -138,7 +141,7 @@ def admin_create(request):
138 141
         raise HttpException(400)
139 142
     return get_response('admin/admin_create.html', target=target_leo)
140 143
 
141
-##@brief Controller's function to delete an object of the editorial model 
144
+##@brief Controller's function to delete an object of the editorial model
142 145
 # @param request : the request (get)
143 146
 # @note the response is given in a html page (in templates/admin) called in get_response_function
144 147
 def admin_delete(request):
@@ -161,7 +164,7 @@ def admin_delete(request):
161 164
             raise HttpException(400)
162 165
         logger.warning('Composed uids broken here')
163 166
         uid_field = target_leo.uid_fieldname()[0]
164
-        
167
+
165 168
     # We also need the uid of the object to delete
166 169
     test_valid = 'lodel_id' in request.GET \
167 170
         and len(request.GET['lodel_id']) == 1
@@ -186,11 +189,11 @@ def admin_delete(request):
186 189
             msg = 'Object successfully deleted';
187 190
     else:
188 191
             msg = 'Oops something wrong happened...object still here'
189
-            
192
+
190 193
     return get_response('admin/admin_delete.html', target=target_leo, lodel_id =lodel_id, msg = msg)
191 194
 
192
-        
193
-        
195
+
196
+
194 197
 def admin_classes(request):
195 198
     # We have to be identified to admin the instance
196 199
     # temporary, the acl will be more restrictive
@@ -211,7 +214,7 @@ def delete_object(request):
211 214
     #if WebUiClient.is_anonymous():
212 215
     #    return get_response('users/signin.html')
213 216
     return get_response('admin/list_classes_delete.html', my_classes = dyncode.dynclasses)
214
-    
217
+
215 218
 def admin_class(request):
216 219
     # We have to be identified to admin the instance
217 220
     # temporary, the acl will be more restrictive
@@ -313,7 +316,7 @@ def process_form(request):
313 316
                 if hasattr(dh, 'default'):
314 317
                     value = dh.default
315 318
                 else:
316
-                    #if not explicit default value, enforcing default as 
319
+                    #if not explicit default value, enforcing default as
317 320
                     #an empty list
318 321
                     value = []
319 322
             else:
@@ -328,4 +331,3 @@ def process_form(request):
328 331
         del(res)
329 332
         raise HttpErrors(errors, title="Form validation error")
330 333
     return res
331
-

+ 11
- 5
lodel/plugins/webui/interface/controllers/listing.py View File

@@ -32,7 +32,7 @@ def collections(request):
32 32
 def issue(request):
33 33
     lodel_id = request.GET['lodel_id']
34 34
     return get_response('listing/issue.html', lodel_id=lodel_id[0], my_classes=dyncode )
35
-    
35
+
36 36
 ##@brief Controller's function to display a type (class) of the editorial model
37 37
 # @param request : the request (get or post)
38 38
 # @note the response is given in a html page called in get_response_function
@@ -65,7 +65,7 @@ def show_object(request):
65 65
             classname = None
66 66
     else:
67 67
         raise HttpException(400)
68
-    
68
+
69 69
     logger.warning('Composed uids broken here')
70 70
     uid_field = target_leo.uid_fieldname()[0]
71 71
 
@@ -82,7 +82,10 @@ def show_object(request):
82 82
     if not test_valid:
83 83
         raise HttpException(400)
84 84
     else:
85
-        if not target_leo.is_exist(lodel_id):
85
+        query_filters = list()
86
+        query_filters.append((uid_field,'=',lodel_id))
87
+        obj = target_leo.get(query_filters)
88
+        if len(obj) == 0:
86 89
             raise HttpException(404)
87 90
     return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
88 91
 
@@ -101,7 +104,7 @@ def show_object_detailled(request):
101 104
             classname = None
102 105
     else:
103 106
         raise HttpException(400)
104
-    
107
+
105 108
     logger.warning('Composed uids broken here')
106 109
     uid_field = target_leo.uid_fieldname()[0]
107 110
 
@@ -118,7 +121,10 @@ def show_object_detailled(request):
118 121
     if not test_valid:
119 122
         raise HttpException(400)
120 123
     else:
121
-        if not target_leo.is_exist(lodel_id):
124
+        query_filters = list()
125
+        query_filters.append((uid_field,'=',lodel_id))
126
+        obj = target_leo.get(query_filters)
127
+        if len(obj) == 0:
122 128
             raise HttpException(404)
123 129
 
124 130
     return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)

Loading…
Cancel
Save