Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
3af44cc1
Commit
3af44cc1
authored
Jul 28, 2021
by
Matheus Miranda
Browse files
Merge branch 'add_video_uploader' into 'develop'
Add video uploader See merge request
!75
parents
95160877
80b8061f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
4 deletions
+71
-4
courses/migrations/0030_video_file.py
courses/migrations/0030_video_file.py
+19
-0
courses/translation.py
courses/translation.py
+5
-0
courses/urls.py
courses/urls.py
+2
-0
courses/videos/models.py
courses/videos/models.py
+12
-0
courses/videos/serializers.py
courses/videos/serializers.py
+16
-2
courses/videos/views.py
courses/videos/views.py
+16
-1
courses/views.py
courses/views.py
+1
-1
No files found.
courses/migrations/0030_video_file.py
0 → 100644
View file @
3af44cc1
# 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
),
),
]
courses/translation.py
View file @
3af44cc1
...
...
@@ -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 VideoFile
from
.certification.models
import
CertificateTemplate
...
...
@@ -49,3 +50,7 @@ class CertificateTemplateTranslationOptions(TranslationOptions):
'base_logo'
,
'signature'
,
'second_signature'
,
'site_logo'
,
'organization_name'
,
'text'
)
#@register(VideoFile)
#class VideoFileTranslationOptions(TranslationOptions):
# fields = ('name', 'file', 'video')
courses/urls.py
View file @
3af44cc1
...
...
@@ -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'
)
...
...
courses/videos/models.py
View file @
3af44cc1
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'
)
...
...
courses/videos/serializers.py
View file @
3af44cc1
from
rest_framework
import
serializers
from
modeltranslation.utils
import
fallbacks
from
.models
import
Video
class
VideoSerializer
(
serializers
.
ModelSerializer
):
file
=
serializers
.
FileField
(
read_only
=
True
)
class
Meta
:
model
=
Video
fields
=
(
'id'
,
'name'
,
'youtube_id'
,
'file'
,)
#def get_file(self, obj):
# with fallbacks(False):
# files = VideoFileSerializer(required=False, allow_null=True, read_only=True, **{'context': self.context}).data
# files = [f for f in files if f['file'] != None]
# return files
class
VideoFileSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Video
fields
=
(
'id'
,
'
name'
,
'youtube_id
'
,)
fields
=
(
'id'
,
'
file
'
,)
courses/videos/views.py
View file @
3af44cc1
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
,)
courses/views.py
View file @
3af44cc1
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment