Skip to content

Commit 9360c9e

Browse files
authored
Most active (#37)
* signals for last active * display most active questions * first post recent post * notification error resolved * recent post ny
1 parent 4edc775 commit 9360c9e

8 files changed

Lines changed: 156 additions & 6 deletions

File tree

static/website/templates/index.html

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515
});
1616

17+
$("#activelistTable").tablesorter({
18+
headers:{
19+
5:{sorter:false}
20+
},
21+
22+
});
23+
1724
});
25+
26+
1827
</script>
1928
<div id="carousel-container">
2029
<div class="carousel">
@@ -66,9 +75,14 @@ <h3 align="center">Answers</h3>
6675
<br>
6776
<div class="panel panel-default">
6877
<div class="panel-heading">
69-
Recent questions
78+
<ul class="nav nav-tabs">
79+
<li class="active"><a data-toggle="tab" href="#recent_question">Recent questions</a></li>
80+
<li><a data-toggle="tab" href="#most_active">Most active questions</a></li>
81+
</ul>
7082
</div>
7183
<div class="panel-body">
84+
<div class="tab-content">
85+
<div id="recent_question" class="tab-pane fade in active">
7286
<table id = "listTable" class="tablesorter-blue">
7387
<thead>
7488
<tr>
@@ -151,6 +165,106 @@ <h3 align="center">Answers</h3>
151165
{% endfor %}
152166
</tbody>
153167
</table>
168+
</div>
169+
<div id="most_active" class="tab-pane fade">
170+
171+
<table id = "activelistTable" class="tablesorter-blue">
172+
<thead>
173+
<tr>
174+
<th> FOSS </th>
175+
<th> Tutorial</th>
176+
<th> Min </th>
177+
<th> Sec </th>
178+
<th> Question <span class="glyphicon glyphicon-link"></span></th>
179+
<th> First Post on</th>
180+
<th> First Post by</th>
181+
<th>Recent Post on </th>
182+
<th>Recent Post by</th>
183+
<th> Views</th>
184+
<th> Answers</th>
185+
</tr>
186+
</thead>
187+
<tbody>
188+
{% for question in active_questions %}
189+
<tr>
190+
<td>
191+
<span href="#" class="category" data-toggle="tooltip" data-placement="top" title="{{ question.category}}">
192+
{{ question.category|truncatechars:12 }}
193+
</span>
194+
<a class="pull-right" href="{% url 'website:filter' question.category %}?qid={{ question.id }}">
195+
<span class="glyphicon glyphicon-search"></span>
196+
</a>
197+
</td>
198+
199+
<td>
200+
<span class="tutorial" data-toggle="tooltip" data-placement="top" title="{{ question.tutorial}}">
201+
{{ question.tutorial|truncatechars:12 }}
202+
</span>
203+
<a class="pull-right" href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}">
204+
<span class="glyphicon glyphicon-search"></span>
205+
</a>
206+
</td>
207+
208+
<td>
209+
<span>
210+
<a href="{% url 'website:filter' question.category question.tutorial question.minute_range %}?qid={{ question.id }}">
211+
{{ question.minute_range }}
212+
</a>
213+
</span>
214+
</td>
215+
216+
<td>
217+
<span>
218+
<a href="{% url 'website:filter' question.category question.tutorial question.minute_range question.second_range%}?qid={{ question.id }}">
219+
{{ question.second_range }}
220+
</a>
221+
</span>
222+
</td>
223+
224+
<td>
225+
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
226+
<a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a>
227+
</span>
228+
</td>
229+
<td>
230+
<span>
231+
<i>
232+
{{ question.date_created|date:"d-m-y" }}
233+
</i>
234+
</span>
235+
</td>
236+
<td>
237+
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.user }}">
238+
{{ question.user|truncatechars:10 }}
239+
</span>
240+
</td>
241+
242+
<td>
243+
<span>
244+
<i>
245+
{{ question.last_active }}
246+
</i>
247+
</span>
248+
</td>
249+
<td>
250+
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.last_post_user }}">
251+
{{ question.last_post_user|truncatechars:10 }}
252+
</span>
253+
</td>
254+
255+
<td>
256+
{{ question.views}}
257+
</td>
258+
259+
<td>
260+
{{ question.answer_set.count }}
261+
</td>
262+
</tr>
263+
{% endfor %}
264+
</tbody>
265+
</table>
266+
</div>
267+
</div>
154268
</div> <!-- /.panel-body -->
155269
</div> <!-- /.panel -->
156270
{% endblock %}

