Commit ca125a86 by Kálmán Viktor

store: fixing pep8 errors

parent 272416ba
# Create your views here. # Create your views here.
from django.core.context_processors import csrf
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect from django.shortcuts import render_to_response, redirect
from django.template import RequestContext from django.template import RequestContext
from store.api import StoreApi from store.api import StoreApi
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User from django.contrib import auth
from django.views.decorators.csrf import csrf_exempt
import os import os
import json import json
import base64 import base64
def estabilish_store_user(request, user): def estabilish_store_user(request, user):
try: try:
details = request.user.cloud_details details = request.user.cloud_details
...@@ -21,18 +20,19 @@ def estabilish_store_user(request, user): ...@@ -21,18 +20,19 @@ def estabilish_store_user(request, user):
key_list.append(key.key) key_list.append(key.key)
except: except:
return HttpResponse('Can not acces to django database!', status=404) return HttpResponse('Can not acces to django database!', status=404)
#Create user # Create user
if not StoreApi.createuser(user, password, key_list, str(quota)): if not StoreApi.createuser(user, password, key_list, str(quota)):
return HttpResponse('User does not exist on store! And could not create!') return HttpResponse('User does not exist on store!'
'And could not create!')
@login_required @login_required
def index(request): def index(request):
user = request.user.username user = request.user.username
if StoreApi.userexist(user) != True: if StoreApi.userexist(user) is not True:
estabilish_store_user(request, user) estabilish_store_user(request, user)
#UpdateAuthorizationInfo # UpdateAuthorizationInfo
try: try:
auth=request.POST['auth']
try: try:
details = request.user.cloud_details details = request.user.cloud_details
password = details.smb_password password = details.smb_password
...@@ -40,146 +40,181 @@ def index(request): ...@@ -40,146 +40,181 @@ def index(request):
for key in request.user.sshkey_set.all(): for key in request.user.sshkey_set.all():
key_list.append(key.key) key_list.append(key.key)
except: except:
return HttpResponse('Can not acces to django database!', status=404) return HttpResponse('Can not acces to django database!',
status=404)
if not StoreApi.updateauthorizationinfo(user, password, key_list): if not StoreApi.updateauthorizationinfo(user, password, key_list):
return HttpResponse('Can not update authorization information!') return HttpResponse('Can not update authorization information!')
except: except:
pass pass
#Download handler # Download handler
try: try:
dl = request.POST['dl'] dl = request.POST['dl']
return redirect(StoreApi.requestdownload(user, dl)) return redirect(StoreApi.requestdownload(user, dl))
except: except:
pass pass
#Upload handler # Upload handler
try: try:
ul = request.POST['ul'] ul = request.POST['ul']
url = StoreApi.requestupload(user,ul) url = StoreApi.requestupload(user, ul)
return render_to_response('store/upload.html', RequestContext(request,{'URL' : url})) return render_to_response('store/upload.html',
RequestContext(request, {'URL': url}))
except: except:
pass pass
#Remove handler # Remove handler
try: try:
rm = request.POST['rm'] rm = request.POST['rm']
succes = StoreApi.requestremove(user,rm) StoreApi.requestremove(user, rm)
except: except:
pass pass
#Remove handler # Remove handler
try: try:
path = request.POST['path'] path = request.POST['path']
new = request.POST['new'] new = request.POST['new']
succes = StoreApi.requestnewfolder(user,path+'/'+new) StoreApi.requestnewfolder(user, path + '/' + new)
except: except:
pass pass
#Simple file list # Simple file list
path = '/' path = '/'
try: try:
path = request.POST['path'] path = request.POST['path']
except: except:
pass pass
#Normalize path (Need double dirname /folder/ -> /folder -> / # Normalize path (Need double dirname /folder/ -> /folder -> /
backpath = os.path.normpath(os.path.dirname(os.path.dirname(path))) backpath = os.path.normpath(os.path.dirname(os.path.dirname(path)))
file_list = StoreApi.listfolder(user,path) file_list = StoreApi.listfolder(user, path)
quota = StoreApi.requestquota(user) quota = StoreApi.requestquota(user)
return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user, 'quota' : quota})) return render_to_response('store/list.html',
RequestContext(request,
{
'file_list': file_list,
'path': path,
'backpath': backpath,
'username': user,
'quota': quota
}
))
@login_required @login_required
def ajax_listfolder(request): def ajax_listfolder(request):
user = request.user.username user = request.user.username
if StoreApi.userexist(user) != True: if StoreApi.userexist(user) is not True:
estabilish_store_user(request, user) estabilish_store_user(request, user)
path = '/' path = '/'
try: try:
path = request.POST['path'] path = request.POST['path']
except: except:
pass pass
#Normalize path (Need double dirname /folder/ -> /folder -> / # Normalize path (Need double dirname /folder/ -> /folder -> /
backpath = os.path.normpath(os.path.dirname(os.path.dirname(path))) # backpath = os.path.normpath(os.path.dirname(os.path.dirname(path)))
file_list = StoreApi.listfolder(user,path) file_list = StoreApi.listfolder(user, path)
return HttpResponse(json.dumps(file_list)) return HttpResponse(json.dumps(file_list))
@login_required @login_required
def ajax_quota(request): def ajax_quota(request):
user = request.user.username user = request.user.username
if StoreApi.userexist(user) != True: if StoreApi.userexist(user) is not True:
estabilish_store_user(request, user) estabilish_store_user(request, user)
return HttpResponse(json.dumps(StoreApi.requestquota(user))) return HttpResponse(json.dumps(StoreApi.requestquota(user)))
#return HttpResponse(json.dumps({'Used':20,'Soft':160,'Hard':200})) # return HttpResponse(json.dumps({'Used':20,'Soft':160,'Hard':200}))
@login_required @login_required
def ajax_download(request): def ajax_download(request):
user = request.user.username user = request.user.username
try: try:
dl = request.POST['dl'] dl = request.POST['dl']
return HttpResponse(json.dumps({'url':StoreApi.requestdownload(user,dl)})) return HttpResponse(json.dumps(
{'url': StoreApi.requestdownload(user, dl)}))
except: except:
pass pass
return HttpResponse('File not found!', status=404) return HttpResponse('File not found!', status=404)
@login_required @login_required
def ajax_upload(request): def ajax_upload(request):
user = request.user.username user = request.user.username
try: try:
ul = request.POST['ul'] ul = request.POST['ul']
url = StoreApi.requestupload(user,ul) url = StoreApi.requestupload(user, ul)
return HttpResponse(json.dumps({'url':url})) return HttpResponse(json.dumps({'url': url}))
except: except:
pass pass
return HttpResponse('Error!', status=404) return HttpResponse('Error!', status=404)
@login_required @login_required
def ajax_delete(request): def ajax_delete(request):
user = request.user.username user = request.user.username
try: try:
rm = request.POST['rm'] rm = request.POST['rm']
return HttpResponse(json.dumps({'success':StoreApi.requestremove(user,rm)})) return HttpResponse(json.dumps(
{'success': StoreApi.requestremove(user, rm)}))
except: except:
pass pass
return HttpResponse('File not found!', status=404) return HttpResponse('File not found!', status=404)
@login_required @login_required
def ajax_new_folder(request): def ajax_new_folder(request):
user = request.user.username user = request.user.username
try: try:
path = request.POST['path'] path = request.POST['path']
new = request.POST['new'] new = request.POST['new']
success = StoreApi.requestnewfolder(user,path+'/'+new) success = StoreApi.requestnewfolder(user, path + '/' + new)
return HttpResponse(json.dumps({'success':success})) return HttpResponse(json.dumps({'success': success}))
except: except:
pass pass
return HttpResponse('Error!', status=404) return HttpResponse('Error!', status=404)
@login_required @login_required
def ajax_rename(request): def ajax_rename(request):
user = request.user.username user = request.user.username
try: try:
path = request.POST['path'] path = request.POST['path']
new = request.POST['new'] new = request.POST['new']
success = StoreApi.requestrename(user,path,new) success = StoreApi.requestrename(user, path, new)
return HttpResponse(json.dumps({'success':success})) return HttpResponse(json.dumps({'success': success}))
except: except:
pass pass
return HttpResponse('Error!', status=404) return HttpResponse('Error!', status=404)
@login_required @login_required
def toplist(request): def toplist(request):
user = request.user.username user = request.user.username
path = backpath = '/' path = backpath = '/'
file_list = StoreApi.toplist(user) file_list = StoreApi.toplist(user)
return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user})) return render_to_response('store/list.html',
RequestContext(request,
{
'file_list': file_list,
'path': path,
'backpath': backpath,
'username': user
}))
@login_required @login_required
def ajax_toplist(request): def ajax_toplist(request):
user = request.user.username user = request.user.username
path = backpath = '/'
file_list = StoreApi.toplist(user) file_list = StoreApi.toplist(user)
return HttpResponse(json.dumps(file_list)) return HttpResponse(json.dumps(file_list))
@login_required @login_required
def gui(request): def gui(request):
user = request.user.username user = request.user.username
if request.method == 'GET': if request.method == 'GET':
return render_to_response('store/gui.html', RequestContext(request, {'username' : user, 'host' : StoreApi.get_host()})) return render_to_response('store/gui.html',
RequestContext(
request,
{
'username': user,
'host': StoreApi.get_host()
}))
elif request.method == 'POST': elif request.method == 'POST':
try: try:
details = request.user.cloud_details details = request.user.cloud_details
...@@ -188,7 +223,8 @@ def gui(request): ...@@ -188,7 +223,8 @@ def gui(request):
for key in request.user.sshkey_set.all(): for key in request.user.sshkey_set.all():
key_list.append(key.key) key_list.append(key.key)
except: except:
return HttpResponse('Can not acces to django database!', status=404) return HttpResponse('Can not acces to django database!',
status=404)
try: try:
lab_key_decoded = base64.b64decode(request.POST['KEY']) lab_key_decoded = base64.b64decode(request.POST['KEY'])
key_list.append(lab_key_decoded) key_list.append(lab_key_decoded)
...@@ -196,14 +232,18 @@ def gui(request): ...@@ -196,14 +232,18 @@ def gui(request):
if StoreApi.updateauthorizationinfo(user, password, key_list): if StoreApi.updateauthorizationinfo(user, password, key_list):
return HttpResponse('Keys resetted succesfully!') return HttpResponse('Keys resetted succesfully!')
else: else:
return HttpResponse('Can not update authorization information!') return HttpResponse('Can not update authorization '
'information!')
if StoreApi.updateauthorizationinfo(user, password, key_list): if StoreApi.updateauthorizationinfo(user, password, key_list):
return HttpResponse('https://cloud.ik.bme.hu/home/'+'?neptun='+user+'&'+'host='+StoreApi.get_host()) return HttpResponse('https://cloud.ik.bme.hu/home/' +
'?neptun=' + user + '&' + 'host=' +
StoreApi.get_host())
else: else:
return HttpResponse('Can not update authorization information!') return HttpResponse('Can not update authorization information!')
else: else:
return HttpResponse('Method not found!', status=404) return HttpResponse('Method not found!', status=404)
def logout(request): def logout(request):
auth.logout(request) auth.logout(request)
return redirect('/') return redirect('/')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment