1
0
mirror of https://github.com/Damillora/Altessimo synced 2024-10-31 21:17:32 +00:00

Compare commits

..

No commits in common. "main" and "v0.1.1" have entirely different histories.
main ... v0.1.1

58 changed files with 98 additions and 968 deletions

3
.gitignore vendored
View File

@ -128,4 +128,5 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
/static/ altessimo/production.py
static/

View File

@ -1,18 +0,0 @@
FROM python:alpine
ADD requirements.txt /app/requirements.txt
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add --no-cache mariadb-dev jpeg-dev zlib-dev libpng-dev \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apk del build-deps
ADD . /app
WORKDIR /app
RUN python manage.py collectstatic
EXPOSE 8000
ENV DJANGO_SETTINGS_MODULE=altessimo.production
CMD ["gunicorn", "--bind", ":8000", "altessimo.wsgi"]

View File

@ -1,16 +0,0 @@
from altessimo.settings import *
import os
DEBUG = False
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('ALTESSIMO_DB_NAME'),
'USER': os.getenv('ALTESSIMO_DB_USER'),
'PASSWORD': os.getenv('ALTESSIMO_DB_PASS'),
'HOST': os.getenv('ALTESSIMO_DB_HOST'),
}
}
ALLOWED_HOSTS = [ os.getenv('ALTESSIMO_WEB_URL') ]

View File

@ -39,14 +39,12 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'categories', 'categories',
'artists', 'artists',
'idols',
'songs', 'songs',
'home', 'home',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',

View File

