def api_register_index(request): apikey = request.GET['api_key'] index_name = request.GET['index_name'] try: account = Account.objects.get(apikey=apikey) except Account.DoesNotExist: #@UndefinedVariable return HttpResponse('{"status":"ERROR", "message":"Invalid account"}') if len(account.indexes.all()) >= account.package.max_indexes: return HttpResponse('{"status":"ERROR", "message":"Account limit reached"}') else: index = Index() index.populate_for_account(account); index.name = index_name index.creation_time = datetime.datetime.now() index.language_code = 'en' try: index.save() except IntegrityError, ie: print('integrityError in api_register_index.', ie) return HttpResponse('{"status":"ERROR", "message":"You already have and Index with that name or code."}') index.base_port = STARTING_BASE_PORT + 10 * index.id index.code = get_index_code(index.id) index.save() start_index(index) response = '{"status":"OK", "index_code":"%s"}' % (index.code) return HttpResponse(response)
def api_register_index(request): apikey = request.GET['api_key'] index_name = request.GET['index_name'] try: account = Account.objects.get(apikey=apikey) except Account.DoesNotExist: #@UndefinedVariable return HttpResponse('{"status":"ERROR", "message":"Invalid account"}') if len(account.indexes.all()) >= account.package.max_indexes: return HttpResponse( '{"status":"ERROR", "message":"Account limit reached"}') else: index = Index() index.populate_for_account(account) index.name = index_name index.creation_time = datetime.datetime.now() index.language_code = 'en' try: index.save() except IntegrityError, ie: print('integrityError in api_register_index.', ie) return HttpResponse( '{"status":"ERROR", "message":"You already have and Index with that name or code."}' ) index.base_port = STARTING_BASE_PORT + 10 * index.id index.code = get_index_code(index.id) index.save() start_index(index) response = '{"status":"OK", "index_code":"%s"}' % (index.code) return HttpResponse(response)
def upload(request): name = "" if request.method == 'POST' and request.POST.get('search', "") == "": context = {} form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newDoc = Document(docfile=request.FILES.get('docfile', "")) name = form.cleaned_data['docfile'].name newDoc.save() documents = Document.objects.all() if name != "": location = "../media/uploads/" + name s = convert_video_to_frame(cwd + "/media/uploads/" + name) sorted_inverted = model_to_inverted_index(s) print sorted_inverted convert_from_mili(sorted_inverted) val = 1 if len(Index.objects.filter()) > 0: val = len(Index.objects.filter()) + 1 b = Index(invertedIndex=json.dumps(sorted_inverted), name=name, video_id=val, images=json.dumps(s)) vid_id = b.video_id b.save() return redirect("/video/%s" % vid_id) return render(request, 'home.html', context) if request.method == 'GET': return render(request, 'upload.html')