Skip to content

Commit f989d09

Browse files
hrchrc
authored andcommitted
simplified and 'merged' index and question views
1 parent c3da8a0 commit f989d09

File tree

18 files changed

+409
-392
lines changed

18 files changed

+409
-392
lines changed

.idea/workspace.xml

Lines changed: 78 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forum/middleware/request_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
class RequestUtils(object):
3+
def __init__(self):
4+
self.request = None
5+
6+
def set_sort_method(self, sort):
7+
self.request.session['questions_sort_method'] = sort
8+
9+
def sort_method(self, default):
10+
sort = self.request.REQUEST.get('sort', None)
11+
if sort is None:
12+
return self.request.session.get('questions_sort_method', default)
13+
else:
14+
self.set_sort_method(sort)
15+
return sort
16+
17+
def page_size(self, default):
18+
pagesize = self.request.REQUEST.get('pagesize', None)
19+
if pagesize is None:
20+
return int(self.request.session.get('questions_pagesize', default))
21+
else:
22+
self.request.session['questions_pagesize'] = pagesize
23+
return int(pagesize)
24+
25+
def process_request(self, request):
26+
self.request = request
27+
request.utils = self
28+
return None
Lines changed: 11 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,16 @@
1-
{% extends "base.html" %}
1+
{% extends "questions.html" %}
22
<!-- index.html -->
3-
{% load i18n %}
4-
{% load extra_tags %}
5-
{% load humanize %}
6-
{% load extra_filters %}
7-
{% load smart_if %}
3+
{% load general_sidebar_tags %}
4+
{% load question_list_tags %}
85
{% load cache %}
9-
{% block title %}{% spaceless %}{% trans "Home" %}{% endspaceless %}{% endblock %}
10-
{% block meta %}<meta name="keywords" content="{{ settings.APP_KEYWORDS }}" />
11-
<meta name="description" content="{{ settings.APP_DESCRIPTION }}" />{% endblock %}
12-
{% block forejs %}
13-
<script type="text/javascript">
14-
var tags = {{ tags_autocomplete|safe }};
15-
$().ready(function(){
16-
var tab_id = "{{ tab_id }}";
17-
$("#"+tab_id).attr('className',"on");
18-
$("#nav_questions").attr('className',"on");
19-
});
20-
</script>
21-
{% endblock %}
22-
{% block content %}
23-
<div class="tabBar">
24-
<div class="headQuestions">{% trans "Questions" %}</div>
25-
<div class="tabsA">
26-
<a id="latest" href="{% url questions %}?sort=latest" title="{% trans "last updated questions" %}" >{% trans "newest" %}</a>
27-
<a id="hottest" href="{% url questions %}?sort=hottest" title="{% trans "hottest questions" %}" >{% trans "hottest" %}</a>
28-
<a id="mostvoted" href="{% url questions %}?sort=mostvoted" title="{% trans "most voted questions" %}" >{% trans "most voted" %}</a>
29-
<a id="all" href="{% url questions %}" title="{% trans "all questions" %}" >{% trans "all questions" %}</a>
30-
</div>
31-
</div>
32-
<!-- ???? -->
33-
{% include "question_list.html" %}
34-
{% endblock %}
356

