Exemplo n.º 1
0
def guide(id=None):
    g.db = connect_db(app.config['USER_DB'])
    error=None
    guides=None
    content=None
    if id == None:
        cur = g.db.execute('select id, title, hero, heroname, score from guide where valid = ?', [1])
        guides = [dict(id=row[0], titre=row[1], hero=row[2], heroname=row[3], score=row[4]) for row in cur.fetchall()]
    else:
        if 'logged_in' in session:
            logged = 1
            droits = get_droits(session['user_id'])['guide']
        else:
            logged = 0
            droits = 0
        cur = g.db.execute('select title, hero, heroname, tag, difficulties, content_markup, autor, score, valid from guide where id = %i' % id)
        content = [dict(titre=row[0], hero=row[1], heroname=row[2], tag=row[3], difficulte=row[4], body=Markup(parse_balise(row[5], row[2])), auteur=row[6], score=row[7], valid=row[8])for row in cur.fetchall()]
        if len(content) == 0:
            flash("Guide inexistant")
            return redirect(url_for('guide'))
        content = content[0]
        if content['valid'] == 0 and droits == 0:
            flash("Guide inexistant")
            return redirect(url_for('guide'))
        cur = g.db.execute("select * from commentaire where id_genre = ? and genre like 'guide'", [id])
        commentaire = [dict(id=row[0],  auteur=row[3],
                            comment=Markup(row[5]))
                       for row in cur.fetchall()]
        return render_template('guide.html', error=error, content=content, guides=guides, id=id, commentaire=commentaire, logged=logged)
    return render_template('guide.html', error=error, content=content, guides=guides, id=id)
Exemplo n.º 2
0
def post_item(name=None):
    if 'logged_in' in session:
        uid = session['user_id']
        g.db = connect_db(app.config['USER_DB'])
        droits = get_droits(uid)
        g.db.close()
        if droits['adm'] == 1:
            if (request.method == 'POST'):
                g.db = connect_db(app.config['USER_DB'])
                cur = g.db.execute('select id from items where nam like ?',
                                   [request.form['nam']])
                entries = [dict(name=row[0]) for row in cur.fetchall()]
                if len(entries) == 0:
                    g.db.execute('insert into items (nam, price, recette, use_in, tooltip, tooltip_untouch, des, categorie) values (?, ?, ?, ?, ?, ?, ?, ?)',
                                 [request.form['nam'], request.form['prix'],
                                  request.form['recette'],
                                  request.form['use_in'],
                                  markdown.markdown(Markup.escape(request.form['tooltip'])),
                                  request.form['tooltip'],
                                  request.form['des'], request.form['categorie']])
                    g.db.commit()
                else:
                    g.db.execute('update items set price = ?, recette = ?, use_in = ?, tooltip = ?, tooltip_untouch = ?, des = ?, categorie = ? where nam like ?',
                                 [request.form['prix'],
                                  request.form['recette'],
                                  request.form['use_in'],
                                  markdown.markdown(Markup.escape(request.form['tooltip'])),
                                  request.form['tooltip'],
                                  request.form['categorie'], request.form['des']])
                    g.db.commit()
                g.db.close()
                return redirect(url_for('item', name = request.form['nam']))
            else:
                if name == None:
                    return render_template('post_item.html')
                else:
                    g.db = connect_db(app.config['USER_DB'])
                    cur = g.db.execute('select * from items where nam like ?',
                                       [name])
                    entries = [dict(id_item=row[0], nam=row[1], prix=row[2],
                                    recette=row[3], use_in=row[4],
                                    tooltip=row[6],
                                    des=row[7], cat=row[8]) for row in cur.fetchall()]
                    g.db.close()
                    if (len(entries) == 0):
                        return render_template('post_item.html')
                    else:
                        return render_template('post_item.html',
                                               entries = entries)
    return redirect(url_for('default'))
Exemplo n.º 3
0
def gestion_item(id=0):
    if 'logged_in' in session:
        uid = session['user_id']
        g.db = connect_db(app.config['USER_DB'])
        droits = get_droits(uid)
        g.db.close()
        if droits['adm'] == 1:
            if id != 0:
                delete_item(id)
                flash(u"L'objet a ete correctement supprime")
            g.db = connect_db(app.config['USER_DB'])
            cur = g.db.execute('select * from items order by id desc')
            entries = [dict(id=row[0], name=row[1]) for row in cur.fetchall()]
            g.db.close()
            return render_template("gestion_item.html", entries=entries)
    flash(u"Vous n'avez pas les droits")
    return redirect(url_for('default'))
