Skip to content

Commit

Permalink
finish making basic action
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-D committed Oct 25, 2015
1 parent 2690259 commit 3f6e53e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
38 changes: 29 additions & 9 deletions Zfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ def get(self):
self.check_user()
db = self.application.db
user = self.get_current_user()
files = db.query("select * from files order by last_modify limit 10")
files = db.query("select * from files where username = %s order by last_modify",user)
self.render("disk.html", files = files, cookieName = user)
class UploadHandler(BaseHandler):
def get(self):
self.write('''
<html>
<head><title>Upload File</title></head>
<body>
<form action='file' enctype="multipart/form-data" method ='post'>
<form action='upload' enctype="multipart/form-data" method ='post'>
<input type='file' name='file'/><br/>
<input type='submit' value ='submit'/>
</form>
Expand All @@ -124,18 +124,35 @@ def post(self):
with open(filepath,'wb') as up:
up.write(meta['body'])
sql = 'insert into files(filename, fileaddress, username)values("%s","%s","%s")'%(filename, filepath, user)
db.excute(sql)
db.execute(sql)
self.redirect("/disk")
class RemoveHandler(BaseHandler):
def get(self):
def get(self,input):
self.check_user()
user = self.get_current_user()
file = self.get_argument('file_name')
os.remove(UPLOADED_FILES+"/"+ user + file)
file = input
user_path = os.path.join(UPLOADED_FILES,user)
file_path = os.path.join(user_path, file)
os.remove(file_path)
db = self.application.db
sql = 'delete from files where filename="%s" and username="%s"'%(file, user)
db.execute(sql)
self.redirect("/disk")

class DownloadHandler(BaseHandler):
def post(self):
pass

def get(self,input):
user = self.get_current_user()
file = input
user_path = os.path.join(UPLOADED_FILES,user)
file_path = os.path.join(user_path, file)
with open(file_path,'rb') as f:
while True:
data = f.read()
if not data:
break
self.write(data)
self.finish()
self.redirect("/disk")
'''
#File Action
class FileHandler(BaseHandler):
Expand Down Expand Up @@ -163,6 +180,9 @@ def __init__(self):
(r"/register", RegisterHandler),
(r"/logout", LogoutHandler),
(r"/disk", DiskHandler),
(r"/upload", UploadHandler),
(r"/download/(\w+)", DownloadHandler),
(r"/remove/(\w+)", RemoveHandler),
]
settings = dict(
template_path = TEMPLATE_PATH,
Expand Down
1 change: 1 addition & 0 deletions files/Tyler/bb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890
1 change: 1 addition & 0 deletions files/Tyler/ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890
1 change: 1 addition & 0 deletions files/hh/bb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890
1 change: 1 addition & 0 deletions files/hh/ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890
4 changes: 2 additions & 2 deletions templates/disk.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<li><a href='/' class='h4 text-primary'>首页</a></li>
<li>欢迎:{{cookieName}}</a></li>
<li><a href='/logout' class='h4 text-primary'>注销</a></li>
<li><a href='/upload' class='h4 text-primary'>上传文件</a></li>
</ul>
{%end%}
{%block content%}
<ul>
{%for i in files%}
<li><a href='/disk' class='text-success h4'>【{{i['username']}}】</a><a href='/files/{{i['username']}}/{{i['filename']}}' class='text-primary h3'>{{i['filename']}}</a></p><p class='text-muted h6'>{{i['last_modify']}}</p></li>
<li><a href='/disk/remove' class='h4 text-primary'> Remove</li>
<li><a href='/disk' class='text-success h4'>【{{i['username']}}】</a><a href='/download/{{i['filename']}}' class='text-primary h3'>{{i['filename']}} </a><a href='/remove/{{i['filename']}}' class='text-warning h6'>删除</a></p><p class='text-muted h6'>{{i['last_modify']}}</p></li>
<br/>
{%end%}
</ul>
Expand Down
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</form>
{%else%}
<li>欢迎:{{cookieName}}</a></li>
<li><a href='/disk' class='h4 text-primary'>管理文件</a></li>
<li><a href='/logout' class='h4 text-primary'>注销</a></li>
{%end%}
</ul>
Expand Down

0 comments on commit 3f6e53e

Please sign in to comment.