Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_post_list_mentions(self):
        """Test getting a list of posts mentioning a user"""

        user1 = 'Contrary'
        user2 = 'Bobalooba'
        user3 = 'Mandible'

        posts = interface.post_list_mentions(self.db, usernick=user1)
        # should include only posts with @Contrary
        self.assertEqual(2, len(posts))
        self.assertListEqual([2, 5], [p[0] for p in posts])
Exemplo n.º 3
0
    def test_post_list_mentions(self):
        """Test getting a list of posts mentioning a user"""

        user1 = 'Contrary'
        user2 = 'Bobalooba'
        user3 = 'Mandible'

        posts = interface.post_list_mentions(self.db, usernick=user1)
        # should include only posts with @Contrary
        self.assertEqual(2, len(posts))
        self.assertListEqual([2, 5], [p[0] for p in posts])
Exemplo n.º 4
0
def mentions(who):
    """Generate a page that lists the mentions of a 
    given user"""
    db = COMP249Db()

    info = dict()
    info['title'] = "Mentions of " + who

    info['posts'] = interface.post_list_mentions(db, usernick=who)

    # re-use the index template since this is just a list of posts
    return template('index', info)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def mentions(user_name):
    """ Page that contains all posts with the given mention
    :param user_name: The username used in the mention
    :return: A page with posts containing the mention
    """
    posts = get_recent_posts(interface.post_list_mentions(db, user_name))
    dic = {
        "loginFailed": "False",
        "posts": posts,
        "name": user_name,
        "userpic": interface.user_get(db, user_name)[2]
    }
    dic.update(determine_user())
    return template("mentions.tpl", dic)
Exemplo n.º 7
0
def user_page(name):
    """
    Returns a page with all of the posts that contain @name in them
    """
    db = PsstDb()
    Mentions = interface.post_list_mentions(db, name, 50)
    mention = {
        'login': has_visited(),
        'searchVal': "",
        'usernamed': users.session_user(db),
        'title': name,
        'content': "Mentions for the user @" + name,
        'posts': Mentions
    }
    return template('index', mention)
Exemplo n.º 8
0
def tags(tag):

    db = COMP249Db()

    posts = interface.post_list_mentions(db, tag)
    html = ""

    if users.session_user(db):
        html += get_form("logout")

    for post in posts:
        html += format_post(post)

    avatar = '<img src="' + posts[0][3] + '" alt="avatar">'

    title = "Pssts about " + tag
    return template('general', title=title, root="tag/" + tag, content=html)
Exemplo n.º 9
0
def tags(tag):

    db = COMP249Db()

    posts = interface.post_list_mentions(db, tag)
    html = ""

    if users.session_user(db):
        html += get_form("logout")

    for post in posts:
        html += format_post(post)

    avatar = '<img src="' + posts[0][3] + '" alt="avatar">'

    title = "Pssts about " + tag
    return template('general', title=title, root="tag/" + tag, content=html)
Exemplo n.º 10
0
def mentions(name):

    db = COMP249Db()

    posts = interface.post_list_mentions(db, name)
    html = ""

    if users.session_user(db):
        html += get_form("logout")

    for post in posts:
        html += format_post(post)

    avatar = '<img src="' + posts[0][3] + '" alt="avatar">'

    title = name + "'s Mentions"
    return template('general', title=title, root="mentions/" + name, content=html)
Exemplo n.º 11
0
def mentions(username):
    """Generate the webpage that displays @users"""
    db = COMP249Db()
    uname = session_user(db) # retrieve user session information from the database
    private = "#private" # string that makes the post private
    loginString = ""
    content = ""
    http = ""
    list = interface.post_list_mentions(db, usernick=username, limit=50)
    list2 = interface.post_list(db, usernick=None, limit=50)
    str = ""
    str = "<h2>These pssts mentioned <b>" + username + "</b>:</h2>" # title
    if not uname:
        # display input field for username and password if the user not logged in
        loginString = "<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>"
        str = str + "<table>"
        for item in list:
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)
            if(bool(private.lower() in http.lower())==False): # not display the posts with the #private tag
                str = str + "<tr>"
                str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + item[
                    1] + "</i></br></br></td></tr>" # username and contents
        str = str + "</table>"
    if uname:
        at_user = "******" + uname
        for item in list2:
            if(uname==item[2]): # if user logged in, display his/her avatar, name, previous posts, the post mention, and logout option
                loginString = "<form action= '/logout' id='logoutform' name='logoutform' method='POST' ><table><tr><td><img src='" + item[4] + "' width='85'></td><td><h3>Logged in as " + uname + "</h3><p><a href='/users/" + uname + "'>Posted pssts</a></p><p><a href='/mentions/" + uname + "'>@me pssts</a></p><p><a href='javascript: document.logoutform.submit();'>Logout</a></p></td></tr></table></form>"
        str = str + "<table>"
        for item in list:
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)

            # this if situation is for private message feature
            if((bool(private.lower() in http.lower()) == False) | ((uname==item[2]) & (bool(private.lower() in http.lower()))) | ((bool(at_user.lower() in http.lower())) & (bool(private.lower() in http.lower())))):
                str = str + "<tr>"
                str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + item[
                    1] + "</i></br></br></td></tr>" # username and contents
        str = str + "</table>"
    return template('base.tpl', base=str, validate='', login=loginString)
Exemplo n.º 12
0
def posts(user):
    db = COMP249Db()
    cont = interface.post_list_mentions(
        db, user, 50
    )  # grab the posts from the database which mention the user specified
    posts = []
    for row in cont:
        li = list(row)  #converting each tuple into a list
        print(li[4])
        li[4] = interface.post_to_html(
            li[4])  #converting the post message into suitable html
        posts.append(
            li)  #populating a list with data ready to display in the template
        print(li)
    print('posts below')
    print(posts)
    return template(os.path.join('views', 'general'),
                    title="Welcome to Psst!",
                    content=posts)
Exemplo n.º 13
0
def mentions(name):

    db = COMP249Db()

    posts = interface.post_list_mentions(db, name)
    html = ""

    if users.session_user(db):
        html += get_form("logout")

    for post in posts:
        html += format_post(post)

    avatar = '<img src="' + posts[0][3] + '" alt="avatar">'

    title = name + "'s Mentions"
    return template('general',
                    title=title,
                    root="mentions/" + name,
                    content=html)
Exemplo n.º 14
0
def mentions_page(usernick):
    """generate the users posts"""
    mentions_posts = interface.post_list_mentions(db, usernick)
    return template('general', title="Posts mentioning " + usernick, posts=mentions_posts)