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 modified __pycache__/database.cpython-37.pyc
Binary file not shown.
96 changes: 72 additions & 24 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from database import DBhandler
import hashlib
import sys
import math
from flask import jsonify

application = Flask(__name__)
application.config["SECRET_KEY"] = "helloosp"
Expand All @@ -16,77 +18,96 @@ def hello():
@application.route("/list")
def view_list():
page = request.args.get("page", 0, type=int)
category = request.args.get("category", "all")
per_page=6
per_row=3
row_count=int(per_page/per_row)
start_idx=per_page*page
end_idx=per_page*(page+1)

data = DB.get_items()
print("################333",data)
if category == "all":
data = DB.get_items()
else:
data = DB.get_items_bycategory(category)
data = dict(sorted(data.items(), key=lambda x: x[0], reverse=False))
item_counts = len(data)
data = dict(list(data.items())[start_idx:end_idx])
if item_counts <= per_page:
data = dict(list(data.items())[:item_counts])
else:
data = dict(list(data.items())[start_idx:end_idx])
tot_count = len(data)

for i in range(row_count):
if (i == row_count-1) and (tot_count%per_row != 0):
locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:])
else:
locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:(i+1)*per_row])


return render_template(
"list.html",
datas=data.items(),
row1=locals()['data_0'].items(),
row2=locals()['data_1'].items(),
limit=per_page,
page=page,
page_count=int((item_counts/per_page)+1),
total=item_counts
page_count=int(math.ceil(item_counts/per_page)),
total=item_counts,
category=category
)

@application.route("/reg_review_init/<name>/")
def reg_review_init(name):
return render_template("reg_reviews.html", name=name)

@application.route("/reg_review", methods=['POST'])
def reg_review():
data = request.form
image_file = request.files["file"]
img_path = "static/images/{}".format(image_file.filename)
image_file.save(img_path)
DB.reg_review(data, image_file.filename)
return redirect(url_for('view_review'))

@application.route("/review")
def view_review():
page = request.args.get("page", 0, type = int)
per_page = 6
per_row = 3
row_count = int(per_page/per_row)
start_idx = per_page*per_page
start_idx = per_page*page
end_idx = per_page*(page+1)

data = DB.get_reviews()
item_counts = len(data)
data = dict(list(data.items())[start_idx:end_idx])
tot_count = len(data)

for i in range(row_count):
if(i == row_cont-1) and (tot_count%per_row != 0):
if(i==row_count-1) and (tot_count%per_row!=0):
locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:])
else:
else:
locals()['data_{}'.format(i)] = dict(list(data.items())[i*per_row:(i+1)*per_row])
return render_template(
"review.html",
data = data.items(),
datas = data.items(),
row1 = locals()['data_0'].items(),
row2 = locals()['data_1'].items(),
limit = per_page,
page = page,
page_count = int(item_counts/per_page+1),
total = item_counts)
total = item_counts
)

@application.route("/view_review_detail/<name>/")
def view_review_detail(name):
review_data = DB.get_review_byname(name)
if review_data:
return render_template("review_detail.html", data=review_data)
else:
return redirect(url_for('view_review'))

@application.route("/reg_items")
def reg_item():
return render_template("reg_items.html")

@application.route("/reg_review_init/<name>/")
def reg_review_init(name):
return render_template("reg_reviews.html", name=name)

@application.route("/reg_review", methods=['POST'])
def reg_review():
data = request.form
DB.reg_review(data)
return redirect(url_for('view_review'))

@application.route("/submit_item_post", methods=['POST'])
def reg_item_submit_post():
image_file = request.files["file"]
Expand Down Expand Up @@ -154,6 +175,33 @@ def view_item_detail(name):
print("####data:",data)
return render_template("detail.html", name=name, data=data)

@application.route('/show_heart/<name>/', methods=['GET'])
def show_heart(name):
my_heart = DB.get_heart_byname(session['id'],name)
return jsonify({'my_heart': my_heart})

@application.route('/like/<name>/', methods=['POST'])
def like(name):
my_heart = DB.update_heart(session['id'],'Y',name)
return jsonify({'msg': '좋아요 완료!'})

@application.route('/unlike/<name>/', methods=['POST'])
def unlike(name):
my_heart = DB.update_heart(session['id'],'N',name)
return jsonify({'msg': '안좋아요 완료!'})

@application.route("/search")
def search():
query = request.args.get("query")
all_items = DB.get_items()

# Filter items based on item name or seller's ID
filtered_items = {name: details for name, details in all_items.items()
if query.lower() in name.lower() or query.lower() in details.get('seller', '').lower()}

return render_template("search_result.html", items=filtered_items)



if __name__ == "__main__":
application.run(host='0.0.0.0', debug=True)
application.run(host='0.0.0.0', debug=True)
58 changes: 52 additions & 6 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def user_duplicate_check(self, id_string):
users = self.db.child("user").get()

