Example #1
0
def not_found_handler(request):
    request.write(
        render(
            '404.html', {
                'users': db.User.find_all(),
                'signed_in': authenticate_cookie(request),
                'username': get_username(request)
            }))
Example #2
0
def handle_list_users(request):
    request.write(
        render(
            'list_users.html', {
                'users': db.User.find_all(),
                'signed_in': authenticate_cookie(request),
                'username': get_username(request)
            }))
Example #3
0
def ask_handler(request):
    name = request.get_field("name")
    request.write(
        render(
            "ask.html", {
                'signed_in': authenticate_cookie(request),
                'username': get_username(request)
            }))
Example #4
0
def signin_handler(request):
    username = request.get_field('username')
    password = request.get_field('password')
    signin = {
        'username': username,
        'password': password,
        'signed_in': authenticate_cookie(request),
        'username': get_username(request)
    }
    request.write(render('signin.html', signin))
Example #5
0
def signup_handler(request):
    request.write(
        render(
            'signup.html', {
                'signed_in': authenticate_cookie(request),
                'username': get_username(request)
            }))
    ident = request.get_field('id')
    username = request.get_field('username')
    email = request.get_field('email')
    password = request.get_field('password')
    doc = request.get_field('doc')
    gender = request.get_field('gender')
    dob = request.get_field('dob')
    if username is not None:
        request.set_secure_cookie("current_user", username)
Example #6
0
def index_handler(request):
    posts = db.Post.find_all()
    if not posts: posts = []
    posts = [{
        'image': i.file if i.file != [] else 'notfound.jpg',
        'question': i.title,
        'id': i.id
    } for i in posts]
    request.write(
        render(
            'index.html', {
                'posts': posts,
                'signed_in': authenticate_cookie(request),
                'username': get_username(request),
                'link': 'view/()'
            }))  # { 'post1': (image location, comment}
Example #7
0
def view_handler(request, username):
    user = db.User.find_by_username(username)
    if user is None:
        request.write("username is not in db")
    else:
        request.write(
            render(
                'profile.html', {
                    'user':
                    user,
                    'picture':
                    get_picture(user),
                    'signed_in':
                    authenticate_cookie(request),
                    'same_user':
                    authenticate_correct_username(request, user.username),
                    'username':
                    user.username
                })
        )  # username required for pages that do not build a user object
Example #8
0
def view_question_handler(request, question_id):
    # try:
    post = db.Post.find(question_id)
    post_info = {
        'user': post.user,
        'description': post.description,
        'question': post.title,
        'date': post.date,
        'file': post.file,
        'signed_in': authenticate_cookie(request),
        'username': get_username(request),
        'comments': post.all_comments(),
        'user_ids': db.User.find_all(),
        'photo_id': post.id,
    }
    for i in post_info['comments']:
        curuser = i.user
        print(curuser.picture)
        i.image = path.join("uploads", "user_image", curuser.picture) if curuser.picture else ""

    request.write(render('view_question.html', post_info))