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
8ca3e461
Commit
8ca3e461
authored
Jul 27, 2021
by
Eduardo Nunes
Browse files
Adding translation into VideoFile model
parent
4c644b7d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
2 deletions
+77
-2
courses/migrations/0031_auto_20210727_1145.py
courses/migrations/0031_auto_20210727_1145.py
+60
-0
courses/translation.py
courses/translation.py
+5
-0
courses/videos/serializers.py
courses/videos/serializers.py
+12
-2
No files found.
courses/migrations/0031_auto_20210727_1145.py
0 → 100644
View file @
8ca3e461
# Generated by Django 2.2.24 on 2021-07-27 14:45
import
courses.videos.models
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'courses'
,
'0030_videofile'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'file_en'
,
field
=
models
.
FileField
(
default
=
None
,
null
=
True
,
upload_to
=
courses
.
videos
.
models
.
get_upload_path
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'file_es'
,
field
=
models
.
FileField
(
default
=
None
,
null
=
True
,
upload_to
=
courses
.
videos
.
models
.
get_upload_path
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'file_pt_br'
,
field
=
models
.
FileField
(
default
=
None
,
null
=
True
,
upload_to
=
courses
.
videos
.
models
.
get_upload_path
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'name_en'
,
field
=
models
.
CharField
(
max_length
=
255
,
null
=
True
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'name_es'
,
field
=
models
.
CharField
(
max_length
=
255
,
null
=
True
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'name_pt_br'
,
field
=
models
.
CharField
(
max_length
=
255
,
null
=
True
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'video_en'
,
field
=
models
.
OneToOneField
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'file'
,
to
=
'courses.Video'
,
verbose_name
=
'file'
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'video_es'
,
field
=
models
.
OneToOneField
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'file'
,
to
=
'courses.Video'
,
verbose_name
=
'file'
),
),
migrations
.
AddField
(
model_name
=
'videofile'
,
name
=
'video_pt_br'
,
field
=
models
.
OneToOneField
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'file'
,
to
=
'courses.Video'
,
verbose_name
=
'file'
),
),
]
courses/translation.py
View file @
8ca3e461
...
...
@@ -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/videos/serializers.py
View file @
8ca3e461
from
rest_framework
import
serializers
from
modeltranslation.utils
import
fallbacks
from
.models
import
Video
,
VideoFile
...
...
@@ -9,6 +9,12 @@ class VideoFileSerializer(serializers.ModelSerializer):
model
=
VideoFile
fields
=
(
'id'
,
'name'
,
'video'
,
'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
VideoSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -16,4 +22,8 @@ class VideoSerializer(serializers.ModelSerializer):
model
=
Video
fields
=
(
'id'
,
'name'
,
'youtube_id'
,
'file'
)
file
=
VideoFileSerializer
(
required
=
False
,
allow_null
=
True
,
read_only
=
True
)
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
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