@ -21,6 +21,5 @@ urlpatterns = [
path('taxonomy/', include('categories.urls')), path('taxonomy/', include('categories.urls')),
path('artists/', include('artists.urls')), path('artists/', include('artists.urls')),
path('songs/', include('songs.urls')), path('songs/', include('songs.urls')),
path('idols/', include('idols.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]

View File

@ -1,54 +1,8 @@
from django.contrib import admin from django.contrib import admin
from django import forms from . import models
from .models import Artist
from categories.models import Category
# Register your models here. # Register your models here.
class ArtistForm(forms.ModelForm):
categories_str = forms.CharField(label='Category', required=False)
aliases_str = forms.CharField(label='Aliases', required=False)
class Meta:
model = Artist
fields = [
'name',
'romanized_name',
'slug',
'categories_str',
'aliases_str',
'about_artist',
'about_music',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['about_artist'].widget.attrs['class'] = 'tm-textfield'
self.fields['about_music'].widget.attrs['class'] = 'tm-textfield'
instance = kwargs.get("instance")
if instance:
self.fields['categories_str'].initial = ", ".join(x.name for x in instance.category.all() )
self.fields['aliases_str'].initial = ", ".join(x.romanized_name for x in instance.aliases.all() )
class ArtistAdmin(admin.ModelAdmin): class ArtistAdmin(admin.ModelAdmin):
form = ArtistForm
search_fields = ['romanized_name','name'] search_fields = ['romanized_name','name']
class Media: admin.site.register(models.Artist, ArtistAdmin)
js = (
'https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.6.2/tinymce.min.js',
'tinymce-init.js'
)
def save_model(self, request, obj, form, change):
categories_str = form.cleaned_data.get('categories_str')
categories = Category.objects.comma_to_qs(categories_str)
aliases_str = form.cleaned_data.get('aliases_str')
aliases = Artist.objects.comma_to_qs(aliases_str)
if not obj.id:
obj.save()
obj.category.clear()
obj.category.add(*categories)
obj.aliases.clear()
obj.aliases.add(*aliases)
obj.save()
admin.site.register(Artist, ArtistAdmin)

View File

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

View File

@ -1,31 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 17:06
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('artists', '0004_auto_20201216_1633'),
]
operations = [
migrations.CreateModel(
name='VoiceActor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Idol',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
('voice_actor', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='artists.voiceactor')),
],
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 17:20
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('songs', '0006_alter_song_idols'),
('artists', '0005_idol_voiceactor'),
]
operations = [
migrations.DeleteModel(
name='Idol',
),
migrations.DeleteModel(
name='VoiceActor',
),
]

View File

@ -1,18 +0,0 @@
# 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

@ -1,18 +0,0 @@
# Generated by Django 4.0.5 on 2022-06-24 14:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('artists', '0007_alter_artist_id'),
]
operations = [
migrations.AlterField(
model_name='artist',
name='aliases',
field=models.ManyToManyField(blank=True, to='artists.artist'),
),
]

View File

@ -4,15 +4,20 @@ from django.utils.text import slugify
# Create your models here. # Create your models here.
class ArtistManager(models.Manager): class ArtistManager(models.Manager):
def create_or_new(self, romanized_name):
romanized_name = romanized_name.strip()
qs = self.get_queryset().filter(romanized_name__iexact=romanized_name)
if qs.exists():
return qs.first(), False
return Artist.objects.create(romanized_name=romanized_name), True
def comma_to_qs(self, artists_str): def comma_to_qs(self, artists_str):
final_ids = [] final_ids = []
if artists_str: for artist in artists_str.split(','):
for artist in artists_str.split(','): obj, created = self.create_or_new(artist.strip())
obj, created = self.get_or_create(romanized_name=artist.strip()) final_ids.append(obj.id)
final_ids.append(obj.id) qs = self.get_queryset().filter(id__in=final_ids).distinct()
qs = self.get_queryset().filter(id__in=final_ids).distinct() return qs
return qs
return self.none()
class Artist(models.Model): class Artist(models.Model):
name = models.CharField(max_length=255,blank=True) name = models.CharField(max_length=255,blank=True)
@ -34,4 +39,3 @@ class Artist(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.slug = slugify(self.romanized_name) self.slug = slugify(self.romanized_name)
super().save(*args,**kwargs) super().save(*args,**kwargs)

View File

@ -4,24 +4,9 @@
{% block content %} {% block content %}
<h1>Artists</h1> <h1>Artists</h1>
<form action="{{ request.path }}" method="GET"> <ul>
<div class="input-group mb-3"> {% for artist in artists %}
<input type="text" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="search-button" name="q"> <li><a href="/artists/{{ artist.slug }}">{{ artist.romanized_name }}</a></li>
<button class="btn btn-outline-secondary" type="submit" id="search-button">Search</button> {% endfor %}
</div> </ul>
</form>
<table class="table">
<thead>
<th>Artist</th>
</thead>
<tbody>
{% for artist in artists %}
<tr>
<td>
<a href="/artists/{{ artist.slug }}">{{ artist.romanized_name }}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %} {% endblock %}

View File

@ -33,7 +33,7 @@
Alias Alias
</th> </th>
<td> <td>
<a href="/artists/{{ alias.slug }}">{{ alias.romanized_name }}</a> <a href="/artists/{{ alias.id }}">{{ alias.romanized_name }}</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -50,9 +50,9 @@
</tbody> </tbody>
</table> </table>
<h2>About Artist</h2> <h2>About Artist</h2>
<div>{{ artist.about_artist|safe }}</div> <p>{{ artist.about_artist }}</p>
<h2>About Music</h2> <h2>About Music</h2>
<div>{{ artist.about_music|safe }}</div> <p>{{ artist.about_music }}</p>
<h2>Credits</h2> <h2>Credits</h2>
{% include 'components/song-table.html' with songs=credit_songs %} {% include 'components/song-table.html' with songs=credit_songs %}
<h2>Sample works outside Idolmaster</h2> <h2>Sample works outside Idolmaster</h2>

View File

@ -4,30 +4,12 @@ from django.shortcuts import render
from .models import Artist from .models import Artist
from songs.models import OutsideSong from songs.models import OutsideSong
def artist_index(request): def artist_index(request):
artists = Artist.objects.all() artists = Artist.objects.all()
objs = {} return render(request,'artists/index.html',{'artists':artists})
if "q" in request.GET:
q = request.GET['q']
artists = Artist.objects.filter(
name__icontains=q) | Artist.objects.filter(romanized_name__icontains=q)
objs['q'] = q
objs['artists'] = artists
return render(request, 'artists/index.html', objs)
def artist_show(request, slug): def artist_show(request, slug):
artist = Artist.objects.filter(slug=slug)[0] artist = Artist.objects.filter(slug=slug)[0]
credit_songs = artist.written_songs.all( credit_songs = (artist.written_songs.all() | artist.composed_songs.all() | artist.arranged_songs.all()).distinct()
) | artist.composed_songs.all() | artist.arranged_songs.all()
aliases = artist.aliases.all()
outside_songs = OutsideSong.objects.filter(composer=artist) outside_songs = OutsideSong.objects.filter(composer=artist)
for alias in aliases: return render(request,'artists/show.html',{'artist': artist,'credit_songs':credit_songs,'outside_songs':outside_songs})
credit_songs = credit_songs | alias.written_songs.all(
) | artist.composed_songs.all() | artist.arranged_songs.all()
outside_songs = outside_songs | OutsideSong.objects.filter(
composer=alias)
credit_songs = credit_songs.distinct()
outside_songs = outside_songs.distinct()
return render(request, 'artists/show.html', {'artist': artist, 'credit_songs': credit_songs, 'outside_songs': outside_songs})

View File

@ -1,47 +1,13 @@
from django.contrib import admin from django.contrib import admin
from django import forms
from .models import Branch, Category from . import models
# Register your models here. # Register your models here.
class BranchForm(forms.ModelForm):
class Meta:
model = Branch
exclude = []
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['description'].widget.attrs['class'] = 'tm-textfield'
class CategoryForm(forms.ModelForm):
class Meta:
model = Category
exclude = []
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['description'].widget.attrs['class'] = 'tm-textfield'
class BranchAdmin(admin.ModelAdmin): class BranchAdmin(admin.ModelAdmin):
form = BranchForm
search_fields = ['name', 'acronym'] search_fields = ['name', 'acronym']
class Media:
js = (
'https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.6.2/tinymce.min.js',
'tinymce-init.js'
)
class CategoryAdmin(admin.ModelAdmin): class CategoryAdmin(admin.ModelAdmin):
form = CategoryForm
search_fields = ['name'] search_fields = ['name']
class Media: admin.site.register(models.Branch, BranchAdmin)
js = ( admin.site.register(models.Category,CategoryAdmin)
'https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.6.2/tinymce.min.js',
'tinymce-init.js'
)
admin.site.register(Branch, BranchAdmin)
admin.site.register(Category,CategoryAdmin)

View File

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

View File

@ -1,23 +0,0 @@
# 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

@ -12,15 +12,20 @@ class Branch(models.Model):
# Create your models here. # Create your models here.
class CategoryManager(models.Manager): class CategoryManager(models.Manager):
def comma_to_qs(self, categories_str): def create_or_new(self, name):
name = name.strip()
qs = self.get_queryset().filter(name__iexact=name)
if qs.exists():
return qs.first(), False
return Category.objects.create(name=name), True
def comma_to_qs(self, categorys_str):
final_ids = [] final_ids = []
if categories_str: for category in categories_str.split(','):
for category in categories_str.split(','): obj, created = self.create_or_new(category)
obj, created = self.get_or_create(name=category.strip()) final_ids.append(obj.id)
final_ids.append(obj.id) qs = self.get_queryset().filter(id__in=final_ids).distinct()
qs = self.get_queryset().filter(id__in=final_ids).distinct() return qs
return qs
return self.none()
class Category(models.Model): class Category(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)

View File

@ -1,69 +0,0 @@
.song-row a {
text-decoration: none;
}
.song-row a:hover {
text-decoration: underline;
}
.branch-765 {
background-color: #ffcdd2;
color: #c62828;
}
.branch-765 a {
color: #c62828;
}
.branch-346 {
background-color: #64b5f6;
color: #0d47a1;
}
.branch-346 a {
color: #0d47a1;
}
.branch-765ML {
background-color: #f9a825;
color: #6d4c41;
}
.branch-765ML a {
color: #6d4c41;
}
.branch-315 {
background-color: #a5d6a7;
color: #1b5e20;
}
.branch-315 a {
color: #1b5e20;
}
.branch-283 {
background-color: #bbdefb;
color: #1976d2;
}
.branch-283 a {
color: #1976d2;
}
.branch-876 {
background-color: #d1c4e9;
color:#512da8;
}
.branch-876 a {
color:#512da8;
}
.branch-961 {
background-color: #f0f4c3;
color: #827717;
}
.branch-961 a {
color: #827717;
}
.branch-5STARS {
background-color: #d81b60;
color: #fce4ec;
}
.branch-5STARS a {
color: #fce4ec;
}
.branch-POP {
background-color: #1663cd;
color: #e8eaf6;
}
.branch-POP a {
color: #e8eaf6;
}

View File

@ -3,18 +3,24 @@
{% block title %}Branches{% endblock %} {% block title %}Branches{% endblock %}
{% block content %} {% block content %}
<h1>Branches</h1> <h1>Branches</h1>
{% for branch in branches %} <table class="table">
<div class="row song-row branch-{{ branch.acronym }}"> <thead>
<div class="col col-md-3"> <th>Acronym</th>
{% if branch.logo %} <th>Logo</th>
<img src="{{ branch.logo.url }}" class="img-fluid"> <th>Name</th>
{% endif %} </thead>
</div> <tbody>
<div class="col col-md-9"> {% for branch in branches %}
<div class="row h-100 align-items-center"> <tr>
<p class="h2"><a href="/taxonomy/branches/{{ branch.acronym }}">{{ branch.name }} [{{ branch.acronym }}]</a></p> <td>{{ branch.acronym }}</td>
</div> <td>
</div> {% if branch.logo %}
</div> <img src="{{ branch.logo.path }}" width=24>
{% endfor %} {% endif %}
</td>
<td><a href="/taxonomy/branches/{{ branch.acronym }}">{{ branch.name }} [{{ branch.acronym }}]</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %} {% endblock %}

