コード例 #1
0
ファイル: views.py プロジェクト: dholth/pyramid-tutorial
def join(request):
    dbsession = DBSession()
    userid = request.params.get('userid')
    user = dbsession.query(User).filter_by(userid=userid).first()
    password = request.params.get('password')
    confirm = request.params.get('confirm')
    fullname = request.params.get('fullname')
    about = request.params.get('about')
    if user:
        return {'app_url': request.application_url,
            'static_url': request.static_url,
            'message': "The userid %s already exists." % userid,
            'userid': userid,
            'fullname': fullname,
            'about': about}
    if confirm != password:
        return {'app_url': request.application_url,
            'static_url': request.static_url,
            'message': "The passwords don't match.",
            'userid': userid,
            'fullname': fullname,
            'about': about}
    if len(password) < 6:
        return {'app_url': request.application_url,
            'static_url': request.static_url,
            'message': "The password is too short. Minimum is 6 characters.",
            'userid': userid,
            'fullname': fullname,
            'about': about}
    user = User(userid, password, fullname, about)
    dbsession.add(user)
    headers = remember(request, userid)
    return HTTPFound(location = '/',
                     headers = headers)
コード例 #2
0
def birdie_view(request):
    dbsession = DBSession()
    chirps = dbsession.query(Chirp).filter(Chirp.author==u'anonymous')
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'elapsed': get_elapsed,
            'chirps': chirps}
コード例 #3
0
ファイル: views.py プロジェクト: dholth/pyramid-tutorial
def birdie_post(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).one()
    chirp = request.params.get('chirp')
    author = user
    timestamp = datetime.utcnow()
    new_chirp = Chirp(chirp, author, timestamp)
    dbsession.add(new_chirp)
    return HTTPFound(location = '/')
コード例 #4
0
ファイル: views.py プロジェクト: cguardia/Pyramid-Tutorial
def birdie_view(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    chirps = dbsession.query(Chirp).filter(Chirp.author==user)
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'userid': userid,
            'user': user,
            'elapsed': get_elapsed,
            'chirps': chirps}
コード例 #5
0
def birdie_post(request):
    dbsession = DBSession()
    chirp = request.params.get('chirp')
    author = u'anonymous'
    timestamp = datetime.utcnow()
    new_chirp = Chirp(chirp, author, timestamp)
    dbsession.add(new_chirp)
    chirps = dbsession.query(Chirp).filter(Chirp.author==u'anonymous')
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'elapsed': get_elapsed,
            'chirps': chirps}
コード例 #6
0
def birdie_view(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    chirps = dbsession.query(Chirp).filter(Chirp.author == user)
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {
        'app_url': request.application_url,
        'static_url': request.static_url,
        'userid': userid,
        'user': user,
        'elapsed': get_elapsed,
        'chirps': chirps
    }
コード例 #7
0
ファイル: views.py プロジェクト: dholth/pyramid-tutorial
def user_chirps(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    matchdict = request.matchdict
    other_userid = matchdict.get('userid')
    other_user = dbsession.query(User).filter_by(userid=other_userid).first()
    url = route_url('users', request, userid=other_userid)
    if other_user is None:
        return HTTPNotFound(location=url)
    chirps = dbsession.query(Chirp).filter(Chirp.author==other_user)
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    follows = dbsession.query(Follower).filter(Follower.follower==other_user.id)
    follows = follows.order_by(Follower.follows.asc()).limit(10)
    followers = dbsession.query(Follower).filter(Follower.follows==other_user.id)
    followers = followers.order_by(Follower.follower.asc()).limit(10)
    followed = dbsession.query(Follower).filter(Follower.follower==user.id)
    followed = followed.filter(Follower.follows==other_user.id).first()
    follow_url = route_url('follow', request, userid=other_userid)
    unfollow_url = route_url('unfollow', request, userid=other_userid)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'userid': userid,
            'chirps': chirps,
            'user_chirps': True,
            'user': other_user,
            'original_user': user,
            'elapsed': get_elapsed,
            'follows': follows,
            'followers': followers,
            'followed': followed,
            'follow_url': follow_url,
            'unfollow_url': unfollow_url
        }
コード例 #8
0
ファイル: views.py プロジェクト: cguardia/Pyramid-Tutorial
def birdie_post(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).one()
    chirp = request.params.get('chirp')
    author = user
    timestamp = datetime.utcnow()
    new_chirp = Chirp(chirp, author, timestamp)
    dbsession.add(new_chirp)
    chirps = dbsession.query(Chirp).filter(Chirp.author==user)
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'elapsed': get_elapsed,
            'userid': userid,
            'user': user,
            'chirps': chirps}
コード例 #9
0
ファイル: views.py プロジェクト: cguardia/appsembler
def birdie_view(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    follows = dbsession.query(Follower).filter(Follower.follower == user.id)
    follows = follows.order_by(Follower.follows.asc()).limit(10)
    followers = dbsession.query(Follower).filter(Follower.follows == user.id)
    followers = followers.order_by(Follower.follower.asc()).limit(10)
    chirpers = [follow.follows for follow in follows]
    chirpers.append(user.id)
    chirps = dbsession.query(Chirp).filter(Chirp.author_id.in_(chirpers))
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    whomtofollow = dbsession.query(User).order_by(func.random()).limit(10)
    return {
        "app_url": request.application_url,
        "static_url": request.static_url,
        "userid": userid,
        "user": user,
        "elapsed": get_elapsed,
        "follows": follows,
        "followers": followers,
        "user_chirps": False,
        "whomtofollow": whomtofollow,
        "chirps": chirps,
    }
コード例 #10
0
ファイル: views.py プロジェクト: cguardia/appsembler
def join(request):
    dbsession = DBSession()
    userid = request.params.get("userid")
    user = dbsession.query(User).filter_by(userid=userid).first()
    password = request.params.get("password")
    confirm = request.params.get("confirm")
    fullname = request.params.get("fullname")
    about = request.params.get("about")
    if user:
        return {
            "app_url": request.application_url,
            "static_url": request.static_url,
            "message": "The userid %s already exists." % userid,
            "userid": userid,
            "fullname": fullname,
            "about": about,
        }
    if confirm != password:
        return {
            "app_url": request.application_url,
            "static_url": request.static_url,
            "message": "The passwords don't match.",
            "userid": userid,
            "fullname": fullname,
            "about": about,
        }
    if len(password) < 6:
        return {
            "app_url": request.application_url,
            "static_url": request.static_url,
            "message": "The password is too short. Minimum is 6 characters.",
            "userid": userid,
            "fullname": fullname,
            "about": about,
        }
    user = User(userid, password, fullname, about)
    dbsession.add(user)
    headers = remember(request, userid)
    return HTTPFound(location="/", headers=headers)
コード例 #11
0
ファイル: views.py プロジェクト: dholth/pyramid-tutorial
def unfollow(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    matchdict = request.matchdict
    other_userid = matchdict.get('userid')
    other_user = dbsession.query(User).filter_by(userid=other_userid).first()
    follower = user.id
    follows = other_user.id
    dbsession.query(Follower).filter(Follower.follower==follower).filter(Follower.follows==follows).delete()
    return HTTPFound(location = '/')
コード例 #12
0
ファイル: views.py プロジェクト: dholth/pyramid-tutorial
def follow(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    matchdict = request.matchdict
    other_userid = matchdict.get('userid')
    other_user = dbsession.query(User).filter_by(userid=other_userid).first()
    follower = user.id
    follows = other_user.id
    new_follower = Follower(follower, follows)
    dbsession.add(new_follower)
    return HTTPFound(location = '/')
コード例 #13
0
ファイル: views.py プロジェクト: cguardia/appsembler
def user_chirps(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    matchdict = request.matchdict
    other_userid = matchdict.get("userid")
    other_user = dbsession.query(User).filter_by(userid=other_userid).first()
    if other_user is None:
        return HTTPNotFound(location=url)
    url = route_url("users", request, userid=other_userid)
    chirps = dbsession.query(Chirp).filter(Chirp.author == other_user)
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    follows = dbsession.query(Follower).filter(Follower.follower == other_user.id)
    follows = follows.order_by(Follower.follows.asc()).limit(10)
    followers = dbsession.query(Follower).filter(Follower.follows == other_user.id)
    followers = followers.order_by(Follower.follower.asc()).limit(10)
    followed = dbsession.query(Follower).filter(Follower.follower == user.id)
    followed = followed.filter(Follower.follows == other_user.id).first()
    follow_url = route_url("follow", request, userid=other_userid)
    unfollow_url = route_url("unfollow", request, userid=other_userid)
    whomtofollow = dbsession.query(User).order_by(func.random()).limit(10)
    return {
        "app_url": request.application_url,
        "static_url": request.static_url,
        "userid": userid,
        "chirps": chirps,
        "user_chirps": True,
        "user": other_user,
        "original_user": user,
        "elapsed": get_elapsed,
        "whomtofollow": whomtofollow,
        "follows": follows,
        "followers": followers,
        "followed": followed,
        "follow_url": follow_url,
        "unfollow_url": unfollow_url,
    }
コード例 #14
0
def birdie_post(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).one()
    chirp = request.params.get('chirp')
    author = user
    timestamp = datetime.utcnow()
    new_chirp = Chirp(chirp, author, timestamp)
    dbsession.add(new_chirp)
    chirps = dbsession.query(Chirp).filter(Chirp.author == user)
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {
        'app_url': request.application_url,
        'static_url': request.static_url,
        'elapsed': get_elapsed,
        'userid': userid,
        'user': user,
        'chirps': chirps
    }
コード例 #15
0
ファイル: views.py プロジェクト: dholth/pyramid-tutorial
def birdie_view(request):
    dbsession = DBSession()
    userid = authenticated_userid(request)
    user = dbsession.query(User).filter_by(userid=userid).first()
    follows = dbsession.query(Follower).filter(Follower.follower==user.id)
    follows = follows.order_by(Follower.follows.asc()).limit(10)
    followers = dbsession.query(Follower).filter(Follower.follows==user.id)
    followers = followers.order_by(Follower.follower.asc()).limit(10)
    chirpers = [follow.follows for follow in follows]
    chirpers.append(user.id)
    chirps = dbsession.query(Chirp).filter(Chirp.author_id.in_(chirpers))
    chirps = chirps.order_by(Chirp.timestamp.desc()).limit(30)
    return {'app_url': request.application_url,
            'static_url': request.static_url,
            'userid': userid,
            'user': user,
            'elapsed': get_elapsed,
            'follows': follows,
            'followers': followers,
            'user_chirps': False,
            'chirps': chirps}
コード例 #16
0
ファイル: views.py プロジェクト: cguardia/Pyramid-Tutorial
def my_view(request):
    dbsession = DBSession()
    root = dbsession.query(MyModel).filter(MyModel.name==u'root').first()
    return {'root':root, 'project':'birdie'}
コード例 #17
0
def my_view(request):
    dbsession = DBSession()
    root = dbsession.query(MyModel).filter(MyModel.name == u'root').first()
    return {'root': root, 'project': 'birdie'}