forked from mirrors/bookwyrm
Search is a view not an action
This commit is contained in:
parent
07aab3806b
commit
7454fb7454
3 changed files with 23 additions and 21 deletions
|
@ -68,13 +68,14 @@ urlpatterns = [
|
|||
re_path(r'^shelf/%s/(?P<shelf_identifier>[\w-]+)(.json)?/?$' % username_regex, views.shelf_page),
|
||||
re_path(r'^shelf/%s/(?P<shelf_identifier>[\w-]+)(.json)?/?$' % localname_regex, views.shelf_page),
|
||||
|
||||
re_path(r'^search/?$', views.search),
|
||||
|
||||
# internal action endpoints
|
||||
re_path(r'^logout/?$', actions.user_logout),
|
||||
re_path(r'^user-login/?$', actions.user_login),
|
||||
re_path(r'^register/?$', actions.register),
|
||||
re_path(r'^edit_profile/?$', actions.edit_profile),
|
||||
|
||||
re_path(r'^search/?$', actions.search),
|
||||
re_path(r'^import_data/?', actions.import_data),
|
||||
re_path(r'^edit_book/(?P<book_id>\d+)/?', actions.edit_book),
|
||||
re_path(r'^upload_cover/(?P<book_id>\d+)/?', actions.upload_cover),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
''' views for actions you can take in the application '''
|
||||
from io import BytesIO, TextIOWrapper
|
||||
import re
|
||||
from PIL import Image
|
||||
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
|
@ -10,7 +9,7 @@ from django.http import HttpResponseBadRequest, HttpResponseNotFound
|
|||
from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
|
||||
from fedireads import forms, models, books_manager, outgoing
|
||||
from fedireads import forms, models, outgoing
|
||||
from fedireads import goodreads_import
|
||||
from fedireads.settings import DOMAIN
|
||||
from fedireads.views import get_user_from_username
|
||||
|
@ -346,22 +345,6 @@ def unfollow(request):
|
|||
return redirect('/user/%s' % user_slug)
|
||||
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
''' that search bar up top '''
|
||||
query = request.GET.get('q')
|
||||
if re.match(r'\w+@\w+.\w+', query):
|
||||
# if something looks like a username, search with webfinger
|
||||
results = [outgoing.handle_account_search(query)]
|
||||
template = 'user_results.html'
|
||||
else:
|
||||
# just send the question over to book search
|
||||
results = books_manager.search(query)
|
||||
template = 'book_results.html'
|
||||
|
||||
return TemplateResponse(request, template, {'results': results})
|
||||
|
||||
|
||||
@login_required
|
||||
def clear_notifications(request):
|
||||
''' permanently delete notification for user '''
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
''' views for pages you can go to in the application '''
|
||||
import re
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Avg, Q
|
||||
from django.http import HttpResponseBadRequest, HttpResponseNotFound,\
|
||||
|
@ -8,8 +10,8 @@ from django.shortcuts import redirect
|
|||
from django.template.response import TemplateResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from fedireads import activitypub
|
||||
from fedireads import forms, models
|
||||
from fedireads import activitypub, outgoing
|
||||
from fedireads import forms, models, books_manager
|
||||
from fedireads import goodreads_import
|
||||
from fedireads.books_manager import get_or_create_book
|
||||
from fedireads.tasks import app
|
||||
|
@ -141,6 +143,22 @@ def get_activity_feed(user, filter_level, model=models.Status):
|
|||
return activities
|
||||
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
''' that search bar up top '''
|
||||
query = request.GET.get('q')
|
||||
if re.match(r'\w+@\w+.\w+', query):
|
||||
# if something looks like a username, search with webfinger
|
||||
results = [outgoing.handle_account_search(query)]
|
||||
template = 'user_results.html'
|
||||
else:
|
||||
# just send the question over to book search
|
||||
results = books_manager.search(query)
|
||||
template = 'book_results.html'
|
||||
|
||||
return TemplateResponse(request, template, {'results': results})
|
||||
|
||||
|
||||
def books_page(request):
|
||||
''' discover books '''
|
||||
recent_books = models.Work.objects
|
||||
|
|
Loading…
Reference in a new issue