add upload

This commit is contained in:
j 2013-02-12 18:49:31 +05:30
parent c8a454dcfa
commit 3f2e6c348a
3 changed files with 24 additions and 7 deletions

View file

@ -57,6 +57,7 @@ def add(request):
request.session.save() request.session.save()
request.session.modified = True request.session.modified = True
file = models.Item() file = models.Item()
file.user = request.user
file.filename = request.POST.get('name', '') file.filename = request.POST.get('name', '')
file.uploader = request.session.session_key file.uploader = request.session.session_key
file.save() file.save()
@ -70,6 +71,7 @@ def add(request):
if 'file' in request.FILES: if 'file' in request.FILES:
new_file = request.FILES['file'] new_file = request.FILES['file']
file = models.Item(filename=new_file.name) file = models.Item(filename=new_file.name)
file.user = request.user
file.done = True file.done = True
file.file.save(new_file.name, new_file) file.file.save(new_file.name, new_file)
os.chmod(file.file.path, 0644) os.chmod(file.file.path, 0644)
@ -83,6 +85,7 @@ def add(request):
def index(request): def index(request):
context = RequestContext(request, { context = RequestContext(request, {
'anonymous': request.user.is_anonymous()
}) })
return render_to_response('index.html', context) return render_to_response('index.html', context)

View file

@ -1,11 +1,25 @@
<!DOCTYPE HTML> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8" /> <title>generic one click host</title>
<title></title> <script src="/static/js/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/static/css/videopdf.css"/> <script src="/static/js/chunkupload.js" type="text/javascript"></script>
<script src="/static/js/upload.js?1" type="text/javascript"></script>
</head> </head>
<body> <body>
<h1>videopdf</h1>
{% if anonymous %}
<div>
you need an account
</div>
{% else %}
<div>
<div id='status'></div>
<form id="addFile">
<input id="file" name="file" type="file" value="Select File.." />
<input id="upload" type="button" value="Upload" style="display: none" />
</form>
</div>
{% endif %}
</body> </body>
</html> </html>

View file

@ -94,7 +94,7 @@ TEMPLATE_LOADERS = (
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', #'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection: # Uncomment the next line for simple clickjacking protection: