示例#1
0
def profile_photo(request, username):
    """
    Serve a user's profile photo
    """
    try:
        user = User.objects.get(username__iexact=username)
        return utility.serve_file(user.profile.photo.path)
    except ObjectDoesNotExist:
        raise Http404()
示例#2
0
def training_report(request, training_id):
    """
    Serve a training report file
    """
    trainings = Training.objects.all()
    if not request.user.is_admin:
        trainings = trainings.filter(user=request.user)

    training = get_object_or_404(trainings, id=training_id)

    if settings.STORAGE_TYPE == StorageTypes.GCP:
        return redirect(training.completion_report.url)

    return utility.serve_file(training.completion_report.path, attach=False)
示例#3
0
def training_report(request, application_slug):
    """
    Serve a training report file
    """
    try:
        application = CredentialApplication.objects.get(slug=application_slug)
    except ObjectDoesNotExist:
        raise Http404()

    if request.user == application.user or request.user.is_admin:
        try:
            return utility.serve_file(application.training_completion_report.path, False)
        except FileNotFoundError:
            raise Http404()

    raise PermissionDenied()
示例#4
0
 def serve_file_field(self, field):
     return serve_file(field.path, attach=False)
示例#5
0
 def serve_photo(self, user):
     return serve_file(user.profile.photo.path)
示例#6
0
def profile_photo(request, username):
    """
    Serve a user's profile photo
    """
    user = User.objects.get(username__iexact=username)
    return utility.serve_file(user.profile.photo.path)