Skip to content

Commit 4dec2ed

Browse files
committed
Move some code from the init methods of OrderItem and ConditionItem to
ItemBase
1 parent 811de80 commit 4dec2ed

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/icat/query.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
class ItemBase:
6868
"""Abstract base class for OrderItem and ConditionItem.
6969
"""
70-
7170
db_func_re = re.compile(r"(?:([A-Za-z_]+)\()?([A-Za-z.]+)(?(1)\))")
7271

7372
def split_db_functs(self, attr):
@@ -76,6 +75,10 @@ def split_db_functs(self, attr):
7675
raise ValueError("Invalid attribute '%s'" % attr)
7776
return m.group(2,1)
7877

78+
def __init__(self, obj):
79+
attr, jpql_func = self.split_db_functs(obj)
80+
self.attr = attr
81+
self.jpql_func = jpql_func
7982

8083
class OrderItem(ItemBase):
8184
"""Represent an item in the ORDER BY clause.
@@ -94,9 +97,7 @@ def __init__(self, obj, cloneFrom=None):
9497
% direction)
9598
else:
9699
direction = None
97-
attr, jpql_func = self.split_db_functs(obj)
98-
self.attr = attr
99-
self.jpql_func = jpql_func
100+
super().__init__(obj)
100101
self.direction = direction
101102

102103
@property
@@ -117,9 +118,7 @@ class ConditionItem(ItemBase):
117118
"""Represent an item in the WHERE clause.
118119
"""
119120
def __init__(self, obj, rhs):
120-
attr, jpql_func = self.split_db_functs(obj)
121-
self.attr = attr
122-
self.jpql_func = jpql_func
121+
super().__init__(obj)
123122
self.rhs = rhs
124123

125124
@property

0 commit comments

Comments
 (0)