Skip to content

Commit e0c9d12

Browse files
initial push
1 parent 7a13614 commit e0c9d12

13 files changed

+805
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ ENV/
8787

8888
# Rope project settings
8989
.ropeproject
90+
.idea/

app.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import bottle
2+
3+
from db_python_class import DatabasePythonClass
4+
5+
db = DatabasePythonClass.db
6+
cities = db.cities
7+
item = cities.find_one()
8+
9+
10+
@bottle.route('/static/:path#.+#', name='static')
11+
def static(path):
12+
return bottle.static_file(path, root='static')
13+
14+
15+
@bottle.route('/')
16+
def home_page():
17+
my_things = ['alexis', 'ozil', 'santi']
18+
return bottle.template('views/index.html', {
19+
'username': 'Ligang', 'things': my_things
20+
})
21+
22+
23+
@bottle.post('/destination')
24+
def destination():
25+
city = bottle.request.forms.get('city')
26+
if city is None or city == '':
27+
city = 'No Destination Selected'
28+
interest = 'place'
29+
bottle.response.set_cookie('city', city, path='/')
30+
bottle.response.set_cookie('interest', interest, path='/')
31+
bottle.redirect('/show_city')
32+
33+
34+
@bottle.route('/show_city')
35+
def show_city():
36+
city = bottle.request.get_cookie('city')
37+
interest = bottle.request.get_cookie('interest')
38+
39+
return bottle.template('views/city.html', {
40+
'city': city,
41+
'interest': interest
42+
})
43+
44+
45+
@bottle.post('/interest')
46+
def post_interest():
47+
city = bottle.request.json['city']
48+
interest = bottle.request.json['interest']
49+
print(city)
50+
print(interest)
51+
if interest is None or interest == '':
52+
interest = 'No Interest Selected'
53+
return bottle.template('views/city.html', {
54+
'city': city,
55+
'interest': interest
56+
})
57+
58+
59+
@bottle.route('/test')
60+
def test_page():
61+
return 'This is a test page'
62+
63+
64+
bottle.debug(True)
65+
bottle.run(host='localhost', port=8080)

credential.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[DatabaseSection]
2+
database.username=python
3+
database.password=class

db_python_class.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pymongo import MongoClient
2+
import configparser
3+
4+
5+
class DatabasePythonClass(object):
6+
# Get credentials
7+
config = configparser.RawConfigParser()
8+
config.read('credential.properties')
9+
db_username = config.get('DatabaseSection', 'database.username')
10+
db_password = config.get('DatabaseSection', 'database.password')
11+
12+
# Connect to database
13+
uri = 'mongodb://' + db_username + ':' + db_password + '@ds031995.mlab.com:31995/python_class'
14+
client = MongoClient(uri)
15+
db = client.python_class
16+
17+
# Connect to collection
18+
# cities = db.cities
19+
20+
# Get info
21+
# item = cities.find_one()
22+
# print(item)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*!
2+
* IE10 viewport hack for Surface/desktop Windows 8 bug
3+
* Copyright 2014-2015 Twitter, Inc.
4+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5+
*/
6+
7+
/*
8+
* See the Getting Started docs for more information:
9+
* http://getbootstrap.com/getting-started/#support-ie10-width
10+
*/
11+
@-webkit-viewport { width: device-width; }
12+
@-moz-viewport { width: device-width; }
13+
@-ms-viewport { width: device-width; }
14+
@-o-viewport { width: device-width; }
15+
@viewport { width: device-width; }

static/main.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
$(document).ready(function () {
2+
'use strict';
3+
4+
$('.selectpicker').selectpicker({
5+
style: 'btn-success',
6+
size: 4
7+
});
8+
9+
let place = $('#place');
10+
let event = $('#event');
11+
let rest = $('#rest');
12+
let placeContent = $('#place-content');
13+
let eventContent = $('#event-content');
14+
let restContent = $('#rest-content');
15+
16+
place.click(function () {
17+
eventContent.removeClass('my-display');
18+
restContent.removeClass('my-display');
19+
eventContent.addClass('my-hide');
20+
restContent.addClass('my-hide');
21+
placeContent.removeClass('my-hide');
22+
placeContent.addClass('my-display');
23+
});
24+
25+
event.click(function () {
26+
placeContent.removeClass('my-display');
27+
restContent.removeClass('my-display');
28+
placeContent.addClass('my-hide');
29+
restContent.addClass('my-hide');
30+
eventContent.removeClass('my-hide');
31+
eventContent.addClass('my-display');
32+
});
33+
34+
rest.click(function () {
35+
eventContent.removeClass('my-display');
36+
placeContent.removeClass('my-display');
37+
eventContent.addClass('my-hide');
38+
placeContent.addClass('my-hide');
39+
restContent.removeClass('my-hide');
40+
restContent.addClass('my-display');
41+
});
42+
43+
function setCookie(name, value) {
44+
document.cookie = name + "=" + encodeURIComponent(value) + "; ";
45+
}
46+
47+
function getCookie(name) {
48+
var value = "; " + document.cookie;
49+
var parts = value.split("; " + name + "=");
50+
if (parts.length == 2) return parts.pop().split(";").shift();
51+
}
52+
53+
$(".interest").click(function () {
54+
var interest_front = this.getAttribute("name");
55+
var city_front = getCookie("city");
56+
console.log(city_front);
57+
setCookie('interest', interest_front);
58+
59+
var interestObj = {
60+
city: city_front,
61+
interest: interest_front
62+
};
63+
var url = 'http://localhost:8080/interest';
64+
var options = {
65+
"method": "POST",
66+
"mode": "cors",
67+
"headers": {
68+
"Content-Type": "application/json;charset=UTF-8"
69+
},
70+
"body": JSON.stringify(interestObj)
71+
};
72+
fetch(url, options);
73+
});
74+
75+
76+
});
77+
78+
79+
80+

