Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS699_COURSEBOOK
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AMAN MORESHWAR JANGDE
CS699_COURSEBOOK
Commits
80b3f15e
Commit
80b3f15e
authored
Nov 26, 2019
by
AMAN MORESHWAR JANGDE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Like counter for threads impl
parent
a892bce0
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
7 deletions
+71
-7
coursebook/urls.py
coursebook/urls.py
+2
-0
discussion/models.py
discussion/models.py
+1
-1
discussion/templates/discussion_thread.html
discussion/templates/discussion_thread.html
+8
-4
discussion/views.py
discussion/views.py
+60
-2
djangodb
djangodb
+0
-0
No files found.
coursebook/urls.py
View file @
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
),
...
...
discussion/models.py
View file @
80b3f15e
...
...
@@ -68,7 +68,7 @@ class Like(models.Model):
is_liked
=
models
.
BooleanField
(
default
=
True
)
def
__str__
(
self
):
return
s
elf
.
tid
return
s
tr
(
self
.
id
)
class
Meta
:
db_table
=
"like"
\ No newline at end of file
discussion/templates/discussion_thread.html
View file @
80b3f15e
...
...
@@ -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 %}
...
...
discussion/views.py
View file @
80b3f15e
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
))
djangodb
View file @
80b3f15e
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment