Commit 86fba63d authored by AMAN MORESHWAR JANGDE's avatar AMAN MORESHWAR JANGDE

Merge branch 'Prof_module_impl' into 'master'

Like counter for threads impl

See merge request !3
parents 63b4d098 80b3f15e
......@@ -35,6 +35,8 @@ urlpatterns = [
path('withdraw_subject/<str:sub_code>', views.withdraw_subject),
path('topics/<str:id>', views.show_topics),
path('threads/<int:id>', views.show_threads),
path('threads/like/<int:thread_id>/<int:topic_id>', views.update_thread_like_count),
path('threads/dislike/<int:thread_id>/<int:topic_id>', views.update_thread_dislike_count),
path('login', views.login),
path('signup', views.signup),
......
......@@ -68,7 +68,7 @@ class Like(models.Model):
is_liked = models.BooleanField(default=True)
def __str__(self):
return self.tid
return str(self.id)
class Meta:
db_table = "like"
\ No newline at end of file
......@@ -20,10 +20,10 @@
</div>
<div class="btn-panel btn-panel-msg">
<!-- <div class="btn-panel btn-panel-msg">
<a href="" class="btn col-sm-3 send-message-btn pull-right" role="button"><i class="fa fa-gears"></i> Settings</a>
</div>
</div> -->
</div>
</div>
<div class="row">
......@@ -49,9 +49,13 @@
<div class="msg-footer-link col-sm-6 col-lg-4">
<!-- <a><div class="col-sm-4 col-lg-4 fa fa-comment"><span> </span>Reply <span>999</span></div></a> -->
<!-- <div class="col-sm-1">|</div> -->
<a><div class="col-sm-4 col-lg-4 fa fa-thumbs-up"><span> </span>Agree <span>{{thread.likes}}</span></div></a>
<a href="/threads/like/{{thread.id}}/{{topic_id}}">
<div class="col-sm-4 col-lg-4 fa fa-thumbs-up"><span> </span>Agree <span>{{thread.likes}}</span></div>
</a>
<!-- <div class="col-sm-1">|</div> -->
<a><div class="col-sm-4 col-lg-4 fa fa-thumbs-down"><span> </span>Disagree <span>{{thread.dislikes}}</span></div></a>
<a href="/threads/dislike/{{thread.id}}/{{topic_id}}">
<div class="col-sm-4 col-lg-4 fa fa-thumbs-down"><span> </span>Disagree <span>{{thread.dislikes}}</span></div>
</a>
</div>
</div>
{% endfor %}
......
from django.shortcuts import render, redirect
from discussion.forms import ThreadForm, TopicForm, SignupForm, SubjectForm, LoginForm
from discussion.models import Subject_Student, Person, Subject, Topic, Thread, Person
from discussion.models import Subject_Student, Person, Subject, Topic, Thread, Person, Like
def login(request):
invalid_user = False
......@@ -279,3 +279,61 @@ def show_threads(request, id):
return render(request,'prof_discussion_threads.html',{'form':form, 'topic_id':id, 'threads':threads, 'context':context, 'is_prof':is_prof})
else:
return render(request,'discussion_thread.html',{'form':form, 'topic_id':id, 'threads':threads, 'context':context, 'is_prof':is_prof})
def update_thread_like_count(request, thread_id, topic_id):
context = request.session['session_context']
try:
thread = Thread.objects.get(id=thread_id)
person = Person.objects.get(pid=context)
except Exception as e:
print (e)
return redirect('/threads/'+str(topic_id))
try:
like = Like.objects.get(thread=thread, person=person)
if like.is_liked == False :
like.is_liked = True
like.save()
thread.likes = thread.likes + 1
thread.dislikes = thread.dislikes - 1
thread.save()
else:
pass
except:
like = Like(thread=thread, person=person, is_liked = True)
like.save()
thread.likes = thread.likes + 1
thread.save()
return redirect('/threads/'+str(topic_id))
def update_thread_dislike_count(request, thread_id, topic_id):
context = request.session['session_context']
try:
thread = Thread.objects.get(id=thread_id)
person = Person.objects.get(pid=context)
except Exception as e:
print (e)
return redirect('/threads/'+str(topic_id))
try:
like = Like.objects.get(thread=thread, person=person)
if like.is_liked == True :
like.is_liked = False
like.save()
thread.likes = thread.likes - 1
thread.dislikes = thread.dislikes + 1
thread.save()
else:
pass
except:
like = Like(thread=thread, person=person, is_liked = False)
like.save()
thread.dislikes = thread.dislikes + 1
thread.save()
return redirect('/threads/'+str(topic_id))
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment