excluded the API from the i18n patterns

This commit is contained in:
Danhia 2022-02-17 13:09:11 +01:00
parent a0b76903a7
commit 8f32ef9a6e
12 changed files with 50 additions and 21 deletions

View File

@ -14,5 +14,4 @@ urlpatterns = [
path('connections/connect/discord/authorize', views.connection.authorize, name='connections-connect-discord-authorize'),
path('connections/disconnect/discord', views.connection.disconnect, name='connections-disconnect-discord'),
path('delete_account/', views.delete_account, name='delete_account'),
path('api/bot/', views.api_bot, name='api_bot'),
]

View File

@ -183,23 +183,3 @@ def rank(request, token):
rank += 1
data = {"rank": rank}
return JsonResponse(data)
def api_bot(request):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})
token = request.GET.get('token')
auth_token = os.getenv('BOT_TOKEN')
if (token != auth_token or not auth_token):
return JsonResponse({'error':'not authorized'})
all_users = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')
data = {}
rank = 1
for user in all_users:
if user.discord_id:
data[user.discord_id] = rank
rank += 1
return JsonResponse(data)

0
src/api/__init__.py Normal file
View File

3
src/api/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
src/api/apps.py Normal file
View File

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

View File

3
src/api/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
src/api/tests.py Normal file
View File

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

6
src/api/urls.py Normal file
View File

@ -0,0 +1,6 @@
from django.urls import path
from . import views
urlpatterns = [
path('bot/discord', views.discord_bot, name='discord_bot'),
]

27
src/api/views.py Normal file
View File

@ -0,0 +1,27 @@
from django.shortcuts import render
from accounts.models import UserProfileInfo
from django.http import JsonResponse
import os
# Create your views here.
def discord_bot(request):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})
token = request.GET.get('token')
auth_token = os.getenv('BOT_TOKEN')
if (token != auth_token or not auth_token):
return JsonResponse({'error':'not authorized'})
all_users = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')
data = {}
rank = 1
for user in all_users:
if user.discord_id:
data[user.discord_id] = rank
rank += 1
return JsonResponse(data)

View File

@ -38,6 +38,7 @@ INSTALLED_APPS = [
'scoreboard.apps.ScoreboardConfig',
'resources.apps.ResourcesConfig',
'django.contrib.sites',
'api.apps.ApiConfig',
]
MIDDLEWARE = [

View File

@ -24,6 +24,7 @@ urlpatterns = [
path('', include('home.urls')),
path('set_lang/<str:lang_code>', home.views.set_language, name="set_language"),
path('dashboard/secret/admin', admin.site.urls),
path('api/', include('api.urls'))
]
urlpatterns += i18n_patterns(