Skip to content

Instantly share code, notes, and snippets.

@brianz
Last active September 15, 2016 21:03
Show Gist options
  • Save brianz/91b2a58709d569443aab5b98aaa38e0b to your computer and use it in GitHub Desktop.
Save brianz/91b2a58709d569443aab5b98aaa38e0b to your computer and use it in GitHub Desktop.
import servant.fields
from servant.exceptions import ActionError
from servant.exceptions import ServantException
from servant.service.actions import Action
class AddAction(Action):
number1 = servant.fields.IntField(
required=True,
)
number2 = servant.fields.IntField(
required=True,
)
result = servant.fields.IntField(
in_response=True,
)
def run(self, **kwargs):
self.result = self.number1 + self.number2
class SubtractAction(AddAction):
def run(self, **kwargs):
self.result = self.number1 - self.number2
class DivideAction(Action):
numerator = servant.fields.DecimalField(
required=True,
in_response=True,
)
denominator = servant.fields.DecimalField(
required=True,
in_response=True,
)
quotient = servant.fields.DecimalField(
in_response=True,
)
def run(self, **kwargs):
if self.denominator == 0:
raise ActionError('Cannot divide by zero')
self.quotient = self.numerator / self.denominator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment