def add_clue(request): if request.method == 'POST': newdoc = Document(docfile=request.FILES.get('file', False)) if newdoc.docfile: newdoc.id = str(request.FILES.get('file').name) newdoc.save() request.session['file'] = newdoc return render_to_response( 'clue.html', {'image': request.session.get('file')}, context_instance=RequestContext(request) )
def list(request): # Handle file upload # del request.session['file'] # Document.objects.all().delete() if request.method == 'POST': # request.session['file'] = request.FILES.get('file', False) newdoc = Document(docfile=request.FILES.get('file', False)) if newdoc.docfile: newdoc.id = str(request.FILES.get('file').name) newdoc.save() request.session['file'] = newdoc # # Redirect to the document list after POST matches = get_matches(str(request.FILES.get('file').name)) if len(matches)>20: matches = matches[:20] matched_images = [] matched_image_names = [] for im_name in matches: matched_images.append(Image.objects.get(pk=im_name)) matched_image_names.append(im_name) request.session['matches'] = matched_images store_location_information(request, matched_image_names) return HttpResponseRedirect(reverse('contextslices.photo.views.search')) if request.method == 'GET': matched_images = [] if request.session.get('file'): matches = get_matches(request.session.get('file').id) if len(matches) > 20: matches = matches[:20] matched_images = [] matched_image_names = [] for im_name in matches: matched_images.append(Image.objects.get(pk=im_name)) matched_image_names.append(im_name) request.session['matches'] = matched_images store_location_information(request, matched_image_names) return render_to_response( 'results.html', {'file': request.session.get('file'), 'matches': matched_images, 'num_results': len(matched_images)}, context_instance=RequestContext(request) )