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

Set certificate template by default

parent 02cf9c28
......@@ -6,6 +6,7 @@ from hashlib import sha1
from time import time
from courses.models import Course, CourseStudent, Forum
from courses.classes.models import Class
from courses.certification.models import CourseCertification, CertificateTemplate
......@@ -20,15 +21,29 @@ def course_student_created_or_updated(sender, created, instance: CourseStudent,
@receiver(post_save, sender=Course)
def course_created(sender, created, instance, **kwargs):
def course_created_or_updated(sender, created, instance, **kwargs):
if created:
c = Class.objects.create(name=instance.name, course=instance)
instance.default_class = c
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], name='Base ' + instance.name)
for type_tuple in CertificateTemplate.TYPES:
type_name = type_tuple[0]
ct = CertificateTemplate(course=instance, document_type=type_name, name='Base ' + instance.name)
ct.save()
if type_name == 'receipt':
instance.default_class.receipt_template = ct
elif type_name == 'certificate':
instance.default_class.certificate_template = ct
instance.default_class.save()
else:
foruns = Forum.objects.filter(id=instance.forum.id)
if foruns:
......
......@@ -343,9 +343,6 @@ class Course(models.Model):
super(Course, self).save(*args, **kwargs)
if is_new:
c = Class.objects.create(name=self.name, course=self)
self.default_class = c
self.save()
CourseMaterial.objects.create(course=self)
......
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