367
{% block sidebar %}
37-
<div class="boxC">
38-
<div class="questions-count">{{ question_count }}</div>
39-
<p>{% trans "questions" %}</p>
40-
</div>
41-
{% if not request.user.is_authenticated %}
42-
<div class="boxA">
43-
<h3>{% trans "welcome to website" %}</h3>
44-
<div class="body">
45-
{{ settings.APP_INTRO|safe }}
46-
<div class="more"><a href="{% url about %}">{% trans "about" %} </a></div>
47-
<div class="more"><a href="{% url faq %}">{% trans "faq" %} </a></div>
48-
</div>
49-
</div>
50-
{% else %}
51-
{% include "tag_selector.html" %}
52-
{% endif %}
53-
<div class="boxC">
54-
<h3>{% trans "Recent tags" %}</h3>
55-
<div class="body">
56-
<div class="tags">
57-
{% cache 60 recent_tags settings.APP_URL %}
58-
{% for tag in tags %}
59-
<a rel="tag"
60-
title="{% blocktrans with tag.name as tagname %}see questions tagged '{{tagname}}'{% endblocktrans %}" href="{% url tag_questions tag.name|urlencode %}">{{ tag.name }}</a>
61-
{% endfor %}
62-
{% endcache %}
63-
</div>
64-
<div class="more"><a href="{% url tags %}">{% trans "popular tags" %} </a> </div>
65-
</div>
66-
</div>
67-
{% if awards %}
68-
<div class="boxC">
69-
<h3>{% trans "Recent awards" %}</h3>
70-
<div class="body">
71-
<ul class="badge-list">
72-
{% cache 60 recent_awards settings.APP_URL %}
73-
{% for award in awards %}
74-
<li>
75-
<a href="{% url badges %}{{award.badge_id}}/{{award.badge_name}}" title="{{ award.badge_description }}" class="medal">
76-
<span class="badge{{ award.badge_type }}">&#9679;</span>&nbsp;{{ award.badge_name }}</a>
77-
<a href="/users/{{ award.user_id }}/{{ award.user_name|slugify }}/">{{ award.user_name }}</a>
78-
</li>
79-
{% endfor %}
80-
{% endcache %}
81-
</ul>
82-
<div class="more"><a href="{% url badges %}">{% trans "all awards" %} </a> </div>
83-
</div>
84-
</div>
85-
{% endif %}
86-
<div id="feeds">
87-
<a href="{% url latest_questions_feed %}" title="{% trans "subscribe to last 30 questions by RSS" %}">{% trans "subscribe to the questions feed" %}</a>
88-
</div>
89-
{% endblock %}
90-
{% block tail %}
91-
<div class="pager">{% cnprog_paginator context %}</div>
92-
<div class="pagesize">{% cnprog_pagesize context %}</div>
93-
<!-- <div style="padding:5px 0 5px 5px;">
94-
<span class="evenMore">{% trans "Still looking for more? See" %} <a href="{% url questions %}">{% trans "complete list of questions" %}</a> {% trans "or" %} <a href="{% url tags %}">{% trans "popular tags" %}</a>{% trans "." %} {% trans "Please help us answer" %} <a href="{% url questions %}unanswered">{% trans "list of unanswered questions" %}</a>{% trans "." %}</span>
95-
</div> -->
8+
{% cache 60 index_sidebar settings.APP_URL %}
9+
{% question_list_count %}
10+
{% tag_selector %}
11+
{% recent_tags %}
12+
{% recent_awards %}
13+
{% endcache %}
9614
{% endblock %}
97-
<!-- index.html -->
15+
<!-- index.html -->
16+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% load i18n %}
2+
{% load humanize %}
3+
4+
<div class="boxC">
5+
{% if searchtag %}
6+
{% blocktrans count questions_count as cnt with questions_count|intcomma as q_num and searchtag as tagname %}
7+
have total {{q_num}} questions tagged {{tagname}}
8+
{% plural %}
9+
have total {{q_num}} questions tagged {{tagname}}
10+
{% endblocktrans %}
11+
{% else %}
12+
{% if searchtitle %}
13+
{% if settings.USE_SPHINX_SEARCH %}
14+
{% blocktrans count questions_count as cnt with questions_count|intcomma as q_num %}
15+
have total {{q_num}} questions containing {{searchtitle}} in full text
16+
{% plural %}
17+
have total {{q_num}} questions containing {{searchtitle}} in full text
18+
{% endblocktrans %}
19+
{% else %}
20+
{% blocktrans count questions_count as cnt with questions_count|intcomma as q_num %}
21+
have total {{q_num}} questions containing {{searchtitle}}
22+
{% plural %}
23+
have total {{q_num}} questions containing {{searchtitle}}
24+
{% endblocktrans %}
25+
{% endif %}
26+
{% else %}
27+
{% if is_unanswered %}
28+
{% blocktrans count questions_count as cnt with questions_count|intcomma as q_num %}
29+
have total {{q_num}} unanswered questions
30+
{% plural %}
31+
have total {{q_num}} unanswered questions
32+
{% endblocktrans %}
33+
{% else %}
34+
{% blocktrans count questions_count as cnt with questions_count|intcomma as q_num %}
35+
have total {{q_num}} question
36+
{% plural %}
37+
have total {{q_num}} questions
38+
{% endblocktrans %}
39+
{% endif %}
40+
{% endif %}
41+
{% endif %}
42+
<p class="nomargin">
43+
{{ sort_description|safe }}
44+
</p>
45+
</div>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% load i18n %}
2+
{% load humanize %}
3+
{% load extra_filters %}
4+
{% load extra_tags %}
5+
6+
<div class="short-summary">
7+
<div class="counts">
8+
<div class="votes">
9+
<div class="item-count">{{question.score|intcomma}}</div>
10+
<div>{% trans "votes" %}</div>
11+
</div >
12+
<div {% if question.answer_accepted %}title="{% trans "this answer has been accepted to be correct" %}"{% endif %} class="status {% if question.answer_accepted %}answered-accepted{% endif %} {% ifequal question.answer_count 0 %}unanswered{% endifequal %}{% ifnotequal question.answer_count 0 %}answered{% endifnotequal %}">
13+
<div class="item-count">{{question.answer_count|intcomma}}</div>
14+
<div>{% trans "answers" %}</div>
15+
</div>
16+
<div class="views">
17+
<div class="item-count">{{question.view_count|cnprog_intword|safe}}</div>
18+
<div>{% trans "views" %}</div>
19+
</div>
20+
</div>
21+
22+
<h2><a title="{{question.summary}}" href="{{ question.get_absolute_url }}">{{question.title}}</a></h2>
23+
<div class="userinfo">
24+
<span class="relativetime" title="{{question.last_activity_at}}">{% diff_date question.last_activity_at %}</span>
25+
{% if question.last_activity_by %}
26+
<a href="/users/{{ question.last_activity_by.id }}/{{ question.last_activity_by.username|slugify }}/">{{ question.last_activity_by }}</a> {% get_score_badge question.last_activity_by %}
27+
{% endif %}
28+
</div>
29+
30+
<div class="tags">
31+
{% for tag in question.tagname_list %}
32+
<a href="{% url tag_questions tag|urlencode %}" title="{% trans "see questions tagged" %} '{{ tag }}' {% trans "using tags" %}" rel="tag">{{ tag }}</a>
33+
{% endfor %}
34+
</div>
35+
</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% load i18n %}
2+
{% load humanize %}
3+
4+
{% if tags %}
5+
<div class="boxC">
6+
<h3 class="subtitle">{% trans "Related tags" %}</h3>
7+
<div class="tags">
8+
{% for tag in tags %}
9+
<a rel="tag" title="{% blocktrans with tag.name as tag_name %}see questions tagged '{{ tag_name }}'{% endblocktrans %}" href="{% url tag_questions tag.name|urlencode %}">{{ tag.name }}</a>
10+
<span class="tag-number">&#215; {{ tag.used_count|intcomma }}</span>
11+
<br />
12+
{% endfor %}
13+
</div>
14+
</div>
15+
{% endif %}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% load i18n %}
2+
3+
<div class="tabsA">
4+
<a id="latest" href="{% url questions %}?sort=latest"{% ifequal current "latest" %} class="on"{% endifequal %} title="{% trans "most recently asked questions" %}">{% trans "newest" %}</a>
5+
<a id="active" href="{% url questions %}?sort=active"{% ifequal current "active" %} class="on"{% endifequal %} title="{% trans "most recently updated questions" %}">{% trans "active" %}</a>
6+
<a id="hottest" href="{% url questions %}?sort=hottest"{% ifequal current "hottest" %} class="on"{% endifequal %} title="{% trans "hottest questions" %}">{% trans "hottest" %}</a>
7+
<a id="mostvoted" href="{% url questions %}?sort=mostvoted"{% ifequal current "mostvoted" %} class="on"{% endifequal %} title="{% trans "most voted questions" %}">{% trans "most voted" %}</a>
8+
</div>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% load i18n %}
2+
{% load extra_tags %}
3+
4+
{% if user_authenticated %}
5+
<div id="tagSelector" class="boxC">
6+
<h3 class="subtitle">{% trans "Interesting tags" %}</h3>
7+
<div class="tags interesting marked-tags">
8+
{% for tag_name in interesting_tag_names %}
9+
{% spaceless %}
10+
<span class="deletable-tag" id="interesting-tag-{{tag_name}}">
11+
<a rel="tag"
12+
title="{% blocktrans with tag as tagname %}see questions tagged '{{ tag_name }}'{% endblocktrans %}"
13+
href="{% url tag_questions tag_name|urlencode %}">{{tag_name}}</a>
14+
<img class="delete-icon"
15+
src="{% media "/media/images/close-small-dark.png" %}"
16+
title="{% blocktrans %}remove '{{tag_name}}' from the list of interesting tags{% endblocktrans %}"/>
17+
</span>
18+
{% endspaceless %}
19+
{% endfor %}
20+
</div>
21+
<input id="interestingTagInput" autocomplete="off" type="text"/>
22+
<input id="interestingTagAdd" type="submit" value="{% trans "Add" %}"/>
23+
<h3 class="subtitle">{% trans "Ignored tags" %}</h3>
24+
<div class="tags ignored marked-tags">
25+
{% for tag_name in ignored_tag_names %}
26+
{% spaceless %}
27+
<span class="deletable-tag" id="ignored-tag-{{tag_name}}">
28+
<a rel="tag"
29+
title="{% blocktrans with tag as tagname %}see questions tagged '{{ tag_name }}'{% endblocktrans %}"
30+
href="{% url tag_questions tag_name|urlencode %}">{{tag_name}}</a>
31+
<img class="delete-icon"
32+
src="{% media "/media/images/close-small-dark.png" %}"
33+
title="{% blocktrans %}remove '{{tag_name}}' from the list of ignored tags{% endblocktrans %}"/>
34+
</span>
35+
{% endspaceless %}
36+
{% endfor %}
37+
</div>
38+
<input id="ignoredTagInput" autocomplete="off" type="text"/>
39+
<input id="ignoredTagAdd" type="submit" value="{% trans "Add" %}"/>
40+
<p id="hideIgnoredTagsControl">
41+
<input id="hideIgnoredTagsCb" type="checkbox" {% if request.user.hide_ignored_questions %}checked="checked"{% endif %} />
42+
<label id="hideIgnoredTagsLabel" for="hideIgnoredTagsCb">{% trans "keep ignored questions hidden" %}</label>
43+
<p>
44+
</div>
45+
{% endif %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% load i18n %}
2+
3+
<div class="headQuestions">
4+
{% if searchtag %}
5+
{% trans "Found by tags" %}
6+
{% else %}
7+
{% if searchtitle %}
8+
{% if settings.USE_SPHINX_SEARCH %}
9+
{% trans "Search results" %}
10+
{% else %}
11+
{% trans "Found by title" %}
12+
{% endif %}
13+
{% else %}
14+
{% if is_unanswered %}
15+
{% trans "Unanswered questions" %}
16+
{% else %}
17+
{% trans "All questions" %}
18+
{% endif %}
19+
{% endif %}
20+
{% endif %}
21+
</div>

0 commit comments

Comments
 (0)