Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d9103dc8
authored
Jan 28, 2013
by
cloud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified code style added dictionary based list parameters
parent
be2f21b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
40 deletions
+40
-40
store/models.py
+20
-20
store/templates/store/list.html
+11
-11
store/views.py
+9
-9
No files found.
store/models.py
View file @
d9103dc8
...
@@ -4,46 +4,46 @@ import json, requests, time
...
@@ -4,46 +4,46 @@ import json, requests, time
# Create your models here.
# Create your models here.
#TODO Handle exceptions locally
#TODO Handle exceptions locally
class
StoreApi
(
models
.
Model
):
class
StoreApi
(
models
.
Model
):
store_url
=
'https://store.cloud.ik.bme.hu'
#
store_url = 'https://store.cloud.ik.bme.hu'
#
store_url = 'http://store.cloud.ik.bme.hu:8080'
store_url
=
'http://store.cloud.ik.bme.hu:8080'
store_user
=
'admin'
store_user
=
'admin'
store_password
=
'IQu8Eice'
store_password
=
'IQu8Eice'
basic_auth
=
True
basic_auth
=
True
verify_ssl
=
False
verify_ssl
=
False
@staticmethod
@staticmethod
def
ListFolder
(
neptun
,
path
):
def
listfolder
(
neptun
,
path
):
url
=
StoreApi
.
store_url
+
'/'
+
neptun
url
=
StoreApi
.
store_url
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'LIST'
,
'PATH'
:
path
})
payload
=
json
.
dumps
({
'CMD'
:
'LIST'
,
'PATH'
:
path
})
headers
=
{
'content-type'
:
'application/json'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
if
r
.
status_code
==
requests
.
codes
.
ok
:
tupplelist
=
json
.
loads
(
r
.
content
)
tupplelist
=
json
.
loads
(
r
.
content
)
for
item
in
tupplelist
:
for
item
in
tupplelist
:
item
[
3
]
=
time
.
ctime
(
item
[
3
])
item
[
'MTIME'
]
=
time
.
ctime
(
item
[
'MTIME'
])
return
tupplelist
return
tupplelist
else
:
else
:
raise
Http404
raise
Http404
@staticmethod
@staticmethod
def
RequestDownload
(
neptun
,
path
):
def
requestdownload
(
neptun
,
path
):
url
=
StoreApi
.
store_url
+
'/'
+
neptun
url
=
StoreApi
.
store_url
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'DOWNLOAD'
,
'PATH'
:
path
})
payload
=
json
.
dumps
({
'CMD'
:
'DOWNLOAD'
,
'PATH'
:
path
})
headers
=
{
'content-type'
:
'application/json'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
response
=
json
.
loads
(
r
.
content
)
response
=
json
.
loads
(
r
.
content
)
return
response
[
'LINK'
]
return
response
[
'LINK'
]
@staticmethod
@staticmethod
def
RequestUpload
(
neptun
,
path
):
def
requestupload
(
neptun
,
path
):
url
=
StoreApi
.
store_url
+
'/'
+
neptun
url
=
StoreApi
.
store_url
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'UPLOAD'
,
'PATH'
:
path
})
payload
=
json
.
dumps
({
'CMD'
:
'UPLOAD'
,
'PATH'
:
path
})
headers
=
{
'content-type'
:
'application/json'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
response
=
json
.
loads
(
r
.
content
)
response
=
json
.
loads
(
r
.
content
)
...
@@ -52,12 +52,12 @@ class StoreApi(models.Model):
...
@@ -52,12 +52,12 @@ class StoreApi(models.Model):
else
:
else
:
raise
Http404
raise
Http404
@staticmethod
@staticmethod
def
RequestRemove
(
neptun
,
path
):
def
requestremove
(
neptun
,
path
):
url
=
StoreApi
.
store_url
+
'/'
+
neptun
url
=
StoreApi
.
store_url
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'REMOVE'
,
'PATH'
:
path
})
payload
=
json
.
dumps
({
'CMD'
:
'REMOVE'
,
'PATH'
:
path
})
headers
=
{
'content-type'
:
'application/json'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
if
r
.
status_code
==
requests
.
codes
.
ok
:
...
@@ -65,12 +65,12 @@ class StoreApi(models.Model):
...
@@ -65,12 +65,12 @@ class StoreApi(models.Model):
else
:
else
:
return
False
return
False
@staticmethod
@staticmethod
def
RequestNewFolder
(
neptun
,
path
):
def
requestnewfolder
(
neptun
,
path
):
url
=
StoreApi
.
store_url
+
'/'
+
neptun
url
=
StoreApi
.
store_url
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'NEW_FOLDER'
,
'PATH'
:
path
})
payload
=
json
.
dumps
({
'CMD'
:
'NEW_FOLDER'
,
'PATH'
:
path
})
headers
=
{
'content-type'
:
'application/json'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
if
r
.
status_code
==
requests
.
codes
.
ok
:
...
@@ -78,7 +78,7 @@ class StoreApi(models.Model):
...
@@ -78,7 +78,7 @@ class StoreApi(models.Model):
else
:
else
:
return
False
return
False
@staticmethod
@staticmethod
def
UserE
xist
(
neptun
):
def
usere
xist
(
neptun
):
url
=
StoreApi
.
store_url
+
'/'
+
neptun
url
=
StoreApi
.
store_url
+
'/'
+
neptun
if
StoreApi
.
basic_auth
:
if
StoreApi
.
basic_auth
:
r
=
requests
.
get
(
url
,
auth
=
(
StoreApi
.
store_user
,
StoreApi
.
store_password
),
verify
=
StoreApi
.
verify_ssl
)
r
=
requests
.
get
(
url
,
auth
=
(
StoreApi
.
store_user
,
StoreApi
.
store_password
),
verify
=
StoreApi
.
verify_ssl
)
...
@@ -89,12 +89,12 @@ class StoreApi(models.Model):
...
@@ -89,12 +89,12 @@ class StoreApi(models.Model):
else
:
else
:
return
False
return
False
@staticmethod
@staticmethod
def
CreateUser
(
neptun
,
password
,
key_list
):
def
createuser
(
neptun
,
password
,
key_list
):
url
=
StoreApi
.
store_url
+
'/new/'
+
neptun
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'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
if
r
.
status_code
==
requests
.
codes
.
ok
:
...
@@ -102,12 +102,12 @@ class StoreApi(models.Model):
...
@@ -102,12 +102,12 @@ class StoreApi(models.Model):
else
:
else
:
return
False
return
False
@staticmethod
@staticmethod
def
UpdateAuthorizationInfo
(
neptun
,
password
,
key_list
):
def
updateauthorizationinfo
(
neptun
,
password
,
key_list
):
url
=
StoreApi
.
store_url
+
'/set/'
+
neptun
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'
}
headers
=
{
'content-type'
:
'application/json'
}
if
StoreApi
.
basic_auth
:
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
:
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
if
r
.
status_code
==
requests
.
codes
.
ok
:
...
...
store/templates/store/list.html
View file @
d9103dc8
...
@@ -53,29 +53,29 @@
...
@@ -53,29 +53,29 @@
{% for item in file_list %}
{% for item in file_list %}
<tr>
<tr>
<td>
<td>
{% if item.
1
== 'D' %}
{% if item.
TYPE
== 'D' %}
<form
action=
"/store/"
method=
"POST"
>
{% csrf_token %}
<form
action=
"/store/"
method=
"POST"
>
{% csrf_token %}
<input
type=
"submit"
value=
"{{ item.
0
}}"
>
<input
type=
"submit"
value=
"{{ item.
NAME
}}"
>
{% if item.
0
!= '/' %}
{% if item.
NAME
!= '/' %}
<input
type=
"hidden"
name=
"path"
value=
"{{ path }}{{ item.
0
}}/"
>
<input
type=
"hidden"
name=
"path"
value=
"{{ path }}{{ item.
NAME
}}/"
>
{% else %}
{% else %}
<input
type=
"hidden"
name=
"path"
value=
"/"
>
<input
type=
"hidden"
name=
"path"
value=
"/"
>
{% endif %}
{% endif %}
</form>
</form>
{% else %}
{% else %}
{{ item.
0
}}
{{ item.
NAME
}}
{% endif %}
{% endif %}
</td>
</td>
<td>
{{ item.
1
}}
</td>
<td>
{{ item.
TYPE
}}
</td>
<td>
{{ item.
2
}}
</td>
<td>
{{ item.
SIZE
}}
</td>
<td>
{{ item.
3
}}
</td>
<td>
{{ item.
MTIME
}}
</td>
<td>
<td>
{% if item.
1
!= 'D' %}
{% if item.
TYPE
!= 'D' %}
<form
action=
"/store/"
method=
"POST"
>
{% csrf_token %}
<form
action=
"/store/"
method=
"POST"
>
{% csrf_token %}
<input
type=
"submit"
value=
"Download"
>
<input
type=
"submit"
value=
"Download"
>
<input
type=
"hidden"
name=
"path"
value=
"{{ path }}"
>
<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>
</form>
{% endif %}
{% endif %}
</td>
</td>
...
@@ -83,7 +83,7 @@
...
@@ -83,7 +83,7 @@
<form
action=
"/store/"
method=
"POST"
>
{% csrf_token %}
<form
action=
"/store/"
method=
"POST"
>
{% csrf_token %}
<input
type=
"submit"
value=
"Remove"
>
<input
type=
"submit"
value=
"Remove"
>
<input
type=
"hidden"
name=
"path"
value=
"{{ path }}"
>
<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>
</form>
</td>
</td>
</tr>
</tr>
...
...
store/views.py
View file @
d9103dc8
...
@@ -18,41 +18,41 @@ def index(request):
...
@@ -18,41 +18,41 @@ def index(request):
key_list
.
append
(
key
.
key
)
key_list
.
append
(
key
.
key
)
except
:
except
:
return
HttpResponse
(
'Can not acces to django database!'
)
return
HttpResponse
(
'Can not acces to django database!'
)
if
StoreApi
.
UserE
xist
(
user
)
!=
True
:
if
StoreApi
.
usere
xist
(
user
)
!=
True
:
#Create user
#Create user
if
not
StoreApi
.
CreateU
ser
(
user
,
password
,
key_list
):
if
not
StoreApi
.
createu
ser
(
user
,
password
,
key_list
):
return
HttpResponse
(
'User does not exist on store! And could not create!'
)
return
HttpResponse
(
'User does not exist on store! And could not create!'
)
#UpdateAuthorizationInfo
#UpdateAuthorizationInfo
try
:
try
:
auth
=
request
.
POST
[
'auth'
]
auth
=
request
.
POST
[
'auth'
]
if
not
StoreApi
.
UpdateAuthorizationI
nfo
(
user
,
password
,
key_list
):
if
not
StoreApi
.
updateauthorizationi
nfo
(
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
.
RequestD
ownload
(
user
,
dl
))
return
redirect
(
StoreApi
.
requestd
ownload
(
user
,
dl
))
except
:
except
:
pass
pass
#Upload handler
#Upload handler
try
:
try
:
ul
=
request
.
POST
[
'ul'
]
ul
=
request
.
POST
[
'ul'
]
url
=
StoreApi
.
RequestU
pload
(
user
,
ul
)
url
=
StoreApi
.
requestu
pload
(
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
.
RequestR
emove
(
user
,
rm
)
succes
=
StoreApi
.
requestr
emove
(
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
.
RequestNewF
older
(
user
,
path
+
'/'
+
new
)
succes
=
StoreApi
.
requestnewf
older
(
user
,
path
+
'/'
+
new
)
except
:
except
:
pass
pass
#Simple file list
#Simple file list
...
@@ -63,8 +63,8 @@ def index(request):
...
@@ -63,8 +63,8 @@ def index(request):
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
.
ListF
older
(
user
,
path
)
file_list
=
StoreApi
.
listf
older
(
user
,
path
)
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
}))
def
logout
(
request
):
def
logout
(
request
):
auth
.
logout
(
request
)
auth
.
logout
(
request
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment