Implemented search page and fixed off-by-one in status
This commit is contained in:
parent
2ff71ac8da
commit
f8013cc831
|
|
@ -2,6 +2,6 @@ from django.urls import path, include
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('search/', views.searchAPI),
|
|
||||||
path('', include('sage_stream.api.urls')),
|
path('', include('sage_stream.api.urls')),
|
||||||
|
path('search/', views.searchAPI),
|
||||||
]
|
]
|
||||||
|
|
@ -56,14 +56,15 @@
|
||||||
</ul>
|
</ul>
|
||||||
<div class="float-right" style="width:100%">
|
<div class="float-right" style="width:100%">
|
||||||
|
|
||||||
<form class="form-inline ml-0 ml-md-3 float-right">
|
<form class="form-inline ml-0 ml-md-3 float-right" action="/search">
|
||||||
<div class="input-group input-group-sm">
|
<div class="input-group input-group-sm">
|
||||||
<input class="form-control form-control-navbar" data-toggle="dropdown"
|
<input class="form-control form-control-navbar" data-toggle="dropdown"
|
||||||
type="search"
|
type="search"
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
aria-label="Search"
|
aria-label="Search"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
id="search">
|
id="search"
|
||||||
|
name="q">
|
||||||
<ul class="dropdown-menu" id="searchdropdown">
|
<ul class="dropdown-menu" id="searchdropdown">
|
||||||
<li><span class="dropdown-item-text">Nothing</span></li>
|
<li><span class="dropdown-item-text">Nothing</span></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.core, name='core'),
|
path('', views.core, name='core'),
|
||||||
path('status/', views.status, name='status'),
|
|
||||||
path('about/', views.about, name='about'),
|
path('about/', views.about, name='about'),
|
||||||
path('random/', views.random, name='random'),
|
path('random/', views.random, name='random'),
|
||||||
|
path('search/', views.search, name='search'),
|
||||||
|
path('status/', views.status, name='status'),
|
||||||
path('view/<int:id>', views.view, name='view'),
|
path('view/<int:id>', views.view, name='view'),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django.db.models import Q
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from core.models import Video
|
from core.models import Video
|
||||||
|
|
@ -8,16 +9,24 @@ def core(request):
|
||||||
videos = Video.objects.all()
|
videos = Video.objects.all()
|
||||||
return render(request, 'base.html', {'videos': videos[::-1]})
|
return render(request, 'base.html', {'videos': videos[::-1]})
|
||||||
|
|
||||||
|
def about(request):
|
||||||
|
return render(request, 'about.html')
|
||||||
|
|
||||||
def random(request):
|
def random(request):
|
||||||
videos = Video.objects.all().order_by("?")
|
videos = Video.objects.all().order_by("?")
|
||||||
ran = videos.first()
|
ran = videos.first()
|
||||||
return redirect('/view/'+str(ran.id))
|
return redirect('/view/'+str(ran.id))
|
||||||
|
|
||||||
|
def search(request):
|
||||||
|
q = request.GET.get('q', '')
|
||||||
|
videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q))
|
||||||
|
return render(request, 'base.html', {'videos': videos})
|
||||||
|
|
||||||
def status(request):
|
def status(request):
|
||||||
highest_id = Video.objects.order_by('-id').first().id
|
highest_id = Video.objects.order_by('-id').first().id
|
||||||
video_list = []
|
video_list = []
|
||||||
|
|
||||||
for i in range(highest_id + 1):
|
for i in range(1, highest_id + 1):
|
||||||
try:
|
try:
|
||||||
video = Video.objects.get(id=i)
|
video = Video.objects.get(id=i)
|
||||||
video_list.append(video)
|
video_list.append(video)
|
||||||
|
|
@ -30,6 +39,3 @@ def view(request, id):
|
||||||
vid = Video.objects.get(id = id)
|
vid = Video.objects.get(id = id)
|
||||||
if vid:
|
if vid:
|
||||||
return render(request, "view.html", {'video': vid})
|
return render(request, "view.html", {'video': vid})
|
||||||
|
|
||||||
def about(request):
|
|
||||||
return render(request, 'about.html')
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user