Exemple #1
0
def delete_cardbox(_id):
    box = CardBox.fetch(db, _id)

    if not box:
        flash('Invalid Cardbox ID.', 'error')
        return redirect(url_for('index'))

    if box._id not in current_user.cardboxs:
        flash('You can only delete cardboxes that you own.', 'error')
        return redirect(url_for('show_box', _id=_id))

    form = ConfirmationForm()
    form.submit.label.text = 'Delete'
    message = 'Are you sure you want to delete CardBox ' + box.name + '?'

    if form.is_submitted():

        CardBox.delete(db, _id)

        current_user.cardboxs.remove(box._id)

        current_user.store(db)
        User.update_score(db, current_user._id)

        flash("Successfully removed CardBox")
        return redirect(
            url_for('huge_list', foption='owner', fterm=current_user._id))

    return render_template('_confirm.html',
                           message=message,
                           address='show_box',
                           add_kwargs={'_id': _id},
                           form=form)
Exemple #2
0
def confirm_challenge(user_id, box_id):
    box = CardBox.fetch(db, box_id)

    if not box:
        flash('Invalid Cardbox ID.', 'error')
        return redirect(url_for('challenge_user', _id=user_id))

    if user_id == current_user._id:
        flash('You can not even challenge yourself. Nice try.', 'error')
        return redirect(url_for('user_list'))

    user = User.fetch(db, user_id)

    if not user:
        flash('Invalid User ID.', 'error')
        return redirect(url_for('user_list'))

    form = ConfirmationForm()
    form.submit.label.text = 'Challenge'
    message = 'Challenge ' + user_id + ' to duel ' + box.name + '?'

    if form.is_submitted():
        challenge.challenge(db, current_user._id, user._id, box._id)
        flash('Challenge request sent!')
        return redirect(url_for('challenge_list', requests='sent'))

    return render_template('_confirm.html',
                           message=message,
                           address='challenge_user',
                           add_kwargs={'_id': user_id},
                           form=form)
Exemple #3
0
def download_cardbox(_id: str):
    box = CardBox.fetch(db, _id)

    if not box:
        abort(404)

    return jsonify(vars(box))
Exemple #4
0
def preview_box(_id):
    box = CardBox.fetch(db, _id)

    if not box:
        flash('Invalid Cardbox ID.', 'error')
        return redirect(url_for('huge_list'))

    return render_template('preview_box.html', box=box)
Exemple #5
0
def show_box(_id):
    box = CardBox.fetch(db, _id)

    if not box:
        flash('Invalid Cardbox ID.', 'error')
        return redirect(url_for('huge_list'))

    owned = box.owner == current_user._id

    return render_template('show_box.html', box=box, owned=owned)
Exemple #6
0
def download_cardbox(_id: str):
    box = CardBox.fetch(db, _id)

    if not box:
        abort(404)

    content = Card.fetch_content_to_list(db, _id)
    vars_box = vars(box)
    vars_box['content'] = content

    # use flask jsonify to create valid json response
    return jsonify(vars_box)
Exemple #7
0
def rate_cardbox(_id):
    box = CardBox.fetch(db, _id)

    if not box:
        flash('Invalid Cardbox ID.', 'error')
        return redirect(url_for('index'))

    if box.increment_rating(db, current_user):
        User.update_score(db, box.owner)
        flash('Successfully rated. Thank you for your appreciation! :3')
        return redirect(url_for('show_box', _id=_id))

    flash("Already rated. Don't try to fool us!", 'error')
    return redirect(url_for('show_box', _id=_id))
Exemple #8
0
def show_user(_id):
    if not User.exists(db, _id):
        flash('Invalid User Name.'
              'Be the first User to have this name! :D', 'error')
        return redirect(url_for('index'))

    score = User.update_score(db, _id)

    user = User.fetch(db, _id)
    picture_filepath = utils.profile_img_path(app, user._id)

    # <-- Showcase -->
    showcase = dict(info=False, cardbox=False, rank=False)

    infocase = user.showcase
    if infocase['show_info']:
        showcase['info'] = infocase['info']
    if infocase['show_cardbox']:
        box = CardBox.fetch(db, infocase['cardbox'])
        if box:
            showcase['cardbox'] = box
        else:
            showcase['cardbox'] = 'string'
    if infocase['show_rank']:
        showcase['rank'] = user.get_rank(db)

    # <-- my own profile? -->
    if user._id == current_user._id:
        return render_template('show_user_myself.html',
                               user=user,
                               showcase=showcase,
                               picture_filepath=picture_filepath,
                               score=score,
                               active='profile')

    return render_template('show_user.html',
                           user=user,
                           active='community',
                           picture_filepath=picture_filepath,
                           showcase=showcase,
                           score=score,
                           following=current_user.is_following(_id))
def challenge(db, challenger_id, challenged_id, box_id):
    new_duel_id = gen_duel_id()

    box = CardBox.fetch(db, box_id)
    content = Card.fetch_content(db, box_id)

    vs_dict = dict(duel_id=new_duel_id,
                   challenger=challenger_id,
                   challenged=challenged_id,
                   box_id=box_id,
                   box_name=box.name,
                   box_content=content,
                   started=False,
                   finish_time=None,
                   winner='')

    db.hset(TABLE_VS, new_duel_id, json.dumps(vs_dict))
    db.rpush(challenger_id + CHALLENGE_SUFFIX, new_duel_id)
    db.rpush(challenged_id + CHALLENGE_SUFFIX, new_duel_id)

    return new_duel_id