|
|
|
|
@ -1,5 +1,8 @@ |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.http import JsonResponse, HttpResponse |
|
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
|
from django.template import loader |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
@ -9,6 +12,7 @@ from django.views.generic import TemplateView, DetailView |
|
|
|
|
|
|
|
|
|
from apps.content.models import Contest, ContestWork, FAQ |
|
|
|
|
from apps.course.models import ContestWorkComment |
|
|
|
|
from apps.user.models import Child |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
@ -124,3 +128,21 @@ class FAQView(TemplateView): |
|
|
|
|
} for f in FAQ.objects.all()] |
|
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
|
|
from apps.notification.tasks import draw_cert |
|
|
|
|
|
|
|
|
|
@csrf_exempt |
|
|
|
|
def get_certificate(request, cert): |
|
|
|
|
signed_path_pattern = 'signed-user-certificates/%d.jpg' |
|
|
|
|
fn = signed_path_pattern % cert |
|
|
|
|
path = os.path.join(settings.RESOURCES_ROOT, fn) |
|
|
|
|
child_id = request.GET.get('child_id') |
|
|
|
|
if child_id: |
|
|
|
|
child = get_object_or_404(Child, pk=child_id) |
|
|
|
|
path = draw_cert(path, child.user.email, child.first_name, child.last_name) |
|
|
|
|
f = open(path, 'rb') |
|
|
|
|
response = HttpResponse(f, content_type='image/jpeg') |
|
|
|
|
response['Content-Disposition'] = 'attachment; filename=%s' % fn |
|
|
|
|
f.close() |
|
|
|
|
if child_id: |
|
|
|
|
os.remove(path) |
|
|
|
|
return response |
|
|
|
|
|