vbv/server/vbv_lernwelt/learnpath/views.py

48 lines
1.6 KiB
Python

# Create your views here.
import glob
from pathlib import Path
from django.conf import settings
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.response import Response
from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt
from vbv_lernwelt.learnpath.models import Circle
from vbv_lernwelt.learnpath.serializers import CircleSerializer
from vbv_lernwelt.learnpath.models import Circle, LearningPath
from vbv_lernwelt.learnpath.serializers import CircleSerializer, LearningPathSerializer
@api_view(['GET'])
def circle_view(request, slug):
circle = Circle.objects.get(slug=slug)
serializer = CircleSerializer(circle)
return Response(serializer.data)
@django_view_authentication_exempt
def generate_web_component_icons(request):
svg_files = []
for filepath in glob.iglob(f'{settings.APPS_DIR}/static/icons/*.svg'):
with open(filepath, 'r') as f:
filename = Path(filepath).stem
elementname = 'it-' + filename
svg_files.append({
'filepath': filepath,
'content': f.read(),
'filename': filename,
'elementname': elementname,
'classname': filename.replace('-', '_'),
})
return render(
request, "learnpath/icons.html",
context={'svg_files': svg_files},
content_type="application/javascript"
)
@api_view(['GET'])
def learningpath_view(request, slug):
learning_path = LearningPath.objects.get(slug=slug)
serializer = LearningPathSerializer(learning_path)
return Response(serializer.data)