Making questions tabbed navigation possible. · pythonDrive/bootcamp@3947955 · GitHub
Skip to content

Commit 3947955

Browse files
Making questions tabbed navigation possible.
1 parent 6242d1b commit 3947955

7 files changed

Lines changed: 78 additions & 30 deletions

File tree

bootcamp/articles/models.py

Lines changed: 14 additions & 14 deletions

bootcamp/articles/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ArticlesListView(LoginRequiredMixin, ListView):
1717

1818
def get_context_data(self, *args, **kwargs):
1919
context = super().get_context_data(*args, **kwargs)
20-
context['popular_tags'] = Article.get_counted_tags()
20+
context['popular_tags'] = Article.objects.get_counted_tags()
2121
return context
2222

2323
def get_queryset(self, **kwargs):

bootcamp/qa/urls.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
app_name = 'qa'
66
urlpatterns = [
7-
url(r'^$', views.QuestionListView.as_view(), name='index'),
8-
url(r'^question-detail/(?P<pk>\d+)/$',
9-
views.QuestionDetailView.as_view(), name='question_detail'),
10-
url(r'^ask-question/$', views.CreateQuestionView.as_view(),
11-
name='ask_question'),
12-
url(r'^propose-answer/(?P<question_id>\d+)/$',
13-
views.CreateAnswerView.as_view(), name='propose_answer'),
7+
url(r'^$', views.QuestionListView.as_view(), name='index_noans'),
8+
url(r'^answered/$', views.QuestionAnsListView.as_view(), name='index_ans'),
9+
url(r'^indexed/$', views.QuestionsIndexListView.as_view(), name='index_all'),
10+
url(r'^question-detail/(?P<pk>\d+)/$',views.QuestionDetailView.as_view(), name='question_detail'),
11+
url(r'^ask-question/$', views.CreateQuestionView.as_view(),name='ask_question'),
12+
url(r'^propose-answer/(?P<question_id>\d+)/$',views.CreateAnswerView.as_view(), name='propose_answer'),
1413
url(r'^question/vote/$', views.question_vote, name='question_vote'),
1514
url(r'^answer/vote/$', views.answer_vote, name='answer_vote'),
1615
url(r'^accept-answer/$', views.accept_answer, name='accept_answer'),

bootcamp/qa/views.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,42 @@
1313
from bootcamp.qa.forms import QuestionForm
1414

1515

16-
class QuestionListView(LoginRequiredMixin, ListView):
17-
"""CBV to render the index view
18-
"""
16+
class QuestionsIndexListView(LoginRequiredMixin, ListView):
17+
"""CBV to render a list view with all the registered questions."""
1918
model = Question
2019
paginate_by = 20
2120
context_object_name = "questions"
2221

22+
def get_context_data(self, *args, **kwargs):
23+
context = super().get_context_data(*args, **kwargs)
24+
context["popular_tags"] = Question.objects.get_counted_tags()
25+
context["active"] = "all"
26+
return context
27+
28+
29+
class QuestionAnsListView(QuestionsIndexListView):
30+
"""CBV to render a list view with all question which have been already
31+
marked as answered."""
32+
def get_queryset(self, **kwargs):
33+
return Question.objects.get_answered()
34+
35+
def get_context_data(self, *args, **kwargs):
36+
context = super().get_context_data(*args, **kwargs)
37+
context["active"] = "answered"
38+
return context
39+
40+
41+
class QuestionListView(QuestionsIndexListView):
42+
"""CBV to render a list view with all question which haven't been marked
43+
as answered."""
44+
def get_queryset(self, **kwargs):
45+
return Question.objects.get_unanswered()
46+
47+
def get_context_data(self, *args, **kwargs):
48+
context = super().get_context_data(*args, **kwargs)
49+
context["active"] = "unanswered"
50+
return context
51+
2352

2453
class QuestionDetailView(LoginRequiredMixin, DetailView):
2554
"""View to call a given Question object and to render all the details about

bootcamp/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<ul class="navbar-nav mr-auto">
4747
<li class="nav-item"><a class="nav-link" href="{% url 'news:list' %}">{% trans 'News' %} <span class="sr-only">(current)</span></a></li>
4848
<li class="nav-item"><a class="nav-link" href="{% url 'articles:list' %}">Blog</a></li>
49-
<li class="nav-item"><a class="nav-link" href="{% url 'qa:index' %}">{% trans 'Q&A' %}</a></li>
49+
<li class="nav-item"><a class="nav-link" href="{% url 'qa:index_noans' %}">{% trans 'Q&A' %}</a></li>
5050
<li class="nav-item"><a class="nav-link" href="{% url 'messager:messages_list' %}">{% trans 'Inbox' %}</a></li>
5151
<li class="nav-item"><a class="nav-link" href="{% url 'users:list' %}">{% trans 'Contacts' %}</a></li>
5252
</ul>

bootcamp/templates/qa/question_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<nav aria-label="breadcrumb">
1313
<ol class="breadcrumb">
1414
<li class="breadcrumb-item"><a href="{% url 'news:list' %}">{% trans 'Home' %}</a></li>
15-
<li class="breadcrumb-item"><a href="{% url 'qa:index' %}">{% trans 'Q.A' %}</a></li>
15+
<li class="breadcrumb-item"><a href="{% url 'qa:index_noans' %}">{% trans 'Q.A' %}</a></li>
1616
<li class="breadcrumb-item active" aria-current="page">{{ question.title }}</li>
1717
</ol>
1818
</nav>

bootcamp/templates/qa/question_list.html

Lines changed: 23 additions & 3 deletions

0 commit comments

Comments
 (0)