Skip to content

Commit 23c42b6

Browse files
Spam tab
1 parent b22dfff commit 23c42b6

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

static/website/templates/index.html

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ <h3 align="center">Answers</h3>
9393
<ul class="nav nav-tabs">
9494
<li class="active"><a data-toggle="tab" href="#recent_question">Recent questions</a></li>
9595
<li><a data-toggle="tab" href="#most_active">Most active questions</a></li>
96+
<li><a data-toggle="tab" href="#spam_pending">Spam Pending-Approval</a></li>
9697
</ul>
9798
</div>
9899
<div class="panel-body">
@@ -279,7 +280,46 @@ <h3 align="center">Answers</h3>
279280
</tbody>
280281
</table>
281282
</div>
282-
</div>
283+
<div id="spam_pending" class="tab-pane fade">
284+
<table id="spamTable" class="tablesorter-blue">
285+
<thead>
286+
<tr>
287+
<th>FOSS</th>
288+
<th>Tutorial</th>
289+
<th>Min</th>
290+
<th>Sec</th>
291+
<th>Question</th>
292+
<th>Date</th>
293+
<th>User</th>
294+
<th>Actions</th>
295+
</tr>
296+
</thead>
297+
<tbody>
298+
{% for question in spam_questions %}
299+
<tr>
300+
<td>{{ question.category|truncatechars:12 }}</td>
301+
<td>{{ question.tutorial|truncatechars:12 }}</td>
302+
<td>{{ question.minute_range }}</td>
303+
<td>{{ question.second_range }}</td>
304+
<td>
305+
<a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">
306+
{{ question.title|truncatechars:40 }}
307+
</a>
308+
</td>
309+
<td>{{ question.date_created|date:"d-m-y" }}</td>
310+
<td>{{ question.user|truncatechars:10 }}</td>
311+
<td>
312+
<!-- Add approve/reject buttons here if needed -->
313+
<a href="{% url 'website:ajax_question_update' %}?qid={{ question.id }}" class="btn btn-xs btn-success">Approve</a>
314+
<a href="{% url 'website:ajax_delete_question' %}?qid={{ question.id }}" class="btn btn-xs btn-danger">Reject</a>
315+
</td>
316+
</tr>
317+
{% empty %}
318+
<tr><td colspan="8">No spam questions pending approval.</td></tr>
319+
{% endfor %}
320+
</tbody>
321+
</table>
322+
</div>
283323
</div> <!-- /.panel-body -->
284324
</div> <!-- /.panel -->
285325
{% endblock %}

website/views.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.core.mail import EmailMultiAlternatives
99
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
1010
from django.contrib.auth import get_user_model
11+
from django.contrib.auth.models import Group
1112
from django.contrib import messages
1213
from website.models import Question, Answer, Notification, AnswerComment
1314
from spoken_auth.models import TutorialDetails, TutorialResources
@@ -18,6 +19,7 @@
1819
from spoken_auth.models import FossCategory
1920
from .sortable import SortableHeader, get_sorted_list, get_field_index
2021
from forums.views import user_logout
22+
from website.permissions import is_administrator
2123

2224
User = get_user_model()
2325
categories = []
@@ -37,7 +39,14 @@ def home(request):
3739
slider_questions = Question.objects.filter(
3840
date_created=Subquery(subquery), status=1
3941
).order_by('category')
40-
42+
43+
# Add spam questions only for admin users
44+
spam_questions = []
45+
is_admin = False
46+
if request.user.is_authenticated and is_administrator(request.user):
47+
spam_questions = Question.objects.filter(status=2).order_by('-date_created') # status=2 for spam
48+
is_admin = True
49+
4150
# Mapping of foss name as in spk db & its corresponding category name in forums db
4251
category_fosses = {val.replace(" ", "-") : val for val in categories}
4352

@@ -62,7 +71,9 @@ def home(request):
6271
context = {
6372
'questions': questions,
6473
'active_questions':active_questions,
65-
'category_question_map': category_question_map
74+
'category_question_map': category_question_map,
75+
'spam_questions': spam_questions,
76+
'is_admin': is_admin,
6677
}
6778
return render(request, "website/templates/index.html", context)
6879

0 commit comments

Comments
 (0)