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
34 changes: 34 additions & 0 deletions gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/ImageDashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "ndf/base.html" %}
{% block title %} Image Gallery {% endblock %}

{% block body_content %}
<center>
<div>
<input type="text" name="imgSearch" id ="imgSearch" placeholder="Enter title to search">
<input type="submit" class="btn btn-large btn-primary" value="search" />
<form id ="imgPost" enctype="multipart/form-data" method="post" action="/ndf/uploadDoc/">{% csrf_token %}
<input type="hidden" name="stId" value={{stId}}>
<input type="hidden" name="pageUrl" value={{pageUrl}}>
<a href="{% url 'uploadDoc' %}">
<input type="submit" class="btn btn-large btn-primary" value="upload" />
</a>
</form>
</div>
</center>
<div style='display:table;'>
<div style='display:table-row;' >
{% for image in imageCollection %}
<div style='display:table-cell;'>
<a href="{% url 'getFullImage' image %}">
<img src="{% url 'getImageThumbnail' image %}"></img><br/>
<span align="center">{{image.name}}</span></a>
</div>
{% if not forloop.last and forloop.counter|divisibleby:"6" %}
</div>
<div style='display:table-row;' >
{% endif %}
{% endfor %}
</div>
</div>

{% endblock %}
2 changes: 2 additions & 0 deletions gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/UploadDoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ <h4>Submit Documents</h4>
<div style='display:table-row;' >
<div style='display:table-cell;' colspan="2">
<input type="hidden" name="user" value={{user.id}}>
<input type="hidden" name="stId" value={{stId}}>
<input type="hidden" name="mainPageUrl" value={{mainPageUrl}}>
<input type="submit" id="submitpostid" value="Upload" class="btn btn-primary btn-large btn-block">
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
{% block body_content %}

