Commit 20452ec6 authored by Virgilio Santos's avatar Virgilio Santos
Browse files

certificates: exchange contract references to workspace ones

parent 71dc144d
......@@ -24,6 +24,9 @@ from courses.certification.models import (
CertificateTemplate,
)
from courses.models import Course
from courses.workspaces.models import Workspace
class CertificateDataMixin(viewsets.ModelViewSet):
def get_queryset(self):
......@@ -32,9 +35,9 @@ class CertificateDataMixin(viewsets.ModelViewSet):
if course:
queryset = queryset.filter(certificate_template__course=course)
contract = self.request.query_params.get('contract', None)
if contract:
queryset = queryset.filter(contract=contract)
workspace = self.request.query_params.get('contract', None)
if workspace:
queryset = queryset.filter(workspace=workspace)
return queryset
......@@ -49,27 +52,27 @@ class CertificateDataViewSet(CertificateDataMixin, viewsets.ModelViewSet):
if generate:
data = request.data
current = CertificateData.objects.filter(certificate_template__course__id=data.get('course', None),
contract__id=data.get('contract', None))
workspace__id=data.get('workspace', None))
if len(current) >= 2:
return Response({'error' : 'Os templates já existem'}, status=status.HTTP_400_BAD_REQUEST)
else:
course = Course.objects.get(pk=data.get('course', None))
contract = Contract.objects.get(pk=data.get('contract', None))
workspace = Workspace.objects.get(pk=data.get('contract', None))
if len(current) > 0:
ct = CertificateTemplate(course=course)
ct.save()
t = CertificateData.TYPES[0]
if 'receipt' == current[0].type:
t = CertificateData.TYPES[1]
cd = CertificateData(type=t[0], contract=contract, certificate_template=ct)
cd = CertificateData(type=t[0], workspace=workspace, certificate_template=ct)
cd.save()
return Response({'message' : 'Os templates foram criados com sucesso'})
else:
for t in CertificateData.TYPES:
ct = CertificateTemplate(course=course)
ct.save()
cd = CertificateData(type=t[0], contract=contract, certificate_template=ct)
cd = CertificateData(type=t[0], workspace=workspace, certificate_template=ct)
cd.save()
return Response({'message' : 'Os templates foram criados com sucesso'})
......
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