def post(self):
        backer = toBacker(self.request.body)

        try :
            backer = self._backerService.CreateBacker(backer.email, backer.username, backer.password, backer.role)
        except ValueError:
            self.response.set_status(409) # TODO: Add a Process Request decorator that can handle RestApiResponses and return proper HTTP status from them
            return RestApiResponse.init('409')

        return RestApiResponse.init('200', backer)
    def get(self):
        proposalId = self.request.get('proposalId')
        results = self._proposalService.GetProposalById(proposalId)

        result = RestApiResponse.init('200', results)

        return result
    def get(self):
        domainId = self.request.get('domainId')
        results = self._proposalService.GetProposalsByDomainAndStatus(domainId, 'OPEN')

        result = RestApiResponse.init('200', results)

        return result
    def get(self):
        user = self.currentUser

        # Add some random properties to test db.Expando serialisation
        user.openProposals = ['test1', 'test2', 'test3']
        user.a_dyn_number  = 34533
        user.a_dyn_bool = True
        user.remaining_votes = [''] # Note: This should be ignored, and the original remaining_votes should be serialised
        # Note: Apparently db.Expando does not allow dict values
#        user.dynamicDict = {
#            "a_number": 1,
#            "a_string": "Hello, World!",
#            "a_bool": True
#        }

        return RestApiResponse.init('200', user)
    def get(self):
        result = None
        proposals = self._proposalService.GetProposalsByStatus('OPEN')

        #filter out proposals that have no votes
        for p in proposals:
            if p.totalRating > 0:
                if result is None:
                    result = []

                result.append(p)

        if result:
            #sort all voted proposals by totalRating DESC
            result = sorted(result, key=lambda Proposal: Proposal.totalRating, reverse=True)

            #keep only the top 3 proposals
            result = result[0:3]

        return RestApiResponse.init('200', result)
    def get(self):
        audits = self._auditService.GetAll()

        return RestApiResponse.init('200', audits)
    def viewPermissions(self):
        roles = db.GqlQuery('SELECT * FROM Role')

        return RestApiResponse.init('200', roles)
    def get(self):
        backer = self._backerService.GetBackerByEmail(self.currentUser.email)

        return RestApiResponse.init('200', backer)
    def get(self):
        result = self._domainService.GetDomainsByStatus("OPEN")

        return RestApiResponse.init("200", result)
    def get(self):
        backerId = int(self.request.get('backerId'))

        result = self._backerVoteService.GetBackerVotesByBackerId(backerId)

        return RestApiResponse.init('200', result)