View File

@ -3,20 +3,7 @@
{% block content %} {% block content %}
<h1>[{{ branch.acronym }}] {{ branch.name }}</h1> <h1>[{{ branch.acronym }}] {{ branch.name }}</h1>
<h2>Description</h2> <h2>Description</h2>
<div>{{ branch.description|safe }}</div> <p>{{ branch.description }}</p>
<h2>Songs</h2> <h2>Songs</h2>
{% include 'components/song-table.html' with songs=page_obj %} {% include 'components/song-table.html' with songs=songs %}
<nav aria-label="Pages">
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page=1">First</a></li>
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a></li>
{% endif %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.number }}">{{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</a></li>
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a></li>
<li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">Last</a></li>
{% endif %}
</ul>
</nav>
{% endblock %} {% endblock %}

View File

@ -5,7 +5,7 @@
{% block content %} {% block content %}
<h1>Category: {{ category.name }}</h1> <h1>Category: {{ category.name }}</h1>
<h2>Description</h2> <h2>Description</h2>
<div>{{ category.description|safe }}</div> <p>{{ category.description }}</p>
<h2>Artists</h2> <h2>Artists</h2>
<ul> <ul>
{% for artist in category.artist_set.all %} {% for artist in category.artist_set.all %}

View File

@ -1,4 +1,3 @@
from django.core.paginator import Paginator
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Branch, Category from .models import Branch, Category
@ -21,7 +20,4 @@ def branch_index(request):
def branch_show(request, acronym): def branch_show(request, acronym):
branch = Branch.objects.filter(acronym=acronym)[0] branch = Branch.objects.filter(acronym=acronym)[0]
songs = Song.objects.filter(branch=branch) songs = Song.objects.filter(branch=branch)
paginator = Paginator(songs, 100) return render(request,"branches/show.html",{'branch':branch,'songs':songs})
page_number = request.GET.get('page',1)
page_obj = paginator.get_page(page_number)
return render(request,"branches/show.html",{'branch':branch,'page_obj':page_obj})

