Commit 336dc526 authored by Raphael Remorosa's avatar Raphael Remorosa

Added a search.html, can select search by <type>, connected search results to...

Added a search.html, can select search by <type>, connected search results to album/artist profile, removed unneccesary search+<text>.html
parent 04c0a080
......@@ -38,7 +38,7 @@ class EditProfile(UpdateView):
def search(request):
type = 'album'
type = request.GET.get('searchtype', '')
term = request.GET.get('search', '')
artistAlbums = album.objects.filter(artist__name__contains = term)
......@@ -55,7 +55,7 @@ def search(request):
'results': results,
'albums': artistAlbums,
}
return render(request, 'search'+type+'.html', context)
return render(request, 'search.html', context)
def artist_profile(request, identifier):
result = artist.objects.filter(id = identifier)
......
......@@ -6,32 +6,6 @@
<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 %}
......@@ -62,11 +36,52 @@
</header>
<script>
function mainA(){
document.getElementById("demo").innerHTML = "Album Search";
document.getElementById("searchbytype").value = "album";
}
function mainB(){
document.getElementById("demo").innerHTML = "Artist Search";
document.getElementById("searchbytype").value = "artist";
}
function mainC(){
document.getElementById("demo").innerHTML = "Song Search";
document.getElementById("searchbytype").value = "song";
}
</script>
<form action="{% url 'search' %}" method="get">
<div class="wrap">
<div class="search">
<input type="text" name="search" placeholder="Search..">
<input id="searchbytype" type="hidden" name="searchtype" value="album">
<p id="demo">Album Search</p></input>
<button>Search</button>
</div>
</div>
</form>
<div>
<a><button onclick="mainA()">By Album</button></a>
<a><button onclick="mainB()">By Artist</button></a>
<a><button onclick="mainC()">By Song</button></a>
</div>
{% block content %}
{% endblock %}
<script>
......
......@@ -2,21 +2,45 @@
{% block title %}Song search test{% endblock %}
{% block sidebar %}
<h2> Search results </h2>
<h2> Search results (by {{type}})</h2>
<p>
You searched for '{{term}}' <br>
Found {{results.count}} results <br>
Source: Local
Source: Local</p>
{% endblock %}
{% block content %}
{% for i in results %}
<div class = "boxified main">
<h3> {{i.album_name}} </h3>
<p> Artist: {{i.artist.name}} <br>
{% for i in results %}
<div class = "boxified main">
{% if type == "album" %}
<h3><a href="/album/{{i.id}}">{{i.album_name}}</a></h3>
<p>Artist: <a href="/artist/{{i.artist.id}}">{{i.artist.name}}</a><br>
Year: {{i.year}} </p>
</div>
{% endfor %}
{% endif %}
{% if type == "artist" %}
<h3><a href="/artist/{{i.id}}">{{i.name}}</a></h3>
{% for j in albums %}
<p> <tab>
{% if j.artist.name == i.name %}
<h3><a href="/album/{{j.id}}">{{ j.album_name }}</a> - {{ j.year }} </h3>
{% endif %} </p>
{% endfor %}
{% endif %}
{% if type == "song" %}
<h3>{{i.song_name}}</h3>
<h3><a href="/album/{{i.album.id}}">{{i.album.album_name}}</a></h3>
<p>Artist: <a href="/artist/{{i.artist.id}}">{{i.artist.name}}</a><br>
Year: {{i.album.year}} </p>
{% endif %}
</div>
{% endfor %}
{% endblock %}
\ No newline at end of file
{% 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