def upload_view(request): if not request.user.userprofile.get_can_upload(): raise exceptions.PermissionDenied if request.method == 'POST': result = handler.upload(request, request.user) if result['result'] == UploadedMedia.UPLOAD_STATUS_SUCCESS: return HttpResponseRedirect(reverse('oppia_av_upload_success', args=[result['media'].id])) else: form = result['form'] else: form = UploadMediaForm() # An unbound form return render(request, 'oppia/av/upload.html', {'form': form, 'title': _(u'Upload Media')})
def upload_view(request): # get the messages to clear possible previous unprocessed messages get_messages_array(request) if request.method != 'POST': return HttpResponse(status=405) required = ['username', 'password'] validation_errors = [] for field in required: if field not in request.POST: validation_errors.append("field '{0}' missing".format(field)) # authenticate user username = request.POST.get("username") password = request.POST.get("password") user = authenticate(username=username, password=password) if user is None or not user.is_active: messages.error(request, "Invalid username/password") response_data = { 'message': _('Authentication errors'), 'messages': get_messages_array(request) } return JsonResponse(response_data, status=401) if validation_errors: return JsonResponse( {'errors': validation_errors}, status=400, ) result = handler.upload(request, user) if result['result'] == UploadedMedia.UPLOAD_STATUS_SUCCESS: media = result['media'] embed_code = media.get_embed_code( request.build_absolute_uri(media.file.url)) return JsonResponse({'embed_code': embed_code}, status=201) else: response = {'messages': result['errors']} return JsonResponse(response, status=400)
def upload_view(request): if not request.user.userprofile.get_can_upload(): raise exceptions.PermissionDenied if request.method == 'POST': result = handler.upload(request, request.user) if result['result'] == UploadedMedia.UPLOAD_STATUS_SUCCESS: return HttpResponseRedirect( reverse('oppia_av_upload_success', args=[result['media'].id])) else: form = result['form'] else: form = UploadMediaForm() # An unbound form return render(request, 'oppia/av/upload.html', { 'form': form, 'title': _(u'Upload Media') })
def upload_view(request): # get the messages to clear possible previous unprocessed messages get_messages_array(request) if request.method != 'POST': return HttpResponse(status=405) required = ['username', 'password'] validation_errors = [] for field in required: if field not in request.POST: validation_errors.append("field '{0}' missing".format(field)) # authenticate user username = request.POST.get("username") password = request.POST.get("password") user = authenticate(username=username, password=password) if user is None or not user.is_active: messages.error(request, "Invalid username/password") response_data = { 'message': _('Authentication errors'), 'messages': get_messages_array(request) } return JsonResponse(response_data, status=401) if validation_errors: return JsonResponse({'errors': validation_errors}, status=400, ) result = handler.upload(request, user) if result['result'] == UploadedMedia.UPLOAD_STATUS_SUCCESS: media = result['media'] embed_code = media.get_embed_code(request.build_absolute_uri(media.file.url)) return JsonResponse({'embed_code': embed_code}, status=201) else: response = {'messages': result['errors']} return JsonResponse(response, status=400)
def upload_view(request): if not request.user.userprofile.get_can_upload(): return HttpResponse('Unauthorized', status=401) if request.method == 'POST': result = handler.upload(request, request.user) if result['result'] == UploadedMedia.UPLOAD_STATUS_SUCCESS: return HttpResponseRedirect( reverse('oppia_av_upload_success', args=[result['media'].id])) else: form = result['form'] else: form = UploadMediaForm() # An unbound form return render_to_response('oppia/av/upload.html', { 'form': form, 'title': _(u'Upload Media') }, context_instance=RequestContext(request))