Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file added Assignment/HW7 - Mega Lab Travel App/app.db
Binary file not shown.
8 changes: 8 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)

from app import views, models
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flask.ext.wtf import Form
from wtforms import StringField, IntegerField, SelectField, PasswordField
# from flask_wtf.html5 import EmailField
from wtforms.validators import DataRequired, EqualTo

class TripsForm(Form):
trip_name = StringField('trip_name', validators=[DataRequired()])
destination = StringField('destination', validators=[DataRequired()])
friends = SelectField('friends', choices=[], coerce=int, validators=[DataRequired()])


class LoginForm(Form):
username = StringField('username', validators=[DataRequired()])
password = StringField('password', validators=[DataRequired()])


class RegisterForm(Form):
name = StringField('name', validators=[DataRequired()])
username = StringField('username', validators=[DataRequired()])
password = PasswordField('password', validators=[DataRequired()])
confirm = PasswordField('Confirm password', validators=[DataRequired(), EqualTo('password', message='Passwords not match.')])
44 changes: 44 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sqlite3 as sql

def login_user(username, password):
with sql.connect("app.db") as con:
con.row_factory = sql.Row
cur = con.cursor()
travellers = cur.execute('SELECT * FROM travellers WHERE username=? and password=?', (username, password)).fetchall()
return travellers

def get_friends(my_id):
with sql.connect("app.db") as con:
con.row_factory = sql.Row
cur = con.cursor()
travellers = cur.execute('SELECT * FROM travellers WHERE traveller_id != ?', (my_id,)).fetchall()
return travellers

def insert_user(user, username, password):
with sql.connect('app.db') as con:
cur = con.cursor()
cur.execute('INSERT INTO travellers (traveller_name, username, password) VALUES(?,?,?)', (user, username, password))
con.commit()
user_id = cur.execute('SELECT last_insert_rowid()').fetchall()[0][0]
return user_id


def insert_trip(trip_name, destination, creator_id, friend_id):
with sql.connect("app.db") as con:
cur = con.cursor()
cur.execute('INSERT INTO trips (trip_name, destination, creator_id, friend_id) VALUES (?,?,?,?)', (trip_name, destination, creator_id, friend_id))
con.commit()

def retrieve_trips(my_id):
with sql.connect("app.db") as con:
con.row_factory = sql.Row
cur = con.cursor()
trips = cur.execute('SELECT * FROM trips WHERE creator_id = ? or friend_id = ?', (my_id, my_id,)).fetchall()
return trips


def delete_trip(trip_name, destination):
with sql.connect("app.db") as con:
cur = con.cursor()
cur.execute('DELETE FROM trips WHERE trip_name = ? and destination = ?', (trip_name, destination,))
con.commit()
22 changes: 22 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/static/interactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// $(document).ready(function () {
$(document).on('click', '#delete-trip', function () {
// $(this.parentNode.parentNode).remove();
trip_name = $(this).parent().prev().prev().text();
destination = $(this).parent().prev().text();
// alert(destination);
$(this).parent().parent().remove();
$.post("http://0.0.0.0:8081/delete_trip",
{
trip_name: trip_name,
destination: destination
},
function(data) {
if (data == "ok") {
alert("Trip deleted.")
} else {
alert("Error.")
}
}
);
});
// });
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
296 changes: 296 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/static/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
/*----------------- CSS RESET ------------------*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
margin-top: 5%;
margin-left: 30%;
}

/*----------------- CSS RESET ------------------*/

html, body {
background-color: #f9f9f9;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
}

header {
background-color: #1a9dbc;
box-shadow: 0 2px 6px 1px #a7a7a7;
color: #ecf0f1;
height: 5rem;
}

footer {
float: left;
background-color: #1a9dbc;
bottom: 0;
color: #ecf0f1;
height: 7rem;
margin-top: 2em;
text-align: center;
width: 100%;
}

footer p {
height: 7rem;
line-height: 7rem;
}

h1, h3 {
padding: 4px;
margin-left: 10%
}

h1 {
font-size: 2rem;
font-weight: bold;
}

h3 {
font-size: 1.4rem;
}

a {
text-decoration: none;
}

input[type="text"], input[type="range"] {
border: 1px solid #bdc3c7;
border-radius: 2px;
margin-left: 1rem;
vertical-align: middle;
}

input[type=range]{
-webkit-appearance: none;
}

input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 1.2rem;
width: 1.2rem;
border-radius: 50%;
background: #1a9dbc;
margin-top: -.5rem;
}

input[type=range]::-webkit-slider-runnable-track {
background: #ccc;
height: .2rem;
}

.action-button {
margin-top: 10%;
margin-left:30%;
background-color: #1a9dbc;
border: none;
border-bottom: 3px solid #1670a03;
border-radius: 2px;
color: #ecf0f1;
display: inline-block;
font-size: 1rem;
font-weight: bold;
height: 3rem;
padding: 4px;
width: 6rem;
}

.action-button:hover {
background-color: #1a9dbc;
}

#site-title-wrapper {
display: inline-block;
height: 5rem;
width: 15%;
}

#site-icon-wrapper {
display: inline-block;
margin-left: 1rem;
margin-top: -.5rem;
vertical-align: middle;
width: 2.5rem;
}

#site-icon-wrapper img {
display: inline-block;
max-height: 100%;
max-width: 100%
}

#site-title {
display: inline-block;
font-weight: bold;
height: 5rem;
line-height: 5rem;
margin-left: .1rem;
}

#username {
margin-right: .7rem;
}

#logout {
float: right;
height: inherit;
line-height: 5rem;
margin-right: 1rem;
}

#logout-button {
background-color: #ecf0f1;
border-bottom-color: #bdc3c7;
color: #222222;
height: 2.5rem;
width: 5rem;
}

#logout-button:hover {
background-color: #bdc3c7;
}

#content {
margin-top: 2rem;
text-align: center;
width: 100%;
}

.main-container {
background: #ecf0f1;
border-radius: 4px;
box-shadow: 0px 2px 10px 2px #95a5a6;
display: block;
min-height: 50vh;
margin: 2rem 0 0 25%;
padding: 1rem;
text-align: left;
width: 50%;
}

.survey-item, .result-item, #results-email-container {
box-sizing: border-box;
display: block;
margin: 1.5rem 0;
padding: 4px;
}

.survey-item span {
font-size: 1rem;
margin-left: 1rem;
}

#email-results-button, #goHome {
height: 2rem;
line-height: 2rem;
margin-left: 1rem;
text-align: center;
}
#site-icon-wrapper {
margin-top: 10%;
}

.section {
float: left;
width: 40%;
margin-top: 5%;
margin-left: 5%;

}
.section a {
display: block;
width: 5em;
background: #1a9dbc;
color: white;
border: 1px solid #1a9dbc;
border-radius: 1em;
margin: 2% 40% 2% 40%;
padding: 1em 1em;
}

td, th {
margin: 1em;
border: 1px solid black;
}

form p {
margin: 1em;
}

#logout-button {
margin-right: 2em;
}
.map {
width: 40%;
float: left;
margin-top: 5%;
margin-left: 5%;
}


#delete-trip {
margin-top: 1%;
margin-left:0;
background-color: #1a9dbc;
border: none;
border-radius: 2px;
color: #ecf0f1;
display: inline-block;
font-size: 1rem;
font-weight: bold;
height: 2.5rem;
padding: 4px;
width: 6rem;
}

/* striped table. */
.striped tr:first-child {
height: 30px;
}

.striped th {
vertical-align: middle;
padding: 0 0.3em;
}
Loading