Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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
# 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
UserE
xist
(
neptun
):
def
usere
xist
(
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
:
...
...
store/templates/store/list.html
View file @
d9103dc8
...
...
@@ -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>
...
...
store/views.py
View file @
d9103dc8
...
...
@@ -18,41 +18,41 @@ def index(request):
key_list
.
append
(
key
.
key
)
except
:
return
HttpResponse
(
'Can not acces to django database!'
)
if
StoreApi
.
UserE
xist
(
user
)
!=
True
:
if
StoreApi
.
usere
xist
(
user
)
!=
True
:
#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!'
)
#UpdateAuthorizationInfo
try
:
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!'
)
except
:
pass
#Download handler
try
:
dl
=
request
.
POST
[
'dl'
]
return
redirect
(
StoreApi
.
RequestD
ownload
(
user
,
dl
))
return
redirect
(
StoreApi
.
requestd
ownload
(
user
,
dl
))
except
:
pass
#Upload handler
try
:
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
}))
except
:
pass
#Remove handler
try
:
rm
=
request
.
POST
[
'rm'
]
succes
=
StoreApi
.
RequestR
emove
(
user
,
rm
)
succes
=
StoreApi
.
requestr
emove
(
user
,
rm
)
except
:
pass
#Remove handler
try
:
path
=
request
.
POST
[
'path'
]
new
=
request
.
POST
[
'new'
]
succes
=
StoreApi
.
RequestNewF
older
(
user
,
path
+
'/'
+
new
)
succes
=
StoreApi
.
requestnewf
older
(
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
.
ListF
older
(
user
,
path
)
return
render_to_response
(
'store/list.html'
,
RequestContext
(
request
,{
'file_list'
:
file_list
,
'path'
:
path
,
'backpath'
:
backpath
,
'username'
:
user
}))
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
}))
def
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