upload file: save a copy in ./upload/%Y/%M/%D/. TODO: distinguish userID

pull/26/head
liuzheng712 2015-11-06 00:56:16 +08:00
parent 12a0a35adf
commit 7a25f348e4
2 changed files with 28 additions and 0 deletions

View File

@ -355,3 +355,25 @@ def Logout(request):
# result = {'auth': {'username': username, 'result': 'failed'}}
#
# return HttpResponse(json.dumps(result, sort_keys=True, indent=2), content_type='application/json')
def upload(request):
if request.method == 'GET':
machines = [{'name':'aaa'}]
return render_to_response('upload.html', locals(), context_instance=RequestContext(request))
elif request.method == 'POST':
from juser.models import Document
upload_files = request.FILES.getlist('file[]', None)
# form = DocumentForm(request.POST, request.FILES)
# if form.is_valid():
# for upload_file in upload_files:
print request.FILES
for file in upload_files:
print file
newdoc = Document(docfile=file, user_id=request.user.id)
newdoc.save()
return HttpResponse("success")
else:
return HttpResponse("ERROR")
def download(request):
return render_to_response('download.html', locals(), context_instance=RequestContext(request))

View File

@ -124,3 +124,9 @@ class AdminGroup(models.Model):
def __unicode__(self):
return '%s: %s' % (self.user.username, self.group.name)
class Document(models.Model):
# TODO: upload path with userID
docfile = models.FileField(upload_to='upload/%Y/%m/%d')
user = models.ForeignKey(User)