View File

@ -1,6 +0,0 @@
tinymce.init({
selector: '.tm-textfield', // change this value according to your HTML
menubar: false,
plugins: 'advlist lists link',
toolbar: 'undo redo | styleselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | link',
});

View File

@ -1,20 +1,15 @@
{% extends 'layouts/base.html' %} {% extends 'layouts/base.html' %}
{% block content %} {% block content %}
<h1>Welcome!</h1> <h1>Welcome!</h1>
<p>This site is a work-in-progress database of Idolmaster songs, composers, arrangers, and lyricists.</p> <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 <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>
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>
<p>This site originated from a spreadsheet I maintained to note the composers' works and their similarities. </p> <h2>Current to-do</h2>
<h2>Current to-do</h2> <ul>
<ul> <li>Complete lyricist credits</li>
<li>Complete lyricist credits</li> <li>Add songs from IDOLM@STER Radio</li>
<li>Add songs from IDOLM@STER Radio</li> <li>Re-add other songs that I might have missed</li>
<li>Re-add other songs that I might have missed</li> <li>Complete showcases of composers</li>
<li>Complete showcases of composers</li> </ul>
</ul>
<h2>Mildly interesting</h2>
<ul>
<li><a href="/randomizer">A song randomizer</a></li>
</ul>
{% endblock %} {% endblock %}

