Ejemplo n.º 1
0
def recstory(story_id):
    if "username" in session:
        if request.method == "POST":
            user = session["username"]

            s = dbsession.query(Story).filter_by(id=story_id).first()
            u = dbsession.query(User).filter_by(name=user).first()
            for rec in s.recs:
                if rec.uname == user:
                    flash("Cannot reccomend more than once.")
                    return redirect("/story/" + str(story_id))
            comment = request.form["comment"]
            rec = Reccomendation(comment)
            rec.uname = user
            rec.uid = u.id
            rec.sid = story_id
            rec.date = datetime.now()

            s.recs.append(rec)
            dbsession.add(s)
            dbsession.commit()
    return redirect("/story/" + str(story_id))
Ejemplo n.º 2
0
        story = dbsession.query(Story).filter_by(id=stories).first()
        for newtagid in xrange(0, 5):
            tag = dbsession.query(Tag).filter_by(id=random.randrange(99)).first()
            story.tags.append(tag)
        dbsession.commit()
        if stories % 500 == 0:
            print "Story " + str(stories) + " tagged."

    print "Adding faves"
    for user in xrange(1, 1000):
        u = dbsession.query(User).filter_by(id=user).first()
        for newfave in range(0, random.randrange(30)):
            s = dbsession.query(Story).filter_by(id=random.randrange(20000)).first()
            u.faves.append(s)
        dbsession.commit()
        if user % 100 == 0:
            print "User " + str(user) + " faves set."

    print "Adding between zero and thirty reccomendations to stories"
    for stories in xrange(1, 20000):
        story = dbsession.query(Story).filter_by(id=stories).first()
        for newrec in xrange(0, random.randrange(30)):
            rec = Reccomendation("this is a good story")
            rec.uid = random.randrange(99) + 1
            u = dbsession.query(User).filter_by(id=rec.uid).first()
            rec.uname = u.name
            rec.sid = story.id
            rec.date = datetime.now()
            story.recs.append(rec)
        dbsession.commit()