Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/DocumentList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "ndf/base.html" %}
{% block title %} List of Documents {% endblock %}
{% block body_content %}

<table border="1">
<tr>
<th>File Name</th>
<th>View</th>
</tr>
{% for doc in filecollection %}
<tr>
<td>{{doc.name}}</td>
<td><a href="{% url 'read_file' doc %}">view</a></td>

<tr/>
{% endfor %}

</table>
{% endblock %}
9 changes: 6 additions & 3 deletions gnowsys-ndf/gnowsys_ndf/ndf/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
url(r'^create_wiki/', views.create_wiki, name='create_wiki'),
url(r'^wikipage/', views.wikipage, name='wikipage'),
url(r'^delete/(?P<_id>[\w-]+)$', views.delete_node, name='delete_node'),
url(r'^uploadDoc/$', TemplateView.as_view(template_name='ndf/UploadDoc.html')),#Direct ot html template
url(r'^submitDoc/', views.submitDoc, name='submitDoc'),
url(r'^submit/', views.submitDoc, name='submitDoc')

url(r'^uploadDoc/$', TemplateView.as_view(template_name='ndf/UploadDoc.html')),#Direct ot html template
url(r'^submitDoc/', views.submitDoc, name='submitDoc'),
url(r'^submit/', views.submitDoc, name='submitDoc'),
url(r'^documentList/', views.GetDoc, name='documentList'),
url(r'^readDoc/(?P<_id>[\w-]+)$', views.readDoc, name='read_file'),
)
19 changes: 18 additions & 1 deletion gnowsys-ndf/gnowsys_ndf/ndf/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ def submitDoc(request):
filetype=magic.from_buffer(files.read()) #Gusing filetype by python-magic
print "test",title,user,memberOf
#this code is for storing Document in gridfs
files.seek(0) #moving files cursor to start
objectid=fileobj.fs.files.put(files.read(),filename=title,content_type=filetype)
#files.seek(0)
#print "fileread:",files.read()
#print "objectid:",objectid
return HttpResponse("File uploaded succesfully and your object id:"+str(objectid))
return HttpResponseRedirect("/ndf/documentList/")
#return HttpResponse("File uploaded succesfully and your object id:"+str(objectid))

def GetDoc(request):
filecollection=get_database()[File.collection_name]
files=filecollection.File.find()
template="ndf/DocumentList.html"
variable=RequestContext(request,{'filecollection':files})
return render_to_response(template,variable)

def readDoc(request,_id):
filecollection=get_database()[File.collection_name]
fileobj=filecollection.File.one({"_id": ObjectId(_id)})
fl=fileobj.fs.files.get_last_version(fileobj.name)
return HttpResponse(fl.read(),content_type=fl.content_type)