def gestion_commentaire(id=0):
    if "logged_in" in session:
        uid = session["user_id"]
        g.db = connect_db(app.config["USER_DB"])
        droits = get_droits(uid)
        g.db.close()
        if droits["news"] == 1 or droits["adm"] == 1:
            if id != 0:
                delete_commentaire(id)
                flash(u"Le commentaire a ete correctemenet supprime")
            g.db = connect_db(app.config["USER_DB"])
            cur = g.db.execute("select * from commentaire order by id desc")
            entries = [dict(id=row[0], auteur=row[3], contenu=row[4]) for row in cur.fetchall()]
            g.db.close()
            return render_template("gestion_commentaire.html", entries=entries)
    flash(u"Vous n'avez pas les droits")
    return redirect(url_for("default"))
Exemplo n.º 5
0
def post_spell(name=None):
    if 'logged_in' in session:
        uid = session['user_id']
        g.db = connect_db(app.config['USER_DB'])
        droits = get_droits(uid)
        g.db.close()
        if droits['adm'] == 1:
            if name == None:
                if (request.method == 'POST'):
                    return redirect(url_for('post_spell',
                                            name = request.form['hero'],
                                            pos = request.form['pos_skill']))
                else:
                    g.db = connect_db(app.config['USER_DB'])
                    cur = g.db.execute('select nam from hero')
                    entries = [dict(name=row[0]) for row in cur.fetchall()]
                    g.db.close()
                    return render_template('post_spell.html', name=name,
                                           entries=entries, len=len(entries),
                                           i=0)
            else:
                if (request.method == 'POST'):
                    g.db = connect_db(app.config['USER_DB'])
                    if len(request.form['id']) == 0:
                        add_spell_base(name)
                    else:
                        update_spell_base(name)
                    g.db.close()
                    return redirect(url_for('hero', name=name))
                else:
                    g.db = connect_db(app.config['USER_DB'])
                    searchword = request.args.get('pos', '')
                    if searchword != '':
                        pos = int(searchword)
                    else:
                        pos = 1
                    cur = g.db.execute('select * from spells where name_hero like ? and pos = ? order by pos asc', [name, pos])
                    entries = [dict(id=row[0], name_hero=row[1],
                                    nam=row[2], tooltip=row[3],
                                    tooltip_untouch=row[4],
                                    pos=row[5]) for row in cur.fetchall()]
                    g.db.close()
                    return render_template('post_spell.html', name=name,
                                           entries=entries, pos=pos,
                                           len_entries=len(entries))
    return redirect(url_for('default'))
Exemplo n.º 6
0
def post_news(id_news=None):
    if 'logged_in' in session:
        uid = session['user_id']
        g.db = connect_db(app.config['USER_DB'])
        droits = get_droits(uid)
        g.db.close()
        if droits['news'] == 1:
            if (request.method == 'POST'):
                if request.form['mode_post'] == 'Previsualisation':
                    news = (Markup.escape(request.form['news']))
                    entries = dict(titre=request.form['titre'],
                                   news=request.form['news'],
                                   tag=request.form['tag'])
                    return render_template('post_news.html', entries=entries,
                                           prevu=1,
                                           id_news=id_news,
                                           titre=request.form['titre'],
                                           news=Markup(markdown.markdown(news)),
                                           tag=request.form['tag'])
                else:
                    if (id_news == None):
                        id_news = add_news()
                    else:
                        update_news(id_news)
                        return redirect(url_for('news', id_news=id_news))
            else:
                if (id_news == None):
                    return render_template('post_news.html')
                else:
                    g.db = connect_db(app.config['USER_DB'])
                    cur = g.db.execute('select * from news where id = ?',
                                       [id_news])
                    entries = [dict(titre=row[1], autor=row[2], tag=row[3],
                                    news=row[4]) for row in cur.fetchall()]
                    if len(entries) != 0:
                        return render_template('post_news.html',
                                               entries=entries[0],
                                               id_news=id_news)
                    else:
                        return render_template('post_news.html')
    
    return redirect(url_for('default'))
