Skip to content

Commit cc2f337

Browse files
committed
Add __expects__ and __returns__ to forms (#112)
1 parent 174d980 commit cc2f337

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

baseframe/forms/form.py

+12
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,17 @@ class Form(BaseForm):
6767
"""
6868
Form with additional methods.
6969
"""
70+
__expects__ = ()
71+
__returns__ = ()
72+
7073
def __init__(self, *args, **kwargs):
7174
super(Form, self).__init__(*args, **kwargs)
75+
76+
for attr in self.__expects__:
77+
if attr not in kwargs:
78+
raise TypeError("Expected parameter %s was not supplied" % attr)
79+
setattr(self, attr, kwargs.pop(attr))
80+
7281
# Make editing objects easier
7382
self.edit_obj = kwargs.get('obj')
7483
self.edit_model = kwargs.get('model')
@@ -88,6 +97,9 @@ def __init__(self, *args, **kwargs):
8897

8998
def validate(self, send_signals=True):
9099
result = super(Form, self).validate()
100+
for attr in self.__returns__:
101+
if not hasattr(self, attr):
102+
setattr(self, attr, None)
91103
if send_signals:
92104
self.send_signals()
93105
return result

0 commit comments

Comments
 (0)