-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from HelloYeew/map-info
Add beatmap info to beatmap card
- Loading branch information
Showing
16 changed files
with
333 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
rurusetto/wiki/migrations/0058_recommendbeatmap_approved_date_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Generated by Django 4.0.5 on 2022-06-13 05:57 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wiki', '0057_alter_ruleset_direct_download_link'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='approved_date', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='creator_id', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='favourite_count', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='genre_id', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='language_id', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='last_update', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='playcount', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='submit_date', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='tags', | ||
field=models.CharField(blank=True, max_length=5000), | ||
), | ||
migrations.AddField( | ||
model_name='recommendbeatmap', | ||
name='total_length', | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
rurusetto/wiki/templates/wiki/snippets/beatmap_info_modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{% load convert_star_rating %} | ||
{% load thousand_seperator %} | ||
{% load length_format %} | ||
{% load round_up %} | ||
{% load get_genre_name %} | ||
{% load get_language_name %} | ||
|
||
<div class="modal fade" id="modal{{ beatmap.0.beatmap_id }}" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> | ||
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="staticBackdropLabel">Beatmap Detail</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body beatmap-info-modal" style="background-image: linear-gradient(to bottom, transparent, #4a4a4a 140px), url({{ beatmap.0.beatmap_cover.url }}); background-size:100%; background-repeat: no-repeat;"> | ||
<h4 class="beatmap-title fw-bold">{{ beatmap.0.title }}</h4> | ||
<h6 class="fw-bold">{{ beatmap.0.artist }}</h6> | ||
<h6 class="fw-bold" style="color: #a5a5a5">{{ beatmap.0.version }}</h6> | ||
{% if beatmap.0.approved == "4" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(241, 101, 160); color: rgb(51, 58, 61); margin-top: -2px">LOVED</span> | ||
{% elif beatmap.0.approved == "3" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(106, 196, 254); color: rgb(51, 58, 61); margin-top: -2px">QUALIFIED</span> | ||
{% elif beatmap.0.approved == "2" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(210, 208, 85); color: rgb(51, 58, 61); margin-top: -2px">APPROVED</span> | ||
{% elif beatmap.0.approved == "1" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(185, 251, 98); color: rgb(51, 58, 61); margin-top: -2px">RANKED</span> | ||
{% elif beatmap.0.approved == "0" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(252, 212, 96); color: rgb(51, 58, 61); margin-top: -2px">PENDING</span> | ||
{% elif beatmap.0.approved == "-1" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(245, 146, 93); color: rgb(51, 58, 61); margin-top: -2px">WIP</span> | ||
{% elif beatmap.0.approved == "-2" %} | ||
<span class="badge rounded-pill bold-font" style="background-color: rgb(0, 0, 0); color: rgb(83, 94, 101); margin-top: -2px">GRAVEYARD</span> | ||
{% endif %} | ||
<i class="fas fa-play-circle"></i> {{ beatmap.0.playcount | thousand_seperator }} | ||
<i class="fas fa-heart"></i> {{ beatmap.0.favourite_count | thousand_seperator }} | ||
<p></p> | ||
<div class="row"> | ||
<div class="col-sm-2"> | ||
<img src="https://s.ppy.sh/a/{{ beatmap.0.creator_id }}" width="120px" height="120px" alt="{{ beatmap.0.creator }}'s profile" class="rounded-3"> | ||
</div> | ||
<div class="col-sm-10"> | ||
<p class="beatmap-infobox-date">mapped by <a href="https://osu.ppy.sh/users/{{ beatmap.0.creator_id }}" class="text-decoration-none spacing-hover">{{ beatmap.0.creator }}</a></p> | ||
<p class="beatmap-infobox-date">submitted {{ beatmap.0.submit_date | date:"j F Y H:i:s" }} UTC</p> | ||
{% if beatmap.0.approved == '1' %} | ||
<p class="beatmap-infobox-date">ranked {{ beatmap.0.approved_date | date:"j F Y H:i:s" }} UTC</p> | ||
{% elif beatmap.0.approved == '3' %} | ||
<p class="beatmap-infobox-date">qualified {{ beatmap.0.approved_date | date:"j F Y H:i:s" }} UTC</p> | ||
{% else %} | ||
<p class="beatmap-infobox-date">last updated {{ beatmap.0.last_update | date:"j F Y H:i:s" }} UTC</p> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% if beatmap.0.source %} | ||
<p class="fw-bold">Source</p> | ||
<p>{{ beatmap.0.source }}</p> | ||
{% endif %} | ||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<p class="fw-bold">Genre</p> | ||
<p>{{ beatmap.0.genre_id|get_genre_name }}</p> | ||
</div> | ||
<div class="col-sm-6"> | ||
<p class="fw-bold">Language</p> | ||
<p>{{ beatmap.0.language_id|get_language_name }}</p> | ||
</div> | ||
|
||
</div> | ||
{% if beatmap.0.tags %} | ||
<p class="fw-bold">Tags</p> | ||
<p>{{ beatmap.0.tags }}</p> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Constants of osu! api. | ||
It is not really constant because osu! API may change. | ||
""" | ||
|
||
languages = { | ||
0: "Any", | ||
1: "Unspecified", | ||
2: "English", | ||
3: "Japanese", | ||
4: "Chinese", | ||
5: "Instrumental", | ||
6: "Korean", | ||
7: "French", | ||
8: "German", | ||
9: "Swedish", | ||
10: "Spanish", | ||
11: "Italian", | ||
12: "Russian", | ||
13: "Polish", | ||
14: "Other" | ||
# Default value is Unknown. | ||
} | ||
|
||
genres = { | ||
0: "Any", | ||
1: "Unspecified", | ||
2: "Video Game", | ||
3: "Anime", | ||
4: "Rock", | ||
5: "Pop", | ||
6: "Other", | ||
7: "Novelty", | ||
# 8 is missing. | ||
9: "Hip-hop", | ||
10: "Electronic", | ||
11: "Metal", | ||
12: "Classical", | ||
13: "Folk", | ||
14: "Jazz", | ||
# Default is unknown. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typing import Union | ||
from django import template | ||
from . import constants | ||
|
||
register = template.Library() | ||
|
||
|
||
def get_genre_name(genre_id: Union[str, int]): | ||
"""Get genre name from osu! genre id.""" | ||
genre_id = int(genre_id) | ||
return constants.genres.get(genre_id, "Unknown") | ||
|
||
register.filter('get_genre_name', get_genre_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typing import Union | ||
from django import template | ||
from . import constants | ||
|
||
register = template.Library() | ||
|
||
|
||
def get_language_name(language_id: Union[str, int]): | ||
"""Get language from osu! language id.""" | ||
language_id = int(language_id) | ||
return constants.languages.get(language_id, "Unknown") | ||
|
||
register.filter('get_language_name', get_language_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django import template | ||
from time import strftime, gmtime | ||
|
||
register = template.Library() | ||
|
||
|
||
def length_format(length): | ||
"""Convert second to minutes and second. Mainly use in beatmap time length. | ||
Args: | ||
length (int): Length of the beatmap in second. | ||
Returns: | ||
str: Formatted length of the beatmap. | ||
""" | ||
if type(length) is not int: | ||
try: | ||
length = int(length) | ||
except ValueError: | ||
return "0:00" | ||
if length >= 3600: | ||
return strftime("%H:%M:%S", gmtime(length)) | ||
return strftime("%M:%S", gmtime(int(length))) | ||
|
||
|
||
register.filter('length_format', length_format) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django import template | ||
import math | ||
|
||
register = template.Library() | ||
|
||
|
||
def round_up(value): | ||
""" | ||
Rounds up a value to the nearest integer. | ||
Arguments: | ||
value (float): The value to round up. | ||
Returns: | ||
int: The rounded up value. | ||
""" | ||
try: | ||
return int(math.ceil(float(value))) | ||
except ValueError: | ||
return value | ||
|
||
|
||
register.filter('round_up', round_up) |
Oops, something went wrong.