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()
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)
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()
def serve_file_field(self, field): return serve_file(field.path, attach=False)
def serve_photo(self, user): return serve_file(user.profile.photo.path)
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)