Exemplo n.º 1
0
def refresh(siteid=-1):
    if siteid >= 0:
        site = Site.query.filter(Site.id == siteid).first()
        capture(site)
        resize(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots', '%s.png' % site.id))
        site.screenshot = '%s.png' % site.id
        db.session.commit()
        return redirect(url_for('index', catid=site.id_cat))
    else:
        return ""
Exemplo n.º 2
0
def add(catid):
    categories = Category.query.order_by(Category.order, Category.title).all()

    if request.method == 'GET':
        return render_template('add.html', current_cat=catid, categories=categories)
    elif request.method == 'POST':
        last = Site.query.filter(Site.id_cat == catid).order_by(Site.order.desc()).first()
        if last is None or last.order is None:
            last = 0
        else:
            last = last.order
        site = Site(request.form['url'], request.form['title'], last + 1, catid)
        db.session.add(site)
        db.session.commit()

        capture(site)
        resize(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots/', '%s.png' % site.id))

        site.screenshot = '%s.png' % site.id
        db.session.commit()
        return redirect(url_for('index', catid=catid))