mirror of
https://github.com/Damillora/Altessimo
synced 2024-12-22 09:53:45 +00:00
Add randomizer
This commit is contained in:
parent
caf7886567
commit
4119eb63de
@ -1,15 +1,20 @@
|
||||
{% extends 'layouts/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Welcome!</h1>
|
||||
<p>This site is a work-in-progress database of Idolmaster songs, composers, arrangers, and lyricists.</p>
|
||||
<p>The primary purpose of this site is to document the people behind the music in Idolmaster, make observations about the music, and showcase other works that might be of interest </p>
|
||||
<p>This site originated from a spreadsheet I maintained to note the composers' works and their similarities. </p>
|
||||
<h2>Current to-do</h2>
|
||||
<ul>
|
||||
<li>Complete lyricist credits</li>
|
||||
<li>Add songs from IDOLM@STER Radio</li>
|
||||
<li>Re-add other songs that I might have missed</li>
|
||||
<li>Complete showcases of composers</li>
|
||||
</ul>
|
||||
<h1>Welcome!</h1>
|
||||
<p>This site is a work-in-progress database of Idolmaster songs, composers, arrangers, and lyricists.</p>
|
||||
<p>The primary purpose of this site is to document the people behind the music in Idolmaster, make observations about
|
||||
the music, and showcase other works that might be of interest </p>
|
||||
<p>This site originated from a spreadsheet I maintained to note the composers' works and their similarities. </p>
|
||||
<h2>Current to-do</h2>
|
||||
<ul>
|
||||
<li>Complete lyricist credits</li>
|
||||
<li>Add songs from IDOLM@STER Radio</li>
|
||||
<li>Re-add other songs that I might have missed</li>
|
||||
<li>Complete showcases of composers</li>
|
||||
</ul>
|
||||
<h2>Mildly interesting</h2>
|
||||
<ul>
|
||||
<li><a href="/randomizer">A song randomizer</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
32
home/templates/randomizer.html
Normal file
32
home/templates/randomizer.html
Normal file
@ -0,0 +1,32 @@
|
||||
{% extends 'layouts/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Song Randomizer</h1>
|
||||
<p>A simple song randomizer. </p>
|
||||
<p><strong>WARNING: Very experimental. Implementation is not very smart yet.</strong></p>
|
||||
{% if num %}
|
||||
<p>Song choice</p>
|
||||
<h2>
|
||||
{{ song.title }}
|
||||
</h2>
|
||||
<p>
|
||||
<a href="/songs/{{ song.id }}/{{ song.title }}">View song info</a>
|
||||
</p>
|
||||
<h2>Idols:</h2>
|
||||
<ul>
|
||||
{% for idol in idols %}
|
||||
<li>{{ idol.romanized_name}} (<a href="/idols/{{ idol.id }}">View idol info</a>)</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<form>
|
||||
<form action="{{ request.path }}" method="GET">
|
||||
<div class="input-group mb-3">
|
||||
<input type="number" class="form-control" placeholder="Number of idols" aria-label="Number of idols"
|
||||
name="num">
|
||||
<button class="btn btn-outline-secondary" type="submit">Randomize song</button>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -4,4 +4,5 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('',views.index),
|
||||
path('randomizer',views.randomizer),
|
||||
]
|
||||
|
@ -1,5 +1,21 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
import random
|
||||
from songs.models import Song
|
||||
from idols.models import Idol
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
return render(request,"index.html")
|
||||
return render(request,"index.html")
|
||||
|
||||
def randomizer(request):
|
||||
obj = {}
|
||||
if "num" in request.GET:
|
||||
obj['num'] = request.GET['num']
|
||||
song_ids = list(Song.objects.values_list('pk',flat=True))
|
||||
song_id = random.choice(song_ids)
|
||||
obj['song'] = Song.objects.get(pk=song_id)
|
||||
idol_ids = list(Idol.objects.values_list('pk',flat=True))
|
||||
idol_selected_ids = random.sample(idol_ids,int(request.GET['num']))
|
||||
obj['idols'] = Idol.objects.filter(pk__in=idol_selected_ids)
|
||||
return render(request,"randomizer.html",obj)
|
Loading…
Reference in New Issue
Block a user