88from django .core .mail import EmailMultiAlternatives
99from django .core .paginator import Paginator , EmptyPage , PageNotAnInteger
1010from django .contrib .auth import get_user_model
11+ from django .contrib .auth .models import Group
1112from django .contrib import messages
1213from website .models import Question , Answer , Notification , AnswerComment
1314from spoken_auth .models import TutorialDetails , TutorialResources
1819from spoken_auth .models import FossCategory
1920from .sortable import SortableHeader , get_sorted_list , get_field_index
2021from forums .views import user_logout
22+ from website .permissions import is_administrator
2123
2224User = get_user_model ()
2325categories = []
@@ -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