mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-01-20 07:12:58 -05:00
you
This commit is contained in:
@@ -1 +1 @@
|
|||||||
VERSION = "7.8"
|
VERSION = "7.8124"
|
||||||
|
|||||||
@@ -38,10 +38,14 @@ class SelectMediaView(View):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""Display media selection interface"""
|
"""Display media selection interface"""
|
||||||
|
|
||||||
# Get deep link session data
|
# Check if this is a TinyMCE request (no deep linking session required)
|
||||||
deep_link_data = request.session.get('lti_deep_link')
|
is_tinymce = request.GET.get('mode') == 'tinymce'
|
||||||
if not deep_link_data:
|
|
||||||
return JsonResponse({'error': 'No deep linking session data found'}, status=400)
|
if not is_tinymce:
|
||||||
|
# Get deep link session data for regular deep linking flow
|
||||||
|
deep_link_data = request.session.get('lti_deep_link')
|
||||||
|
if not deep_link_data:
|
||||||
|
return JsonResponse({'error': 'No deep linking session data found'}, status=400)
|
||||||
|
|
||||||
# Reuse MediaList logic to get media with proper permissions
|
# Reuse MediaList logic to get media with proper permissions
|
||||||
media_list_view = MediaList()
|
media_list_view = MediaList()
|
||||||
@@ -54,8 +58,25 @@ class SelectMediaView(View):
|
|||||||
if show_my_media_only:
|
if show_my_media_only:
|
||||||
media_queryset = media_queryset.filter(user=request.user)
|
media_queryset = media_queryset.filter(user=request.user)
|
||||||
|
|
||||||
# Order by recent and limit for performance
|
# Order by recent
|
||||||
media_list = media_queryset.order_by('-add_date')[:100]
|
media_queryset = media_queryset.order_by('-add_date')
|
||||||
|
|
||||||
|
# TinyMCE mode: Use pagination
|
||||||
|
if is_tinymce:
|
||||||
|
from django.core.paginator import Paginator
|
||||||
|
|
||||||
|
paginator = Paginator(media_queryset, 24) # 24 items per page
|
||||||
|
page_number = request.GET.get('page', 1)
|
||||||
|
page_obj = paginator.get_page(page_number)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'media_list': page_obj,
|
||||||
|
'page_obj': page_obj,
|
||||||
|
}
|
||||||
|
return render(request, 'lti/tinymce_select_media.html', context)
|
||||||
|
|
||||||
|
# Deep linking mode: Limit for performance
|
||||||
|
media_list = media_queryset[:100]
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'media_list': media_list,
|
'media_list': media_list,
|
||||||
|
|||||||
@@ -21,4 +21,6 @@ urlpatterns = [
|
|||||||
path('embed/<str:friendly_token>/', views.EmbedMediaLTIView.as_view(), name='embed_media'),
|
path('embed/<str:friendly_token>/', views.EmbedMediaLTIView.as_view(), name='embed_media'),
|
||||||
# Manual sync
|
# Manual sync
|
||||||
path('sync/<int:platform_id>/<str:context_id>/', views.ManualSyncView.as_view(), name='manual_sync'),
|
path('sync/<int:platform_id>/<str:context_id>/', views.ManualSyncView.as_view(), name='manual_sync'),
|
||||||
|
# TinyMCE integration (reuses select-media with mode=tinymce parameter)
|
||||||
|
path('tinymce-embed/<str:friendly_token>/', views.TinyMCEGetEmbedView.as_view(), name='tinymce_embed'),
|
||||||
]
|
]
|
||||||
|
|||||||
36
lti/views.py
36
lti/views.py
@@ -407,3 +407,39 @@ class ManualSyncView(APIView):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response({'error': 'Sync failed', 'message': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response({'error': 'Sync failed', 'message': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(xframe_options_exempt, name='dispatch')
|
||||||
|
class TinyMCEGetEmbedView(View):
|
||||||
|
"""
|
||||||
|
API endpoint to get embed code for a specific media item (for TinyMCE integration).
|
||||||
|
|
||||||
|
Returns JSON with the embed code for the requested media.
|
||||||
|
Requires: User must be logged in (via LTI session)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request, friendly_token):
|
||||||
|
"""Get embed code for the specified media."""
|
||||||
|
# Verify user is authenticated
|
||||||
|
if not request.user.is_authenticated:
|
||||||
|
return JsonResponse({'error': 'Authentication required'}, status=401)
|
||||||
|
|
||||||
|
# Verify media exists
|
||||||
|
media = Media.objects.filter(friendly_token=friendly_token).first()
|
||||||
|
|
||||||
|
if not media:
|
||||||
|
return JsonResponse({'error': 'Media not found'}, status=404)
|
||||||
|
|
||||||
|
# Build embed URL
|
||||||
|
embed_url = request.build_absolute_uri(reverse('get_embed') + f'?m={friendly_token}')
|
||||||
|
|
||||||
|
# Generate iframe embed code
|
||||||
|
embed_code = f'<iframe src="{embed_url}" ' f'width="960" height="540" ' f'frameborder="0" ' f'allowfullscreen ' f'title="{media.title}">' f'</iframe>'
|
||||||
|
|
||||||
|
return JsonResponse(
|
||||||
|
{
|
||||||
|
'embedCode': embed_code,
|
||||||
|
'title': media.title,
|
||||||
|
'thumbnail': media.thumbnail_url if hasattr(media, 'thumbnail_url') else '',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user