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): ...@@ -38,7 +38,7 @@ class EditProfile(UpdateView):
def search(request): def search(request):
type = 'album' type = request.GET.get('searchtype', '')
term = request.GET.get('search', '') term = request.GET.get('search', '')
artistAlbums = album.objects.filter(artist__name__contains = term) artistAlbums = album.objects.filter(artist__name__contains = term)
...@@ -55,7 +55,7 @@ def search(request): ...@@ -55,7 +55,7 @@ def search(request):
'results': results, 'results': results,
'albums': artistAlbums, 'albums': artistAlbums,
} }
return render(request, 'search'+type+'.html', context) return render(request, 'search.html', context)
def artist_profile(request, identifier): def artist_profile(request, identifier):
result = artist.objects.filter(id = identifier) result = artist.objects.filter(id = identifier)
......
...@@ -6,32 +6,6 @@ ...@@ -6,32 +6,6 @@
<link rel="stylesheet" href="/files/css/mymusiclist.css"> <link rel="stylesheet" href="/files/css/mymusiclist.css">
<link rel="stylesheet" href="/files/css/font-awesome.css"> <link rel="stylesheet" href="/files/css/font-awesome.css">
</head> </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> <body>
<header> <header>
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
...@@ -60,11 +34,52 @@ ...@@ -60,11 +34,52 @@
{% endblock %} {% endblock %}
</div> </div>
</header> </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>
<form action="{% url 'search' %}" method="get">
<input type="text" name="search" placeholder="Search..">
</form>
{% block content %} {% block content %}
......
...@@ -2,21 +2,45 @@ ...@@ -2,21 +2,45 @@
{% block title %}Song search test{% endblock %} {% block title %}Song search test{% endblock %}
{% block sidebar %} {% block sidebar %}
<h2> Search results </h2> <h2> Search results (by {{type}})</h2>
<p> <p>
You searched for '{{term}}' <br> You searched for '{{term}}' <br>
Found {{results.count}} results <br> Found {{results.count}} results <br>
Source: Local Source: Local</p>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% for i in results %}
<div class = "boxified main"> {% for i in results %}
<h3> {{i.album_name}} </h3> <div class = "boxified main">
<p> Artist: {{i.artist.name}} <br> {% if type == "album" %}
Year: {{i.year}} </p> <h3><a href="/album/{{i.id}}">{{i.album_name}}</a></h3>
</div> <p>Artist: <a href="/artist/{{i.artist.id}}">{{i.artist.name}}</a><br>
{% endfor %} Year: {{i.year}} </p>
{% endblock %} {% 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