Skip to content

Commit e0f7cca

Browse files
committed
Merge pull request #18 from krishna31/mongokit
Basic implementation of gridfs with uploading file and retriving file on browser
2 parents 4da6a77 + 0ae5640 commit e0f7cca

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "ndf/base.html" %}
2+
{% block title %} List of Documents {% endblock %}
3+
{% block body_content %}
4+
5+
<table border="1">
6+
<tr>
7+
<th>File Name</th>
8+
<th>View</th>
9+
</tr>
10+
{% for doc in filecollection %}
11+
<tr>
12+
<td>{{doc.name}}</td>
13+
<td><a href="{% url 'read_file' doc %}">view</a></td>
14+
15+
<tr/>
16+
{% endfor %}
17+
18+
</table>
19+
{% endblock %}

gnowsys-ndf/gnowsys_ndf/ndf/urls.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
url(r'^create_wiki/', views.create_wiki, name='create_wiki'),
1111
url(r'^wikipage/', views.wikipage, name='wikipage'),
1212
url(r'^delete/(?P<_id>[\w-]+)$', views.delete_node, name='delete_node'),
13-
url(r'^uploadDoc/$', TemplateView.as_view(template_name='ndf/UploadDoc.html')),#Direct ot html template
14-
url(r'^submitDoc/', views.submitDoc, name='submitDoc'),
15-
url(r'^submit/', views.submitDoc, name='submitDoc')
13+
14+
url(r'^uploadDoc/$', TemplateView.as_view(template_name='ndf/UploadDoc.html')),#Direct ot html template
15+
url(r'^submitDoc/', views.submitDoc, name='submitDoc'),
16+
url(r'^submit/', views.submitDoc, name='submitDoc'),
17+
url(r'^documentList/', views.GetDoc, name='documentList'),
18+
url(r'^readDoc/(?P<_id>[\w-]+)$', views.readDoc, name='read_file'),
1619
)

gnowsys-ndf/gnowsys_ndf/ndf/views.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ def submitDoc(request):
100100
filetype=magic.from_buffer(files.read()) #Gusing filetype by python-magic
101101
print "test",title,user,memberOf
102102
#this code is for storing Document in gridfs
103+
files.seek(0) #moving files cursor to start
103104
objectid=fileobj.fs.files.put(files.read(),filename=title,content_type=filetype)
105+
#files.seek(0)
106+
#print "fileread:",files.read()
104107
#print "objectid:",objectid
105-
return HttpResponse("File uploaded succesfully and your object id:"+str(objectid))
108+
return HttpResponseRedirect("/ndf/documentList/")
109+
#return HttpResponse("File uploaded succesfully and your object id:"+str(objectid))
110+
111+
def GetDoc(request):
112+
filecollection=get_database()[File.collection_name]
113+
files=filecollection.File.find()
114+
template="ndf/DocumentList.html"
115+
variable=RequestContext(request,{'filecollection':files})
116+
return render_to_response(template,variable)
117+
118+
def readDoc(request,_id):
119+
filecollection=get_database()[File.collection_name]
120+
fileobj=filecollection.File.one({"_id": ObjectId(_id)})
121+
fl=fileobj.fs.files.get_last_version(fileobj.name)
122+
return HttpResponse(fl.read(),content_type=fl.content_type)

0 commit comments

Comments
 (0)