Level 2 web application Python CS
当前位置:以往案例 > >Level 2 web application Python CS
2018-08-13

Level 2


In this phase you will write a basic version of the web application that can
display but not create job listings. This means we don't yet have to worry about login
and sessions but that you must interface to the database to lists positions.


Following the model-view-controller architecture, the first thing that you'll
implement is the database model. This is contained in a moduleinterface.py
with all of the code to retrieve and store positions in the database.
You will then implement the views (templates) and controllers for the web application
that makes use of the models present the data on the web.


All of the work you do will be tested using unit tests. For the database interface,
there are straightforward unit tests of the functions that you will write. To test the
behaviour of the web application we'll use functional testing that requests your pages
and checks that they have certain contents, and that we can login and position
messages. We will do this using a module called WebTest that is designed specifically
for functional testing of Python web applications.


Unit Tests


All procedures will be implemented in
the moduleinterface.py. A version has been supplied that contains the procedure
stubs only.


When we refer to a database connection below we mean the connection returned byCOMP249Dbfrom thedatabasemodule that we provide. This is just a
regular SQLite database connection, but the code we provide ensures we can
control which database you are using for testing purposes.


  • position_list

    There is a functionposition_list(db, limit=10).dbis a database connection
    and the optional argument limit is an integer. The function returns a list of tuples
    representing the positions stored in the database, each tuple contains:(id, timestamp, owner,
    title,
    location, company, description).
    Messages are returned in reverse
    order of the timestamp, most recent first.

  • position_get

    There is a functionposition_get(db, id).dbis a database connection
    andidis an integer position identifier.
    The function returns a tuple
    representing the position with the given id,
    the tuple contains:(id, timestamp, owner, title,
    location, company, description).

    If theiddoes not match a record in the
    database, the function should returnNone.

  • position_add

    There is a functionposition_add(db, usernick, title, location, company, description).dbis a database connection, the argumentusernickis a user name andtitle, location, companyanddescriptionare the values of
    the respective fields in the positions table. The function adds the new position
    to the database.

    Ifusernickdoes not a user in the users table, no new record should
    be created and the function should returnFalse

    If the record is added successfully, the function should returnTrue.


Functional requirements


The functional requirements describe what a user should be able to see and do
on the web application. They describe what happens when you load a particular URL
or submit a form in a page. There are automated tests to check that you have
implemented this functionality correctly.


  • Home Page List of positions

    As a visitor to the site, when I load the home page (URL /) I see a list of
    up to 10 positions in order of their timestamps, most recent first. Each position
    must include the position timestamp, title, owner and the first 100 characters of
    the text of the position description. At the end of each listing
    should be a link to view the entire position with the text "Read More" and the
    url/positions/DD
    whereDDis the position id.

    The list of positions that appears should be the
    result of a call toposition_listwhich will extract the most recent
    10 positions from the database.

  • Position Page

    As a visitor to the site, I can click on the "Read More" link after a position
    description on the home page, I see a page with the full description of the
    position at the URL/positions/DDwhereDDis the position id.

    The position page should contain all of the database fields for the position, laid out
    in a readable way. It should also contain a link to return to the main page.


Your Task


To achieve these requirements you need to write code ininterface.pyto implement the
different functions to interface to the database. Run the unit tests inlevel2_unit.py
to check whether you have met the requirements.


Once you have a working version ofinterface.pyyou can move on to write the
application itself inmain.py. Take each required page in turn and write the
code to generate the content using the functions you have written. You can check
the functional requirements yourself and run the unit tests inlevel2_functional.py
to validate that you've met the requirements.




在线提交订单