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
2380a0c5
Commit
2380a0c5
authored
Dec 21, 2021
by
Matheus Miranda
Browse files
Merge branch 'develop' into 'master'
Develop See merge request
!97
parents
a3131837
dd3b7188
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
91 additions
and
15 deletions
+91
-15
courses/migrations/0038_auto_20211215_1805.py
courses/migrations/0038_auto_20211215_1805.py
+23
-0
courses/migrations/0039_auto_20211221_1626.py
courses/migrations/0039_auto_20211221_1626.py
+25
-0
courses/models.py
courses/models.py
+6
-0
courses/signals.py
courses/signals.py
+16
-8
courses/tasks.py
courses/tasks.py
+5
-3
courses/translation.py
courses/translation.py
+2
-3
courses/urls.py
courses/urls.py
+3
-1
courses/views.py
courses/views.py
+11
-0
No files found.
courses/migrations/0038_auto_20211215_1805.py
0 → 100644
View file @
2380a0c5
This diff is collapsed.
Click to expand it.
courses/migrations/0039_auto_20211221_1626.py
0 → 100644
View file @
2380a0c5
# Generated by Django 2.2.25 on 2021-12-21 19:26
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'courses'
,
'0038_auto_20211215_1805'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'course'
,
name
=
'slug_en'
,
),
migrations
.
RemoveField
(
model_name
=
'course'
,
name
=
'slug_es'
,
),
migrations
.
RemoveField
(
model_name
=
'course'
,
name
=
'slug_pt_br'
,
),
]
courses/models.py
View file @
2380a0c5
...
...
@@ -27,6 +27,7 @@ from .classroom.models import Classroom, Event
from
.scheduling.models
import
ScheduledTask
import
re
import
pytz
class
CourseCategory
(
models
.
Model
):
...
...
@@ -903,6 +904,7 @@ class Lesson(PositionedModel):
(
'draft'
,
_
(
'Draft'
)),
(
'published'
,
_
(
'Published'
)),
)
TIMEZONE_CHOICES
=
zip
(
pytz
.
all_timezones
,
pytz
.
all_timezones
)
course
=
models
.
ForeignKey
(
Course
,
...
...
@@ -950,6 +952,7 @@ class Lesson(PositionedModel):
blank
=
True
,
default
=
None
,
)
release_date_timezone
=
models
.
CharField
(
max_length
=
255
,
default
=
'UTC'
,
blank
=
True
,
choices
=
TIMEZONE_CHOICES
)
scheduled_task
=
GenericRelation
(
ScheduledTask
,
related_query_name
=
'lesson'
)
collection_name
=
'course'
...
...
@@ -1003,6 +1006,8 @@ class Unit(PositionedModel):
(
'draft'
,
_
(
'Draft'
)),
(
'published'
,
_
(
'Published'
)),
)
TIMEZONE_CHOICES
=
zip
(
pytz
.
all_timezones
,
pytz
.
all_timezones
)
title
=
models
.
CharField
(
_
(
'Title'
),
max_length
=
128
,
...
...
@@ -1050,6 +1055,7 @@ class Unit(PositionedModel):
blank
=
True
,
default
=
None
,
)
release_date_timezone
=
models
.
CharField
(
max_length
=
255
,
default
=
'UTC'
,
blank
=
True
,
choices
=
TIMEZONE_CHOICES
)
scheduled_task
=
GenericRelation
(
ScheduledTask
,
related_query_name
=
'unit'
)
collection_name
=
'lesson'
...
...
courses/signals.py
View file @
2380a0c5
...
...
@@ -6,6 +6,8 @@ from .tasks import publish_lesson, publish_unit
from
.scheduling.models
import
ScheduledTask
from
celery.result
import
AsyncResult
from
celery
import
Celery
app
=
Celery
()
def
schedule_task
(
content_type
,
instance
):
...
...
@@ -18,8 +20,7 @@ def schedule_task(content_type, instance):
previous_task_hash
=
st
.
task_hash
if
previous_task_hash
:
from
celery.task.control
import
revoke
revoke
(
previous_task_hash
)
app
.
control
.
revoke
(
previous_task_hash
)
if
content_type
.
name
==
'Lesson'
:
new_task_hash
=
publish_lesson
.
apply_async
(
args
=
[
instance
.
id
],
eta
=
instance
.
release_date
)
...
...
@@ -33,20 +34,27 @@ def schedule_task(content_type, instance):
@
receiver
(
pre_save
,
sender
=
Lesson
)
def
pre_lesson_created_or_updated
(
sender
,
instance
:
Lesson
,
**
kwargs
):
previous_release_date
=
None
prev_release_date
=
None
prev_release_date_tz
=
'UTC'
if
instance
.
id
:
previous_lesson
=
Lesson
.
objects
.
get
(
id
=
instance
.
id
)
previous_release_date
=
previous_lesson
.
release_date
prev_release_date
=
previous_lesson
.
release_date
prev_release_date_tz
=
previous_lesson
.
release_date_timezone
import
pytz
tz
=
pytz
.
timezone
(
instance
.
release_date_timezone
)
instance
.
release_date
=
instance
.
release_date
.
astimezone
(
tz
)
new_release_date
=
instance
.
release_date
new_release_date_tz
=
instance
.
release_date_timezone
if
new_release_date
:
new_release_date
=
new_release_date
.
replace
(
microsecond
=
0
,
second
=
0
)
if
prev
ious
_release_date
:
prev
ious
_release_date
=
prev
ious
_release_date
.
replace
(
microsecond
=
0
,
second
=
0
)
if
prev_release_date
:
prev_release_date
=
prev_release_date
.
replace
(
microsecond
=
0
,
second
=
0
)
if
(
not
instance
.
id
or
new_release_date
!=
prev
ious
_release_date
)
\
and
instance
.
release_date
:
if
(
not
instance
.
id
or
new_release_date
!=
prev
_release_date
or
new_release_date_tz
!=
prev
_release_date
_tz
)
\
and
instance
.
release_date
and
instance
.
release_date_timezone
:
from
django.contrib.contenttypes.models
import
ContentType
content_type
=
ContentType
.
objects
.
get_for_model
(
instance
)
...
...
courses/tasks.py
View file @
2380a0c5
from
.models
import
Lesson
,
Unit
from
celery.decorators
import
task
#fro celery.decorators import task
from
celery
import
Celery
app
=
Celery
()
@
task
()
@
app
.
task
()
def
publish_lesson
(
object_id
):
lesson
=
Lesson
.
objects
.
filter
(
id
=
object_id
)
if
lesson
.
exists
():
...
...
@@ -10,7 +12,7 @@ def publish_lesson(object_id):
lesson
.
status
=
'published'
lesson
.
save
()
@
task
()
@
app
.
task
()
def
publish_unit
(
object_id
):
unit
=
Unit
.
objects
.
filter
(
id
=
object_id
)
if
unit
.
exists
():
...
...
courses/translation.py
View file @
2380a0c5
...
...
@@ -8,9 +8,8 @@ from .certification.models import CertificateTemplate
@
register
(
Course
)
class
CourseTranslationOptions
(
TranslationOptions
):
fields
=
(
'slug'
,
'name'
,
'application'
,
'requirement'
,
'abstract'
,
'structure'
,
'workload'
,
'course_load'
,
'pronatec'
,
'thumbnail'
,
'home_thumbnail'
,
fields
=
(
'name'
,
'application'
,
'requirement'
,
'abstract'
,
'structure'
,
'workload'
,
'course_load'
,
'pronatec'
,
'thumbnail'
,
'home_thumbnail'
,
'min_percent_to_complete'
,
'informations'
,
'description'
)
...
...
courses/urls.py
View file @
2380a0c5
...
...
@@ -14,6 +14,7 @@ from .views import (
CourseAuthorViewSet
,
CoursePictureUploadViewSet
,
TranslateSlugView
,
TimezonesView
,
)
from
.videos.views
import
VideoViewSet
from
.course_material.views
import
CourseMaterialViewSet
,
CourseMaterialFileViewSet
...
...
@@ -48,7 +49,6 @@ from courses.notes.views import (
NotesViewSet
,
UserNotesViewSet
,
)
from
courses.certification.views
import
(
CourseCertificationPDFView
,
)
...
...
@@ -111,6 +111,8 @@ urlpatterns = [
url
(
r
'^user-access'
,
UserAccessView
.
as_view
(),
name
=
'user-access'
),
url
(
r
'^translate-slug'
,
TranslateSlugView
.
as_view
(),
name
=
'translate-slug'
),
url
(
r
'^timezones'
,
TimezonesView
.
as_view
(),
name
=
'timezones'
),
url
(
r
'^certificate/(?P<slug>[-a-zA-Z0-9_]+)/pdf/$'
,
CourseCertificationPDFView
.
as_view
(
template_name
=
"certificate_pdf.html"
),
name
=
'certificate-pdf'
,
...
...
courses/views.py
View file @
2380a0c5
from
django.db.models
import
Q
from
django.db
import
IntegrityError
from
django.contrib.auth
import
get_user_model
from
django.http
import
HttpResponse
from
rest_framework
import
views
,
viewsets
,
mixins
,
permissions
,
status
from
rest_framework.response
import
Response
...
...
@@ -335,3 +336,13 @@ class TranslateSlugView(views.APIView):
return
Response
({
'slug'
:
translated_slug
},
status
=
status
.
HTTP_200_OK
)
class
TimezonesView
(
views
.
APIView
):
permission_classes
=
[
permissions
.
IsAuthenticated
]
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
import
pytz
import
json
timezones
=
json
.
dumps
({
"timezones"
:
pytz
.
all_timezones
})
return
HttpResponse
(
timezones
,
content_type
=
"application/json"
)
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