Skip to content

Commit

Permalink
main: optimize index view
Browse files Browse the repository at this point in the history
  • Loading branch information
sapuri committed Mar 5, 2024
1 parent 0253aaf commit aa9d92b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 1 addition & 2 deletions main/templates/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ <h2 class="page-header danger">ログイン方法に関する重要なお知ら

<h2 class="page-header">このサイトについて</h2>
<p>スパランドットコムは、<a href="https://p.eagate.573.jp/game/popn/unilab/index.html" target="_blank" rel="noopener">ポップンミュージック</a>のスパラン愛好家のためのクリア状況管理サイトです。</p>
<p>各楽曲ごとにスパラン(S乱)でのクリアメダルやBAD数を記録し、管理することができます</p>
<p>各楽曲ごとにスパラン(S乱)でのクリアメダルやBAD数を記録して管理できます</p>
<p>スパラン上級者の方はもちろん、初心者の方やこれから始めようと思っている方にも気軽に使っていただけるサイトを目指します。</p>
<p>当サイトで扱っているS乱レベルは<a href="https://popn.wiki/%E3%81%9D%E3%81%AE%E4%BB%96/s%E4%B9%B1%E3%82%AF%E3%83%AA%E3%82%A2%E9%9B%A3%E6%98%93%E5%BA%A6%E8%A1%A8" target="_blank" rel="noopener">S乱クリア難易度表</a>に基いています。</p>
<p>楽曲情報は毎日自動的に更新されるので、常に最新の難易度表を使ってクリア状況を記録できます。</p>
<p>レスポンシブ設計なので、スマートフォンやタブレットでもご利用できます。</p>

<div id="activity" class="row">
<div id="updated-recently" class="col-xs-12 col-md-5">
Expand Down
20 changes: 9 additions & 11 deletions main/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
def index(request: HttpRequest) -> HttpResponse:
""" トップページ """

medal_num = Medal.objects.all().count()
recent_medal = Medal.objects.all().order_by('-updated_at')[:10]
recent_music_id_list = list(recent_medal.values_list('music', flat=True))
recent_music = []
for recent_music_id in recent_music_id_list:
recent_music.append(Music.objects.get(pk=recent_music_id))
medal_num = Medal.objects.count()
recent_medals = Medal.objects.order_by('-updated_at')[:10]

recent_music_ids = list(recent_medals.values_list('music', flat=True))
recent_music = Music.objects.filter(id__in=recent_music_ids)

search_form = SearchForm(request.GET)

user_google_ids = []
user = request.user
if user.is_authenticated:
socials = UserSocialAuth.objects.filter(user=user, provider="google-oauth2")
for social in socials:
user_google_ids.append(social.uid)
if request.user.is_authenticated:
user_google_ids = UserSocialAuth.objects.filter(user=request.user, provider="google-oauth2").values_list('uid',
flat=True)

context = {
'medal_num': medal_num,
Expand Down
5 changes: 3 additions & 2 deletions users/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from users.models import Location, Theme, CustomUser
from users.models import CustomUser, Location, Theme


def create_user(username: str = 'test', location: str = 'test', theme: str = 'test', premium: bool = False) -> CustomUser:
def create_user(username: str = 'test', location: str = 'test', theme: str = 'test',
premium: bool = False) -> CustomUser:
location = Location.objects.create(location=location)
theme = Theme.objects.create(theme=theme)
return CustomUser.objects.create_user(username, location=location, theme=theme, premium=premium)

0 comments on commit aa9d92b

Please sign in to comment.