Issues (15)

app/views.py (1 issue)

1
import random
0 ignored issues
show
There seems to be a cyclic import (app -> app.views).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
2
3
from flask import render_template, url_for, redirect
4
from pymongo import MongoClient
5
6
from . import app
7
8
base = 'mongodb://localhost:21017'
9
10
client = MongoClient(base)
11
db = client["facemash"]
12
13
14
@app.route('/')
15
def index():
16
    f = db.data.find_one({"id": random.randint(1, db.data.count())})
17
    s = db.data.find_one({"id": random.randint(1, db.data.count())})
18
    if f == s:
19
        s = db.data.find_one({"id": random.randint(1, db.data.count())})
20
    return render_template('index.html', first=str(f["id"]), second=str(s["id"]))
21
22
23
@app.route('/vote/<v>')
24
def vote(v):
25
    vote = db.data.find_one({"id": int(v)})["vote"] + 1
26
    db.data.update({"id": int(v)}, {"$set": {"vote": vote}})
27
    return redirect(url_for('index'), 302)
28