From 7a25f348e48fdde9a6f9f6f60479aa2d6cd9c2a6 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 6 Nov 2015 00:56:16 +0800 Subject: [PATCH] upload file: save a copy in ./upload/%Y/%M/%D/. TODO: distinguish userID --- jumpserver/views.py | 22 ++++++++++++++++++++++ juser/models.py | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/jumpserver/views.py b/jumpserver/views.py index 379a35489..2e5b1e519 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -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)) \ No newline at end of file diff --git a/juser/models.py b/juser/models.py index c030b8454..65f7908f1 100644 --- a/juser/models.py +++ b/juser/models.py @@ -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)