Commit d10d7cff authored by Raphael Remorosa's avatar Raphael Remorosa

Added a search bar in base.html, and 3 different searches. Only album search...

Added a search bar in base.html, and 3 different searches. Only album search is working with the search bar as of now.
parent 6c1efd64
......@@ -36,10 +36,31 @@ class EditProfile(UpdateView):
slug_field = 'username'
slug_url_kwarg = 'slug'
def search(request,term):
results = album.objects.filter(album_name__contains = term)
custom()
return render(request, 'search.html',{'term': term, 'results': results})
def search(request):
type = 'album'
term = request.GET.get('search', '')
artistAlbums = album.objects.filter(artist__name__contains = term)
if type == 'song':
results = song.objects.filter(song_name__contains = term)
elif type == 'album':
results = album.objects.filter(album_name__contains = term)
elif type == 'artist':
results = artist.objects.filter(name__contains = term)
context = {
'type': type,
'term': term,
'results': results,
'albums': artistAlbums,
}
return render(request, 'search'+type+'.html', context)
# def search(request,term):
# results = album.objects.filter(album_name__contains = term)
# custom()
# return render(request, 'search.html',{'term': term, 'results': results})
# def edit_profile(request, username):
# if request.method == 'POST':
......
......@@ -24,8 +24,12 @@ urlpatterns = [
url(r'^logout/$', auth_views.logout, {'template_name': 'logged_out.html'}, name='logout'),
url(r'^admin/', admin.site.urls),
url(r'^signup/$', core_views.signup, name='signup'),
url(r'^search/(?P<term>[A-Za-z0-9-+_.@]+)/$',core_views.search, name='search'),
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$', core_views.user_profile_page, name='viewprofile'),
# url(r'^search_by_(?P<type>[A-Za-z0-9-+_.@]+)/?search=(?P<term>[A-Za-z0-9-+_.@]+)/$',core_views.search, name='search'),
url(r'^search/$',core_views.search, name='search'),
# url(r'^search/(?P<term>[A-Za-z0-9-+_.@]+)/$',core_views.search, name='search'),
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$', core_views.user_profile_page, name='viewprofile'),
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', core_views.EditProfile.as_view(success_url=reverse_lazy('home')), name='editprofile'),
# url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', core_views.EditProfile.as_view(success_url=reverse_lazy('profile', kwargs={'update':'true'})), name='editprofile'),
url(r'^$', core_views.home, name='home')
......
......@@ -6,6 +6,32 @@
<link rel="stylesheet" href="/files/css/mymusiclist.css">
<link rel="stylesheet" href="/files/css/font-awesome.css">
</head>
<style>
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 80%;
}
</style>
<body>
<header>
{% if request.user.is_authenticated %}
......@@ -35,6 +61,12 @@
</div>
</header>
<form action="{% url 'search' %}" method="get">
<input type="text" name="search" placeholder="Search..">
</form>
{% block content %}
{% endblock %}
<script>
......
{% extends 'base.html' %}
{% block title %}Song search test{% endblock %}
{% block sidebar %}
<h2> Search results (by {{type}})</h2>
<p>
You searched for '{{term}}' <br>
Found {{results.count}} results <br>
Source: Local
{% endblock %}
{% block content %}
{% for i in results %}
<div class = "boxified main">
<h3> {{i.album_name}} </h3>
<p> Artist: {{i.artist.name}} <br>
Year: {{i.year}} </p>
</div>
{% endfor %}
{% endblock %}
{% extends 'base.html' %}
{% block title %}Song search test{% endblock %}
{% block sidebar %}
<h2> Search results (by {{type}})</h2>
<p>
You searched for '{{term}}' <br>
Found {{results.count}} results <br>
Source: Local
{% endblock %}
{% block content %}
{% for i in results %}
<div class = "boxified main">
<h3>{{i.name}}</h3>
{% for j in albums %}
<p> <tab>
{% if j.artist.name == i.name %}
<h3> {{ j.album_name }} - {{ j.year }} </h3>
{% endif %} </p>
{% endfor %}
</div>
{% endfor %}
{% endblock %}
{% extends 'base.html' %}
{% block title %}Song search test{% endblock %}
{% block sidebar %}
<h2> Search results (by {{type}})</h2>
<p>
You searched for '{{term}}' <br>
Found {{results.count}} results <br>
Source: Local
{% endblock %}
{% block content %}
{% for i in results %}
<div class = "boxified main">
<h3> {{i.song_name}} </h3>
<h3> {{i.album_name}} </h3>
<p> Artist: {{i.artist.name}} <br>
Year: {{i.year}} </p>
</div>
{% endfor %}
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment