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

Merge branch 'develop' into 'master'

Set certificate template by default

See merge request !82
parents b59467bd e8c333a1
...@@ -6,6 +6,7 @@ from hashlib import sha1 ...@@ -6,6 +6,7 @@ from hashlib import sha1
from time import time from time import time
from courses.models import Course, CourseStudent, Forum from courses.models import Course, CourseStudent, Forum
from courses.classes.models import Class
from courses.certification.models import CourseCertification, CertificateTemplate from courses.certification.models import CourseCertification, CertificateTemplate
...@@ -20,15 +21,29 @@ def course_student_created_or_updated(sender, created, instance: CourseStudent, ...@@ -20,15 +21,29 @@ def course_student_created_or_updated(sender, created, instance: CourseStudent,
@receiver(post_save, sender=Course) @receiver(post_save, sender=Course)
def course_created(sender, created, instance, **kwargs): def course_created_or_updated(sender, created, instance, **kwargs):
if created: 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") forum = Forum.objects.create(title=instance.name, is_public=True, forum_type="course")
instance.forum = forum instance.forum = forum
instance.save() instance.save()
for type_ in CertificateTemplate.TYPES: for type_tuple in CertificateTemplate.TYPES:
ct = CertificateTemplate(course=instance, document_type=type_[0], name='Base ' + instance.name) type_name = type_tuple[0]
ct = CertificateTemplate(course=instance, document_type=type_name, name='Base ' + instance.name)
ct.save() 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: else:
foruns = Forum.objects.filter(id=instance.forum.id) foruns = Forum.objects.filter(id=instance.forum.id)
if foruns: if foruns:
......
...@@ -343,9 +343,6 @@ class Course(models.Model): ...@@ -343,9 +343,6 @@ class Course(models.Model):
super(Course, self).save(*args, **kwargs) super(Course, self).save(*args, **kwargs)
if is_new: if is_new:
c = Class.objects.create(name=self.name, course=self)
self.default_class = c
self.save()
CourseMaterial.objects.create(course=self) 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