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

[FeedSearch/searchHashTag] 해시태그 검색, 중복 해시태그 등록 안 되게 하기 #86

Open
wants to merge 3 commits into
base: develop
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
1 change: 1 addition & 0 deletions templates/certificationRegister.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1 style="color:black">새 인증서</h1>
<form class="cert-music-input" action="methods" enctype="multipart/form-data">
<input type="text" id="songinfo" class="whatToSearch form-white-btn" placeholder="검색" autocomplete="off"/>
<button type="button" class="" id='addMusicBtn'>검색</button>
<input type="text" style="display: none" />
</form>
</div>
<button id="registerMusic" class="form-white-btn form-submit-btn">노래 등록</button>
Expand Down
71 changes: 33 additions & 38 deletions templates/feedSearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,38 @@
{% if feed.inputTags %}
<div id ="newHash" style="display:none";>{{feed.inputTags}}</div>
<script>
const hashTag = document.querySelector("#newHash").innerHTML;
console.log(hashTag);
addInputTag(hashTag);
const usersTag = document.querySelector("#newHash").innerHTML;
const choiceTags = document.querySelectorAll('.hashtag--btn');
let choiceTagList = []
for (let i=0; i < choiceTags.length; i++) {
let choiceTag = choiceTagList.push(choiceTags[i].innerText);
}
addInputTag(usersTag);

function addInputTag(tags) {
console.log("!!")
const hashTagArray = tags.split(' ');

for (let i=0; i < hashTagArray.length; i++) {
const newDiv = document.createElement('div');
newDiv.setAttribute("class", "hashtag--btn");
const newText = document.createTextNode(hashTagArray[i]);
newDiv.appendChild(newText);
const tagDiv = document.querySelector('.feed-hashtagList');
tagDiv.append(newDiv);
let uniqueTagArray = [];
hashTagArray.forEach((element) => {
if (!uniqueTagArray.includes(element)) {
uniqueTagArray.push(element);
}
});

//choiceTags 안에서도 동일할 때를 처리해 줘야 함
for (let i=0; i < uniqueTagArray.length; i++) {
if (!(choiceTagList.includes(uniqueTagArray[i]))) {
const newDiv = document.createElement('div');
newDiv.setAttribute("class", "hashtag--btn");
const newText = document.createTextNode(uniqueTagArray[i]);
newDiv.appendChild(newText);
const tagDiv = document.querySelector('.feed-hashtagList');
tagDiv.append(newDiv);
}
else {
}
};
}
</script>
</script>
{% endif %}
</div>
</div>
Expand All @@ -145,10 +160,6 @@
<img src="{% static 'img/default.jpeg' %}" class="feed--userImg" alt="userImg">
{% endif %}
<p class="feed--userName">{{feed.userId.nickName}}</p>
<!--<div class="feed-twobtn">
<a href="">수정</a>
<a href="">삭제</a>
</div>-->
</div>
</div>
{% endif %}
Expand Down Expand Up @@ -294,29 +305,13 @@ <h5 class="modal-title" style="color: black;">피드 등록하기</h5>
}
}

function hashTagsToArray(tags) {
console.log("!!")
const hashTagArray = str.split(" ");

for (let i = 0; i < hashTagArray.length; i++){
//const element = document.querySelector(`.hashTag`);
const newDiv = document.createElement('div');
newDiv.setAttribute("class", "hashtag--btn");
const newText = document.createTextNode(hashTagArray[i]);
newDiv.appendChild(newText);
const tagDiv = document.querySelector('.feed-hashtagList');
tagDiv.append(newDiv);

}
}

function autolink() {
var container = document.getElementsByClassName("feed-content");
for (let i = 0; i < container.length; i++) {
var doc = container[i].innerHTML;
var regURL = new RegExp("(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)","gi");
container[i].innerHTML = doc.replace(regURL,"<a href='$1://$2' target='_blank'>$1://$2</a>");
}
for (let i = 0; i < container.length; i++) {
var doc = container[i].innerHTML;
var regURL = new RegExp("(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)","gi");
container[i].innerHTML = doc.replace(regURL,"<a href='$1://$2' target='_blank'>$1://$2</a>");
}
}

autolink();
Expand Down
60 changes: 47 additions & 13 deletions templates/updateFeed.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{% extends "searchBase.html" %}
{% load static %}
{% load bootstrap4 %}
{% block content %}
<div class="feed-result">
<p class="my_search_text">검색 결과: <b>"{{query}}"</b></p>
Expand All @@ -25,6 +25,7 @@
<a href="{% url 'user:searchMyFeed' %}"><button class="feed-my" value="myFeed">내 글 모아보기</button></a>
<a href="#"><button class="feed-like">좋아요 모아보기</button></a>
</div>
{% endif %}


{% for feed in feeds %}
Expand Down Expand Up @@ -60,7 +61,7 @@
<i class="far fa-heart likeButton" data-id="{{ feed.id }}" style="color:red"></i>
{% endif %}
<span id="like-count-{{ feed.id }}">{{ feed.like_users.count }}</span>
{% endif %}
{% endif %}
<div class="feed-hashtagList">
{% for tag in feed.tags.all %}
<div class="hashtag--btn">{{tag}}
Expand Down Expand Up @@ -103,12 +104,47 @@
<i class="far fa-heart likeButton" data-id="{{ feed.id }}" style="color:red"></i>
{% endif %}
<span id="like-count-{{ feed.id }}">{{ feed.like_users.count }}</span>
{% endif %}
{% endif %}
<div class="feed-hashtagList">
{% for tag in feed.tags.all %}
<div class="hashtag--btn">{{tag}}
</div>
<div id="hashTag" class="hashtag--btn">{{tag}}</div>
{% endfor %}
{% if feed.inputTags %}
<div id ="newHash" style="display:none";>{{feed.inputTags}}</div>
<script>
const usersTag = document.querySelector("#newHash").innerHTML;
const choiceTags = document.querySelectorAll('.hashtag--btn');
let choiceTagList = []
for (let i=0; i < choiceTags.length; i++) {
let choiceTag = choiceTagList.push(choiceTags[i].innerText);
}
addInputTag(usersTag);

function addInputTag(tags) {
const hashTagArray = tags.split(' ');
let uniqueTagArray = [];
hashTagArray.forEach((element) => {
if (!uniqueTagArray.includes(element)) {
uniqueTagArray.push(element);
}
});

//choiceTags 안에서도 동일할 때를 처리해 줘야 함
for (let i=0; i < uniqueTagArray.length; i++) {
if (!(choiceTagList.includes(uniqueTagArray[i]))) {
const newDiv = document.createElement('div');
newDiv.setAttribute("class", "hashtag--btn");
const newText = document.createTextNode(uniqueTagArray[i]);
newDiv.appendChild(newText);
const tagDiv = document.querySelector('.feed-hashtagList');
tagDiv.append(newDiv);
}
else {
}
};
}
</script>
{% endif %}
</div>
</div>

Expand Down Expand Up @@ -138,7 +174,7 @@
</div>


{% endfor %}
{% endfor %}
</div>

<!--<div class="white-form tag-list">
Expand Down Expand Up @@ -169,12 +205,11 @@ <h5 class="modal-title" style="color: black">피드 등록하기</h5>
<div class="musicListList"></div>

<button id="registerMusic" style="

border-radius: 1rem;
border-width: 0.1rem;
background-color: cornflowerblue;
color: white;
onclick="registerMusic()">
border-radius: 1rem;
border-width: 0.1rem;
background-color: cornflowerblue;
color: white;"
onclick="registerMusic()">
노래 등록
</button>
<form method="POST" class="post-form" enctype="multipart/form-data">
Expand All @@ -187,7 +222,6 @@ <h5 class="modal-title" style="color: black">피드 등록하기</h5>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
<
crossorigin="anonymous"></script>

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
Expand Down
15 changes: 9 additions & 6 deletions user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def mainSearch(request):
continue
else:
hashTagList[count]=random_object.name
count += 1;
count += 1
print(hashTagList)
return render(request, 'mainPage.html', {'hashTags':hashTagList})

Expand Down Expand Up @@ -117,11 +117,14 @@ def searchResult(request):
feeds = Feed.objects.all().order_by('-createdDate')
return render(request, 'feedSearch.html', {'query':query, 'feeds':feeds, 'form':form})
if query[0] == '#':
tagId = HashTag.objects.filter(name=query)
try:
feeds = Feed.objects.all().filter(tags=tagId[0].id).order_by('-createdDate')
except:
feeds = None;
choiceTag = HashTag.objects.filter(name=query)
#inputTags 안에서도 검색할 수 있도록#
if len(choiceTag) != 0:
feeds = Feed.objects.all().filter(tags=choiceTag[0].id).order_by('-createdDate')
elif len(choiceTag) == 0:
feeds = Feed.objects.all().filter(Q(inputTags__icontains=query)).order_by('-createdDate')
else:
feeds = None
return render(request, 'feedSearch.html', {'query':query, 'feeds':feeds, 'form':form})
feeds = Feed.objects.all().filter(Q(music__icontains=query) | Q(artist__icontains=query) | Q(content__icontains=query)).order_by('-createdDate')

Expand Down