Welcome to itucsdb1710’s documentation!¶
Team: | Restaurant Reviewer |
---|---|
Members: |
|
Restaurant Reviewer is a platform where a user can add a Restaurant, other users can share their own experience about this restaurant, find the best restaurant by checking the comments and rates shared by other users, add a Restaurant to your favourite list, find restaurant nearby your location and view a Restaurant by their food category. Also Restaurant Reviewer can be used by anyone to simply help them know more about the restaurant they are looking for
Contents:
User Guide¶
In this section, we show how the application works from the user perspective.
If you want to learn more about our database design then we suggest you to look in the Developer Guide.
Parts Implemented by Lina Alrehaili¶
Signup, Signin, Mainpage, Restaurant, MyFavourite and Food Category are pages created by Lina Alrehaili.
Signup Page¶
To Signup it is required to fill all the information given in order to register successfully, the email address is unique which means you can’t use the same email twise. The information are kept in the user table which is the main table for this website. If you already have an account click on ‘Here!’ to redirect you to the Signin page.
Signin Page¶
To access the Restaurant Reviewer website, you have to Signin successfully first! If you try to access a page that requires an authorizatiton without being signed in, the system redirects you to the Signin page. If you don’t have an account click on ‘Here!’ to redirect you to the Signup page.
Mainpage¶
After you sign in successfully, this page appear which is the Mainpage, the header of the page includes the name of the user after the sentence ‘Welcome Back,’ where you can see below the name of the user is ‘admin’, underneath the sentence you can see all the restaurant as link that where added to this website from any user, you can click on one of the restaurants from the list which will redirect you to the Restaurant Page of the clicked restaurant, on the right side you can add a new restaurant to the website where afterwards it will show on the list of the left side, and the name of the restaurant and the user who added it will be stored in the Restaurant table.
Restaurant Page¶
In this Restaurant page you can add your own comment and rate about the restaurant you’ve chosen, you can also see other users comments and rates about this restaurant. On the the left side the name of the restaurant is shown which is ‘Mado’ in this page, any user can add this restaurant to their favourite list, when you add a restaurant, the location and category values are default to ‘Not provided’, but afterwards you can edit both of them by clicking on the ‘Edit’ button to redirect you to the edit_restaurant Page, if you didn’t add this restaurant then you can’t edit it’s information’ as seen in ‘Figure-1’. Also you can edit comments which will redirect you to edit_comment page.
edit_restaurant Page¶
In this page you can edit both information of location and food category or just edit one of them. After you finish, you can save your changes or cancel it.
edit_comment Page¶
You can edit your own comment and delete as seen in ‘Figure-1’, but if you edit other users comment then you can’t delete it as seen in ‘Figure-2’.
favourite Page¶
In this page you can see all your favourite restaurants on the left side, you can also remove a restaurant from your favourite by typing the restaurant name on the text box then click remove to delete it from the your favourite list.
Food category Page¶
In this page you can see the restaurants accordding to their food category.
Parts Implemented by jilan alrehaili¶
i have made few pages in this project which i have titled them as: profile page, edit profile page, friend page, nearby page, search page, setting page. and i will show the function of the pages and illustrate all of them in here
profile page¶
the user can access his profile page from the navigation bar by clicking on ‘profile’. when the user first registers to the website all his personal informations (name, surname, age…) will be set as defult until he decides to update them. the user in this page is free to either edit his personal information or simply just see them or he can even add or delete a friend from his profile page.
edit profile page¶
the user can access his edit profile page by clicking on ‘edit’. all his informations can be updated at anytime and he can also choose to edit few or all of his information.
edit profile page 1
the user in this case choice to update two fields the country and the city, lets say he moved out!
edit profile page 2
the user have clicked ‘save’ to save his changes, and a message window appeared to show that the changes have been saved in the database and in his profile.
edit profile page 3
this image shows the updated information.
friend page¶
in this section the user can add a friend to his list or delete a friend, this can be done by typing the username, only the user can edit this information for everyone to see.
friend page 1
after clicking ‘add’ this user ‘admin123’ is added to the friend list in his profile
nearby page¶
the user can access nearby page from the navigation bar by clicking on ‘nearby resturants’.the user can feel free to search for a resturant by its location, we defined this in a drop-down list where he can see all the resturants in the locations.
nearby page 1
the user decided to search at this location!
nearby page 2
the user here picked a location and ‘Burger king’ resturant appeared in that location.
search page¶
the user can access search page from the navigation bar by clicking on ‘search’.this website has another feature which allows the user to search for resturants by its name.
search page 1
the user decided to search for ‘Burger king’ resturant.
search page 2
after clicking on the resturant link it takes you to the resturant’s page.
setting page¶
the user can access his settting page from the navigation bar by clicking on ‘settings’. he is free to change his email and his password, after he puts his prefered updates he can click ‘save’. if he decided to delete his account all his information from comments to friends list will be deleted from the database.
Developer Guide¶
Database Design¶
Below you can see the tables of our database and their attributes, also the connections between the tables.
Entity Distribution¶
Lina Alrehaili: |
|
---|---|
Jilan Alrehaili: | |
|
Details¶
Parts Implemented by Lina Alrehaili¶
The tables of the database which was implemented by Lina Alrehaili
The E/R diagram of the above tables
Login Management System¶
For the login part, i have used flask_login packages.
from flask_login import LoginManager
from flask_login.utils import login_required, login_user, current_user, logout_user
login_required This property should return True if the user is authenticated. login_user Once a user has authenticated, you log them in with the login_user function. logout_user Logs a user out. current_user you can access the logged-in user with the current_user proxy.
USERS TABLE¶
The USERS table stores the informations of the users such as their name, username, mail, password.
CREATE TABLE USERS (
NAME VARCHAR(80) NOT NULL,
USERNAME VARCHAR(20) PRIMARY KEY,
MAIL VARCHAR(80) NOT NULL UNIQUE,
PASSWORD VARCHAR(120) NOT NULL)
To connect the database with the login system, I have used a user class as shown below.
class User(UserMixin):
def __init__(self, name, userName, eMail, password):
self.name = name
self.userName = userName
self.email = eMail
self.password = password
self.active = True
self.is_admin = False
def get_id(self):
return self.userName
@property
def is_active(self):
return self.active
In the signup page, a new user is created and their information is added to the USERS table, later on you can use this e-mail and password to login successfully. The query below shows it.
INSERT INTO USERS (NAME, USERNAME, MAIL, PASSWORD) VALUES (%s, %s, %s, %s)
I have used SELECT operation for the USERS table in the Mainpage to show the name of the user shown below.
SELECT * FROM USERS
After selecting the users table, in the mainpage.html we see that if current_user.userName is the same as the username in the USERS table, then print the name of the user.
{% if users %}
{% for u in users %}
{% if user.userName == u[1] %}
<h1 class="title">Welcome back, {{u[0]}}</h1>
{% endif %}
{% endfor %}
{% endif %}
RESTAURANT TABLE¶
The RESTAURANT table stores the restaurant name and the username for the user who have added this restaurant, also the name of the restaurant has to be unique as shown in table below.
CREATE TABLE RESTAURANT (
ID SERIAL PRIMARY KEY,
NAME VARCHAR(20) NOT NULL,
USERNAME VARCHAR(20) REFERENCES USERS(USERNAME) ON DELETE CASCADE,
UNIQUE(NAME) )
I have used insertion and selection operations in the Mainpage to add a new restaurant and list it in this page as shown below.
INSERT INTO RESTAURANT(NAME, USERNAME) VALUES(%s, %s)
SELECT * FROM RESTAURANT"
Below in the mainpage.html it shows all the restaurants in the table printed the names as a link to restaurant_page
{% if names %}
{% for name in names %}
<a href="{{url_for('site.restaurant_page', rst_id = name[0] )}}" class="" style= "font-size: 15px">
<li>{{name[1]}}</li>
</a>
{% endfor %}
{% endif %}
I have used delete operation on the restaurant_page to delete a restaurant, also select operation to print the name of the restaurant where the id for both is the id of the restaurant chosen as shown below.
DELETE FROM RESTAURANT WHERE ID = %s
SELECT * FROM RESTAURANT WHERE ID = %s
at restaurant_page.html below is the given code to print the name of the restaurant.
{% if names %}
{% for name in names %}
<h1 >{{name[1]}}<br> Restaurant</h1>
{% endfor %}
{% endif %}
In the edit_restaurant page I have used the select operation to print the name of the restaurant as mentioned before.
RST_DETAILS TABLE¶
To have full informatoin about this table you can see it in jilan’s part, but i have used an update operation in this table to update the location and food category of the selected restaurant as shown below.
if len(location)!=0 or len(food)!=0 :
execute=[]
query="""UPDATE RST_DETAILS SET """
if len(location)!=0:
execute+=[str(location)]
query+="""LOCATION=%s"""
if len(food)!=0:
execute+=[str(food)]
if len(location)!=0:
query+=""", """
query+="""CATEGORY=%s"""
query+=""" WHERE (ID=%s)"""
execute+=[rst_id[0]]
the code above can let you update one information or both of them.
MYFAVOURITE TABLE¶
The MYFAVOURITE table stores the username, restaurant name and restaurant id as shown below.
CREATE TABLE MYFAVORITE (
USERNAME VARCHAR(30) REFERENCES USERS(USERNAME) ON DELETE CASCADE,
RESTAURANT VARCHAR(50) REFERENCES RESTAURANT(NAME) ON DELETE CASCADE,
RST_ID SERIAL REFERENCES RESTAURANT(ID) ON DELETE CASCADE,
PRIMARY KEY(USERNAME,RESTAURANT) )
I used insert operation in the restaurant page to add a restaurant to the myfavourite table as shown below.
INSERT INTO MYFAVORITE(USERNAME, RESTAURANT,RST_ID) VALUES(%s, %s,%s)
on the favourite page I used delete and select operation to list the favourite restaurants or delete one as shown below.
SELECT * FROM MYFAVORITE
DELETE FROM MYFAVORITE WHERE (USERNAME= %s and RESTAURANT = %s)
POST TABLE¶
The POST table is for the comments and rate which stores postid, username, comment and rate as shown below.
POSTID SERIAL PRIMARY KEY,
USERNAME VARCHAR(20) REFERENCES USERS(USERNAME) ON DELETE CASCADE,
COMMENT VARCHAR(500) NOT NULL,
RATE VARCHAR(20) DEFAULT 1)
In the restaurant page i have used insert operation to insert the feeds to the POST table, also select POSTId from this table to add it to the POSTCAST table which i will explain later, also the last select operation is for printing all the posts for the chosen rastaurant page
INSERT INTO POST(USERNAME, COMMENT,RATE) VALUES(%s, %s,%s)
SELECT POSTID FROM POST WHERE (USERNAME = %s and COMMENT = %s)
SELECT * FROM POST WHERE POSTID= %s
In the edit_comment page i have used delete and select operation to delete a comment and to print it in screen as shown below.
DELETE FROM POST WHERE (POSTID= %s)
SELECT * FROM POST WHERE POSTID = %s
POSTCAST TABLE¶
The POSTCAST table is cast for POST and RESTAURANT tables which stores id, restaurant id and post id as shown below.
CREATE TABLE POSTCAST (
ID SERIAL PRIMARY KEY,
RSTID INTEGER REFERENCES RESTAURANT(ID) ON DELETE CASCADE,
POSTID INTEGER REFERENCES POST(POSTID) ON DELETE CASCADE )
In the **restaurant page** I have used the insert operation also delete operation after a restaurant is deleted the POSTCAST with the same restaurant is also deleted, also an importent select operation which will select the post id that have the restaurant id of the chosen restaurant to print all the posts of this restaurant in this page as shown below.
INSERT INTO POSTCAST(RSTID, POSTID) VALUES(%s, %s)
DELETE FROM POSTCAST WHERE RSTID = %s
SELECT POSTID FROM POSTCAST WHERE RSTID = %s
Parts Implemented by jilan alrehaili¶
the tables i have used to create my parts in this project are: [USERS, RESTURANT, RST_DETAILS, INFO, FRIENDS entities] thses can accomplish all tasks from Deleting and adding a friend, checking and updating user personal profile information (name, surname, age, country, city, gender). deleting user account, changing user email and password, search existing restaurant by name, search nearby restaurants by location.
the tables of the database which i have used:
the E/R Diagram of the database which i have used:
FRIENDS table¶
FRIENDS table adds/deletes a friend to the users profile. the USERNAME & FRIEND are primary key because each user is kept well distinguished in the process of deleting or adding a friend to the table. both USERNAME & FRIENDS have a maximum of 50 character and this table is connected to the USERS table.
CREATE TABLE FRIENDS USERNAME VARCHAR(30) REFERENCES USERS(USERNAME) ON DELETE CASCADE, FRIEND VARCHAR(50) REFERENCES USERS(USERNAME) ON DELETE CASCADE, PRIMARY KEY(USERNAME,FRIEND) )
if the user choose to update one of his operations the below code will handle this task, he can only do one update at a time as it can be seen below
friend=request.form['friend'] if request.form['action'] == 'add': query = """INSERT INTO FRIENDS(USERNAME, FRIEND) VALUES(%s, %s)""" cursor.execute(query,(current_user.userName, friend)) connection.commit() elif request.form['action'] == 'remove': query = """DELETE FROM FRIENDS WHERE (USERNAME= %s and FRIEND = %s)""" cursor.execute(query,(current_user.userName, friend)) connection.commit() return redirect(url_for('profile_page'))
the friend that the user typed in, is added to the FRIENDS table and into the users profile as seen below.
if request.form['action'] == 'add': query = """INSERT INTO FRIENDS(USERNAME, FRIEND) VALUES(%s, %s)""" cursor.execute(query,(current_user.userName, friend)) connection.commit()
the friend that the user typed in, is deleted from the FRIENDS table and from the users profile as seen below.
elif request.form['action'] == 'remove': query = """DELETE FROM FRIENDS WHERE (USERNAME= %s and FRIEND = %s)""" cursor.execute(query,(current_user.userName, friend)) connection.commit() return redirect(url_for('profile_page'))
INFO table¶
INFO table stores all user’s information. the table has different necessary varriables like the ‘USERNAME’, it is both the primary and foreign key in the table and it refers to the USERS table primary key, and it has a maximum of 50 characters, other varriable is ‘AGE’ which has a maximum of 20 characters, the ‘COUNTRY’ & ‘city’ has a maximum of 100 characters, the ‘GENDER’ which has a maximum of 50 characters the name is a maximum of 80 characters
CREATE TABLE INFO ( USERNAME VARCHAR (50) REFERENCES USERS(USERNAME) ON DELETE CASCADE, NAME VARCHAR(80) NULL, AGE VARCHAR(20) NULL, COUNTRY VARCHAR(100)NULL, CITY VARCHAR(100) NULL, GENDER VARCHAR(50) NULL, PRIMARY KEY(USERNAME)) cursor.execute(query)
the bellow data is inserted in the table while initializing database.
query = """INSERT INTO INFO (USERNAME, SURNAME,AGE,COUNTRY,CITY,GENDER) VALUES ('admin123','alrehaili','30','turkey','istanbul','female')""" cursor.execute(query)
the initial stage of these informations are as defult values. and the user can pick to update all or some of his information only the user by his account can change these personal informations no other user can access this page.
query = """INSERT INTO INFO (USERNAME, SURNAME, AGE, COUNTRY,CITY,GENDER)
VALUES ('%s','%s', '%s', '%s', '%s', '%s')""" %(username,'........','........','........','........','........')
cursor.execute(query)
connection.commit()
login_user(user)
return redirect(url_for('site.main_page'))
the bellow code makes a form request with the data specified in the values to access the form data.
surname=request.form['Surname']
age=request.form['Age']
country=request.form['Country']
city=request.form['City']
gender=request.form['Gender']
this instructions checks for columns that has new data to insert into the INFO table, and it handles any data that is updated.
if len(surname)!=0 or len(age)!=0 or len(country)!=0 or len(city)!=0 or len(gender)!=0: execute=[] query="""UPDATE INFO SET """ if len(surname)!=0: execute+=[str(surname)] query+="""SURNAME=%s""" if len(age)!=0: execute+=[str(age)] if len(surname)!=0: query+=""", """ query+="""AGE=%s""" if len(country)!=0: execute+=[str(country)] if len(surname)!=0 or len(age)!=0: query+=""", """ query+="""COUNTRY=%s""" if len(city)!=0: execute+=[str(city)] if len(surname)!=0 or len(age)!=0 or len(country)!=0: query+=""", """ query+="""CITY=%s""" if len(gender)!=0: execute+=[str(gender)] if len(surname)!=0 or len(age)!=0 or len(country)!=0 or len(city)!=0: query+=""", """ query+="""GENDER=%s"""
RST_DETAILS table¶
RESTURANT table stores the names of the resturants and the usernames of who added the resturant, the ‘ID’ in the table is the primary key with a serial number, and the ‘USERNAME’ is the foreign key with a maximum of 20 characters, and the last one is the ‘NAME’ with a ‘20’ characters as shown bellow. this table is connected to the RESTURANTS table which is connected to USERS table.
CREATE TABLE RST_DETAILS ( ID SERIAL REFERENCES RESTAURANT(ID) ON DELETE CASCADE, NAME VARCHAR(20) REFERENCES RESTAURANT(NAME) ON DELETE CASCADE, LOCATION VARCHAR(20) NULL, CATEGORY VARCHAR(20) NULL, PRIMARY KEY(ID) )
the bellow data is inserted in the table while initializing database.
query = """INSERT INTO RST_DETAILS ( NAME, LOCATION,CATEGORY ) VALUES ('Burger king', 'Levent','Fast food')""" cursor.execute(query) query = """INSERT INTO RST_DETAILS ( NAME, LOCATION,CATEGORY ) VALUES ('Mado', 'Taksim','Turkish food')""" cursor.execute(query)
the nearby page uses the RST_DETAILS table to fetch all the information needed in this operation. the ‘LOCATION’ attribute of the RST_DETAILS table is used to distinguish the location of each resturant.
def nearby_page(): if request.method == 'POST': with dbapi2.connect(app.config['dsn']) as connection: cursor = connection.cursor() location = request.form['Location'] query = """SELECT * FROM RST_DETAILS WHERE LOCATION = %s""" cursor.execute(query,[location]) names = cursor.fetchall() connection.commit() return render_template("nearby.html",names=names) else: return render_template("nearby.html")
Installation Guide¶
You have to install all of the below application in order to run our project successfully.
After that run “server.py” and connect to “localhost:5000”.
- Install Python (version 3.4 or higher)
https://www.python.org/downloads/
- Install Flask
pip3 install -U flask
- Install Psycopg2
pip3 install -U psycopg2
- Install flask_login
pip3 install flask-login
- Install passlib
pip3 install passlib