Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hw 7 done - Mudit and Rohit #247

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/Untitled.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{\rtf1\ansi\ansicpg1252\cocoartf1504
{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;\red255\green255\blue255;}
{\*\expandedcolortbl;\csgray\c100000;\csgray\c0;\csgray\c100000;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0

\f0\fs22 \cf2 \cb3 \CocoaLigature0 sqlite3 app.db < schema.sql}
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.
29 changes: 29 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,29 @@
from flask.ext.wtf import Form
from wtforms import StringField, SelectField
from wtforms.validators import DataRequired


class TripForm(Form):
'''
Add trip input form fields
'''
name_of_trip = StringField('name_of_trip', validators=[DataRequired()])
destination = StringField('destination', validators=[DataRequired()])
friend2 = SelectField('friend2', validators=[DataRequired()])


class SignupForm(Form):
'''
Add user input form fields
'''
user_name = StringField('user_name', validators=[DataRequired()])
password = StringField('password', validators=[DataRequired()])


class LoginForm(Form):
'''
Login form fields
'''
user_name = StringField('user_name', validators=[DataRequired()])
password = StringField('password', validators=[DataRequired()])

Binary file added Assignment/HW7 - Mega Lab Travel App/app/forms.pyc
Binary file not shown.
64 changes: 64 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,64 @@
import sqlite3 as sql


def create_trip(name_of_trip, destination, friend1, friend2):
'''
Creates a trip entry to db
'''
with sql.connect("app.db") as con:
cur = con.cursor()
cur.execute("PRAGMA foreign_keys=ON;")
try:
cur.execute(
"INSERT INTO trips (trip_name, destination, friend1, friend2) VALUES (?, ?, ?, ?)", (name_of_trip, destination, friend1, friend2))
con.commit()
except Exception as e:
print("Error in inseting trip records: ", e)


def create_user(user_name, password):
'''
Creates a user entry to db
'''
with sql.connect("app.db") as con:
cur = con.cursor()
try:
cur.execute(
"INSERT INTO users (user_name, password) VALUES (?, ?)", (user_name, password))
con.commit()
except Exception as e:
print("Error in inseting user records: ", e)


def retrieve_users():
'''
Retrieves users from db
'''
with sql.connect("app.db") as con:
con.row_factory = sql.Row
cur = con.cursor()
users = cur.execute("SELECT * FROM users").fetchall()
return users


def retrieve_trips():
'''
Retrieves trip details from db
'''
with sql.connect("app.db") as con:
con.row_factory = sql.Row
cur = con.cursor()
trips = cur.execute(
"SELECT * from trips").fetchall()
return trips


def delete_trip(trip_name):
'''
Deletes trip details from db
'''
stmt = "DELETE FROM trips where trip_name = '" + trip_name + "'"
with sql.connect("app.db") as con:
cur = con.cursor()
cur.execute(stmt)
con.commit()
Binary file added Assignment/HW7 - Mega Lab Travel App/app/models.pyc
Binary file not shown.
21 changes: 21 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/static/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$(document).ready(function() {
$('select').material_select();
});

$(".delete-row").click(function() {
var tripName = $(this).closest('tr').children()[0].innerHTML
var trRemove = $(this).closest('tr')
$.ajax({
type: "POST",
url: "/delete_trip",
data: JSON.stringify({ "tripName" : tripName }),
contentType: "application/json",
success: function(response){
console.log(response)
$(this).closest('tr').remove()
trRemove.fadeOut(1000,function(){
trRemove.remove();
});
}
});
});
17 changes: 17 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
{% if title %}
<title>{{ title }} - Travel App</title>
{% else %}
<title>Welcome to IO Lab Travel App</title>
{% endif %}
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css">
</head>
<body>
{% block content %}{% endblock %}
</body>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
<script src="../static/main.js"></script>
</html>
39 changes: 39 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row">
<h1>Welcome to MegaLab Travel App</h1>
<div class= "section">
<a href="{{ url_for('create_trip') }}">Create a Trip</a>
|
Logged in as: {{ user }}
<a href="{{ url_for('logout') }}">Logout</a>
</div>
<div class="divider"></div>
<div class="section">
<h3>You have the below trips</h3>
<table class="striped">
<thead>
<tr>
<th data-field="trip_name">Trip Name</th>
<th data-field="destinaton">Destination</th>
<th data-field="friend1">Friend 1</th>
<th data-field="friend2">Friend 2</th>
</tr>
</thead>

{% for trip in trips %}
<tr>
<td> {{ trip['trip_name']}} </td>
<td> {{ trip['destination']}} </td>
<td> {{ trip['friend1']}} </td>
<td> {{ trip['friend2']}} </td>
<td><button type="button" class="delete-row">Delete</button></td>
</tr>
{% endfor %}

</table>
</div>
</div>
</div>
{% endblock %}
29 changes: 29 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row">
<div class= "section">
<a href="{{ url_for('create_user') }}">Signup</a>
</div>
<h4>Login</h4>

<form action="" method="post" name="login">
{{ form.hidden_tag() }}

<div class="divider"></div>
<div class="section">
<p>
User Name:<br>
{{ form.user_name(size=120) }}<br>
</p>
<p>
Password:<br>
{{ form.password(size=120) }}<br>
</p>
</div>
<p><input type="submit" value="Login"></p>
</form>

</div>
</div>
{% endblock %}
26 changes: 26 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row">
<h4>Create a User</h4>

<form action="" method="post" name="create_user">
{{ form.hidden_tag() }}

<div class="divider"></div>
<div class="section">
<p>
User Name:<br>
{{ form.user_name(size=120) }}<br>
</p>
<p>
Password:<br>
{{ form.password(size=120) }}<br>
</p>
</div>
<p><input type="submit" value="Create User"></p>
</form>

</div>
</div>
{% endblock %}
37 changes: 37 additions & 0 deletions Assignment/HW7 - Mega Lab Travel App/app/templates/trip.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row">
<div class= "section">
Logged in as: {{ user }}
<a href="{{ url_for('logout') }}">Logout</a>
</div>
<div class="divider"></div>
<h4>Create a Trip</h4>

<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3149.5237775144756!2d-122.26068738452288!3d37.871431879742026!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x80857c25ca729ded%3A0x939d9d90e630ccb6!2sSouth+Hall!5e0!3m2!1sen!2sin!4v1477551412881" width="800" height="600" frameborder="0" style="border:0" allowfullscreen></iframe>

<form action="" method="post" name="create_trip">
{{ form.hidden_tag() }}

<div class="divider"></div>
<div class="section">
<p>
<div>Name of Trip:</div>
<div>{{ form.name_of_trip(size=120) }}</div>
</p>
<p>
<div>Destination:</div>
<div>{{ form.destination(size=120) }}</div>
</p>
<p>
<div>Friend you're going with:</div>
<div>{{ form.friend2() }}</div>
</p>
</div>
<p><input type="submit" value="Create Trip"></p>

</form>
</div>
</div>
{% endblock %}
Loading