mirror of
https://github.com/Damillora/Altessimo
synced 2024-11-23 06:07:32 +00:00
Rework randomizer interface
This commit is contained in:
parent
4119eb63de
commit
01d2c14e27
@ -2,4 +2,5 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class ArtistsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'artists'
|
||||
|
18
artists/migrations/0007_alter_artist_id.py
Normal file
18
artists/migrations/0007_alter_artist_id.py
Normal 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'),
|
||||
),
|
||||
]
|
@ -2,4 +2,5 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class CategoriesConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'categories'
|
||||
|
23
categories/migrations/0010_auto_20210710_0700.py
Normal file
23
categories/migrations/0010_auto_20210710_0700.py
Normal 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'),
|
||||
),
|
||||
]
|
@ -4,29 +4,58 @@
|
||||
<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>
|
||||
|
||||
{% if song %}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Branch</th>
|
||||
<th>Song</th>
|
||||
</tr>
|
||||
<tr class="song-row branch-{{ song.branch.acronym }}">
|
||||
<td class="col-1">
|
||||
<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 %}
|
||||
<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 %}
|
||||
</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">
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if song is None and idols is None %}
|
||||
<form action="{{ request.path }}" method="GET">
|
||||
<button class="btn btn-outline-secondary" type="submit">Randomize song</button>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
{% 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 %}
|
@ -5,17 +5,23 @@ 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))
|
||||
if "song_id" in request.GET:
|
||||
obj['song'] = Song.objects.get(pk=request.GET['song_id'])
|
||||
else:
|
||||
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']))
|
||||
if "num" in request.GET:
|
||||
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)
|
||||
return render(request,"randomizer.html",obj)
|
||||
return render(request, "randomizer.html", obj)
|
||||
|
17
idols/migrations/0004_alter_idol_options.py
Normal file
17
idols/migrations/0004_alter_idol_options.py
Normal 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']},
|
||||
),
|
||||
]
|
@ -2,4 +2,5 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class SongsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'songs'
|
||||
|
23
songs/migrations/0007_auto_20210710_0700.py
Normal file
23
songs/migrations/0007_auto_20210710_0700.py
Normal 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'),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue
Block a user