View File

@ -1,61 +0,0 @@
{% 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 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 %}
<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 %}
</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>
</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 %}

View File

@ -4,5 +4,4 @@ from . import views
urlpatterns = [ urlpatterns = [
path('',views.index), path('',views.index),
path('randomizer',views.randomizer),
] ]

View File

@ -1,27 +1,5 @@
from django.shortcuts import render from django.shortcuts import render
import random
from songs.models import Song
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):
obj = {}
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)
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)

View File

View File

@ -1,6 +0,0 @@
from idols.models import Idol
from django.contrib import admin
# Register your models here.
admin.site.register(Idol)

View File

@ -1,6 +0,0 @@
from django.apps import AppConfig
class IdolsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'idols'

View File

@ -1,32 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 17:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='VoiceActor',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Idol',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
('voice_actor', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='idols.voiceactor')),
],
),
]

View File

@ -1,27 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 17:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('idols', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='idol',
name='voice_actor',
),
migrations.AddField(
model_name='idol',
name='romanized_voice_actor_name',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='idol',
name='voice_actor_name',
field=models.CharField(blank=True, max_length=255),
),
]

View File

@ -1,24 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 18:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('categories', '0009_auto_20201216_1732'),
('idols', '0002_auto_20210709_1733'),
]
operations = [
migrations.DeleteModel(
name='VoiceActor',
),
migrations.AddField(
model_name='idol',
name='branch',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='categories.branch'),
preserve_default=False,
),
]

View File

@ -1,17 +0,0 @@
# 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

@ -1,33 +0,0 @@
from django.db import models
# Create your models here.
# Create your models here.
class IdolManager(models.Manager):
def comma_to_qs(self, idols_str):
final_ids = []
if idols_str:
for idol in idols_str.split(','):
obj, created = self.get_or_create(romanized_name=idol.strip())
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
return self.none()
class Idol(models.Model):
branch = models.ForeignKey("categories.Branch", on_delete=models.PROTECT)
name = models.CharField(max_length=255, blank=True)
romanized_name = models.CharField(max_length=255)
voice_actor_name = models.CharField(max_length=255, blank=True)
romanized_voice_actor_name = models.CharField(max_length=255, blank=True)
objects = IdolManager()
class Meta:
ordering = [ 'romanized_name','name' ]
def __str__(self):
return self.romanized_name+" "+"["+self.branch.acronym+"] "+" (CV: "+self.romanized_voice_actor_name+")"

View File