static/navbar-fixed-top.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
min-height: 2000px;
3+
padding-top: 70px;
4+
}

static/simple-sidebar.css

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*!
2+
* Start Bootstrap - Simple Sidebar (http://startbootstrap.com/)
3+
* Copyright 2013-2016 Start Bootstrap
4+
* Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE)
5+
*/
6+
7+
body {
8+
overflow-x: hidden;
9+
}
10+
11+
/* Toggle Styles */
12+
13+
#wrapper {
14+
padding-left: 0;
15+
-webkit-transition: all 0.5s ease;
16+
-moz-transition: all 0.5s ease;
17+
-o-transition: all 0.5s ease;
18+
transition: all 0.5s ease;
19+
}
20+
21+
#wrapper.toggled {
22+
padding-left: 250px;
23+
}
24+
25+
#sidebar-wrapper {
26+
z-index: 1000;
27+
position: fixed;
28+
left: 250px;
29+
width: 0;
30+
height: 100%;
31+
margin-left: -250px;
32+
overflow-y: auto;
33+
background: #000;
34+
-webkit-transition: all 0.5s ease;
35+
-moz-transition: all 0.5s ease;
36+
-o-transition: all 0.5s ease;
37+
transition: all 0.5s ease;
38+
}
39+
40+
#wrapper.toggled #sidebar-wrapper {
41+
width: 250px;
42+
}
43+
44+
#page-content-wrapper {
45+
width: 100%;
46+
position: absolute;
47+
padding: 15px;
48+
}
49+
50+
#wrapper.toggled #page-content-wrapper {
51+
position: absolute;
52+
margin-right: -250px;
53+
}
54+
55+
/* Sidebar Styles */
56+
57+
.sidebar-nav {
58+
position: absolute;
59+
top: 0;
60+
width: 250px;
61+
margin: 0;
62+
padding: 0;
63+
list-style: none;
64+
}
65+
66+
.sidebar-nav li {
67+
text-indent: 20px;
68+
line-height: 40px;
69+
}
70+
71+
.sidebar-nav li a {
72+
display: block;
73+
text-decoration: none;
74+
color: #999999;
75+
}
76+
77+
.sidebar-nav li a:hover {
78+
text-decoration: none;
79+
color: #fff;
80+
background: rgba(255,255,255,0.2);
81+
}
82+
83+
.sidebar-nav li a:active,
84+
.sidebar-nav li a:focus {
85+
text-decoration: none;
86+
}
87+
88+
.sidebar-nav > .sidebar-brand {
89+
height: 65px;
90+
font-size: 18px;
91+
line-height: 60px;
92+
}
93+
94+
.sidebar-nav > .sidebar-brand a {
95+
color: #999999;
96+
}
97+
98+
.sidebar-nav > .sidebar-brand a:hover {
99+
color: #fff;
100+
background: none;
101+
}
102+
103+
@media(min-width:768px) {
104+
#wrapper {
105+
padding-left: 250px;
106+
}
107+
108+
#wrapper.toggled {
109+
padding-left: 0;
110+
}
111+
112+
#sidebar-wrapper {
113+
width: 250px;
114+
}
115+
116+
#wrapper.toggled #sidebar-wrapper {
117+
width: 0;
118+
}
119+
120+
#page-content-wrapper {
121+
padding: 20px;
122+
position: relative;
123+
}
124+
125+
#wrapper.toggled #page-content-wrapper {
126+
position: relative;
127+
margin-right: 0;
128+
}
129+
}
130+
131+

0 commit comments

Comments
 (0)