diff --git a/campics_/content/urls.py b/campics_/content/urls.py index 7773ac60717dbeec898613c30b40ba172795b3fc..fdd5cadf17cd010d9e61f35a2e641d02de288519 100644 --- a/campics_/content/urls.py +++ b/campics_/content/urls.py @@ -1,11 +1,12 @@ from django.urls import path -from .views import UploadFeed, LikeFeed, DeleteFeed +from .views import UploadFeed, LikeFeed, DeleteFeed, searchUniv, searchUser urlpatterns = [ path('upload', UploadFeed.as_view(), name='upload_feed'), path('delete', DeleteFeed.as_view(), name='delete_feed'), path('like', LikeFeed.as_view(), name='like'), - + path('searchUniv', searchUniv.as_view(), name='seacrh_univ'), + path('searchUser', searchUser.as_view(), name='search_user'), ] diff --git a/campics_/content/views.py b/campics_/content/views.py index 603196e22e9d07af491950b3c90f4c45882d241c..39bd045113dfac04347150ec432aa3a6b4dbcdac 100644 --- a/campics_/content/views.py +++ b/campics_/content/views.py @@ -90,4 +90,29 @@ class DeleteFeed(APIView): feed.delete() return render(request, "jinstagram/main.html") #프로필페이지 else: - return Response(status=500, data=dict(message='삭제 실패')) \ No newline at end of file + return Response(status=500, data=dict(message='삭제 실패')) + +class searchUniv(APIView): + def get(self, request): + # search_word = request.data.get('univ') + search_word = '대학' + + univ_list = Univ.objects.filter(univ__contains=search_word).values('univ') + + if univ_list.count() == 0: + return Response(status=404, data=dict(message='대학이 없습니다.')) + else: + return Response(status=200, data=dict(univ=univ_list)) + +class searchUser(APIView): + def get(self, request): + # search_word = request.data.get('user') + search_word = 's1' + user_list = Feed.objects.filter(user_id__contains=search_word) # .values() 뭐 필요? + + print(user_list) + + if user_list.count() == 0: + return Response(status=404, data=dict(message='유저가 없습니다.')) + else: + return Response(status=200, data=dict(user=user_list)) \ No newline at end of file diff --git a/campics_/jinstagram/views.py b/campics_/jinstagram/views.py index 7fb57ab6cb2c69d9ffc7ca898374a4a654180dfa..046a52f8780ef6075818199e236b2d9a0b2244a3 100644 --- a/campics_/jinstagram/views.py +++ b/campics_/jinstagram/views.py @@ -41,12 +41,14 @@ class Ranking(APIView): def get(self, request): univ_list = Feed.objects.values('univ')\ - .annotate(score=Count('univ') + Sum('views') + Sum('like_count')) + .annotate(score=Count('univ') + Sum('views') + Sum('like_count'))\ + .order_by('-score') print(univ_list) - + for i in range(len(univ_list)): + print(i, univ_list[i]['univ']) return render(request, - 'jinstagram/main.html', + 'jinstagram/ranking.html', context=dict(univ_list=univ_list)) @@ -67,7 +69,6 @@ class Profile(APIView): for feed in feed_object_list: like_count = FeedLike.objects.filter(feed_id=feed.id, is_like=True).count() is_like = FeedLike.objects.filter(feed_id=feed.id, is_like=True, email=email).exists() - reply_count = Reply.objects.filter(feed_id=feed.id).count() row_feed_list.append(dict( id=feed.id, profile_image=feed.profile_image, @@ -76,7 +77,6 @@ class Profile(APIView): content=feed.content, like_count=like_count, is_like=is_like, - reply_count=reply_count )) if len(row_feed_list) == 3: @@ -86,42 +86,9 @@ class Profile(APIView): if len(row_feed_list) > 0: feed_list.append(dict(row_feed_list=row_feed_list)) - following_count = Follow.objects.filter(follower=email, is_live=True).count() - follower_count = Follow.objects.filter(following=email, is_live=True).count() - - bookmark_list = Bookmark.objects.filter(email=email, is_bookmarked=True).order_by('-id') - bookmark_feed_list = [] - row_bookmark_feed_list = [] - for bookmark in bookmark_list: - feed = Feed.objects.filter(id=bookmark.feed_id).first() - if feed is None: - continue - like_count = FeedLike.objects.filter(feed_id=feed.id, is_like=True).count() - is_like = FeedLike.objects.filter(feed_id=feed.id, is_like=True, email=email).exists() - reply_count = Reply.objects.filter(feed_id=feed.id).count() - row_bookmark_feed_list.append(dict( - id=feed.id, - profile_image=feed.profile_image, - user_id=feed.user_id, - image=feed.image, - content=feed.content, - like_count=like_count, - is_like=is_like, - reply_count=reply_count - )) - - if len(row_bookmark_feed_list) == 3: - bookmark_feed_list.append(dict(row_bookmark_feed_list=row_bookmark_feed_list)) - row_bookmark_feed_list = [] - - if len(row_bookmark_feed_list) > 0: - bookmark_feed_list.append(dict(row_bookmark_feed_list=row_bookmark_feed_list)) return render(request, 'jinstagram/profile.html', context=dict(feed_list=feed_list, - bookmark_feed_list=bookmark_feed_list, feed_count=feed_count, - following_count=following_count, - follower_count=follower_count, user=user)) diff --git a/campics_/templates/jinstagram/ranking.html b/campics_/templates/jinstagram/ranking.html index 0bb9cc03dc867cdf038a57a9da9a6ce7acfa32ed..fcfbb37b3be3bd67d2482b3c6463f5e3f1b8b439 100644 --- a/campics_/templates/jinstagram/ranking.html +++ b/campics_/templates/jinstagram/ranking.html @@ -44,48 +44,17 @@ <thead> <tr> <th scope="col">순위</th> - <th scope="col">이미지</th> <th scope="col">학교</th> - <th scope="col">등록자</th> - <th scope="col">조회수</th> + <th scope="col">점수</th> </tr> </thead> <tbody> - <tr> - <th scope="row">1</th> - <td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td> - <td class="align-middle">아주대학교</td> - <td class="align-middle">아주대사랑꾼</td> - <td class="align-middle">123</td> - </tr> - <tr> - <th scope="row">2</th> - <td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td> - <td class="align-middle">아주대학교</td> - <td class="align-middle">아주대사랑꾼</td> - <td class="align-middle">123</td> - </tr> - <tr> - <th scope="row">3</th> - <td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td> - <td class="align-middle">아주대학교</td> - <td class="align-middle">아주대사랑꾼</td> - <td class="align-middle">123</td> - </tr> - <tr> - <th scope="row">4</th> - <td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td> - <td class="align-middle">아주대학교</td> - <td class="align-middle">아주대사랑꾼</td> - <td class="align-middle">123</td> - </tr> - <tr> - <th scope="row">5</th> - <td><a href="boarddetail.html"><img src="{% static '/img/empty.png' %}" class="rounded" style="width:3em" alt="..."></a></td> - <td class="align-middle">아주대학교</td> - <td class="align-middle">아주대사랑꾼</td> - <td class="align-middle">123</td> - </tr> + {% for univ in univ_list %} + <tr> + <td class="align-middle">{{univ.univ}}</td> + <td class="align-middle">{{univ.score}}</td> + </tr> + {% endfor %} </tbody> </table> </div> diff --git a/campics_/user/views.py b/campics_/user/views.py index 0dca363a171b451c71edd40fe77bf99bda8d3796..66a992d1a815947b6006541d223b218d9381ff5a 100644 --- a/campics_/user/views.py +++ b/campics_/user/views.py @@ -43,7 +43,7 @@ class Join(APIView): def post(self, request): password = request.data.get('password') # email = request.data.get('user_id') - email = "ksshhses@ajou.ac.kr" + email = "ksshhses@khu.ac.kr" user_id = request.data.get('nickname') name = request.data.get('name') univ = request.data.get('univname')