Commit 9dc2f0ab authored by Virgilio Santos's avatar Virgilio Santos
Browse files

certificate: change certificate generation workflow

parent bb78c335
......@@ -3,3 +3,6 @@ from django.apps import AppConfig
class CoursesCertificationConfig(AppConfig):
name = 'courses.certification'
def ready(self):
import courses.certification.signals
\ No newline at end of file
# Generated by Django 2.2.13 on 2020-07-01 02:23
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('certification', '0002_certificatedata'),
operations = [
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.Workspace'),
......@@ -287,6 +287,7 @@ class CertificateData(models.Model):
workspace = models.ForeignKey(
certificate_template = models.ForeignKey(
......@@ -58,7 +58,9 @@ class CertificateDataSerializer(serializers.ModelSerializer):
return None
def get_contract(self, obj):
return SimpleWorkspaceSerializer(obj.workspace).data
if obj.workspace:
return SimpleWorkspaceSerializer(obj.workspace).data
return None
def update(self, instance, validated_data):
ct = dict(validated_data.pop('certificate_template'))
from django.db.models.signals import post_save
from django.dispatch import receiver
from base64 import urlsafe_b64encode as ub64
from hashlib import sha1
from time import time
from courses.models import CourseStudent
from courses.certification.models import CourseCertification
from courses.models import Course, CourseStudent
from courses.certification.models import CourseCertification, CertificateTemplate, CertificateData
@receiver(post_save, sender=CourseStudent)
......@@ -17,4 +18,15 @@ def course_student_created_or_updated(sender, created, instance, **kwargs):
is_valid=True, link_hash=link_hash.decode())
\ No newline at end of file
@receiver(post_save, sender=Course)
def course_created(sender, created, instance, **kwargs):
if created:
for type_ in CertificateData.TYPES:
ct = CertificateTemplate(course=instance)
cd = CertificateData(type=type_[0], certificate_template=ct)
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