def reject_resource_authorization(request, resource_id): try: resource = downman_models.ResourceLocator.objects.get( pk=int(resource_id)) resource.authorization = downman_models.ResourceLocator.AUTHORIZATION_REJECTED resource.save() processDownloadRequest.apply_async( args=[resource.request.pk], queue='resolvreq') #@UndefinedVariable return redirect( reverse('downman-update-request', args=(resource.request.pk, ))) except: logger.exception("Error") raise Http404
def requestDownload(request): if request.is_ajax(): if request.method == 'POST': json_data = json.loads(request.body) try: downRequest = downman_models.DownloadRequest() """ # if any of the resoures requires authorization: usage = json_data.get('downloadAuthorizationUsage', '') if not usage: # return an error pass """ if request.user and not request.user.is_anonymous(): downRequest.requested_by_user = request.user.username else: downRequest.requested_by_external = json_data.get( 'email', '') if not downRequest.requested_by_external: pass downRequest.language = get_language() downRequest.validity = downman_models.get_default_validity() downRequest.request_random_id = date.today().strftime( "%Y%m%d") + get_random_string(length=32) downRequest.json_request = request.body.decode("UTF-8") tracking_url = reverse('download-request-tracking', args=(downRequest.request_random_id, )) resources = json_data.get('resources', []) if downman_models.get_shopping_cart_max_items() > 0 and len( resources ) > downman_models.get_shopping_cart_max_items(): return JsonResponse({ "status": "error", 'error_message': "Invalid request" }) if len(resources) == 0 and json_data.get('request_desc'): downRequest.pending_authorization = True downRequest.generic_request = True shared_view_state = json_data.get('shared_view_state') shv_pid = shared_view_state.get('pid') shv_state = shared_view_state.get('view_state') shv_description = shared_view_state.get('description', '') shv_expiration = date(9999, 12, 31) shv = gvsigol_core.views.do_save_shared_view( shv_pid, shv_description, shv_state, shv_expiration, request.user, True) downRequest.shared_view_url = shv.url downRequest.save() for resource in json_data.get('resources', []): createResourceLocator(resource, downRequest) except: logger.exception('error creating DownloadRequest') raise try: #processDownloadRequest(downRequest.id) # this requires the Celery worker to be started, see README processDownloadRequest.apply_async( args=[downRequest.id], queue='resolvreq') #@UndefinedVariable notifyReceivedRequest.apply_async( args=[downRequest.id], queue='notify') #@UndefinedVariable except: logger.exception("error queuing task") downRequest.request_status = downman_models.DownloadRequest.QUEUEING_ERROR downRequest.save() return JsonResponse({ "status_code": downRequest.request_status, "status": downRequest.status_desc, 'download_id': downRequest.request_random_id, 'tracking_url': tracking_url }) # TODO: error handling return JsonResponse({"status": "error"})