Skip to content

Commit d2dbac4

Browse files
committed
Issue #25: __model_cls__ attribute for contexts' class, __model__ for instance of this class.
1 parent c493730 commit d2dbac4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

domain_models/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
class ContextView(object):
66
"""Contextual view class."""
77

8-
__model__ = None
8+
__model_cls__ = None
99

1010
def __init__(self, model):
1111
"""Model validation.
1212
1313
:param model: DomainModel
1414
"""
15-
if not issubclass(self.__model__, models.DomainModel):
15+
if not issubclass(self.__model_cls__, models.DomainModel):
1616
raise TypeError("Attribute __model__ must be subclass of "
1717
"DomainModel")
1818

19-
if not isinstance(model, self.__model__):
19+
if not isinstance(model, self.__model_cls__):
2020
raise TypeError("\"{0}\" is not an instance of {1}".format(
21-
model, self.__model__))
21+
model, self.__model_cls__))
2222

2323
self.__model__ = model
2424

tests/test_context_view.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Profile(models.DomainModel):
3030

3131
class PublicProfile(views.ContextView):
3232
"""Profile data in public context."""
33-
__model__ = Profile
33+
__model_cls__ = Profile
3434

3535
def _get_oid(self):
3636
"""Calculate open id.
@@ -60,7 +60,7 @@ def get_data(self):
6060

6161
class PrivateProfile(views.ContextView):
6262
"""Profile data in private context."""
63-
__model__ = Profile
63+
__model_cls__ = Profile
6464

6565
def _get_photos(self):
6666
photos = []
@@ -85,7 +85,7 @@ def get_data(self):
8585

8686
class PublicPhoto(views.ContextView):
8787
"""Photo data in public context."""
88-
__model__ = Photo
88+
__model_cls__ = Photo
8989

9090
def _get_oid(self):
9191
return self.__model__.id << 8
@@ -101,7 +101,7 @@ def get_data(self):
101101

102102

103103
class PrivatePhoto(views.ContextView):
104-
__model__ = Photo
104+
__model_cls__ = Photo
105105

106106
def get_data(self):
107107
return {
@@ -120,15 +120,15 @@ def get_data(self):
120120

121121
class WrongModelContext(views.ContextView):
122122
"""Wrong model defined."""
123-
__model__ = type
123+
__model_cls__ = type
124124

125125
def get_data(self):
126126
pass
127127

128128

129129
class GetterUndefinedContext(views.ContextView):
130130
"""Getter undefined."""
131-
__model__ = Profile
131+
__model_cls__ = Profile
132132

133133

134134
class TestContextView(unittest.TestCase):

0 commit comments

Comments
 (0)