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

Compare commits

...

22 Commits
v0.1.1 ... main

Author SHA1 Message Date
6474253b09 Upgrade Django 2022-06-24 21:09:12 +07:00
01d2c14e27 Rework randomizer interface 2021-07-10 20:41:17 +07:00
4119eb63de Add randomizer 2021-07-10 02:51:55 +07:00
caf7886567 Add idol layout to frontend 2021-07-10 01:48:51 +07:00
4c618458c3 More Dockerfile update 2021-07-10 01:36:21 +07:00
f02f7b826a Add idol listing 2021-07-10 01:25:07 +07:00
b48045956c Modify Dockerfile 2021-06-08 21:23:19 +07:00
661d57ab56 Add initial Dockerfile 2021-06-08 21:20:26 +07:00
c086f10b3c Add robots 2021-06-08 15:23:30 +02:00
c75f64766a Only filter by id when query by title 2021-01-09 14:30:51 +01:00
ed4c2065b6 Case insensitive search 2020-12-17 22:59:22 +07:00
0ed9d7b1d5 Add search to where it matters 2020-12-17 22:48:07 +07:00
986d0ee869 manohoops 2020-12-17 20:27:03 +07:00
2cc9a7bd31 Do not add blank string artists and categories if comma-separated string is empty 2020-12-17 20:23:55 +07:00
c184dc3534 Make aliases field optional 2020-12-17 19:32:12 +07:00
56a3460160 Add TinyMCE for admin 2020-12-17 19:21:43 +07:00
5205dab431 Change ordering 2020-12-17 15:12:26 +07:00
6b9b0d1458 Sort by what is used to be on the sheet 2020-12-17 14:21:11 +07:00
6577d008b9 Add static 2020-12-17 14:16:15 +07:00
b1f9605fab Add colors and alias handling 2020-12-17 14:12:26 +07:00
ee8f443e5d Revise migrations 2020-12-17 02:25:33 +07:00
e4958148b1 Add pagination to branches 2020-12-17 01:02:21 +07:00
58 changed files with 968 additions and 98 deletions

3
.gitignore vendored
View File

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

18
Dockerfile Normal file
View File

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

16
altessimo/production.py Normal file
View File

@ -0,0 +1,16 @@
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,12 +39,14 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'categories',
'artists',
'idols',
'songs',
'home',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',

View File

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

View File

@ -1,8 +1,54 @@
from django.contrib import admin
from . import models
from django import forms
from .models import Artist
from categories.models import Category
# 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):
form = ArtistForm
search_fields = ['romanized_name','name']
admin.site.register(models.Artist, ArtistAdmin)
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):
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,4 +2,5 @@ from django.apps import AppConfig
class ArtistsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'artists'

View File

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

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

@ -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

@ -0,0 +1,18 @@
# 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,20 +4,15 @@ from django.utils.text import slugify
# Create your models here.
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):
final_ids = []
for artist in artists_str.split(','):
obj, created = self.create_or_new(artist.strip())
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
if artists_str:
for artist in artists_str.split(','):
obj, created = self.get_or_create(romanized_name=artist.strip())
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
return self.none()
class Artist(models.Model):
name = models.CharField(max_length=255,blank=True)
@ -39,3 +34,4 @@ class Artist(models.Model):
def save(self, *args, **kwargs):
self.slug = slugify(self.romanized_name)
super().save(*args,**kwargs)

View File

@ -4,9 +4,24 @@
{% block content %}
<h1>Artists</h1>
<ul>
{% for artist in artists %}
<li><a href="/artists/{{ artist.slug }}">{{ artist.romanized_name }}</a></li>
{% endfor %}
</ul>
<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>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 %}

View File

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

View File

@ -4,12 +4,30 @@ from django.shortcuts import render
from .models import Artist
from songs.models import OutsideSong
def artist_index(request):
artists = Artist.objects.all()
return render(request,'artists/index.html',{'artists':artists})
objs = {}
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):
artist = Artist.objects.filter(slug=slug)[0]
credit_songs = (artist.written_songs.all() | artist.composed_songs.all() | artist.arranged_songs.all()).distinct()
credit_songs = artist.written_songs.all(
) | artist.composed_songs.all() | artist.arranged_songs.all()
aliases = artist.aliases.all()
outside_songs = OutsideSong.objects.filter(composer=artist)
return render(request,'artists/show.html',{'artist': artist,'credit_songs':credit_songs,'outside_songs':outside_songs})
for alias in aliases:
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,13 +1,47 @@
from django.contrib import admin
from django import forms
from . import models
from .models import Branch, Category
# 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):
form = BranchForm
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):
form = CategoryForm
search_fields = ['name']
admin.site.register(models.Branch, BranchAdmin)
admin.site.register(models.Category,CategoryAdmin)
class Media:
js = (
'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,4 +2,5 @@ from django.apps import AppConfig
class CategoriesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
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

@ -12,20 +12,15 @@ class Branch(models.Model):
# Create your models here.
class CategoryManager(models.Manager):
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):
def comma_to_qs(self, categories_str):
final_ids = []
for category in categories_str.split(','):
obj, created = self.create_or_new(category)
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
if categories_str:
for category in categories_str.split(','):
obj, created = self.get_or_create(name=category.strip())
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
return self.none()
class Category(models.Model):
name = models.CharField(max_length=255)

