mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Merge pull request #58 from chibicitiberiu/development
Added video detail page
This commit is contained in:
30
app/YtManagerApp/views/video.py
Normal file
30
app/YtManagerApp/views/video.py
Normal file
@ -0,0 +1,30 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpRequest, StreamingHttpResponse, FileResponse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.views import View
|
||||
from django.views.generic import DetailView
|
||||
|
||||
from YtManagerApp.models import Video
|
||||
|
||||
|
||||
class VideoDetailView(LoginRequiredMixin, DetailView):
|
||||
template_name = 'YtManagerApp/video.html'
|
||||
model = Video
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
video, mime = self.object.find_video()
|
||||
if video is not None:
|
||||
context['video_mime'] = mime
|
||||
|
||||
return context
|
||||
|
||||
|
||||
@login_required
|
||||
def video_detail_view(request: HttpRequest, pk):
|
||||
video = Video.objects.get(id = pk)
|
||||
video_file, _ = video.find_video()
|
||||
|
||||
f = open(video_file, 'rb')
|
||||
return FileResponse(f)
|
Reference in New Issue
Block a user