Skip to content

Commit

Permalink
search_front
Browse files Browse the repository at this point in the history
  • Loading branch information
white-bean committed Jan 14, 2022
1 parent 1a0563a commit ed4a730
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 68 deletions.
6 changes: 4 additions & 2 deletions WNrecomm/static/css/q3.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ table{
font-size: 20px;
width:100%;
height:25px;

flex-direction: row-reverse;
display:inline;
margin-top: 5px;
}

.star-rating input {
Expand All @@ -81,7 +83,7 @@ table{
color:#ccc;
cursor:pointer;
float:left;
margin:3px 3px 0 0;
margin:0 3px 0 0;
}

.star-rating :checked ~ label {
Expand Down
46 changes: 11 additions & 35 deletions WNrecomm/templates/q3.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
<table>
<colgroup>
<col style="width:30%">
<col style="width:50%">
<col style="width:20%">
<col style="width:70%">
</colgroup>
{% for novel in search_result %}
<tr>
<td class="thumbnail"><img src="{% static 'img/adult_yes.svg' %}" alt=""></td>
<td class="thumbnail"><img src="{{novel.image}}" alt="" width="85" height="122"></td>
<td>
<p class="title">제목</p>
<div class="author">작가</div>
<div class="genre">장르</div>
<p class="title">{{novel.title}}</p>
<div class="author">{{novel.author}}</div>
<div class="genre">{{novel.genre}}</div>
<div class="star-rating">
<input type="radio" id="5-stars" name="rating" value="5" />
<label for="5-stars" class="star">&#9733;</label>
Expand All @@ -59,34 +59,10 @@
<input type="radio" id="1-star" name="rating" value="1" />
<label for="1-star" class="star">&#9733;</label>
</div>
</td>
<td valign="bottom">
<button type="button" class="add_btn">선택</button>
</td>
</tr>
<tr>
<td class="thumbnail"><img src="{% static 'img/adult_yes.svg' %}" alt=""></td>
<td>
<p class="title">제목</p>
<div class="author">작가</div>
<div class="genre">장르</div>
<div class="star-rating">
<input type="radio" id="5-stars" name="rating" value="5" onclick="rating(this)"/>
<label for="5-stars" class="star">&#9733;</label>
<input type="radio" id="4-stars" name="rating" value="4" onclick="rating(this)"/>
<label for="4-stars" class="star">&#9733;</label>
<input type="radio" id="3-stars" name="rating" value="3" onclick="rating(this)"/>
<label for="3-stars" class="star">&#9733;</label>
<input type="radio" id="2-stars" name="rating" value="2" onclick="rating(this)"/>
<label for="2-stars" class="star">&#9733;</label>
<input type="radio" id="1-star" name="rating" value="1" onclick="rating(this)"/>
<label for="1-star" class="star">&#9733;</label>
</div>
</td>
<td valign="bottom">
<button type="button" class="add_btn">선택</button>
</td>
<button type="button" class="add_btn" onclick="select_novel()">선택</button>
</td>
</tr>
{% endfor %}
</table>

<a type='button' href="{% url 'novel_list' %}">
Expand All @@ -100,8 +76,8 @@
{% endblock %}
{% block script %}
<script>
function rating(field){
console.log(field.value);
function select_novel(){

}
</script>
{% endblock %}
67 changes: 36 additions & 31 deletions WNrecomm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
import requests
#import requests
import urllib.request
import json
from collections import OrderedDict

novel = pd.read_csv('novel.csv',encoding='cp949').drop('Unnamed: 0',axis=1)
review = pd.read_csv('review.csv')
text = pd.read_csv('text.csv').drop('Unnamed: 0',axis=1)
cos = pd.read_csv('cosine_sim.csv').drop('Unnamed: 0',axis=1)
novel = pd.read_csv('WNrecomm/static/novel.csv',encoding='cp949').drop('Unnamed: 0',axis=1)
review = pd.read_csv('WNrecomm/static/review.csv')
text = pd.read_csv('WNrecomm/static/text.csv').drop('Unnamed: 0',axis=1)
cos = pd.read_csv('WNrecomm/static/cosine_sim.csv').drop('Unnamed: 0',axis=1)



def main(request):
return render(request, 'main.html')


def q_base(request):
return render(request, 'q_base.html')

Expand All @@ -47,39 +46,45 @@ def q2(request):
cb = 0


dict_user = {'like' : 0 , 'avgrating' : 0 , 'totalreview':0, 'purchase':0, 'waiting':0, 'keywords':0}
#dict_user = {'like' : 0 , 'avgrating' : 0 , 'totalreview':0, 'purchase':0, 'waiting':0, 'keywords':0}
dict_user=[0, 0, 0, 0, 0, 0]

def q3(request):
if request.method == 'GET':
selected = request.GET.get('chb')
for i in selected :
dict_user[i-1] = 1

search = request.GET.get('search') # 검색어. json 형태로 보내기
idx_list = []
for i in range(len(novel)) :
if str(search) in novel['제목'][i] :
idx_list.append(i)



idx_dict = {
'image' : novel.loc[idx_list,'썸네일'].tolist() ,
'title' : novel.loc[idx_list,'제목'].tolist() ,
'author': novel.loc[idx_list,'작가'].tolist() ,
'genre' : novel.loc[idx_list,'장르'].tolist()
}

targetJson = json.dumps(idx_dict)


return render(request, 'q3.html',{'targetjson' : targetJson})
if request.GET.get('chb'):
selected = request.GET.get('chb')
for i in range(0, len(selected)+1, 2) :
dict_user[int(selected[i])-1] = 1
#print(dict_user)
return render(request, 'q3.html')

elif request.GET.get('search'):
search = request.GET.get('search') # 검색어. json 형태로 보내기
idx_list = []
for i in range(len(novel)) :
if str(search) in novel['제목'][i] :
idx_list.append(i)

search_result = []
for i in idx_list:
idx_dict = {
'image' : novel.loc[i,'썸네일'],
'title' : novel.loc[i,'제목'],
'author': novel.loc[i,'작가'],
'genre' : novel.loc[i,'장르']
}
search_result.append(idx_dict)

#print(search_result)
#targetJson = json.dumps(idx_dict)
return render(request, 'q3.html',{'search_result' : search_result})


# 프론트 : 별점 평가, 장바구니 담기기 -- novellist (가상 유저 데이터 프레임 생성)



'''
# (1차완) 추천 코드 복붙 & 수정 -- 추천 결과 리스트 json 반환되게 하기 -- 프론트에 넘기는
Expand Down Expand Up @@ -280,7 +285,7 @@ def cf_item_recomm(pred_df, ID, unseen_list, top_n=10):
#####################################################

'''
def loading(request):
return render(request, 'loading.html')

Expand Down

0 comments on commit ed4a730

Please sign in to comment.