View File

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

View File

@ -3,7 +3,20 @@
{% block content %}
<h1>[{{ branch.acronym }}] {{ branch.name }}</h1>
<h2>Description</h2>
<p>{{ branch.description }}</p>
<div>{{ branch.description|safe }}</div>
<h2>Songs</h2>
{% include 'components/song-table.html' with songs=songs %}
{% include 'components/song-table.html' with songs=page_obj %}
<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 %}

View File

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

View File

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

@ -0,0 +1,6 @@
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,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 %}

View File

@ -0,0 +1,61 @@
{% 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,4 +4,5 @@ from . import views
urlpatterns = [
path('',views.index),
path('randomizer',views.randomizer),
]

View File

@ -1,5 +1,27 @@
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 "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)

0
idols/__init__.py Normal file
View File

6
idols/admin.py Normal file
View File

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

6
idols/apps.py Normal file
View File

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

View File

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

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

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

@ -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

33
idols/models.py Normal file
View File

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

@ -0,0 +1,27 @@
{% 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

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

3
idols/tests.py Normal file
View File

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

8
idols/urls.py Normal file
View File

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

19
idols/views.py Normal file
View File

@ -0,0 +1,19 @@
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})

5
requirements.txt Normal file
View File

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

2
robots.txt Normal file
View File

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

View File

@ -1,13 +1,80 @@
from django import forms
from django.contrib import admin
from . import models
from .models import Song, OutsideSong
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):
search_fields = ['romanized_title','title']
form = SongForm
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):
search_fields = ['title']
admin.site.register(models.Song, SongAdmin)
admin.site.register(models.OutsideSong, OutsideSongAdmin)
admin.site.register(Song, SongAdmin)
admin.site.register(OutsideSong, OutsideSongAdmin)

View File

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

View File

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

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

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

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

@ -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'),
),
]

View File

@ -4,15 +4,16 @@ from django.db import models
# Create your models here.
class Song(models.Model):
branch = models.ForeignKey("categories.Branch", on_delete=models.PROTECT)
title = models.CharField(max_length=255,blank=True)
romanized_title = models.CharField(max_length=255)
title = models.CharField(max_length=255)
romanized_title = models.CharField(max_length=255,blank=True)
lyricist = models.ManyToManyField("artists.Artist", blank=True, related_name="written_songs")
composer = models.ManyToManyField("artists.Artist", blank=True, related_name="composed_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)
class Meta:
ordering = [ 'romanized_title','title' ]
ordering = [ '-branch__acronym','romanized_title','title' ]
def __str__(self):
return "["+self.branch.acronym+"] "+self.title

View File

@ -4,6 +4,12 @@
{% block content %}
<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 %}
<nav aria-label="Pages">
<ul class="pagination">

View File

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

View File

@ -5,15 +5,21 @@ from .models import Song
# Create your views here.
def song_index(request):
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)
page_number = request.GET.get('page',1)
page_obj = paginator.get_page(page_number)
return render(request,'songs/index.html',{'page_obj':page_obj})
objs['page_obj'] = page_obj
return render(request,'songs/index.html',objs)
def song_id(request, id):
song = Song.objects.filter(id=id)[0]
return redirect(song_show,id=song.id,title=song.title)
def song_show(request, id, title):
song = Song.objects.filter(id=id,title=title)[0]
song = Song.objects.filter(id=id)[0]
return render(request,'songs/show.html',{'song':song})

View File

@ -8,15 +8,9 @@
</thead>
<tbody>
{% for song in songs %}
<tr>
<tr class="song-row branch-{{ song.branch.acronym }}">
<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>
{% endif %}
</td>
<td>
<a href="/songs/{{ song.id }}/{{ song.title }}">{{ song.title }}</a>

View File

@ -1,3 +1,5 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
@ -9,6 +11,7 @@
</title>
<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">
<link href="{% static 'branches.css' %}" rel="stylesheet">
</head>
<body>
@ -27,6 +30,9 @@
<li class="nav-item">
<a class="nav-link" href="/songs">Songs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/idols">Idols</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/artists">Artists</a>
</li>