X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/90c94238301b5d208461f810021e572a9b06e8e7..745f67c37acdb9574c5297004adde2b9a7da5fdb:/forum/views/readers.py?ds=sidebyside diff --git a/forum/views/readers.py b/forum/views/readers.py index fbc0ed1..991a6b6 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -6,6 +6,7 @@ from forum import settings as django_settings from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpResponsePermanentRedirect from django.core.paginator import Paginator, EmptyPage, InvalidPage +from django.core.exceptions import ObjectDoesNotExist from django.template import RequestContext from django import template from django.utils.html import * @@ -101,8 +102,15 @@ def questions(request): @decorators.render('questions.html') def tag(request, tag): + + try: + tag = Tag.active.get(name=unquote(tag)) + except Tag.DoesNotExist: + raise Http404 + + return question_list(request, - Question.objects.filter(tags__name=unquote(tag)), + Question.objects.filter(tags=tag), mark_safe(_('questions tagged %(tag)s') % {'tag': tag}), None, mark_safe(_('Questions Tagged With %(tag)s') % {'tag': tag}), @@ -192,7 +200,7 @@ def search(request): return HttpResponseRedirect(reverse('tags') + '?q=%s' % urlquote(keywords.strip())) elif search_type == "user": return HttpResponseRedirect(reverse('users') + '?q=%s' % urlquote(keywords.strip())) - elif search_type == "question": + else: return question_search(request, keywords) else: return render_to_response("search.html", context_instance=RequestContext(request)) @@ -232,16 +240,14 @@ def tags(request): }) def update_question_view_times(request, question): - if not 'last_seen_in_question' in request.session: - request.session['last_seen_in_question'] = {} + last_seen_in_question = request.session.get('last_seen_in_question', {}) - last_seen = request.session['last_seen_in_question'].get(question.id, None) + last_seen = last_seen_in_question.get(question.id, None) - if (not last_seen) or last_seen < question.last_activity_at: + if (not last_seen) or (last_seen < question.last_activity_at): QuestionViewAction(question, request.user, ip=request.META['REMOTE_ADDR']).save() - request.session['last_seen_in_question'][question.id] = datetime.datetime.now() - - request.session['last_seen_in_question'][question.id] = datetime.datetime.now() + last_seen_in_question[question.id] = datetime.datetime.now() + request.session['last_seen_in_question'] = last_seen_in_question def match_question_slug(id, slug): slug_words = slug.split('-') @@ -267,7 +273,7 @@ def answer_redirect(request, answer): else: raise Http404() - count = answer.question.answers.filter(Q(marked=True) | filter).count() + count = answer.question.answers.filter(Q(marked=True) | filter).exclude(state_string="(deleted)").count() pagesize = pc.pagesize(request) page = count / pagesize @@ -314,9 +320,9 @@ def question(request, id, slug='', answer=None): return HttpResponsePermanentRedirect(question.get_absolute_url()) if request.POST: - answer_form = AnswerForm(question, request.POST) + answer_form = AnswerForm(request.POST, user=request.user) else: - answer_form = AnswerForm(question) + answer_form = AnswerForm(user=request.user) answers = request.user.get_visible_answers(question)