|
@@ -14,6 +14,7 @@ from django.db.models.aggregates import Sum
|
|
|
from django.http.response import HttpResponse
|
|
from django.http.response import HttpResponse
|
|
|
from django.shortcuts import render, get_object_or_404, redirect
|
|
from django.shortcuts import render, get_object_or_404, redirect
|
|
|
from django.urls.base import reverse
|
|
from django.urls.base import reverse
|
|
|
|
|
+from django.utils import datastructures
|
|
|
from martor.utils import LazyEncoder
|
|
from martor.utils import LazyEncoder
|
|
|
from notifications.models import Notification
|
|
from notifications.models import Notification
|
|
|
from notifications.signals import notify
|
|
from notifications.signals import notify
|
|
@@ -464,30 +465,26 @@ def comment_del(request, comment_id):
|
|
|
return redirect(request.META['HTTP_REFERER'].split("#")[0] + "#a-comment-section")
|
|
return redirect(request.META['HTTP_REFERER'].split("#")[0] + "#a-comment-section")
|
|
|
|
|
|
|
|
@login_required
|
|
@login_required
|
|
|
-def search(request):
|
|
|
|
|
- qstr = request.GET["q"]
|
|
|
|
|
-
|
|
|
|
|
- results = []
|
|
|
|
|
- results += Epic.objects.filter(name__icontains=qstr)
|
|
|
|
|
- results += Story.objects.filter(name__icontains=qstr)
|
|
|
|
|
|
|
+def search_api(request):
|
|
|
|
|
+ try:
|
|
|
|
|
+ qstr = request.GET["q"]
|
|
|
|
|
+ except datastructures.MultiValueDictKeyError:
|
|
|
|
|
+ qstr = ""
|
|
|
|
|
+
|
|
|
|
|
+ results = set()
|
|
|
|
|
+ results |= set(Epic.objects.filter(name__icontains=qstr).order_by("-updated"))
|
|
|
|
|
+ results |= set(Story.objects.filter(name__icontains=qstr).order_by("-updated"))
|
|
|
|
|
+
|
|
|
|
|
+ results |= set(Epic.objects.filter(description__icontains=qstr).order_by("-updated"))
|
|
|
|
|
+ results |= set(Story.objects.filter(description__icontains=qstr).order_by("-updated"))
|
|
|
|
|
|
|
|
- results += Epic.objects.filter(description__icontains=qstr)
|
|
|
|
|
- results += Story.objects.filter(description__icontains=qstr)
|
|
|
|
|
|
|
+ fmt_results = [{"id": reverse(f"{r.model_name()}_details", args=[r.id]),
|
|
|
|
|
+ "text": f"{r.model_name().title()}: {r.name}"}
|
|
|
|
|
+ for r in results]
|
|
|
|
|
|
|
|
- if len(results) == 1:
|
|
|
|
|
- r = results[0]
|
|
|
|
|
- if isinstance(r, Epic):
|
|
|
|
|
- return redirect("epic_details", r.id)
|
|
|
|
|
- else:
|
|
|
|
|
- return redirect("story_details", r.id)
|
|
|
|
|
- else:
|
|
|
|
|
-
|
|
|
|
|
- paginator = Paginator(results, 10)
|
|
|
|
|
- page = request.GET.get('page')
|
|
|
|
|
- results = paginator.get_page(page)
|
|
|
|
|
-
|
|
|
|
|
- return render(request, 'search_results.html', {'results': results, 'pages': range(1, paginator.num_pages + 1)})
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return HttpResponse(json.dumps({"results": fmt_results,
|
|
|
|
|
+ "pagination": { "more": True }
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
# notifications
|
|
# notifications
|
|
|
|
|
|