1
0
mirror of https://github.com/Damillora/Altessimo synced 2024-11-23 06:07:32 +00:00

Rework randomizer interface

This commit is contained in:
Damillora 2021-07-10 20:41:17 +07:00
parent 4119eb63de
commit 01d2c14e27
9 changed files with 147 additions and 28 deletions

View File

@ -2,4 +2,5 @@ from django.apps import AppConfig
class ArtistsConfig(AppConfig): class ArtistsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'artists' name = 'artists'

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2021-07-10 07:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('artists', '0006_auto_20210709_1720'),
]
operations = [
migrations.AlterField(
model_name='artist',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]

View File

@ -2,4 +2,5 @@ from django.apps import AppConfig
class CategoriesConfig(AppConfig): class CategoriesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'categories' name = 'categories'

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.5 on 2021-07-10 07:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('categories', '0009_auto_20201216_1732'),
]
operations = [
migrations.AlterField(
model_name='branch',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='category',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]

View File

@ -4,29 +4,58 @@
<h1>Song Randomizer</h1> <h1>Song Randomizer</h1>
<p>A simple song randomizer. </p> <p>A simple song randomizer. </p>
<p><strong>WARNING: Very experimental. Implementation is not very smart yet.</strong></p> <p><strong>WARNING: Very experimental. Implementation is not very smart yet.</strong></p>
{% if num %}
<p>Song choice</p> {% if song %}
<h2> <table class="table">
{{ song.title }} <tr>
</h2> <th>Branch</th>
<p> <th>Song</th>
<a href="/songs/{{ song.id }}/{{ song.title }}">View song info</a> </tr>
</p> <tr class="song-row branch-{{ song.branch.acronym }}">
<h2>Idols:</h2> <td class="col-1">
<ul> <a href="/taxonomy/branches/{{ song.branch.acronym }}">{{ song.branch.acronym }}</a>
</td>
<td>
<a href="/songs/{{ song.id }}/{{ song.title }}">{{ song.title }}</a>
</td>
</tr>
</table>
{% endif %}
{% if idols %}
<table class="table">
<tr>
<th>Branch</th>
<th>Idol</th>
</tr>
{% for idol in idols %} {% for idol in idols %}
<li>{{ idol.romanized_name}} (<a href="/idols/{{ idol.id }}">View idol info</a>)</li> <tr class="song-row branch-{{ idol.branch.acronym }}">
<td class="col-1">
<a href="/taxonomy/branches/{{ idol.branch.acronym }}">{{ idol.branch.acronym }}</a>
</td>
<td><a href="/idols/{{ idol.id }}">{{ idol.romanized_name}}</a></td>
</tr>
{% endfor %} {% endfor %}
</ul> </table>
{% else %} {% endif %}
<form> {% if song is None and idols is None %}
<form action="{{ request.path }}" method="GET"> <form action="{{ request.path }}" method="GET">
<div class="input-group mb-3"> <button class="btn btn-outline-secondary" type="submit">Randomize song</button>
<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> </form>
{% endif %} {% endif %}
{% if song and idols is None%}
<form action="{{ request.path }}" method="GET">
<div class="input-group mb-3">
<input type="hidden" name="song_id" value="{{ song.id }}">
<input type="number" class="form-control" placeholder="Number of idols" aria-label="Number of idols"
value="{{ num }}" name="num">
<button class="btn btn-outline-secondary" type="submit">Randomize idols</button>
</div>
</form>
{% endif %}
<form action="{{ request.path }}" method="GET">
<div class="input mb-3">
<button class="btn btn-outline-secondary" type="submit">Randomize song again</button>
</div>
</form>
{% endblock %} {% endblock %}

View File

@ -5,17 +5,23 @@ from songs.models import Song
from idols.models import Idol from idols.models import Idol
# Create your views here. # Create your views here.
def index(request): def index(request):
return render(request,"index.html") return render(request, "index.html")
def randomizer(request): def randomizer(request):
obj = {} obj = {}
if "num" in request.GET: if "song_id" in request.GET:
obj['num'] = request.GET['num'] obj['song'] = Song.objects.get(pk=request.GET['song_id'])
song_ids = list(Song.objects.values_list('pk',flat=True)) else:
song_ids = list(Song.objects.values_list('pk', flat=True))
song_id = random.choice(song_ids) song_id = random.choice(song_ids)
obj['song'] = Song.objects.get(pk=song_id) obj['song'] = Song.objects.get(pk=song_id)
idol_ids = list(Idol.objects.values_list('pk',flat=True)) if "num" in request.GET:
idol_selected_ids = random.sample(idol_ids,int(request.GET['num'])) obj['num'] = request.GET['num']
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) obj['idols'] = Idol.objects.filter(pk__in=idol_selected_ids)
return render(request,"randomizer.html",obj) return render(request, "randomizer.html", obj)

View File

@ -0,0 +1,17 @@
# Generated by Django 3.2.5 on 2021-07-10 07:00
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('idols', '0003_auto_20210709_1803'),
]
operations = [
migrations.AlterModelOptions(
name='idol',
options={'ordering': ['romanized_name', 'name']},
),
]

View File

@ -2,4 +2,5 @@ from django.apps import AppConfig
class SongsConfig(AppConfig): class SongsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'songs' name = 'songs'

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.5 on 2021-07-10 07:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('songs', '0006_alter_song_idols'),
]
operations = [
migrations.AlterField(
model_name='outsidesong',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='song',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]