@ -1,27 +0,0 @@
{% extends 'layouts/base.html' %}
{% block title %} Idols {% endblock %}
{% block content %}
<h1>Idols</h1>
<form action="{{ request.path }}" method="GET">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="search-button" name="q">
<button class="btn btn-outline-secondary" type="submit" id="search-button">Search</button>
</div>
</form>
<table class="table">
<thead>
<th>Idol</th>
</thead>
<tbody>
{% for idol in idols %}
<tr>
<td>
<a href="/idols/{{ idol.slug }}">{{ idol.romanized_name }}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -1,52 +0,0 @@
{% extends 'layouts/base.html' %}
{% block title %} Idol: {{ idol.romanized_name }} {% endblock %}
{% block content %}
<h1>Idol: {{ idol.romanized_name }}</h1>
<h2>Metadata</h2>
<table class="table">
<tbody>
{% if idol.name %}
<tr>
<th scope="row">
Name
</th>
<td>
{{ idol.name }}
</td>
</tr>
{% endif %}
{% if idol.romanized_name %}
<tr>
<th scope="row">
Romanized Name
</th>
<td>
{{ idol.romanized_name }}
</td>
</tr>
{% endif %}
{% if idol.voice_actor_name %}
<tr>
<th scope="row">
Voice Actor Name
</th>
<td>
{{ idol.voice_actor_name }}
</td>
</tr>
{% endif %}
{% if idol.romanized_voice_actor_name %}
<tr>
<th scope="row">
Romanized Voice Actor Name
</th>
<td>
{{ idol.romanized_voice_actor_name }}
</td>
</tr>
{% endif %}
</tbody>
</table>
{% endblock %}

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,8 +0,0 @@
from django.urls import path
from . import views
urlpatterns = [
path('',views.idol_index),
path('<int:id>',views.idol_show)
]

View File

@ -1,19 +0,0 @@
from idols.models import Idol
from django.shortcuts import render
# Create your views here.
def idol_index(request):
idols = Idol.objects.all()
objs = {}
if "q" in request.GET:
q = request.GET['q']
idols = Idol.objects.filter(name__icontains=q) | Idol.objects.filter(
romanized_name__icontains=q)
objs['q'] = q
objs['idols'] = idols
return render(request, 'idols/index.html', objs)
def idol_show(request, id):
idol = Idol.objects.filter(id=id)[0]
return render(request, 'idols/show.html', {'idol': idol})

View File

@ -1,5 +0,0 @@
Django>=4.0,<5.0
mysqlclient
gunicorn
whitenoise
Pillow

View File

@ -1,2 +0,0 @@
User-Agent: *
Disallow: /

View File

@ -1,80 +1,13 @@
from django import forms
from django.contrib import admin from django.contrib import admin
from .models import Song, OutsideSong from . import models
from artists.models import Artist
from idols.models import Idol
class SongForm(forms.ModelForm):
lyricist_str = forms.CharField(label='Lyricists', required=False)
composer_str = forms.CharField(label='Composers', required=False)
arranger_str = forms.CharField(label='Arrangers', required=False)
idols_str = forms.CharField(label='Idols', required=False)
class Meta:
model = Song
fields = [
'branch',
'title',
'romanized_title',
'lyricist_str',
'composer_str',
'arranger_str',
'idols_str',
'impression',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['impression'].widget.attrs['class'] = 'tm-textfield'
instance = kwargs.get("instance")
if instance:
self.fields['lyricist_str'].initial = ', '.join(
x.romanized_name for x in instance.lyricist.all())
self.fields['composer_str'].initial = ', '.join(
x.romanized_name for x in instance.composer.all())
self.fields['arranger_str'].initial = ', '.join(
x.romanized_name for x in instance.arranger.all())
self.fields['idols_str'].initial = ', '.join(
x.romanized_name for x in instance.idols.all())
class SongAdmin(admin.ModelAdmin): class SongAdmin(admin.ModelAdmin):
form = SongForm search_fields = ['romanized_title','title']
search_fields = ['romanized_title', 'title']
class Media:
js = (
'https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.6.2/tinymce.min.js',
'tinymce-init.js'
)
def save_model(self, request, obj, form, change):
lyricist_str = form.cleaned_data.get('lyricist_str')
composer_str = form.cleaned_data.get('composer_str')
arranger_str = form.cleaned_data.get('arranger_str')
idols_str = form.cleaned_data.get('idols_str')
lyricist = Artist.objects.comma_to_qs(lyricist_str)
composer = Artist.objects.comma_to_qs(composer_str)
arranger = Artist.objects.comma_to_qs(arranger_str)
idols = Idol.objects.comma_to_qs(idols_str)
if not obj.id:
obj.save()
obj.lyricist.clear()
obj.lyricist.add(*lyricist)
obj.composer.clear()
obj.composer.add(*composer)
obj.arranger.clear()
obj.arranger.add(*arranger)
obj.idols.clear()
obj.idols.add(*idols)
obj.save()
class OutsideSongAdmin(admin.ModelAdmin): class OutsideSongAdmin(admin.ModelAdmin):
search_fields = ['title'] search_fields = ['title']
admin.site.register(models.Song, SongAdmin)
admin.site.register(Song, SongAdmin) admin.site.register(models.OutsideSong, OutsideSongAdmin)
admin.site.register(OutsideSong, OutsideSongAdmin)

View File

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

View File

@ -1,23 +0,0 @@
# Generated by Django 3.1.4 on 2020-12-16 19:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('songs', '0002_auto_20201216_1622'),
]
operations = [
migrations.AlterField(
model_name='song',
name='romanized_title',
field=models.CharField(blank=True, max_length=255),
),
migrations.AlterField(
model_name='song',
name='title',
field=models.CharField(max_length=255),
),
]

