コード例 #1
0
 def get(self):
     id = request.args['id']
     try:
         hacker = Hacker.get_by_id(id)
     except:
         abort(404, message = "Hacker not found")
     item = self.choose_next(hacker)
     if item != None:
         try:
             if hacker.next_proj != None and hacker.next_proj != item:
                 hacker.prev_proj = hacker.next_proj
             hacker.next_proj = item
             hacker.save()
         except:
             abort(409, message = "Unable to save next project to hacker")
         res = jsonify({
             "table": item.table,
             "title": item.name,
             "url": item.url
         })
         res.status_code = 200
         return res
     else:
         res = jsonify({"table": None})
         res.status_code = 200
         return res
コード例 #2
0
 def get(self):
     id = request.args['id']
     try:
         hacker = Hacker.get_by_id(id)
         if hacker.verified:
             res = jsonify({"verified": "True"})
             res.status_code = 200
             return res
         raise DoesNotExit()
     except DoesNotExist:
         res = jsonify({"verified": "False"})
         res.status_code = 200
         return res
コード例 #3
0
    def get(self, hacker_id, skill):

        self._current_user = self.require_login()
        if not self._current_user:
            self.response.out.write(json.dumps({"error": "please log in"}))
            return

        hacker = Hacker.get_by_id(hacker_id)
        if not hacker or hacker.user != self._current_user.id:
            self.response.out.write(json.dumps({"error": "could not find hacker or hacker not owned by you"}))
            return

        hacker.talents.append(skill)
        hacker.put()
        self.response.out.write(json.dumps({"success": "level up successful"}))
コード例 #4
0
 def post(self):
     id = request.args['id']
     try:
         hacker = Hacker.get_by_id(id)
     except:
         abort(404, message = "Hacker not found")
     if hacker.next_proj.table == int(request.args['table']):
         try:
             View.create(hacker = hacker, project = hacker.next_proj)
             res = jsonify({"status" : "View recorded"})
             res.status_code = 201
             return res
         except:
             abort(409, message = "Unable to submit view")
     else:
         abort(409, message = "Submission and database mismatch")
コード例 #5
0
    def post(self):
        id = request.args['id']
        code = request.args['code']
        try:
            hacker = Hacker.get_by_id(id)
            # If the account exists and is verified return an error
            if hacker.verified:
                abort(409, message="Hacker already verified")
        except DoesNotExist:
            abort(409, message="Verification not started")

        if code == hacker.verification and datetime.datetime.now(
        ) < hacker.verification_expiration:
            hacker.verified = True
            hacker.save()
            res = jsonify({"status": "Hacker verified", "code": 0})
            res.status_code = 201
            return res
        abort(403, message="Invalid or expired code")
コード例 #6
0
    def post(self):
        id = request.args['id']
        next_won = request.args['next_won'] == 'True'
        try:
            hacker = Hacker.get_by_id(id)
        except:
            abort(404, message = "Hacker not found")
        if hacker.prev_proj.table == int(request.args['prev_table']) and hacker.next_proj.table == int(request.args['next_table']):
            if hacker.prev_proj.active and hacker.next_proj.active:
                self.perform_vote(hacker, next_won)
                if next_won:
                    Vote.create(hacker = hacker, winner = hacker.next_proj, loser = hacker.prev_proj)
                else:
                    Vote.create(hacker = hacker, winner = hacker.prev_proj, loser = hacker.next_proj)
            hacker.prev_proj = None
            hacker.save()
            res = jsonify({"status" : "Vote recorded"})

            res.status_code = 201
            return res
        else:
            abort(409, message = "Submission and database mismatch")
コード例 #7
0
 def post(self):
     id = request.args['id']
     table = request.args.get('table', None)
     try:
         hacker = Hacker.get_by_id(id)
     except:
         abort(404, message = "Hacker not found")
     hacker.updated_vote = datetime.datetime.utcnow()
     if table != None:
         try:
             hacker.own_proj = Project.get_by_id(table)
             View.create(hacker = hacker, project = hacker.own_proj)
         except:
             abort(404, message = "Project not found")
     try:
         hacker.save()
     except:
         abort(501, message = "Unable to create hacker entry")
     status = {"status": "Setup hacker to start voting"}
     if table != None:
         status["title"] = Project.get_by_id(table).name
     res = jsonify(status)
     res.status_code = 201
     return res