1
0
mirror of https://github.com/djohnlewis/stackdump synced 2024-12-04 23:17:37 +00:00

Added indicator for accepted answer.

This commit is contained in:
Samuel Lai 2012-02-12 15:54:03 +11:00
parent 67f1ac7a3a
commit cab37377f7
5 changed files with 45 additions and 3 deletions

View File

@ -162,6 +162,10 @@ pre code {
padding: 10px 5px;
}
.post-stat-img {
background-color: transparent;
}
.post-stat p {
margin-bottom: 0;
}
@ -176,6 +180,10 @@ pre code {
color: #AAAAAA;
}
.post-stat-value-good {
color: #5ebb00;
}
.post-summary {
padding-left: 72px; /* 64px for post-stats-vertical + 8px for padding */
}
@ -220,7 +228,7 @@ pre code {
}
.post-comments {
clear: both;
clear: right;
}
.post-comments ul {

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

View File

@ -306,7 +306,9 @@ def view_question(site_key, question_id):
retrieve_users(results)
retrieve_sites(results)
context['result'] = results.docs[0]
result = results.docs[0]
sort_answers(result)
context['result'] = result
return render_template('question.html', context)
@ -601,6 +603,27 @@ def get_random_questions(site_key=None, count=3):
return results
def sort_answers(result):
'''\
Sorts the answers in the given result such that the accepted answer (if one)
is sorted first, and all others are sorted by their votes.
'''
answers = result.get('answers')
if not answers:
return
accepted_answer_id = result['question'].get('acceptedAnswerId', None)
def comparison_function(a, b):
if a['id'] == accepted_answer_id:
return 1
elif b['id'] == accepted_answer_id:
return -1
return cmp(a.get('score'), b.get('score'))
answers.sort(comparison_function, reverse=True)
# END VIEW HELPERS
# INITIALISATION

View File

@ -20,8 +20,12 @@
<p>vote{% if r.question.score != 1 %}s{% endif %}</p>
</div>
<div class="post-stat">
<p class="post-stat-value {% if r.answers|length == 0 %}post-stat-value-poor{% endif %}">
<p class="post-stat-value {% if r.answers|length == 0 %}post-stat-value-poor{% endif %} {% if r.question.acceptedAnswerId %}post-stat-value-good{% endif %}">
{% if r.question.acceptedAnswerId %}
<span title="One of the answers has been accepted as the correct answer.">{{ r.answers|length }}</span>
{% else %}
{{ r.answers|length }}
{% endif %}
</p>
<p>answer{% if r.answers|length != 1 %}s{% endif %}</p>
</div>

View File

@ -100,6 +100,13 @@
</p>
<p>vote{% if a.score != 1 %}s{% endif %}</p>
</div>
{% if r.question.acceptedAnswerId %}
{% if r.question.acceptedAnswerId == a.id %}
<div class="post-stat post-stat-img">
<img src="{{ SETTINGS.APP_URL_ROOT }}media/images/accepted_answer.png" alt="Accepted answer" />
</div>
{% endif %}
{% endif %}
</div>
<div class="post-body">
{{ a.body|safe }}