from django.http import Http404
from django.shortcuts import render
from django.conf import settings
from datetime import datetime, timedelta
from starbowmodweb import mybb
from starbowmodweb.ladder.helpers import get_leaderboard
from starbowmodweb.ladder.models import BATTLENET_REGION_NA, BATTLENET_REGION_EU, BATTLENET_REGION_KR
from starbowmodweb.streams.models import StreamInfo


def home(request):
    recent_discussions = mybb.get_threads(forum_name=settings.DISCUSSION_FORUMS, count=7, orderby="mybb_threads.dateline", sort="DESC")

    ladder_na = get_leaderboard(region=BATTLENET_REGION_NA, orderby=['division__ladder_group', 'ladder_points'], sort="DESC", count=10)
    ladder_eu = get_leaderboard(region=BATTLENET_REGION_EU, orderby=['division__ladder_group', 'ladder_points'], sort="DESC", count=10)
    ladder_kr = get_leaderboard(region=BATTLENET_REGION_KR, orderby=['division__ladder_group', 'ladder_points'], sort="DESC", count=10)
    online_streams = StreamInfo.objects.filter(online=True).order_by('-viewers')[:7]

    return render(request, 'site_home.html', dict(
        recent_discussions=recent_discussions,
        ladder_na=ladder_na,
        ladder_eu=ladder_eu,
        ladder_kr=ladder_kr,
        online_streams=online_streams,
    ))


def view_news(request):
    articles = mybb.get_threads(forum_name="News and Announcements", orderby="mybb_threads.dateline", sort="DESC")
    return render(request, 'news.html', dict(articles=articles))


def view_events(request):
    now = datetime.utcnow()
    later = now + timedelta(seconds=30*86400)
    events = mybb.get_events_in_range("Default Calendar", now, later)
    return render(request, 'events.html', dict(events=events))


def about_page(request, name):
    name = name.lower() or 'overview'
    if name not in settings.ABOUT_PAGES:
        raise Http404
    return render(request, 'thread_page.html', dict(thread=mybb.get_thread(settings.ABOUT_PAGES[name][1])))

def thread_page(request, name):
    name = name.lower()
    if name not in settings.THREAD_PAGES:
        raise Http404
    return render(request, 'thread_page.html', dict(thread=mybb.get_thread(settings.THREAD_PAGES[name][1])))

@@ -1776,36 +1776,32 @@
 ew'%0A    if name 
-not 
 in settings.ABOU
@@ -1813,34 +1813,16 @@
 ES:%0A    
-    raise Http404%0A
     retu
@@ -1925,77 +1925,22 @@
 )))%0A
-%0Adef thread_page(request, name):%0A    name = name.lower()%0A
     
+el
 if name 
 not 
@@ -1939,12 +1939,8 @@
 ame 
-not 
 in s
@@ -1951,44 +1951,28 @@
 ngs.
-THREAD_PAGES:%0A        raise Http404%0A
+ABOUT_PAGES_KR:%0A    
     
@@ -2055,20 +2055,22 @@
 ngs.
-THREAD
+ABOUT
 _PAGES
+_KR
 %5Bnam
@@ -2066,20 +2066,57 @@
 AGES_KR%5Bname%5D%5B1%5D)))%0A
+    else:%0A        raise Http404%0A    %0A

Update views.py for korean pages