Exemplo n.º 7
0
def post_guide(id_guide=None):
    if 'logged_in' in session:
        uid = session['user_id']
        nameid = session['user_login']
        g.db = connect_db(app.config['USER_DB'])
        droits = get_droits(uid)
        heros = get_heros()
        g.db.close()
        herolen = len(heros)
        if id_guide != None:
            if isGuideCreator(nameid, id_guide) != True and droits['adm'] != 1:
                flash(u"Vous n'avez pas les droits pour éditer ce guide")
                return redirect(url_for('guide', id = id_guide))
        if (request.method == 'POST'):
            if request.form['mode_post'] == 'Previsualisation':
                guide = (Markup.escape(request.form['content']))
                hid = request.form['hero']
                titre=request.form['titre']
                content=request.form['content']
                tag=request.form['tag']
                diff = request.form['difficulte']
                g.db = connect_db(app.config['USER_DB'])
                heroname = get_heroName(request.form['hero'])
                g.db.close()
                return render_template('post_guide.html',
                                       previsualisation=1,
                                       guide=Markup(parse_balise(markdown(guide), heroname)),
                                       hero=heros, herolen=herolen, hid=hid,# heros liste
                                       titre=titre, tag=tag, content=content, diff=diff)
            else:
                val = valid_guide(heros)
                if val != True:
                    return val
                flash(u'Ce guide doit maintenant être validé, il sera disponible sous peu.')
                # mail_guide(id_guide)
                if (id_guide == None):
                    id_guide = add_guide(droits['guide'])
                else:
                    if droits['guide'] == 1 or droits['adm'] == 1:
                        drts = -1
                    else:
                        drts = 0
                    print "on update"
                    update_guide(id_guide, drts)
        else:
            if (id_guide == None):
                return render_template('post_guide.html', hero=heros, herolen=herolen)
            else:
                g.db = connect_db(app.config['USER_DB'])
                cur = g.db.execute('select title, autor, tag, difficulties, content_untouch from guide where id = ?',
                                   [id_guide])
                row = cur.fetchall()
                if len(row) != 0:
                    titre=row[0][0]
                    autor=row[0][1]
                    tag=row[0][2]
                    diff=row[0][3]
                    guide=row[0][4]
                    return render_template('post_guide.html',
                                           id_guide=id_guide,
                                           hero=heros, herolen=herolen,
                                           titre=titre, tag=tag, content=guide, diff=diff)
                else:
                    return render_template('post_guide.html', hero=heros, herolen=herolen)
    return redirect(url_for('guide', id=id_guide))
Exemplo n.º 8
0
def post_hero(name=None):
    if 'logged_in' in session:
        uid = session['user_id']
        g.db = connect_db(app.config['USER_DB'])
        droits = get_droits(uid)
        g.db.close()
        if droits['adm'] == 1:
            if (request.method == 'POST'):
                g.db = connect_db(app.config['USER_DB'])
                cur = g.db.execute('select id from hero where nam like ?',
                                   [request.form['nam']])
                entries = [dict(name=row[0]) for row in cur.fetchall()]
                if len(entries) == 0:
                    g.db.execute('insert into hero (nam, typ, des, bio, str_start, agi_start, int_start, str_lvl, agi_lvl, int_lvl, life, mana, damages, range, cast_speed, anim_speed, vision, armor, aspeed, ms) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
                                 [request.form['nam'], request.form['typ'],
                                  request.form['des'], request.form['bio'],
                                  request.form['str_start'],
                                  request.form['agi_start'],
                                  request.form['int_start'],
                                  request.form['str_lvl'],
                                  request.form['agi_lvl'],
                                  request.form['int_lvl'],
                                  request.form['life'], request.form['mana'],
                                  request.form['damages'],
                                  request.form['range'],
                                  request.form['cast_speed'],
                                  request.form['anim_speed'],
                                  request.form['vision'],
                                  request.form['armor'],
                                  request.form['aspeed'],
                                  request.form['ms']])
                    g.db.commit()
                else:
                    g.db.execute('update hero set typ = ?, des = ?, bio = ?, str_start = ?, agi_start = ?, int_start = ?, str_lvl = ?, agi_lvl = ?, int_lvl = ?, life = ?, mana = ?, damages = ?, range = ?, cast_speed = ?, anim_speed = ?, vision = ?, armor = ?, aspeed = ?, ms = ?, nam = ? where nam like ?',
                                 [request.form['typ'], request.form['des'],
                                  request.form['bio'],
                                  request.form['str_start'],
                                  request.form['agi_start'],
                                  request.form['int_start'],
                                  request.form['str_lvl'],
                                  request.form['agi_lvl'],
                                  request.form['int_lvl'],
                                  request.form['life'],
                                  request.form['mana'],
                                  request.form['damages'],
                                  request.form['range'],
                                  request.form['cast_speed'],
                                  request.form['anim_speed'],
                                  request.form['vision'],
                                  request.form['armor'],
                                  request.form['aspeed'],
                                  request.form['ms'], request.form['nam'],
                                  request.form['nam']])
                    g.db.commit()
                g.db.close()
                return redirect(url_for('hero', name = request.form['nam']))
            else:
                if name == None:
                    return render_template('post_hero.html')
                else:
                    g.db = connect_db(app.config['USER_DB'])
                    cur = g.db.execute('select * from hero where nam like ?',
                                       [name])
                    entries = [dict(id_hero=row[0], nam=row[1], typ=row[2],
                                    des=row[3], bio=row[4], str_start=row[5],
                                    agi_start=row[6], int_start=row[7],
                                    str_lvl=row[8], agi_lvl=row[9],
                                    int_lvl=row[10], life=row[11],
                                    mana=row[12], damages=row[13],
                                    rang=row[14], cast_speed=row[15],
                                    anim_speed=row[16], vision=row[17],
                                    armor=row[18], aspeed=row[19],
                                    ms=row[20]) for row in cur.fetchall()]
                    g.db.close()
                    if (len(entries) == 0):
                        return render_template('post_hero.html')
                    else:
                        return render_template('post_hero.html',
                                               entries = entries)
    return redirect(url_for('default'))