{% if user.is_authenticated %}
<a href="{% url 'uploadDoc' %}">
{#<a href="{% url 'uploadDoc' %}">
<input type="submit" class="btn btn-large btn-primary" value="Upload a {{title}}" />
</a>
</a>#}
<hr />
{% endif %}

Expand Down
7 changes: 7 additions & 0 deletions gnowsys-ndf/gnowsys_ndf/ndf/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
urlpatterns += patterns('gnowsys_ndf.ndf.views.file',
url(r'^gapp/file/(?P<file_id>[\w-]+)$', 'file', name='file'),
#url(r'^uploadDoc/$', TemplateView.as_view(template_name='ndf/UploadDoc.html')), #Direct ot html template
# url(r'^uploadDoc/(?P<pageurl>\w+)/$', 'uploadDoc', name='uploadDoc'), #Direct ot html template
url(r'^uploadDoc/$', 'uploadDoc', name='uploadDoc'), #Direct ot html template
url(r'^submitDoc/', 'submitDoc', name='submitDoc'),
url(r'^submit/', 'submitDoc', name='submitDoc'),
url(r'^documentList/', 'GetDoc', name='documentList'),
url(r'^readDoc/(?P<_id>[\w-]+)$', 'readDoc', name='read_file'),
)
urlpatterns += patterns('gnowsys_ndf.ndf.views.imageDashboard',
url(r'^gapp/image/(?P<image_id>[\w-]+)$', 'imageDashboard', name='image'),
#url(r'^images/', 'imageDashboard', name='imageDashboard'),
url(r'^imageThumbnail/(?P<_id>[\w-]+)$', 'getImageThumbnail', name='getImageThumbnail'),
url(r'^fullImage/(?P<_id>[\w-]+)$', 'getFullImage', name='getFullImage'),
)

urlpatterns += patterns('gnowsys_ndf.ndf.views.ajax-views',
url(r'^ajax/edit_collection/', 'edit_collection', name='edit_collection'),
Expand Down
39 changes: 29 additions & 10 deletions gnowsys-ndf/gnowsys_ndf/ndf/views/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,41 @@ def file(request, file_id):


def uploadDoc(request):
return render_to_response("ndf/UploadDoc.html", context_instance=RequestContext(request))
stId,mainPageUrl="",""
if request.method=="POST":
stId=request.POST.get("stId","")
mainPageUrl=request.POST.get("pageUrl","")
template="ndf/UploadDoc.html"
if stId and mainPageUrl:
variable=RequestContext(request,{'stId':stId,'mainPageUrl':mainPageUrl})
else:
print "else"
variable=RequestContext(request,{})
return render_to_response(template,variable)



def submitDoc(request):
if request.method=="POST":
title = request.POST.get("docTitle","")
userid = request.POST.get("user","")
print "userid",userid
stId = request.POST.get("stId","")
mainPageUrl = request.POST.get("mainPageUrl","")
memberOf = request.POST.get("memberOf","")
for each in request.FILES.getlist("doc[]",""):
checkmd5=save_file(each,title,userid,memberOf)
checkmd5=save_file(each,title,userid,memberOf,stId)
if (checkmd5=="True"):
return HttpResponse("File alreaday uploaded")
else:
return HttpResponseRedirect("/ndf/documentList/")

def save_file(files,title,userid,memberOf):
db=get_database()[File.collection_name]
fileobj=db.File()
return HttpResponse("File already uploaded")
if mainPageUrl:
return HttpResponseRedirect(mainPageUrl)
else:
return HttpResponseRedirect("/ndf/documentList/")

def save_file(files,title,userid,memberOf,stId):
fcol=db[File.collection_name]
print "stid",stId
fileobj=fcol.File()
#gst=gst_collection.GSystemType.one({"_id":ObjectId(stId)})
filemd5= hashlib.md5(files.read()).hexdigest()
files.seek(0)
filetype=magic.from_buffer(files.read()) #Gusing filetype by python-magic
Expand All @@ -83,6 +100,8 @@ def save_file(files,title,userid,memberOf):
fileobj.created_by=int(userid)
#fileobj.member_of=unicode(memberOf) #shuold be group
fileobj.mime_type=filetype
if stId:
fileobj.gsystem_type.append(ObjectId(stId))
fileobj.save()
files.seek(0) #moving files cursor to start
filename=files.name
Expand Down
35 changes: 35 additions & 0 deletions gnowsys-ndf/gnowsys_ndf/ndf/views/imageDashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
''' -- imports from installed packages -- '''
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import render_to_response, render
from django.template import RequestContext

from django_mongokit import get_database

try:
from bson import ObjectId
except ImportError: # old pymongo
from pymongo.objectid import ObjectId
from gnowsys_ndf.ndf.models import *

db = get_database()
collection=db[File.collection_name]
def imageDashboard(request,image_id):
imgcol=collection.File.find({'mime_type': {'$regex': 'image'}})
template="ndf/ImageDashboard.html"
url=request.get_full_path()
variable=RequestContext(request,{'imageCollection':imgcol,'pageUrl':url,'stId':image_id})
return render_to_response(template,variable)

def getImageThumbnail(request,_id):
imgobj=collection.File.one({"_id": ObjectId(_id)})
if (imgobj.fs.files.exists(imgobj.fs_file_ids[1])):
fl=imgobj.fs.files.get(ObjectId(imgobj.fs_file_ids[1]))
return HttpResponse(fl.read())


def getFullImage(request,_id):
imgobj=collection.File.one({"_id": ObjectId(_id)})
if (imgobj.fs.files.exists(imgobj.fs_file_ids[0])):
fl=imgobj.fs.files.get(ObjectId(imgobj.fs_file_ids[0]))
return HttpResponse(fl.read(),content_type=fl.content_type)
2 changes: 1 addition & 1 deletion gnowsys-ndf/gnowsys_ndf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

GAPPS = [u"Page", u"File", "Group"]
GAPPS = [u"Page", u"File", u"Group",u"Image"]

###########################################################################

Expand Down