creating admin API

This commit is contained in:
louai98 2023-05-25 16:13:25 +02:00
parent 38f2b96ea1
commit d98acb5963
73 changed files with 92137 additions and 96219 deletions

0
admin_api/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
admin_api/admin.py Normal file
View File

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

6
admin_api/apps.py Normal file
View File

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

View File

3
admin_api/models.py Normal file
View File

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

12
admin_api/serializer.py Normal file
View File

@ -0,0 +1,12 @@
from rest_framework import serializers
from .models import Level, Standards
class LevelSerializer(serializers.ModelSerializer):
class Meta:
model = Level
fields = '__all__'
class StandardsSerializer(serializers.ModelSerializer):
class Meta:
model = Standards
fields = '__all__'

3
admin_api/tests.py Normal file
View File

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

14
admin_api/urls.py Normal file
View File

@ -0,0 +1,14 @@
from django.urls import path, include
from rest_framework import routers
from .views import LevelViewSet, StandardsViewSet
from . import views
router = routers.DefaultRouter()
router.register(r'levels', LevelViewSet)
router.register(r'standards', StandardsViewSet)
urlpatterns = [
path('', include(router.urls)),
path('content-list/', views.contentList, name='content-list'),
]

50
admin_api/views.py Normal file
View File

@ -0,0 +1,50 @@
from django.shortcuts import render
from rest_framework import viewsets
from search_tfidf.models import Level, Standards
from search_tfidf.serializer import LevelSerializer, StandardsSerializer
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import json
import os
from pathlib import Path
from rest_framework.decorators import api_view
# Create your views here.
class LevelViewSet(viewsets.ModelViewSet):
queryset = Level.objects.all()
serializer_class = LevelSerializer
class StandardsViewSet(viewsets.ModelViewSet):
queryset = Standards.objects.all()
serializer_class = StandardsSerializer
@csrf_exempt
@api_view(['GET'])
def contentList(request):
# Get the values from the request parameters
level = request.GET.get('level')
standard = request.GET.get('standard')
data = ""
#module_path = filePath(level, standard)
print(level, standard)
# Read the JSON file
#with open(module_path) as f:
# data = json.load(f)
# Return the filtered data as a JSON response
return JsonResponse({'contents': data})
BASE_DIR = Path(__file__).resolve().parent.parent
def filePath(level_input, standard_input):
standards_dir = os.path.join(BASE_DIR, 'static/data/')
file_path = ''
levels = next(os.walk(os.path.join(BASE_DIR, 'static/data')), (None, None, []))[1]
if str(level_input) in levels:
filenames = next(os.walk(standards_dir+level_input), (None, None, []))[2]
for file in filenames:
if str(standard_input) in file:
file_path = standards_dir+str(level_input)+'/'+file
return file_path

View File

@ -46,6 +46,7 @@ INSTALLED_APPS = [
'rest_framework', 'rest_framework',
'django_filters', 'django_filters',
'search_tfidf', 'search_tfidf',
'admin_api',
'corsheaders', 'corsheaders',
] ]

View File

@ -18,5 +18,6 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('search_tfidf.urls')), path('client_api/', include('search_tfidf.urls')),
path('admin_api/', include('admin_api.urls')),
] ]

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[]

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[]

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long