Skip to content

Commit a530a8e

Browse files
author
erickim0919
committed
Merge branch 'users' of github.com:vs2961/reimagined-rotary-phone into users
2 parents 9fc3334 + 69d7426 commit a530a8e

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

website/app/views.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ def serve():
2929
def dump_sorted():
3030
req_data = request.get_json()
3131
cars = Car.query
32+
sort = False
3233
big_cars = []
33-
3434
if req_data["Price"]:
35+
sort = True
3536
for price in req_data["Price"]:
3637
mini_cars = cars.filter(Car.MSRP <= price[1])\
3738
.filter(Car.MSRP >= price[0])
3839
big_cars.append(mini_cars)
3940

4041
if req_data["Type"]:
42+
sort = True
4143
if len(big_cars) == 0:
4244
for car_type in req_data["Type"]:
4345
mini_cars = cars.filter_by(type=car_type)
@@ -51,6 +53,7 @@ def dump_sorted():
5153
big_cars = poses.copy()
5254

5355
if req_data["Seats"]:
56+
sort = True
5457
if len(big_cars) == 0:
5558
for seat in req_data["Seats"]:
5659
mini_cars = cars.filter(Car.seats.between(
@@ -63,18 +66,22 @@ def dump_sorted():
6366
pos = big_cars[i].filter(Car.seats.between(seat[0], seat[1]))
6467
poses.append(pos)
6568
big_cars = poses.copy()
66-
final_list = []
67-
for car in big_cars:
68-
for k in car.all():
69-
if k not in final_list:
70-
final_list.append(k)
71-
if req_data["sort_by"] == "MSRP":
72-
cars = sorted([car.serialize() for car in final_list],
73-
key=lambda x: x[req_data["sort_by"]])
69+
if sort:
70+
final_list = []
71+
for car in big_cars:
72+
for k in car.all():
73+
if k not in final_list:
74+
final_list.append(k)
75+
if req_data["sort_by"] == "MSRP":
76+
cars = sorted([car.serialize() for car in final_list],
77+
key=lambda x: x[req_data["sort_by"]])
78+
else:
79+
cars = sorted([car.serialize() for car in final_list],
80+
key=lambda x: x[req_data["sort_by"]], reverse=True)
7481
else:
75-
cars = sorted([car.serialize() for car in final_list],
82+
cars = sorted([car.serialize() for car in cars.all()],
7683
key=lambda x: x[req_data["sort_by"]], reverse=True)
77-
84+
7885
return jsonify(split(cars, 3))
7986

8087

@@ -83,13 +90,16 @@ def dump_rating():
8390
req_data = request.get_json()
8491
cars = Car.query
8592
big_cars = []
93+
sort = False
8694
if req_data["Price"]:
95+
sort = True
8796
for price in req_data["Price"]:
8897
mini_cars = cars.filter(Car.MSRP <= price[1])\
8998
.filter(Car.MSRP >= price[0])
9099
big_cars.append(mini_cars)
91100

92101
if req_data["Type"]:
102+
sort = True
93103
if len(big_cars) == 0:
94104
for car_type in req_data["Type"]:
95105
mini_cars = cars.filter_by(type=car_type)
@@ -103,6 +113,7 @@ def dump_rating():
103113
big_cars = poses.copy()
104114

105115
if req_data["Seats"]:
116+
sort = True
106117
if len(big_cars) == 0:
107118
for seat in req_data["Seats"]:
108119
mini_cars = cars.filter(Car.seats.between(
@@ -115,13 +126,17 @@ def dump_rating():
115126
pos = big_cars[i].filter(Car.seats.between(seat[0], seat[1]))
116127
poses.append(pos)
117128
big_cars = poses.copy()
118-
final_list = []
119-
for car in big_cars:
120-
for k in car.all():
121-
if k not in final_list:
122-
final_list.append(k)
123-
cars = sorted([car.serialize() for car in final_list],
124-
key=lambda x: x[req_data["sort_by"]], reverse=True)
129+
if sort:
130+
final_list = []
131+
for car in big_cars:
132+
for k in car.all():
133+
if k not in final_list:
134+
final_list.append(k)
135+
cars = sorted([car.serialize() for car in final_list],
136+
key=lambda x: x[req_data["sort_by"]], reverse=True)
137+
else:
138+
cars = sorted([car.serialize() for car in cars.all()],
139+
key=lambda x: x[req_data["sort_by"]], reverse=True)
125140

126141
return jsonify(cars)
127142

website/client/src/homepage/Welcome.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class Welcome extends React.PureComponent {
5353
Price: [],
5454
Type: [],
5555
Seats: [],
56-
futureRound: this.rounds[1],
5756
sort_by: this.state.currentFilter,
5857
};
5958

website/client/src/results/ResultPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ResultPage extends React.PureComponent {
2323
this.sortedRatings = this.props.location.state.sortedRatings;
2424
this.sortedMpg = this.props.location.state.sortedMpg;
2525
}
26-
console.log(this.badgePrices);
26+
console.log(this.sortedPrices);
2727

2828
this.state = {
2929
currentFilter: this.sortedPrices,
@@ -120,6 +120,7 @@ class ResultPage extends React.PureComponent {
120120
<Grid container>
121121
{/* maps each car onto the page */}
122122
{Object.entries(this.state.currentFilter).map(([key, value]) => {
123+
console.log(value);
123124
var badges = {};
124125
var foundPrice = false;
125126
for (var i = 0; i < this.badgePrices.length && !foundPrice; i++) {

0 commit comments

Comments
 (0)