print("users###", users.val())
if str(users.val()) == "None": # first registration
if str(users.val()) == "None":
return True
else:
for res in users.each():
Expand Down Expand Up @@ -74,16 +74,62 @@ def get_item_byname(self, name):
target_value=res.val()
return target_value

def reg_review(self, data):
def get_items_bycategory(self, cate):
items = self.db.child("item").get()
target_value = []
target_key = []
for res in items.each():
value = res.val()
key_value = res.key()

if value['category'] == cate:
target_value.append(value)
target_key.append(key_value)
print("######target_value", target_value)
new_dict = {}

for k, v in zip(target_key, target_value):
new_dict[k] = v

return new_dict

def reg_review(self, data, img_path):
review_info ={
"rate": data['reviewStar'],
"review": data['reviewContents']
"title": data['title'],
"review": data['reviewContents'],
"img_path": img_path
}
self.db.child("review").child(data['name']).set(review_info)
return True

def get_review(self):
review = self.db.child("review").get().val()
def get_review_byname(self,name):
reviews = self.db.child("review").get().val()
for key, value in reviews.items():
if key == name:
return value

def get_reviews(self):
reviews = self.db.child("review").get().val()
return reviews


def get_heart_byname(self,uid,name):
hearts = self.db.child("heart").child(uid).get()
target_value=""
if hearts.val() == None:
return target_value
for res in hearts.each():
key_value = res.key()

if key_value == name:
target_value=res.val()
return target_value

def update_heart(self,user_id,isHeart,item):
heart_info={
"interested":isHeart
}
self.db.child("heart").child(user_id).child(item).set(heart_info)
return True


Empty file added static/images/apple_review.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/apple_review.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/ball_review.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/kiwi_review.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/orange_review.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/potato_review.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added static/images/sweet_review.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/sweet_review.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion static/main.js
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

9 changes: 9 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ body {
resize: none;
}

#heart {
color: grey;
font-size: 50px;
}

#heart.red {
color: red;
}

/* Responsive layout - when the screen is less than 400px wide, make the navigation links stack on top of each other instead of next to each other */
@media screen and (max-width: 400px) {
.navbar__menu li {
Expand Down
67 changes: 67 additions & 0 deletions templates/detail.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
{% extends "index.html" %}

{% block section %}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
</head>

<script>
function showHeart() {
$.ajax({
type: 'GET',
url: '/show_heart/{{name}}/',
data: {},
success: function (response){
let my_heart = response['my_heart'];
if (my_heart['interested'] == 'Y') {
$("#heart").css("color","red");
$("#heart").attr("onclick","unlike()");
}
else {
$("#heart").css("color","grey");
$("#heart").attr("onclick","like()");
}
//alert("showheart!")

}
});
}
function like() {
$.ajax({
type: 'POST',
url: '/like/{{name}}/',
data: {
interested : "Y"
},
success: function (response) {
alert(response['msg']);
window.location.reload()
}
});
}
function unlike() {
$.ajax({
type: 'POST',
url: '/unlike/{{name}}/',
data: {
interested : "N"
},
success: function (response) {
alert(response['msg']);
window.location.reload()
}
});
}
$(document).ready(function(){
showHeart();
});
</script>

<p>
item name is <b>{{name}}</b> and address is {{data.addr}}
</p>
Expand All @@ -20,5 +76,16 @@
<button onclick = "location.href='/reg_review_init/{{name}}/';">
리뷰등록
</button>
<i class="fa fa-heart" id="heart"></i>

<style>
#heart{
color:grey;
font-size: 50px;
}

#heart.red{
color:red;
}
</style>
{% endblock section %}
6 changes: 5 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>Home</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<script src="{{ url_for('static', filename='main.js') }}" defer></script>
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<nav class="navbar">
Expand All @@ -27,7 +28,10 @@
</nav>
<section>
{% block section %}

<form action="/search" method="get">
<input type="text" name="query" placeholder="상품명, 판매자 아이디 검색">
<button type="submit">Search</button>
</form>
{% endblock section %}
</section>
</body>
Expand Down
18 changes: 18 additions & 0 deletions templates/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{% extends "index.html" %}

{% block section %}
<script>
$(document).ready(function() {
//alert("{{category}}");
$('#category option:contains("{{category}}")').prop("selected", true);
});
</script>

<div>
<select id="category" name="category" onchange="location=this.value">
<option value="{{url_for('view_list', page=i, category='all')}}">All</option>
<option value="{{url_for('view_list', page=i, category='Clothes')}}">Clothes</option>
<option value="{{url_for('view_list', page=i, category='Beauty')}}">Beauty</option>
<option value="{{url_for('view_list', page=i, category='Books')}}">Books</option>
<option value="{{url_for('view_list', page=i, category='Furniture')}}">Furniture</option>
<option value="{{url_for('view_list', page=i, category='Electronics')}}">Electronics</option>
<option value="{{url_for('view_list', page=i, category='ETC')}}">ETC</option>
</select>
</div>
{% if total > 0 %}
<p>
상품 리스트 -- 현재까지 {{total}}개 등록됨
Expand Down
Loading