summaryrefslogtreecommitdiffstats
path: root/templates/question.html
blob: 9cbe16640238b90742c7083f873297b619fee891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
{% extends "base.html" %}{% load extra_tags %}{% load extra_filters %}{% load humanize %}
{% block title %}{% spaceless %}{{ question.get_question_title }}{% endspaceless %}{% endblock %}
{% block forejs %}
        {% if not question.closed and request.user.is_authenticated %}
        <script type='text/javascript' src='/content/js/com.cnprog.editor.js'></script>
        <script type='text/javascript' src='/content/js/wmd/showdown-min.js'></script>
        <script type='text/javascript' src='/content/js/wmd/wmd-min.js'></script>
        <link rel="stylesheet" type="text/css" href="/content/js/wmd/wmd.css" />
        {% endif %}
        <script type='text/javascript' src='/content/js/com.cnprog.post.pack.js'></script>
        <script type='text/javascript' src='/content/js/jquery.validate.pack.js'></script>
        <script type="text/javascript">
        // define reputation needs for comments
        var repNeededForComments = 50;
        $().ready(function(){
            $("#nav_questions").attr('className',"on");
            var answer_sort_tab = "{{ tab_id }}";
            $("#" + answer_sort_tab).attr('className',"on");
            
            Vote.init({{ question.id }}, '{{ question.author.id }}','{{ request.user.id }}');
            
            {% if not question.closed and request.user.is_authenticated %}initEditor();{% endif %}
            
            lanai.highlightSyntax();
            $('#btLogin').bind('click', function(){window.location.href='/account/signin/'; } )
        });
        
        function initEditor(){
            $('#editor').TextAreaResizer();
            //highlight code synctax when editor has new text
            $("#editor").typeWatch({highlight: false, wait: 3000,
                             captureLength: 5, callback: lanai.highlightSyntax});
                             
            var display = true;
            var txt = "[禁用预览]";
            $('#pre-collapse').text(txt);
            $('#pre-collapse').bind('click', function(){
                txt = display ? "[启用预览]" : "[禁用预览]";
                display = !display;
                $('#previewer').toggle();
                $('#pre-collapse').text(txt);
            });
            
            setupFormValidation("#fmanswer", CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
        }
         
        </script>
{% endblock %}
        
{% block content %}
<div class="headNormal">
    <a href="{{ question.get_absolute_url }}">{{ question.get_question_title }}</a>
</div>
<div id="main-body" class="">
    <div id="askform">
        <form id="fmanswer" action="{% url answer question.id %}" method="post">
            <table style="width:100%;" id="question-table" {% if question.deleted %}class="deleted"{%endif%}>
                <tr>
                    <td style="width:30px;vertical-align:top">
                        <div class="vote-buttons">
                            {% if question_vote %}
                            <img id="question-img-upvote-{{ question.id }}" class="question-img-upvote" src="/content/images/vote-arrow-up{% if question_vote.is_upvote %}-on{% endif %}.png" title="这篇帖子有价值(再次点击取消操作)" >
                            <div id="question-vote-number-{{ question.id }}" class="vote-number" title="当前总票数">
                                {{ question.score }}
                            </div>
                            <img id="question-img-downvote-{{ question.id }}" class="question-img-downvote" src="/content/images/vote-arrow-down{% if question_vote.is_downvote %}-on{% endif %}.png" title="这篇帖子没有价值(再次点击取消操作)" >
                           
                            {% else %}
                            <img id="question-img-upvote-{{ question.id }}" class="question-img-upvote" src="/content/images/vote-arrow-up.png" title="这篇帖子有价值(再次点击取消操作)" >
                            <div id="question-vote-number-{{ question.id }}" class="vote-number" title="当前总票数">
                                {{ question.score }}
                            </div>
                            <img id="question-img-downvote-{{ question.id }}" class="question-img-downvote" src="/content/images/vote-arrow-down.png" title="这篇帖子没有价值(再次点击取消操作)" >    
          
                            {% endif %}
                            <br><br>
                            {% if favorited %}
                            <img class="question-img-favorite" src="/content/images/vote-favorite-on.png" title="我要收藏这个问题(再次点击取消操作)" >
                            <div id="favorite-number" class="favorite-number my-favorite-number">
                                {{ question.favourite_count }}
                            </div>
                            {% else %}
                            <img class="question-img-favorite" src="/content/images/vote-favorite-off.png" title="我要收藏这个问题(再次点击取消操作)" >   
                                
                            <div id="favorite-number" class="favorite-number">{% ifnotequal question.favourite_count 0 %}{{ question.favourite_count }}{% endifnotequal %}
                            </div>
                        
                            {% endif %}
                            
                        </div>
                    </td>
                    <td>
                        <div id="item-right">
                            <div class="question-body">
                                {{ question.html|safe }}
                            </div>
                            <div id="question-tags" class="tags" >
                                {% for tag in question.tagname_list %}
                                    <a href="{% url forum.views.tag tag|urlencode %}" class="post-tag" title="查看有关'{{ tag }}'的问题" rel="tag">{{ tag }}</a>
                                {% endfor %}
                            </div>
                            <div id="question-controls" style="clear:both;">
                                <table width="100%">
                                    <tr>
                                        <td width="210px" style="vertical-align:top">
                                            
                                            {% if request.user|can_edit_post:question %}
                                            <span class="action-link"><a href="{% url edit_question question.id %}">编辑</a></span>
                                            <span class="action-link-separator">|</span>
                                            {% endif %}
                                            {% if request.user|can_delete_post:question %}
                                            <span class="action-link"><a id="question-delete-link-{{question.id}}">删除</a></span>
                                            <span class="action-link-separator">|</span>
                                            {% endif %}
                                            {% if question.closed %}
                                            {% if request.user|can_reopen_question:question %}
                                            <span class="action-link"><a href="{% url reopen question.id %}">打开</a></span>
                                            <span class="action-link-separator">|</span>
                                            {% endif %}
                                            {% else %}
                                            {% if request.user|can_close_question:question %}
                                            <span class="action-link"><a href="{% url close question.id %}">关闭</a></span>
                                            <span class="action-link-separator">|</span>
                                            {% endif %}
                                            {% endif %}
                                            
                                            <span id="question-offensive-flag-{{ question.id }}" class="offensive-flag" title="检举该帖为垃“水帖”(含广告、人身攻击、恶意言论等)"><a>垃圾帖?</a><span class="darkred">{% if request.user|can_view_offensive_flags %}{% if question.offensive_flag_count %}({{ question.offensive_flag_count }}){% endif %}{% endif %}</span>
                                                             
                                            </span>
                                            
                                        </td>
                                        <td width="210px" style="vertical-align:top">
                                            {% if question.last_edited_by %}
                                            <div class="question-edit" >
                                                <table width="200px" >
                                                    <tr>
                                                        <td colspan="2"> 
                                                         更新于<a href="{% url question_revisions question.id %}"><strong title="{{question.last_edited_at }}">{% diff_date question.last_edited_at  %}</strong></a>
                                                        </td>
                                                        
                                                    </tr>
                                                    {% if question.wiki %}
                                                    <tr>
                                                        <td style="width:40px;vertical-align:bottom">
                                                        {% gravatar question.last_edited_by 32 %}
                                                        </td>
                                                        <td style="width:160px; vertical-align:top">
                                                            <a href="/users/{{ question.last_edited_by.id }}/{{ question.last_edited_by.username }}">{{ question.last_edited_by.username }}</a>
                                                        </td>
                                                    </tr>
                                                    {% else %}
                                                    {% ifequal question.last_edited_by question.author %}
                                                    <tr>
                                                        <td> </td>
                                                        <td> </td>
                                                    </tr>
                                                    {% else %}
                                                    <tr>
                                                        <td style="width:40px;vertical-align:bottom">
                                                        {% gravatar question.last_edited_by 32 %}
                                                        </td>
                                                        <td style="width:160px; vertical-align:top">
                                                            <div><a href="/users/{{ question.last_edited_by.id }}/{{ question.last_edited_by.username }}">{{ question.last_edited_by.username }}</a></div>
                                
                                                            <div>
                                                            {% get_score_badge question.last_edited_by %}
                                                            </div>
                                                          
                                                        </td>
                                                    </tr>
                                                    {% endifequal %}
                                                    {% endif %}
                                                </table>
                                            </div>
                                            {% endif %}
                                            
                                        </td>
                                        <td style="vertical-align:top">
                                            {% if question.wiki %}
                                            <span class="wiki-category">社区Wiki</span>
                                            <div style="margin-bottom:10px"></div>
                                            {% else %}
                                            <div  class="question-mark">
                                                <table width="200px">
                                                    <tr>
                                                        <td colspan="2"> 
                                                        提问于<strong title="{{ question.added_at }}">{% diff_date question.added_at %}</strong>
                                                        </td>
                                                        
                                                    </tr>
                                                    
                                                    <tr>
                                                        <td style="width:40px; vertical-align:bottom">
                                                        {% gravatar question.author 32 %}
                                                        </td>
                                                        <td align="left" style="width:160px;vertical-align:top">
                                                            <div><a href="/users/{{ question.author.id }}/{{ question.author }}">{{ question.author }}</a></div>
                                                            <div>
                                                            {% get_score_badge question.author %}
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    
                                                </table>
                                            </div>
                                            {% endif %}
                                        
                                        </td>
                                    </tr>
                                </table>
                                
                            </div>
                            
                            <div class="post-comments" style="margin-bottom:20px">
                                <input id="can-post-comments-question-{{question.id}}" type="hidden" value="{{ request.user|can_add_comments }}"/>
                                <a id="comments-link-question-{{question.id}}" class="comments-link">{% if question.comment_count %}评论 <strong>({{question.comment_count}})</strong>{% else %}添加评论{% endif %}</a>
                                <div id="comments-question-{{question.id}}" class="comments-container">
                                <div class="comments"/></div>
                            </div>
                            
                        </div>
                        
                    </td>
                </tr>
            </table>
            {% if question.closed %}
            <div class="question-status" style="margin-bottom:15px">
            <h3>问题以“{{ question.get_close_reason_display }}”的原因已被 <a href="{{ question.closed_by.get_profile_url }}">{{ question.closed_by.username }}</a>{% diff_date question.closed_at %}<font class="darkred">关闭</font></h3>
            </div>
            {% endif %}
            
            {% ifnotequal question.answer_count 0 %}
                <div class="tabBar">
                    <a name="sort-top"></a>
                    <div class="headQuestions">{{ question.answer_count }}个回答:</div>
                    <div class="tabsA">
                         <a id="oldest" href="?sort=oldest#sort-top" title="最先回答显示在最前面">最先回答</a>
                        <a id="latest" href="?sort=latest#sort-top" title="最晚回答显示在最前面">最近回答</a>
                        <a id="votes" href="?sort=votes#sort-top" title="投票次数最多的显示在最前面">投票最多</a>   
                    </div>
                </div>
                {% cnprog_paginator context %}
  
                {% for answer in answers %}
                    <a name="{{ answer.id }}"></a>
                    <div id="answer-container-{{ answer.id }}" class="answer {% if answer.accepted %}accepted-answer{% endif %}{% if answer.deleted %}deleted{% endif %} {% ifequal answer.author_id question.author_id %} answered-by-owner{% endifequal %}">
                        <table style="width:100%;">
                            <tr>
                                <td style="width:30px;vertical-align:top">
                                    <div class="vote-buttons">
                                        <img id="answer-img-upvote-{{ answer.id }}" class="answer-img-upvote" src="/content/images/vote-arrow-up{% get_user_vote_image user_answer_votes answer.id 1 %}.png" title="这篇帖子有价值(再次点击取消操作)" >
                                        <div id="answer-vote-number-{{ answer.id }}" class="vote-number" title="当前总票数">
                                            {{ answer.score }}
                                        </div>
                                        <img id="answer-img-downvote-{{ answer.id }}" class="answer-img-downvote" src="/content/images/vote-arrow-down{% get_user_vote_image user_answer_votes answer.id -1 %}.png" title="这篇帖子没有价值(再次点击取消操作)" >
                                     
                                        <br><br>
                                        {% ifequal request.user question.author  %}
                                        <img id="answer-img-accept-{{ answer.id }}" class="answer-img-accept" src="/content/images/vote-accepted{% if answer.accepted %}-on{% endif %}.png" title="最佳答案(再次点击取消操作)" >
                                        {% else %}
                                            {% if answer.accepted %}
                                            <img id="answer-img-accept-{{ answer.id }}" class="answer-img-accept" src="/content/images/vote-accepted{% if answer.accepted %}-on{% endif %}.png" title="这个答案已经被提问作者标记为最佳答案" >
                                            {% endif %}
                                        {% endifequal %}
                                    </div>
                                </td>
                                <td>
                                    <div class="item-right">
                                        <div class="answer-body">
                                            {{ answer.html|safe }}
                                        </div>
                                        <div class="answer-controls" style="clear:both;">
                                            <table width="100%">
                        	                    <tr>
                                                    <td width="210px" style="vertical-align:top">
                                                        {% if request.user|can_edit_post:answer %}
                                                        <span class="action-link"><a href="{% url edit_answer answer.id %}">编辑</a></span>
                                                        <span class="action-link-separator">|</span>
                                                        {% endif %}
                                                        {% if request.user|can_delete_post:answer %}
                                                        <span class="action-link"><a id="answer-delete-link-{{answer.id}}">删除</a></span>
                                                        <span class="action-link-separator">|</span>
                                                        {% endif %}
                                                        <span class="linksopt">
                                                            <a href="#{{ answer.id }}" title="该回答的链接地址">
                                                            永久链接
                                                            </a>
                                                        </span>
                                                        <span class="action-link-separator">|</span>
                                                        <span id="answer-offensive-flag-{{ answer.id }}" class="offensive-flag" title="检举该帖为垃“水帖”(含广告、人身攻击、恶意言论等)"><a>垃圾帖?</a><span class="darkred">{% if request.user|can_view_offensive_flags %}{% if answer.offensive_flag_count %}({{ answer.offensive_flag_count }}){% endif %}{% endif %}</span></span>
                                                    </td>
                        	                    	<td width="210px" style="vertical-align:top">
                                                    {% if answer.last_edited_by %}
                                                    <div class="question-edit" >
                                                        <table width="200px" >
                                                            <tr>
                                                                <td colspan="2"> 
                                                                 更新于<a href="{% url answer_revisions answer.id %}"><strong title="{{answer.last_edited_at }}">{% diff_date answer.last_edited_at  %}</strong></a>
                                                                </td>
                                                                
                                                            </tr>
                                                            {% if answer.wiki %}
                                                            <tr>
                                                                <td width="40px" style="vertical-align:bottom">
                                                                {% gravatar answer.last_edited_by 32 %}
                                                                </td>
                                                                <td style="width:160px; vertical-align:top">
                                                                    <div><a href="/users/{{ answer.last_edited_by.id }}/{{ answer.last_edited_by.username }}">{{ answer.last_edited_by.username }}</a></div>
                                                               
                                                                </td>
                                                            </tr>
                                                            {% else %}
                                                            {% ifequal answer.last_edited_by answer.author %}
                                                            <tr>
                                                                <td> </td>
                                                                <td> </td>
                                                            </tr>
                                                            {% else %}
                                                            <tr>
                                                                <td width="40px" style="vertical-align:bottom">
                                                                {% gravatar answer.last_edited_by 32 %}
                                                                </td>
                                                                <td style="width:160px; vertical-align:top">
                                                                    <div><a href="/users/{{ answer.last_edited_by.id }}/{{ answer.last_edited_by.username }}">{{ answer.last_edited_by.username }}</a></div>
                                                                    <div>
                                                                    {% get_score_badge answer.last_edited_by %}
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                            {% endifequal %}
                                                            {% endif %}
                                                        </table>
                                                    </div>
                                                    {% endif %}
                                                    
                                                </td>
                                                 <td style="vertical-align:top">
                                                    {% if answer.wiki %}
                                                    <span class="wiki-category">社区Wiki</span>
                                                    <div style="margin-bottom:10px"></div>
                                                    {% else %}
                                                    <div  class="answer-mark">
                                                        <table width="200px">
                            	                            <tr>
                                	                            	<td colspan="2"> 
                                                                回答于<strong title="{{answer.added_at}}">{% diff_date answer.added_at %}</strong>
                                                                </td>
                            	                            	
                            	                            </tr>
                            	                            <tr>
                                                                <td width="40px" style="vertical-align:bottom">
                                                                {% gravatar answer.author 32 %}
                                                                </td>
                                                                <td style="width:160px; vertical-align:top">
                                                                    <div><a href="/users/{{ answer.author.id }}/{{ answer.author.username }}">{{ answer.author }}</a></div>
                                                                    <div>
                                                                    {% get_score_badge answer.author %}
                                                                    </div>
                                                                </td>
                            	                            </tr>
                                                        </table>
                                                    </div>
                                                    {% endif %}
                                                    
                                                 </td>
                        	                    </tr>
                        	                    
                                            </table>
                                            
                                        </div>
                                        <div id="comment-{{ answer.id }}" class="post-comments" >
                                            <input id="can-post-comments-answer-{{answer.id}}" type="hidden" value="{{ request.user|can_add_comments }}"/>
                                            <a id="comments-link-answer-{{answer.id}}" class="comments-link">{% if answer.comment_count %}评论 <strong>({{answer.comment_count}})</strong>{% else %}添加评论{% endif %}</a>
                                            <div id="comments-answer-{{answer.id}}" class="comments-container">
                                            <div class="comments"/></div>
                                        </div>
                                        
                                    </div>
                                    
                                </td>
                            </tr>
                        </table>
                    </div>
                {% endfor %}
                <div class="paginator-container-left">
                    {% cnprog_paginator context %}
                </div>
            {% else %}
                <div class="line"></div>
            {% endifnotequal %}
            <div style="clear:both">
            </div>
            
            {% if not question.closed %}
            {% if request.user.is_authenticated %}
            <div style="padding:10px 0 0 0;">
                <div class="headNormal">您的回答:</div>
            </div>

            <div id="description" class="" >
                <div id="wmd-button-bar" class="wmd-panel"></div>
                {{ answer.text }}
                <div class="preview-toggle">
                    <table width="100%">
                        <tr>
                            <td>
                                <span id="pre-collapse" title="打开或者关闭Markdown编辑器的实时预览">预览开关</span>
                            </td>
                            <td style="text-align:right;">
                                {{ answer.wiki }} <span style="font-weight:normal;cursor:help" title="{{answer.wiki.help_text}}">{{ answer.wiki.label_tag }} </span>
                            </td>
                        </tr>
                    
                    </table>  
                </div>
                <div id="previewer" class="wmd-preview"></div>
                {{ answer.text.errors }}
                
            </div>
            <br>
            <input type="submit" value="回答该问题" class="submit"><span class="form-error"></span>
            {% else %}
            <input id="btLogin" type="button" class="submit" style="width:200px" value="登录并回答该问题">
            {% endif %}
            {% endif %}
            <br><br>
        </form>
    </div>
</div>
{% endblock %}

{% block sidebar %}
<div class="boxC">
    <p>
        您正在浏览的问题含有以下标签:
    </p>
    <p class="tags" >
        {% for tag in tags %}
        <a href="{% url forum.views.tag tag.name|urlencode %}" title="查看有关'{{ tag.name }}'的问题" rel="tag">{{ tag.name }}</a> <span class="tag-number">× {{ tag.used_count|intcomma }}</span><br>
        {% endfor %}
    </p>
    <p>
        提问时间: <br><strong title="{{ question.added_at }}">{{ question.added_at|timesince }}</strong>
    </p>
    <p> 
     目前浏览数量:<br><strong>{{ question.view_count|intcomma }}</strong>
    </p>
    <p> 
        最后更新时间:<br><strong title="{{ question.last_activity_at }}">{{ question.last_activity_at|timesince }}</strong>
    </p>
</div>

<div class="boxC">
    <h3 class="subtitle">相似的问题</h3>
    <div class="questions-related">
        {% for question in similar_questions %}
        <p>
            <a href="/questions/{{question.id}}/{{ question.get_question_title }}">{{ question.get_question_title }}</a>
        </p>
        {% endfor %}
    </div>
    <br>  
</div>

{% endblock %}

{% block endjs %}
{% endblock %}