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
|
||||
|
||||
urlpatterns = [
|
||||
path('search/', views.searchAPI),
|
||||
path('', include('sage_stream.api.urls')),
|
||||
path('search/', views.searchAPI),
|
||||
]
|
||||
|
|
@ -56,14 +56,15 @@
|
|||
</ul>
|
||||
<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">
|
||||
<input class="form-control form-control-navbar" data-toggle="dropdown"
|
||||
type="search"
|
||||
placeholder="Search"
|
||||
aria-label="Search"
|
||||
autocomplete="off"
|
||||
id="search">
|
||||
id="search"
|
||||
name="q">
|
||||
<ul class="dropdown-menu" id="searchdropdown">
|
||||
<li><span class="dropdown-item-text">Nothing</span></li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path('', views.core, name='core'),
|
||||
path('status/', views.status, name='status'),
|
||||
path('about/', views.about, name='about'),
|
||||
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'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from django.db.models import Q
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import redirect
|
||||
from core.models import Video
|
||||
|
|
@ -8,16 +9,24 @@ def core(request):
|
|||
videos = Video.objects.all()
|
||||
return render(request, 'base.html', {'videos': videos[::-1]})
|
||||
|
||||
def about(request):
|
||||
return render(request, 'about.html')
|
||||
|
||||
def random(request):
|
||||
videos = Video.objects.all().order_by("?")
|
||||
ran = videos.first()
|
||||
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):
|
||||
highest_id = Video.objects.order_by('-id').first().id
|
||||
video_list = []
|
||||
|
||||
for i in range(highest_id + 1):
|
||||
for i in range(1, highest_id + 1):
|
||||
try:
|
||||
video = Video.objects.get(id=i)
|
||||
video_list.append(video)
|
||||
|
|
@ -30,6 +39,3 @@ def view(request, id):
|
|||
vid = Video.objects.get(id = id)
|
||||
if vid:
|
||||
return render(request, "view.html", {'video': vid})
|
||||
|
||||
def about(request):
|
||||
return render(request, 'about.html')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user