-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1383 from sumandari/1371_certification_type
Add Certificate Type
- Loading branch information
Showing
22 changed files
with
627 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
django_project/certification/migrations/0007_certificatetype.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 2.2.18 on 2021-12-03 00:56 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def add_certification_type_as_existing_value(apps, schema_editor): | ||
CertificateType = apps.get_model('certification', 'CertificateType') | ||
CertificateType.objects.create( | ||
name='attendance and completion', | ||
wording='Has attended and completed the course:', | ||
order=0 | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('certification', '0006_auto_20210730_0615'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CertificateType', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(help_text='Certificate type.', max_length=200, unique=True)), | ||
('description', models.TextField(blank=True, help_text='Certificate type description - 1000 characters limit.', max_length=1000, null=True)), | ||
('wording', models.CharField(help_text='Wording that will be placed on certificate. e.g. "Has attended and completed".', max_length=500)), | ||
('order', models.IntegerField(blank=True, null=True, unique=True)), | ||
], | ||
), | ||
|
||
migrations.RunPython(add_certification_type_as_existing_value, reverse_code=migrations.RunPython.noop), | ||
] |
38 changes: 38 additions & 0 deletions
38
django_project/certification/migrations/0008_projectcertificatetype.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 2.2.18 on 2021-12-10 02:23 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
def create_existing_project_certificate_type(apps, schema_editor): | ||
CertificateType = apps.get_model('certification', 'CertificateType') | ||
ProjectCertificateType = apps.get_model('certification', 'ProjectCertificateType') | ||
Project = apps.get_model('base', 'Project') | ||
certificate_type = CertificateType.objects.filter( | ||
name='attendance and completion').first() | ||
projects = Project.objects.all() | ||
|
||
for project in projects: | ||
ProjectCertificateType.objects.create( | ||
project=project, | ||
certificate_type=certificate_type | ||
) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('base', '0006_auto_20210308_0244'), | ||
('certification', '0007_certificatetype'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ProjectCertificateType', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('certificate_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='certification.CertificateType')), | ||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='base.Project')), | ||
], | ||
), | ||
|
||
migrations.RunPython(create_existing_project_certificate_type, reverse_code=migrations.RunPython.noop), | ||
] |
41 changes: 41 additions & 0 deletions
41
django_project/certification/migrations/0009_course_certificate_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 2.2.18 on 2021-12-10 08:31 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
def set_existing_certificate_type_value(apps, shcema_editor): | ||
CertificateType = apps.get_model('certification', 'CertificateType') | ||
Course = apps.get_model('certification', 'Course') | ||
certificate_type = CertificateType.objects.filter( | ||
name='attendance and completion').first() | ||
courses = Course.objects.all() | ||
|
||
for course in courses: | ||
course.certificate_type = certificate_type | ||
course.save(update_fields=['certificate_type']) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('certification', '0008_projectcertificatetype'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='course', | ||
name='certificate_type', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='certification.CertificateType'), | ||
), | ||
|
||
migrations.RunPython(set_existing_certificate_type_value, reverse_code=migrations.RunPython.noop), | ||
|
||
migrations.AlterField( | ||
model_name='course', | ||
name='certificate_type', | ||
field=models.ForeignKey(null=False, on_delete=django.db.models.deletion.PROTECT, | ||
to='certification.CertificateType'), | ||
preserve_default=False, | ||
), | ||
|
||
] |
14 changes: 14 additions & 0 deletions
14
django_project/certification/migrations/0010_merge_20220212_0417.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 2.2.18 on 2022-02-12 02:17 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('certification', '0007_courseconvener_is_active'), | ||
('certification', '0009_course_certificate_type'), | ||
] | ||
|
||
operations = [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Certificate type model for certification app""" | ||
|
||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from base.models.project import Project | ||
|
||
|
||
class CertificateType(models.Model): | ||
name = models.CharField( | ||
help_text=_('Certificate type.'), | ||
max_length=200, | ||
null=False, | ||
blank=False, | ||
unique=True, | ||
) | ||
|
||
description = models.TextField( | ||
help_text=_('Certificate type description - 1000 characters limit.'), | ||
max_length=1000, | ||
null=True, | ||
blank=True, | ||
) | ||
|
||
wording = models.CharField( | ||
help_text=_( | ||
'Wording that will be placed on certificate. ' | ||
'e.g. "Has attended and completed".' | ||
), | ||
max_length=500, | ||
null=False, | ||
blank=False | ||
) | ||
|
||
order = models.IntegerField( | ||
blank=True, | ||
null=True, | ||
unique=True | ||
) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class ProjectCertificateType(models.Model): | ||
"""A model to store a certificate type linked to a project""" | ||
|
||
project = models.ForeignKey( | ||
Project, | ||
on_delete=models.CASCADE | ||
) | ||
certificate_type = models.ForeignKey( | ||
CertificateType, | ||
on_delete=models.CASCADE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
django_project/certification/templates/certificate_type/list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{% extends "project_base.html" %} | ||
|
||
{% block extra_js %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<style> | ||
.table tbody:first-of-type tr { | ||
background-color: transparent; | ||
} | ||
</style> | ||
|
||
<div class="page-header"> | ||
<h1 class="text-muted">Certificate Types</h1> | ||
</div> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Certificate Type</th> | ||
<th scope="col">Wording</th> | ||
<th scope="col">Apply</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<form action="{% url 'certificate-type-update' project_slug %}" method="post"> | ||
{% csrf_token %} | ||
{% for cer_type in certificate_types %} | ||
<tr {% if cer_type.id in certificate_types_applied %}style="background-color: #d7e5f0" {% endif %}> | ||
<td>{{ cer_type.name }}</td> | ||
<td>{{ cer_type.wording }}</td> | ||
<td> | ||
<input type="checkbox" name="certificate_types" value="{{ cer_type.name }}" | ||
{% if cer_type.id in certificate_types_applied %}checked{% endif %} | ||
> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
<input class="btn btn-primary" type="submit" value="Save"> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.