示例#1
0
    signed_requests = False

    def action(self, test):
        dividend = self.cleaned_data.get('dividend')
        divisor = self.cleaned_data.get('divisor')
        try:
            return float(dividend) / float(divisor)
        except ZeroDivisionError:
            self.add_error("DIVISION BY ZERO, OH SHIIIIII")


class ProgrammingLanguages(calls.APICall):
    RUBY = 'ruby'
    PYTHON = 'python'
    JAVA = 'java'
    LANGUAGES = (
        (RUBY, 'Freshman'),
        (PYTHON, 'Sophomore'),
        (JAVA, 'Junior')
    )
    languages = forms.MultipleChoiceField(choices=LANGUAGES)

    def action(self, test):
        return u'Good for you'


API.register(AuthenticateUserCall, 'user', 'authenticate', version='v1.0.0')
API.register(DivisionCall, 'math', 'divide', version='v1.0.0')
API.register(ProgrammingLanguages, 'comp', 'lang', version='v1.0.0')
示例#2
0
        if self.user_cache:
            return self.user_cache.id
        return None

    def get_user(self):
        return self.user_cache


class DivisionCall(calls.APICall):
    """
    Returns the quotient of two integers
    """
    dividend = forms.IntegerField()
    divisor = forms.IntegerField()

    signed_requests = False

    def action(self, test):
        dividend = self.cleaned_data.get('dividend')
        divisor = self.cleaned_data.get('divisor')
        try:
            return float(dividend) / float(divisor)
        except ZeroDivisionError:
            self.add_error("DIVISION BY ZERO, OH SHIIIIII")

API.register(AuthenticateUserCall, 'user', 'authenticate', version='v1.0.0')
API.register(DivisionCall, 'math', 'divide', version='v1.0.0')



示例#3
0
    """

    dividend = forms.IntegerField()
    divisor = forms.IntegerField()

    signed_requests = False

    def action(self, test):
        dividend = self.cleaned_data.get("dividend")
        divisor = self.cleaned_data.get("divisor")
        try:
            return float(dividend) / float(divisor)
        except ZeroDivisionError:
            self.add_error("DIVISION BY ZERO, OH SHIIIIII")


class ProgrammingLanguages(calls.APICall):
    RUBY = "ruby"
    PYTHON = "python"
    JAVA = "java"
    LANGUAGES = ((RUBY, "Freshman"), (PYTHON, "Sophomore"), (JAVA, "Junior"))
    languages = forms.MultipleChoiceField(choices=LANGUAGES)

    def action(self, test):
        return u"Good for you"


API.register(AuthenticateUserCall, "user", "authenticate", version="v1.0.0")
API.register(DivisionCall, "math", "divide", version="v1.0.0")
API.register(ProgrammingLanguages, "comp", "lang", version="v1.0.0")