File tree Expand file tree Collapse file tree 2 files changed +16
-24
lines changed Expand file tree Collapse file tree 2 files changed +16
-24
lines changed Original file line number Diff line number Diff line change @@ -89,35 +89,18 @@ def check_properties(mcs, attributes):
8989 :type attributes: dict
9090 """
9191 include , exclude = mcs .get_prepared_include_exclude (attributes )
92-
93- if include :
94- intersections = mcs .get_intersections (attributes , include )
95- attr = '__include__'
96- elif exclude :
97- intersections = mcs .get_intersections (attributes , exclude )
98- attr = '__exclude__'
99- else :
100- return None
101-
92+ properties = mcs .get_properties (attributes )
93+ intersections = list (
94+ set (properties ).intersection (include if include else exclude ))
10295 if not intersections :
10396 return None
10497
98+ attr_name = '__include__' if include else '__exclude__'
99+
105100 raise AttributeError (
106101 "It is not allowed to mention already defined properties: "
107- "{0} in {1} attributes." .format (", " .join (intersections ), attr ))
108-
109- @classmethod
110- def get_intersections (mcs , attributes , attr ):
111- """Return intersection with defined properties if exists.
112-
113- :type attributes: dict
114- :type attr: list
115- :rtype: list
116- """
117- if not attr :
118- return []
119- properties = mcs .get_properties (attributes )
120- return list (set (properties ).intersection (attr ))
102+ "{0} in {1} attributes." .format (", " .join (intersections ),
103+ attr_name ))
121104
122105
123106@six .add_metaclass (ContextViewMetaClass )
Original file line number Diff line number Diff line change @@ -156,6 +156,15 @@ class WrongContext(views.ContextView):
156156 __model_cls__ = Profile
157157 __exclude__ = [Profile .name ]
158158
159+ with self .assertRaises (AttributeError ):
160+ class WrongContext (views .ContextView ):
161+ __model_cls__ = Profile
162+ __include__ = (Profile .id , Profile .name )
163+
164+ @property
165+ def name (self ):
166+ return "Any name"
167+
159168 with self .assertRaises (AttributeError ):
160169 class WrongContext (views .ContextView ):
161170 __model_cls__ = Profile
You can’t perform that action at this time.
0 commit comments