enotcode /
facemash
| 1 | import random |
||
|
0 ignored issues
–
show
|
|||
| 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
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 |
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.