Commit d9103dc8 by cloud

Modified code style added dictionary based list parameters

parent be2f21b2
......@@ -4,46 +4,46 @@ import json, requests, time
# Create your models here.
#TODO Handle exceptions locally
class StoreApi(models.Model):
store_url = 'https://store.cloud.ik.bme.hu'
# store_url = 'http://store.cloud.ik.bme.hu:8080'
# store_url = 'https://store.cloud.ik.bme.hu'
store_url = 'http://store.cloud.ik.bme.hu:8080'
store_user = 'admin'
store_password = 'IQu8Eice'
basic_auth = True
verify_ssl = False
@staticmethod
def ListFolder(neptun,path):
def listfolder(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'LIST', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content)
for item in tupplelist:
item[3] = time.ctime(item[3])
item['MTIME'] = time.ctime(item['MTIME'])
return tupplelist
else:
raise Http404
@staticmethod
def RequestDownload(neptun,path):
def requestdownload(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'DOWNLOAD', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
response = json.loads(r.content)
return response['LINK']
@staticmethod
def RequestUpload(neptun,path):
def requestupload(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'UPLOAD', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
response = json.loads(r.content)
......@@ -52,12 +52,12 @@ class StoreApi(models.Model):
else:
raise Http404
@staticmethod
def RequestRemove(neptun,path):
def requestremove(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'REMOVE', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
......@@ -65,12 +65,12 @@ class StoreApi(models.Model):
else:
return False
@staticmethod
def RequestNewFolder(neptun,path):
def requestnewfolder(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'NEW_FOLDER', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
......@@ -78,7 +78,7 @@ class StoreApi(models.Model):
else:
return False
@staticmethod
def UserExist(neptun):
def userexist(neptun):
url = StoreApi.store_url+'/'+neptun
if StoreApi.basic_auth:
r = requests.get(url, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
......@@ -89,12 +89,12 @@ class StoreApi(models.Model):
else:
return False
@staticmethod
def CreateUser(neptun,password,key_list):
def createuser(neptun, password, key_list):
url = StoreApi.store_url+'/new/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password,'KEYS' : key_list })
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
......@@ -102,12 +102,12 @@ class StoreApi(models.Model):
else:
return False
@staticmethod
def UpdateAuthorizationInfo(neptun,password,key_list):
def updateauthorizationinfo(neptun, password, key_list):
url = StoreApi.store_url+'/set/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password,'KEYS' : key_list })
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
......
......@@ -53,29 +53,29 @@
{% for item in file_list %}
<tr>
<td>
{% if item.1 == 'D' %}
{% if item.TYPE == 'D' %}
<form action="/store/" method="POST">{% csrf_token %}
<input type="submit" value="{{ item.0 }}">
{% if item.0 != '/' %}
<input type="hidden" name="path" value="{{ path }}{{ item.0 }}/">
<input type="submit" value="{{ item.NAME }}">
{% if item.NAME != '/' %}
<input type="hidden" name="path" value="{{ path }}{{ item.NAME }}/">
{% else %}
<input type="hidden" name="path" value="/">
{% endif %}
</form>
{% else %}
{{ item.0 }}
{{ item.NAME }}
{% endif %}
</td>
<td>{{ item.1 }}</td>
<td>{{ item.2 }}</td>
<td>{{ item.3 }}</td>
<td>{{ item.TYPE }}</td>
<td>{{ item.SIZE }}</td>
<td>{{ item.MTIME }}</td>
<td>
{% if item.1 != 'D' %}
{% if item.TYPE != 'D' %}
<form action="/store/" method="POST">{% csrf_token %}
<input type="submit" value="Download">
<input type="hidden" name="path" value="{{ path }}">
<input type="hidden" name="dl" value="{{ path }}{{ item.0 }}">
<input type="hidden" name="dl" value="{{ path }}{{ item.NAME }}">
</form>
{% endif %}
</td>
......@@ -83,7 +83,7 @@
<form action="/store/" method="POST">{% csrf_token %}
<input type="submit" value="Remove">
<input type="hidden" name="path" value="{{ path }}">
<input type="hidden" name="rm" value="{{ path }}{{ item.0 }}">
<input type="hidden" name="rm" value="{{ path }}{{ item.NAME }}">
</form>
</td>
</tr>
......
......@@ -18,41 +18,41 @@ def index(request):
key_list.append(key.key)
except:
return HttpResponse('Can not acces to django database!')
if StoreApi.UserExist(user) != True:
if StoreApi.userexist(user) != True:
#Create user
if not StoreApi.CreateUser(user,password,key_list):
if not StoreApi.createuser(user,password,key_list):
return HttpResponse('User does not exist on store! And could not create!')
#UpdateAuthorizationInfo
try:
auth=request.POST['auth']
if not StoreApi.UpdateAuthorizationInfo(user,password,key_list):
if not StoreApi.updateauthorizationinfo(user,password,key_list):
return HttpResponse('Can not update authorization information!')
except:
pass
#Download handler
try:
dl = request.POST['dl']
return redirect(StoreApi.RequestDownload(user,dl))
return redirect(StoreApi.requestdownload(user,dl))
except:
pass
#Upload handler
try:
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}))
except:
pass
#Remove handler
try:
rm = request.POST['rm']
succes = StoreApi.RequestRemove(user,rm)
succes = StoreApi.requestremove(user,rm)
except:
pass
#Remove handler
try:
path = request.POST['path']
new = request.POST['new']
succes = StoreApi.RequestNewFolder(user,path+'/'+new)
succes = StoreApi.requestnewfolder(user,path+'/'+new)
except:
pass
#Simple file list
......@@ -63,8 +63,8 @@ def index(request):
pass
#Normalize path (Need double dirname /folder/ -> /folder -> /
backpath = os.path.normpath(os.path.dirname(os.path.dirname(path)))
file_list = StoreApi.ListFolder(user,path)
return render_to_response('store/list.html', RequestContext(request,{'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user}))
file_list = StoreApi.listfolder(user,path)
return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user}))
def logout(request):
auth.logout(request)
......
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