Commit 7fd3195b authored by Glaucia S. Santos's avatar Glaucia S. Santos

Create a forum after creating a course

parent c1b458ee
......@@ -5,13 +5,12 @@ from base64 import urlsafe_b64encode as ub64
from hashlib import sha1
from time import time
from courses.models import Course, CourseStudent
from courses.models import Course, CourseStudent, Forum
from courses.certification.models import CourseCertification, CertificateTemplate
@receiver(post_save, sender=CourseStudent)
def course_student_created_or_updated(sender, created, instance: CourseStudent, **kwargs):
if created:
link_hash = ub64(sha1((str(time()) + instance.user.last_name).encode('utf-8')).digest()[0:6])
receipt = CourseCertification(course_student=instance,
......@@ -22,8 +21,11 @@ def course_student_created_or_updated(sender, created, instance: CourseStudent,
@receiver(post_save, sender=Course)
def course_created(sender, created, instance, **kwargs):
if created:
forum = Forum.objects.create(title=instance.name, is_public=True, forum_type="course")
instance.forum = forum
instance.save()
for type_ in CertificateTemplate.TYPES:
ct = CertificateTemplate(course=instance, document_type=type_[0])
ct.save()
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