Exemple #1
0
def search():
    """Search feature, can search user name and / or contents"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    loginString = ""
    content = ""
    http = ""
    avatar = ""

    if 'search' in request.forms:
        search = request.forms['search'] # get user inputs from the search field
        str = "<h2>Search results for '" + search + "':</h2>" # title
        list = interface.post_list(db, usernick=None, limit=50)
        if not username: # display the things below only if user not logged in
            # display input field for username and password if the user not logged in
            loginString = "<h3>member login</h3></br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"

        if username: # display the things below only if user logged in
            avatar = interface.user_avatar(db,username)
            loginString = "<a href='/users/" + username + "'><img src='" + avatar + "'><h3 style='text-align:center; margin-left:0px;'>" + username + "</h3></a><br><form action= '/logout' id='logoutform' name='logoutform' method='POST' ><input type='submit' value='logout' class='sun-flower-button'></form>"

        for item in list:
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)
            dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
            dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
            if ((bool(search.lower() in item[2].lower())) | (bool(search.lower() in http.lower()))):
                str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display

        return template('base.tpl', base=str, validate='', login=loginString)
Exemple #2
0
def mentions(username):
    """Generate the webpage that displays @users"""
    db = COMP249Db()
    uname = session_user(db) # retrieve user session information from the database
    loginString = ""
    content = ""
    http = ""
    list = interface.post_list_mentions(db, usernick=username, limit=50)
    str = ""
    avatar = ""

    str = "<h2>Posts mentioned " + username + ":</h2>" # title
    if not uname:
        # display input field for username and password if the user not logged in
        loginString = "<h3>member login</h3></br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"

    if uname:
        avatar = interface.user_avatar(db,uname)
        loginString = "<a href='/users/" + uname + "'><img src='" + avatar + "'><h3 style='text-align:center; margin-left:0px;'>" + uname + "</h3></a><br><form action= '/logout' id='logoutform' name='logoutform' method='POST' ><input type='submit' value='logout' class='sun-flower-button'></form>"

    for item in list:
        content = interface.post_to_html(item[3])
        http = interface.post_to_html(content)
        dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
        dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
        str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display

    return template('base.tpl', base=str, validate='', login=loginString)
Exemple #3
0
def index():
    """Index of Psst site"""
    db = COMP249Db()
    username = session_user(db)
    loginString = ""
    content = ""
    http = ""
    str = ""
    avatar = ""
    list = interface.post_list(db, usernick=None, limit=50)

    # if user not logged in
    if not username:
        # display input field for username and password if the user not logged in
        loginString = "<h3>member login</h3><br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"

    # if user logged in
    if username:
        avatar = interface.user_avatar(db,username)
        # display the input field for adding posts instead of the title
        str = str + "<form action='/post' id='postform' method='POST'><input type='postfield' name='post' placeholder='post content, formats: [i]image urls[/i][t]title[/t][p]contents[/p]#tags #tags2' value='[i]image urls[/i][t]title[/t][p]contents[/p]#tags #tags2' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        loginString = "<a href='/users/" + username + "'><img src='" + avatar + "'><h3 style='text-align:center; margin-left:0px;'>" + username + "</h3></a><br><form action= '/logout' id='logoutform' name='logoutform' method='POST' ><input type='submit' value='logout' class='sun-flower-button'></form>"

    for item in list:
        content = interface.post_to_html(item[3])
        http = interface.post_to_html(content)
        dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
        dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
        str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display

    return template('base.tpl', base=str, validate='', login=loginString)
Exemple #4
0
def about():
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': 'About',
        'header': 'About Psst!',
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    return template('views/about.html', info)
Exemple #5
0
def index(login=None):
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': 'Welcome to Psst!',
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_list(COMP249Db())
    return template('views/index.html', info)
Exemple #6
0
def mentionspage(name):
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': name + "'s mentions",
        'header': 'Posts that mention ' + name,
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_list_mentions(COMP249Db(), name)
    return template('views/mentions.html', info)
Exemple #7
0
def myPosts():
    user = users.session_user(COMP249Db())
    searchkey = request.forms.get('searchbar')
    info = {
        'title': 'Psst!',
        'message': "Search",
        'header': 'Posts with "' + searchkey + '"',
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_search(COMP249Db(), searchkey)
    print(info['posts'])
    return template('views/search.html', info)