Esempio n. 1
0
 def deleteQuest(self, key):
     q = Quest.get_by_id(int(key))
     if q.creator == users.get_current_user():
         q.delete()
         return True
     else:
         return False
Esempio n. 2
0
    def addeditQuest(self, params):
        if params.has_key("key"):
            q = Quest.get_by_id(int(params["key"]))
            if not (q.creator == users.get_current_user()):
                return False
            q.name = params["name"]
        else:
            q = Quest(creator=users.get_current_user(), name=params["name"])

        q.desc = params["desc"]
        q.points = params["points"]
        q.tags = params["tags"]
        if params.has_key("opthotcold"):
            q.opthotcold = "checked"
        else:
            q.opthotcold = ""
        if params.has_key("optmap"):
            q.optmap = "checked"
        else:
            q.optmap = ""
        if params.has_key("optarrows"):
            q.optarrows = "checked"
        else:
            q.optarrows = ""
        if params.has_key("optdraft"):
            q.optdraft = "checked"
        else:
            q.optdraft = ""
        q.put()
        return modelrowtodict(q)
Esempio n. 3
0
def add(question, answer, game_id, id=None):
    game = Game.get_by_id(long(game_id))
    if game is None:
        raise Exception("game id: %s not found" % game_id)
    if id is not None:
        quest = Quest.get_by_id(long(id))
        quest.answer = answer
        quest.question = question
        quest_key = quest.put()
    else:
        quest_key = Quest(question=question, answer=answer, jog=game.key).put()

    return json.dumps({"quest_id": quest_key.id()})
Esempio n. 4
0
def answer_question(answer, tries, quest_id):
    response = {}
    quest = Quest.get_by_id(long(quest_id))
    if quest is None:
        raise Exception("the quest associated with %s doe not exists" % quest_id)
    if quest.answer.lower() == answer.lower():
        response['right'] = True
    else:
        response['right'] = False
    game = quest.jog.get()
    game_dict = game.to_dict()
    if tries < game_dict['qtd']:
        response['can_try_again'] = True
    else:
        response['can_try_again'] = False

    return JsonResponse(response)
Esempio n. 5
0
 def showQuest(self, key):
     return modelrowtodict(Quest.get_by_id(int(key)))
Esempio n. 6
0
def delete(quest_id):
    quest = Quest.get_by_id(long(quest_id))
    if quest is not None:
        quest.key.delete()
        return json.dumps({})
    raise Exception("quest id: %s not found" % quest_id)