View File

@ -1,17 +0,0 @@
# Generated by Django 3.1.4 on 2020-12-17 08:12
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('songs', '0003_auto_20201216_1925'),
]
operations = [
migrations.AlterModelOptions(
name='song',
options={'ordering': ['-branch__acronym', 'romanized_title', 'title']},
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 17:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('artists', '0005_idol_voiceactor'),
('songs', '0004_auto_20201217_0812'),
]
operations = [
migrations.AddField(
model_name='song',
name='idols',
field=models.ManyToManyField(blank=True, related_name='idol_songs', to='artists.Idol'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.2.5 on 2021-07-09 17:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('idols', '0001_initial'),
('songs', '0005_song_idols'),
]
operations = [
migrations.AlterField(
model_name='song',
name='idols',
field=models.ManyToManyField(blank=True, related_name='idol_songs', to='idols.Idol'),
),
]

View File

@ -1,23 +0,0 @@
# 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'),
),
]

View File

@ -4,16 +4,15 @@ from django.db import models
# Create your models here. # Create your models here.
class Song(models.Model): class Song(models.Model):
branch = models.ForeignKey("categories.Branch", on_delete=models.PROTECT) branch = models.ForeignKey("categories.Branch", on_delete=models.PROTECT)
title = models.CharField(max_length=255) title = models.CharField(max_length=255,blank=True)
romanized_title = models.CharField(max_length=255,blank=True) romanized_title = models.CharField(max_length=255)
lyricist = models.ManyToManyField("artists.Artist", blank=True, related_name="written_songs") lyricist = models.ManyToManyField("artists.Artist", blank=True, related_name="written_songs")
composer = models.ManyToManyField("artists.Artist", blank=True, related_name="composed_songs") composer = models.ManyToManyField("artists.Artist", blank=True, related_name="composed_songs")
arranger = models.ManyToManyField("artists.Artist", blank=True, related_name="arranged_songs") arranger = models.ManyToManyField("artists.Artist", blank=True, related_name="arranged_songs")
idols = models.ManyToManyField("idols.Idol",blank=True,related_name="idol_songs")
impression = models.TextField(blank=True) impression = models.TextField(blank=True)
class Meta: class Meta:
ordering = [ '-branch__acronym','romanized_title','title' ] ordering = [ 'romanized_title','title' ]
def __str__(self): def __str__(self):
return "["+self.branch.acronym+"] "+self.title return "["+self.branch.acronym+"] "+self.title

View File

@ -4,12 +4,6 @@
{% block content %} {% block content %}
<h1>Songs</h1> <h1>Songs</h1>
<form action="{{ request.path }}" method="GET">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="search-button" name="q">
<button class="btn btn-outline-secondary" type="submit" id="search-button">Search</button>
</div>
</form>
{% include 'components/song-table.html' with songs=page_obj %} {% include 'components/song-table.html' with songs=page_obj %}
<nav aria-label="Pages"> <nav aria-label="Pages">
<ul class="pagination"> <ul class="pagination">

View File

@ -8,7 +8,7 @@
<table class="table"> <table class="table">
<tbody> <tbody>
{% if song.branch %} {% if song.branch %}
<tr class="song-row branch-{{ song.branch.acronym }}"> <tr>
<th scope="row">Branch</th> <th scope="row">Branch</th>
<td><a href="/taxonomy/branches/{{ song.branch.acronym }}">[{{ song.branch.acronym }}] {{ song.branch.name }}</a></td> <td><a href="/taxonomy/branches/{{ song.branch.acronym }}">[{{ song.branch.acronym }}] {{ song.branch.name }}</a></td>
</tr> </tr>
@ -46,5 +46,5 @@
</tbody> </tbody>
</table> </table>
<h2>Impression</h2> <h2>Impression</h2>
<div>{{ song.impression|safe }}</div> <p>{{ song.impression }}</p>
{% endblock %} {% endblock %}

View File

@ -5,21 +5,15 @@ from .models import Song
# Create your views here. # Create your views here.
def song_index(request): def song_index(request):
songs = Song.objects.all() songs = Song.objects.all()
objs = {}
if "q" in request.GET:
q = request.GET['q']
songs = Song.objects.filter(title__icontains=q) | Song.objects.filter(romanized_title__icontains=q)
objs['q'] = q
paginator = Paginator(songs, 100) paginator = Paginator(songs, 100)
page_number = request.GET.get('page',1) page_number = request.GET.get('page',1)
page_obj = paginator.get_page(page_number) page_obj = paginator.get_page(page_number)
objs['page_obj'] = page_obj return render(request,'songs/index.html',{'page_obj':page_obj})
return render(request,'songs/index.html',objs)
def song_id(request, id): def song_id(request, id):
song = Song.objects.filter(id=id)[0] song = Song.objects.filter(id=id)[0]
return redirect(song_show,id=song.id,title=song.title) return redirect(song_show,id=song.id,title=song.title)
def song_show(request, id, title): def song_show(request, id, title):
song = Song.objects.filter(id=id)[0] song = Song.objects.filter(id=id,title=title)[0]
return render(request,'songs/show.html',{'song':song}) return render(request,'songs/show.html',{'song':song})

View File

@ -8,9 +8,15 @@
</thead> </thead>
<tbody> <tbody>
{% for song in songs %} {% for song in songs %}
<tr class="song-row branch-{{ song.branch.acronym }}"> <tr>
<td> <td>
{% if song.branch.logo %}
<a href="/taxonomy/branches/{{ song.branch.acronym }}">
<img src="{{ song.branch.logo.url }}" width=24>
</a>
{% else %}
<a href="/taxonomy/branches/{{ song.branch.acronym }}">{{ song.branch.acronym }}</a> <a href="/taxonomy/branches/{{ song.branch.acronym }}">{{ song.branch.acronym }}</a>
{% endif %}
</td> </td>
<td> <td>
<a href="/songs/{{ song.id }}/{{ song.title }}">{{ song.title }}</a> <a href="/songs/{{ song.id }}/{{ song.title }}">{{ song.title }}</a>

View File

@ -1,5 +1,3 @@
{% load static %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -11,7 +9,6 @@
</title> </title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link href="{% static 'branches.css' %}" rel="stylesheet">
</head> </head>
<body> <body>
@ -30,9 +27,6 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/songs">Songs</a> <a class="nav-link" href="/songs">Songs</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="/idols">Idols</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/artists">Artists</a> <a class="nav-link" href="/artists">Artists</a>
</li> </li>