Commit 5ac943ea authored by Laury Bueno's avatar Laury Bueno
Browse files

[Certification] Add new functions to CertificateTemplateViewSet

parent 8bce54ba
......@@ -8,7 +8,7 @@ from . import views
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'course_certification', views.CourseCertificationViewSet, base_name='course_certification')
router.register(r'certification_process', views.CertificationProcessViewSet, base_name='certification_process')
router.register(r'certificate_template', views.CertificateDataViewSet, base_name='certificate_template')
router.register(r'certificate_template', views.CertificateTemplateViewSet, base_name='certificate_template')
app_name = 'courses.certification'
urlpatterns = [
......
......@@ -107,10 +107,38 @@ class CourseCertificationViewSet(viewsets.ModelViewSet):
class CertificateTemplateViewSet(viewsets.ModelViewSet):
model = CertificateTemplate
queryset = CertificateTemplate.objects.all()
lookup_field = 'course'
permission_classes = [permissions.IsAuthenticated,]
# lookup_field = 'course'
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, )
serializer_class = CertificateTemplateSerializer
def get_serializer_class(self):
if self.action == 'create':
return CertificateTemplateCreateSerializer
return CertificateTemplateSerializer
@action(detail=True, methods=['get', 'post'])
def images(self, request, pk=None):
obj = self.get_object()
errors = []
clear_logos = (
('cert_logo', request.data.get('cert_logo_clear', None)),
('base_logo', request.data.get('base_logo_clear', None)),
('signature', request.data.get('signature_clear', None)),
('site_logo', request.data.get('site_logo_clear', None)),
)
for cl in clear_logos:
if(cl[1]):
setattr(obj, cl[0], None)
serializer = CertificateTemplateImageSerializer(obj, request.FILES)
if serializer.is_valid():
serializer.save()
return Response(CertificateTemplateSerializer(obj).data,
status=status.HTTP_200_OK)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def update(self, request, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data)
......
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