def document(request, id): try: doc = fs.get(id) except gridfs.NoFile: raise Http404 return HttpResponse(doc.read(), mimetype=doc.content_type)
def import_versions(state, solr_url="http://localhost:8983/solr/"): for bill in db.bills.find({'state': state}): for version in bill['versions']: if 'document_id' not in version: continue doc = fs.get(version['document_id']) params = {} params['literal.bill_id'] = doc.metadata['bill']['bill_id'] params['literal.state'] = doc.metadata['bill']['state'] params['literal.chamber'] = doc.metadata['bill']['chamber'] params['literal.bill_title'] = ( doc.metadata['bill']['title'].encode('ascii', 'replace')) params['literal.document_name'] = doc.metadata['name'] params['literal.url'] = doc.metadata['url'] params['literal.id'] = version['document_id'] params['commit'] = 'false' url = "%supdate/extract?%s" % (solr_url, urllib.urlencode(params)) req = urllib2.Request(url, {'file': doc}) urllib2.urlopen(req)