X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/204b196b015876b87379c526b3f92e7e396464bd..54d34ece196890ca3688f8c1c0807e4e93710790:/forum/views/commands.py diff --git a/forum/views/commands.py b/forum/views/commands.py index 0436047..4fba05f 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -10,7 +10,6 @@ from forum.models import * from forum.models.node import NodeMetaClass from forum.actions import * from django.core.urlresolvers import reverse -from django.contrib.auth.decorators import login_required from forum.utils.decorators import ajax_method, ajax_login_required from decorators import command, CommandException, RefreshPageCommand from forum.modules import decorate @@ -435,6 +434,36 @@ def convert_to_comment(request, id): return RefreshPageCommand() +@decorate.withfn(command) +def convert_to_question(request, id): + user = request.user + answer = get_object_or_404(Answer, id=id) + question = answer.question + + if not request.POST: + description = lambda a: _("Answer by %(uname)s: %(snippet)s...") % {'uname': a.author.username, + 'snippet': a.summary[:10]} + nodes = [(question.id, _("Question"))] + [nodes.append((a.id, description(a))) for a in + question.answers.filter_state(deleted=False).exclude(id=answer.id)] + + return render_to_response('node/convert_to_question.html', {'answer': answer}) + + if not user.is_authenticated(): + raise AnonymousNotAllowedException(_("convert answers to questions")) + + if not user.can_convert_to_question(answer): + raise NotEnoughRepPointsException(_("convert answers to questions")) + + try: + title = request.POST.get('title', None) + except: + raise CommandException(_("You haven't specified the title of the new question")) + + AnswerToQuestionAction(user=user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=dict(title=title)) + + return RefreshPageCommand() + @decorate.withfn(command) def subscribe(request, id, user=None): if user: @@ -491,13 +520,25 @@ def matching_tags(request): if len(request.GET['q']) == 0: raise CommandException(_("Invalid request")) - possible_tags = Tag.active.filter(name__istartswith = request.GET['q']) + possible_tags = Tag.active.filter(name__icontains = request.GET['q']) tag_output = '' for tag in possible_tags: - tag_output += (tag.name + "|" + tag.name + "." + tag.used_count.__str__() + "\n") + tag_output += "%s|%s|%s\n" % (tag.id, tag.name, tag.used_count) return HttpResponse(tag_output, mimetype="text/plain") +def matching_users(request): + if len(request.GET['q']) == 0: + raise CommandException(_("Invalid request")) + + possible_users = User.objects.filter(username__icontains = request.GET['q']) + output = '' + + for user in possible_users: + output += ("%s|%s|%s\n" % (user.id, user.decorated_name, user.reputation)) + + return HttpResponse(output, mimetype="text/plain") + def related_questions(request): if request.POST and request.POST.get('title', None): can_rank, questions = Question.objects.search(request.POST['title'])