Commit a06a05b7 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

Add feature for uploading videos

See merge request !76
parents a6934054 2242cd07
# Generated by Django 2.2.24 on 2021-07-28 12:35
import courses.videos.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('courses', '0029_auto_20210719_2107'),
]
operations = [
migrations.AddField(
model_name='video',
name='file',
field=models.FileField(default=None, null=True, upload_to=courses.videos.models.get_upload_path),
),
]
......@@ -2,6 +2,7 @@ from modeltranslation.translator import register, TranslationOptions
from .models import Course, Lesson, Unit, ProfessorMessage
from .course_material.models import CourseMaterial, File
from .stats.models import AccessibleArea
from .videos.models import Video
from .certification.models import CertificateTemplate
......@@ -49,3 +50,7 @@ class CertificateTemplateTranslationOptions(TranslationOptions):
'base_logo', 'signature', 'second_signature', 'site_logo',
'organization_name', 'text')
@register(Video)
class VideoTranslationOptions(TranslationOptions):
fields = ('name', 'youtube_id', 'file',)
......@@ -15,6 +15,7 @@ from .views import (
CoursePictureUploadViewSet,
)
from .videos.views import VideoViewSet
from .course_material.views import CourseMaterialViewSet, CourseMaterialFileViewSet
from .import_export.views import ExportCourseView, ImportCourseView
from courses.workspaces.views import (
......@@ -54,6 +55,7 @@ router.register(r'my-courses', MyCoursesViewSet, base_name='my-courses')
router.register(r'course_material', CourseMaterialViewSet, base_name='course_material')
router.register(r'course_material_file', CourseMaterialFileViewSet, base_name='course_material_file')
router.register(r'course-by-slug', CourseBySlugViewSet, base_name='course_by_slug'),
router.register(r'videos', VideoViewSet, base_name='course_by_slug'),
# Lessons
router.register(r'course-lessons/(?P<course_id>[1-9][0-9]*)', LessonViewSet, base_name='lessons')
......
from django.apps import AppConfig
class VideosConfig(AppConfig):
name = 'videos'
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.text import slugify
def get_upload_path(instance, filename):
filename, fileextension = filename.split(".", 2)
filename = slugify(filename.split("/", 2)[-1])
return 'course_videos/{0}.{1}'.format(filename, fileextension)
class Video(models.Model):
name = models.CharField(
......@@ -8,6 +15,11 @@ class Video(models.Model):
youtube_id = models.CharField(
max_length=100,
)
file = models.FileField(
upload_to=get_upload_path,
default=None,
null=True,
)
class Meta:
verbose_name = _('Video')
......
from rest_framework import serializers
from modeltranslation.utils import fallbacks
from .models import Video
......@@ -8,3 +8,11 @@ class VideoSerializer(serializers.ModelSerializer):
class Meta:
model = Video
fields = ('id', 'name', 'youtube_id',)
read_only_fields = ('file',)
class VideoFileSerializer(serializers.ModelSerializer):
class Meta:
model = Video
fields = ('id', 'file',)
from django.shortcuts import render
# Create your views here.
from rest_framework import viewsets
from courses.videos.models import Video
from courses.videos.serializers import VideoFileSerializer
from courses.permissions import (
IsProfessorCoordinatorOrAdminPermissionOrReadOnly,
)
class VideoViewSet(viewsets.ModelViewSet):
model = Video
queryset = Video.objects.all()
serializer_class = VideoFileSerializer
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly,)
......@@ -321,4 +321,4 @@ class CoursePictureUploadViewSet(viewsets.ModelViewSet):
serializer.save()
return Response(serializer.data, status=200)
else:
return Response(serializer.errors, status=400)
\ No newline at end of file
return Response(serializer.errors, status=400)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment