Issues (15)

app/views.py (1 issue)

1
import random
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
0 ignored issues
show
Comprehensibility Bug introduced by
vote is re-defining a name which is already available in the outer-scope (previously defined on line 24).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
26
    db.data.update({"id": int(v)}, {"$set": {"vote": vote}})
27
    return redirect(url_for('index'), 302)
28