static/website/templates/notify.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% if question %}
12
<div class="notification">
23
{% if notification.cid != 0 and notification.aid != 0 %}
34
<small>
@@ -13,3 +14,4 @@
1314
<span class="glyphicon glyphicon-remove-circle"></span>
1415
</a>
1516
</div> <!-- /.notification closed -->
17+
{% endif %}

website/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default_app_config = 'website.apps.WebsiteConfig'

website/apps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from django.apps import AppConfig
2-
2+
from django.db.models.signals import post_save
33

44
class WebsiteConfig(AppConfig):
5-
name = 'website'
5+
name = 'website'
6+
7+
def ready(self):
8+
from .models import Answer, AnswerComment
9+
from .signals import last_active_signal_from_answer, last_active_signal_from_reply
10+
post_save.connect(last_active_signal_from_answer, sender=Answer, dispatch_uid='trigger_last_active_answer')
11+
post_save.connect(last_active_signal_from_reply, sender=AnswerComment, dispatch_uid='trigger_last_active_reply')

website/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ class Question(models.Model):
1616
date_modified = models.DateTimeField(auto_now=True)
1717
views = models.IntegerField(default=1)
1818
status = models.IntegerField(default=1)
19+
last_active = models.DateTimeField(null=True)
20+
last_post_by = models.IntegerField(null=True)
1921
# votes = models.IntegerField(default=0)
2022

2123
def user(self):
2224
user = User.objects.get(id=self.uid)
2325
return user.username
26+
27+
def last_post_user(self):
28+
user = User.objects.get(id=self.last_post_by)
29+
return user.username
2430

2531
class Meta:
2632
get_latest_by = "date_created"

website/signals.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.utils import timezone
2+
3+
def last_active_signal_from_answer(sender, instance, created, **kwargs):
4+
if created or not created:
5+
instance.question.last_active = timezone.now()
6+
instance.question.last_post_by = instance.uid
7+
instance.question.save()
8+
9+
def last_active_signal_from_reply(sender, instance, created, **kwargs):
10+
if created or not created:
11+
instance.answer.question.last_active = timezone.now()
12+
instance.answer.question.last_post_by = instance.uid
13+
instance.answer.question.save()

website/templatetags/notify.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77

88
def get_notification(nid):
99
notification = Notification.objects.get(pk=nid)
10-
question = Question.objects.get(pk=notification.qid)
11-
answer = Answer.objects.get(pk=notification.aid)
10+
try:
11+
question = Question.objects.get(pk=notification.qid)
12+
except Question.DoesNotExist:
13+
question = None
14+
try:
15+
answer = Answer.objects.get(pk=notification.aid)
16+
except Answer.DoesNotExist:
17+
answer = None
1218
context = {
1319
'notification': notification,
1420
'question': question,

website/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131

3232
def home(request):
3333
questions = Question.objects.filter(status=1).order_by('date_created').reverse()[:100]
34+
active_questions = Question.objects.filter(status=1, last_active__isnull=False).order_by('last_active').reverse()[:100]
3435
context = {
3536
'categories': categories,
36-
'questions': questions
37+
'questions': questions,
38+
'active_questions':active_questions
3739
}
3840
return render(request, "website/templates/index.html", context)
3941

0 commit comments

Comments
 (0)