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 module interface.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 module interface.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 by COMP249Db
from the database
module 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 function
position_list(db, limit=10)
.db
is 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 function
position_get(db, id)
.db
is a database connection
andid
is 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 the
id
does not match a record in the
database, the function should returnNone
. -
position_add
There is a function
position_add(db, usernick, title, location, company, description)
.db
is a database connection, the argumentusernick
is a user name andtitle, location, company
anddescription
are the values of
the respective fields in the positions table. The function adds the new position
to the database.If
usernick
does 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 return
True
.
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
whereDD
is the position id.The list of positions that appears should be the
result of a call toposition_list
which 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/DD
whereDD
is 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 in interface.py
to implement the
different functions to interface to the database. Run the unit tests in level2_unit.py
to check whether you have met the requirements.
Once you have a working version of interface.py
you can move on to write the
application itself in main.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 in level2_functional.py
to validate that you've met the requirements.
-
Python and SQLite describes the
way to send queries to SQLite and get results back. -
Generating HTML Pages looks at
the Bottle page templating system. -
Testing Python Programs covers
running unit tests.
代写CS&Finance|建模|代码|系统|报告|考试
编程类:C++,JAVA ,数据库,WEB,Linux,Nodejs,JSP,Html,Prolog,Python,Haskell,hadoop算法,系统 机器学习
金融类:统计,计量,风险投资,金融工程,R语言,Python语言,Matlab,建立模型,数据分析,数据处理
服务类:Lab/Assignment/Project/Course/Qzui/Midterm/Final/Exam/Test帮助代写代考辅导
E-mail:850190831@qq.com 微信:BadGeniuscs 工作时间:无休息工作日-早上8点到凌晨3点
如果您用的手机请先保存二维码到手机里面,识别图中二维码。如果用电脑,直接掏出手机果断扫描。