コード例 #1
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()})
コード例 #2
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
コード例 #3
0
ファイル: criar.py プロジェクト: IuryAlves/Novos-Bandeirantes
def inserir(**propriedades):
    quest_form = QuestForm(**propriedades)
    erro = quest_form.validate()
    if erro:
            contexto={'criar_modelo': router.to_path(salvar),
                      'quest': quest_form,
                      'erro': erro}
            return TemplateResponse(contexto, 'criar/criandoform.html')
    else:
        questao = Quest(**propriedades)
        query = Game.query(Game.tit == titulo)
        if query is not None:
            jogos = query.fetch()
        for j in jogos:
            questao.jog.append(j.key)
        questao.put()
        return RedirectResponse(router.to_path(continuar))
コード例 #4
0
 def listQuests(self):
     qs = Quest.all()
     qs.order("name")
     listResults = modelfetchtoarray(qs.fetch(500))
     if len(listResults) > 0:
         return listResults
     else:
         return True
コード例 #5
0
ファイル: server.py プロジェクト: willproctor/KidQuestServer
def add_quest_to_user(user_id):
    user = User.query.get(user_id)
    verify_user(user)

    if request.method == 'GET':
        return jsonify(quests=[q.serialize() for q in user.quests])

    elif request.method == 'POST':
        required_json = ['title', 'difficulty_level']
        json = request.json

        if not valid_json(json, required_json):
            abort(400)

        diff = json.get('difficulty_level')
        quest = Quest(title=json.get('title'), user_id=user_id, difficulty_level=diff)
        if 'expiry_date' in json:
            quest.expiry_date = json.get('expiry_date')
        quest.xp_reward = calculate_xp_reward(diff, user)
        quest.gold_reward = calc_triangular_difficulty(diff)

        if json['description']:
            quest.description = json['description']

        db.session.add(quest)
        db.session.commit()

        notify_if_partner("A new quest is available!")

        return jsonify(quest.serialize()), 201
コード例 #6
0
ファイル: jogar.py プロジェクト: IuryAlves/Novos-Bandeirantes
def index(_logged_user, game_id):
    game = Game.get_by_id(long(game_id))
    quests = Quest.query().fetch()
    quest_list = [quest.to_dict(exclude=["jog"]) for quest in quests if quest.jog.id() == game.key.id()]
    dict_ = {
        'game': json.dumps(game.to_dict()),
        'quests': json.dumps(quest_list)
    }
    return TemplateResponse(context=dict_, template_path="jogar/jogar.html")
コード例 #7
0
 def listMyQuests(self):
     qs = Quest.all()
     qs.filter("creator =", users.get_current_user())
     qs.order("name")
     listResults = modelfetchtoarray(qs.fetch(500))
     if len(listResults) > 0:
         return listResults
     else:
         return True
コード例 #8
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)
コード例 #9
0
def pergunta(game_id):
    quest_form = QuestForm()
    quests = [quest_form.fill_with_model(quest) for quest in Quest.query().fetch()]

    return TemplateResponse({"quests": quests, "game_id": game_id}, template_path="gerenciar/pergunta.html")
コード例 #10
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)
コード例 #11
0
 def showQuest(self, key):
     return modelrowtodict(Quest.get_by_id(int(key)))
コード例 #12
0
ファイル: quests.py プロジェクト: roloenusa/CST363Common
alerts = []

character_id = False
quest_id = False

if 'create' in form:
    type_id = int(form["type_id"].value.strip())
    title = form["title"].value.strip()
    description = form["description"].value.strip()
    reward = int(form["reward"].value.strip())
    xp = int(form["xp"].value.strip())
    try:
        Quest.Create(type_id=type_id,
                     title=title,
                     description=description,
                     reward=reward,
                     xp=xp)
    except Exception as e:
        alerts.append(('danger', e))

if 'character_id' in form:
    character_id = form['character_id'].value

if 'quest_id' in form:
    quest_id = form['quest_id'].value

if character_id and quest_id:
    res = QuestLog.AddQuest(character_id, quest_id)
    if res:
        alerts.append(('success', "Quest added!"))
コード例 #13
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)
コード例 #14
0
def all(game_id):
    game = Game.get_by_id(long(game_id))
    if game is not None:
        quests = Quest.query(Quest.jog==game.key).fetch()
        return JsonResponse([quest.to_dict(exclude=["jog"]) for quest in quests])
    raise Exception("game id: %s not found" % game_id)