コード例 #1
0
    def test_get_user_details(self):
        """The get_user_details procedure returns user first and last name given
        the email address"""

        for email, password, nick, avatar in self.users:

            stored_nick, stored_avatar = interface.get_user_details(self.db, email)

            self.assertEqual(nick, stored_nick)
            self.assertEqual(avatar, stored_avatar)

        # test an unknown user
        result = interface.get_user_details(self.db, "*****@*****.**")
        self.assertEqual(result, None, "Expected None result for unknown user in get_user_details")
コード例 #2
0
def comments(comment_list):
    # Function to add comments from a tuple of tuples
    comment_page = ""
    if comment_list != None:
        for id, useremail, page, comment in comment_list:
            user_details = interface.get_user_details(db, useremail)
            if user_details[1] == 'mary':
                # Get picture of mary online
                avatar_url = 'http://i.imgur.com/AVSXTkb.png'
            elif user_details[1] == 'bob':
                # Get picture of bob online
                avatar_url = 'http://i.imgur.com/ReA9ucT.png'
            else:
                # Get picture of default only
                avatar_url = 'http://i.imgur.com/PTkEfBS.png'
            comment_page += "<TABLE><TR><TH><H3><IMG SRC='%s' ALT='' HEIGHT ='60' WIDTH = '60'> %s commented on " % (
                avatar_url, user_details[0])
            webpage = str(page).replace('http://', '')
            comment_page += "<A HREF='%s'> %s </A> &nbsp&nbsp&nbsp" % (
                str(page), webpage)
            url = "http://localhost:8000/conversation?page=" + urllib.quote(
                str(page), safe='')
            comment_page += "<A HREF='%s' TITLE = 'View all comments on this webpage'>(View all) </A> </H3></TH></TR>" % (
                url)
            comment_page += "<TR><TD> %s </TD></TR></TABLE><BR>" % (
                str(comment))
    return comment_page
コード例 #3
0
    def test_get_user_details(self):
        """The get_user_details procedure returns user first and last name given
        the email address"""

        for email, password, nick, avatar in self.users:

            stored_nick, stored_avatar = interface.get_user_details(
                self.db, email)

            self.assertEqual(nick, stored_nick)
            self.assertEqual(avatar, stored_avatar)

        # test an unknown user
        result = interface.get_user_details(self.db, '*****@*****.**')
        self.assertEqual(
            result, None,
            'Expected None result for unknown user in get_user_details')
コード例 #4
0
def topnav(environ):
    # Function that defines the top navigation bar, and what appears in it.
    session = str(interface.user_from_cookie(db, environ))
    if session == 'None':
        topnav = """ 
        <DIV ID='topnav'>
            <DIV CLASS='topleft'>
                <UL>
                    <H3><LI><A HREF='/' TITLE='Philip's Webpage'> Philip </A></LI></H3>
                    <DIV CLASS='SELECTED'> <LI><A HREF='/' TITLE ='Homepage'> Home </a></LI> </DIV>
                </UL>
            </DIV>
            <DIV CLASS = "topright">
                <FORM NAME = "login" METHOD="post">
                    <INPUT NAME='username' PLACEHOLDER = 'Email' TITLE='Username or email'> <INPUT NAME='password' TYPE = 'password' PLACEHOLDER='Password' TITLE='Password'>
                    <INPUT TYPE='submit' VALUE='Sign In' TITLE="Click here to login" CLASS='signin'>
                </FORM>
            </DIV>
        </DIV>
        <DIV ID = 'container'>
        <BR><BR><BR><BR>
                    """
    else:
         nick, avatar = interface.get_user_details(db, session)
         topnav = """
                    <DIV ID ='topnav'>
                        <DIV CLASS = 'topleft'>
                            <UL>
                                <H3> <LI><A HREF='/' TITLE="Philip's Webpage"> Philip </A></LI> </H3>
                    """
         if environ['PATH_INFO'] == '/':
             topnav += "<DIV CLASS ='selected'> <LI><A HREF='/' TITLE='Homepage'> Home </A></LI> </DIV>"
         else:
             topnav += "<LI><A HREF='/' TITLE='Homepage'> Home </A></LI>"
         if environ['PATH_INFO'] == '/my':
             topnav += "<DIV CLASS='selected'> <LI><A HREF='/my' TITLE='Go to my comments'> My Comments </A></LI> </DIV>"
         else:
             topnav += "<LI><A HREF='/my' TITLE='Go to my comments'> My Comments </A></LI>"
         if environ['PATH_INFO'] == '/comment':
             topnav += "<DIV CLASS='selected'>  <LI><A HREF='/comment' TITLE='Go to add a comment'> Add Comment </A></LI> </DIV>"
         else:
             topnav += "<LI><A HREF='/comment' TITLE='Go to add a comment'> Add Comment </A></LI>"
         topnav += """
                            </UL>
                        </DIV>
                        <DIV CLASS = 'topright'>
                            <UL>
                                <LI><A HREF='/my' TITLE='Go to my profile'> %s </A></LI>
                                <LI><A HREF='/logout' TITLE='Logout'> Sign Out </A></LI>
                            </UL>
                        </DIV>
                    </DIV>
                    <DIV ID = 'container'>
                    <BR><BR><BR><BR>
                    """ % (nick)
    return topnav
コード例 #5
0
def topnav(environ):
    # Function that defines the top navigation bar, and what appears in it.
    session = str(interface.user_from_cookie(db, environ))
    if session == 'None':
        topnav = """ 
        <DIV ID='topnav'>
            <DIV CLASS='topleft'>
                <UL>
                    <H3><LI><A HREF='/' TITLE='Philip's Webpage'> Philip </A></LI></H3>
                    <DIV CLASS='SELECTED'> <LI><A HREF='/' TITLE ='Homepage'> Home </a></LI> </DIV>
                </UL>
            </DIV>
            <DIV CLASS = "topright">
                <FORM NAME = "login" METHOD="post">
                    <INPUT NAME='username' PLACEHOLDER = 'Email' TITLE='Username or email'> <INPUT NAME='password' TYPE = 'password' PLACEHOLDER='Password' TITLE='Password'>
                    <INPUT TYPE='submit' VALUE='Sign In' TITLE="Click here to login" CLASS='signin'>
                </FORM>
            </DIV>
        </DIV>
        <DIV ID = 'container'>
        <BR><BR><BR><BR>
                    """
    else:
        nick, avatar = interface.get_user_details(db, session)
        topnav = """
                    <DIV ID ='topnav'>
                        <DIV CLASS = 'topleft'>
                            <UL>
                                <H3> <LI><A HREF='/' TITLE="Philip's Webpage"> Philip </A></LI> </H3>
                    """
        if environ['PATH_INFO'] == '/':
            topnav += "<DIV CLASS ='selected'> <LI><A HREF='/' TITLE='Homepage'> Home </A></LI> </DIV>"
        else:
            topnav += "<LI><A HREF='/' TITLE='Homepage'> Home </A></LI>"
        if environ['PATH_INFO'] == '/my':
            topnav += "<DIV CLASS='selected'> <LI><A HREF='/my' TITLE='Go to my comments'> My Comments </A></LI> </DIV>"
        else:
            topnav += "<LI><A HREF='/my' TITLE='Go to my comments'> My Comments </A></LI>"
        if environ['PATH_INFO'] == '/comment':
            topnav += "<DIV CLASS='selected'>  <LI><A HREF='/comment' TITLE='Go to add a comment'> Add Comment </A></LI> </DIV>"
        else:
            topnav += "<LI><A HREF='/comment' TITLE='Go to add a comment'> Add Comment </A></LI>"
        topnav += """
                            </UL>
                        </DIV>
                        <DIV CLASS = 'topright'>
                            <UL>
                                <LI><A HREF='/my' TITLE='Go to my profile'> %s </A></LI>
                                <LI><A HREF='/logout' TITLE='Logout'> Sign Out </A></LI>
                            </UL>
                        </DIV>
                    </DIV>
                    <DIV ID = 'container'>
                    <BR><BR><BR><BR>
                    """ % (nick)
    return topnav
コード例 #6
0
def my_comments(environ, start_response):
    # Page to look at your own comments.
    username = interface.user_from_cookie(db, environ)
    user_details = interface.get_user_details(db, username)
    my_page_text = "<H1> Welcome back %s! </H1><BR><H2> Your recent comments </H2>" % (user_details[0])
    my_page_comments = comments(interface.list_comments_user(db, username))
    headers = [('content-type', 'text/html')]
    start_response('200 OK', headers)
    page = ["<HTML>", css, topnav(environ), my_page_text, my_page_comments, "</DIV></HTML>" ]
    return page
コード例 #7
0
def my_comments(environ, start_response):
    # Page to look at your own comments.
    username = interface.user_from_cookie(db, environ)
    user_details = interface.get_user_details(db, username)
    my_page_text = "<H1> Welcome back %s! </H1><BR><H2> Your recent comments </H2>" % (
        user_details[0])
    my_page_comments = comments(interface.list_comments_user(db, username))
    headers = [('content-type', 'text/html')]
    start_response('200 OK', headers)
    page = [
        "<HTML>", css,
        topnav(environ), my_page_text, my_page_comments, "</DIV></HTML>"
    ]
    return page
コード例 #8
0
def comments(comment_list):
    # Function to add comments from a tuple of tuples
    comment_page = ""
    if comment_list != None:
        for id, useremail, page, comment in comment_list:
            user_details = interface.get_user_details(db, useremail)
            if user_details[1] == 'mary':
                # Get picture of mary online
                avatar_url = 'http://i.imgur.com/AVSXTkb.png'
            elif user_details[1] == 'bob':
                # Get picture of bob online
                avatar_url = 'http://i.imgur.com/ReA9ucT.png'
            else:
                # Get picture of default only
                avatar_url = 'http://i.imgur.com/PTkEfBS.png'
            comment_page += "<TABLE><TR><TH><H3><IMG SRC='%s' ALT='' HEIGHT ='60' WIDTH = '60'> %s commented on " % (avatar_url, user_details[0])
            webpage = str(page).replace('http://', '')
            comment_page += "<A HREF='%s'> %s </A> &nbsp&nbsp&nbsp" % (str(page), webpage)
            url = "http://localhost:8000/conversation?page="+urllib.quote(str(page), safe='')
            comment_page += "<A HREF='%s' TITLE = 'View all comments on this webpage'>(View all) </A> </H3></TH></TR>" % (url)            
            comment_page += "<TR><TD> %s </TD></TR></TABLE><BR>" % (str(comment))
    return comment_page