Exemplo n.º 9
0
def post_comment(id_genre=None):
    if 'logged_in' in session:
        if (request.method == 'POST'):
            if request.form['mode_post'].encode('utf-8') == 'Prévisualisation':
                entries = dict(genre=request.form['genre'],
                               id_genre=id_genre,
                               comment=request.form['comment'])
                return render_template('post_comment.html',
                                       entries=entries, comment=entries['comment'], id_comment=None, prevu=1)
            if request.form['mode_post'] == 'Edition':
                id_comment = request.args.get('id_comment', '')
                if id_comment != None:
                    g.db = connect_db(app.config['USER_DB'])
                    cur = g.db.execute('select * from commentaire where id = ?',
                                       [id_comment])
                    entries = [dict(id_genre=row[1], autor=row[3],
                                    genre=row[2], comment=row[4]) for row in cur.fetchall()]
                    if not (entries[0]['autor'] == session['user_login'] or (entries[0]['autor'] != session['user_login'] and get_droits(session['user_id'])['news'] == 1)
                            or (entries[0]['autor'] != session['user_login'] and get_droits(session['user_id'])['adm'] == 1)):
                        g.db.close()
                        return redirect(url_for('default'))
                    else:
                        g.db.close()
                        return render_template('post_comment.html',
                                               id_comment=id_comment,
                                               entries=entries[0])
            if request.form['mode_post'].encode('utf-8') == 'Avancé':
                print request.form['mode_post']
                entries = dict(genre=request.form['genre'],
                               id_genre=id_genre,
                               comment=request.form['comment'])
                return render_template('post_comment.html',
                                       entries=entries)
            temp = request.args.get('id_comment', '')
            if request.form['comment'] == '':
                if request.form['genre'] == 'news':
                    return redirect(url_for('news', id_news=id_genre))
                else:
                    return redirect(url_for('guide', id=id_genre))
            if (temp != ''):
                id_comment = int(temp)
            else:
                id_comment = 0
            if (id_comment != 0):
                g.db = connect_db(app.config['USER_DB'])
                cur = g.db.execute('select * from commentaire where id = ?', [id_comment])
                entries = [dict(id_genre=row[1], autor=row[4],
                                genre=row[2]) for row in cur.fetchall()]
                if not (entries[0]['autor'] == session['user_login'] or (entries[0]['autor'] != session['user_login'] and get_droits(session['user_id'])['news'] == 1)
                        or (entries[0]['autor'] != session['user_login'] and get_droits(session['user_id'])['adm'] == 1)):
                    g.db.close()
                    return redirect(url_for('default'))
                g.db.execute('update commentaire set content_untouch = ?, content_markup = ?, date_last_modif = ? where id = ?',
                             [request.form['comment'],
                              markdown.markdown(Markup.escape(request.form['comment'])),
                              datetime.today(), id_comment])
                g.db.commit()
                g.db.close()
                if (entries[0]['genre'] == 'news'):
                    return redirect(url_for('news', id_news=id_genre))
                else:
                    return redirect(url_for('guide', id=id_genre))
            g.db = connect_db(app.config['USER_DB'])
            g.db.execute('insert into commentaire (id_genre, genre, autor, content_untouch, content_markup, date_create, date_last_modif) values (?, ?, ?, ?, ?, ?, ?)',
                         [id_genre,
                          request.form['genre'],
                          session['user_login'],
                          request.form['comment'],
                          markdown.markdown(Markup.escape(request.form['comment'])),
                          datetime.today(), datetime.today()])
            g.db.commit()
            g.db.close()
            if (request.form['genre'] == 'news'):
                return redirect(url_for('news', id_news=id_genre))
            else:
                return redirect(url_for('guide', id=id_genre))
        else:
            return redirect(url_for('default'))
    else:
        return redirect(url_for('default'))