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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
7fe4e4d1
authored
Jul 03, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add store features
parent
a30f9eb3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
33 deletions
+149
-33
circle/dashboard/templates/dashboard/store/list.html
+94
-28
circle/dashboard/urls.py
+6
-2
circle/dashboard/views.py
+49
-3
No files found.
circle/dashboard/templates/dashboard/store/list.html
View file @
7fe4e4d1
...
...
@@ -8,32 +8,62 @@
<div
class=
"row"
>
<div
class=
"col-md-12"
>
<ul
id=
"store-list-list"
>
<div
class=
"list-group"
id=
"store-list-list"
>
<a
href=
"?directory={{ up_url }}"
class=
"list-group-item store-list-item"
data-item-type=
"D"
>
<i
class=
"icon-reply store-list-item-icon"
></i>
..
<div
class=
"pull-right"
>
{{ current }}
</div>
</a>
{% for f in root %}
<li
class=
"store-list-item"
>
<a
class=
"list-group-item store-list-item"
data-item-type=
"{{ f.TYPE }}"
href=
"{% if f.TYPE == "
D
"
%}?
directory=
{{
f
.
path
}}{%
else
%}
{#
url
"
dashboard
.
views
.
store-download
"
#}?
path=
{{
f
.
path
}}{%
endif
%}"
>
<div
class=
"store-list-item-icon"
>
<i
class=
"icon-{% if f.TYPE == "
D
"
%}
folder-open-alt
{%
else
%}
file-alt
{%
endif
%}"
></i>
<i
class=
"
icon-{% if f.TYPE == "
D
"
%}
folder-open-alt
{%
else
%}
file-alt
{%
endif
%}"
></i>
</div>
{{ f.NAME }}
<div
class=
"store-list-item-size"
>
{
% if f.TYPE == "D" %}{% trans "directory" %}{% else %}{% bytes_to_megabytes f.SIZE %}MB{% endif %
}
{
{ f.human_readable_size }
}
</div>
<div
class=
"clearfix"
></div>
</a>
<div
class=
"infos"
style=
"position: relative;"
>
<a
href=
"{% url "
dashboard
.
views
.
store-download
"
%}?
path=
{{
f
.
path
}}"
class=
"btn btn-primary"
style=
"position: absolute; right: 15px; top: 32px;"
>
<i
class=
"icon-download"
></i>
Download
</a>
<dl
class=
"dl-horizontal"
style=
"margin: 0; padding: 0;"
>
<dt>
Filename
</dt>
<dd>
{{ f.NAME }}
</dd>
<div
class=
"store-list-item-actions"
>
<span
title=
"{% trans "
Last
modified:
"
%}
{%
timestamp_to_date
f
.
MTIME
%}"
class=
"btn btn-default btn-xs"
>
<i
class=
"icon-time"
></i>
</span>
<span
class=
"btn btn-default btn-xs"
>
<i
class=
"icon-cloud-download"
></i>
</span>
</div>
<dt>
Size
</dt>
<dd>
{{ f.human_readable_size }}
</dd>
<div
class=
"clearfix"
></div>
</li>
<dt>
Latest modification
</dt>
<dd>
{{ f.human_readable_date }}
</dd>
</dl>
</div>
{% empty %}
<a
class=
"list-group-item"
>
{% trans "This folder is empty." %}
</a>
{% endfor %}
</ul>
<div
class=
"list-group-item"
>
Upload file to this folder
<form
action=
""
data-action=
"{% url "
dashboard
.
views
.
store-upload
"
%}"
method=
"POST"
enctype=
"multipart/form-data"
class=
"pull-right"
>
{% csrf_token %}
<input
type=
"hidden"
name=
"current_dir"
value=
"{{ current }}"
></a>
<input
type=
"file"
name=
"data"
/>
<input
type=
"submit"
/>
</form>
</div>
</div>
</div>
</div>
...
...
@@ -43,36 +73,72 @@
}
.store-list-item
{
padding
:
0
8px
0
8px
;
cursor
:
pointer
;
line-height
:
35px
;
height
:
35px
;
}
.store-list-item
:hover
{
background
:
rgba
(
0
,
0
,
0
,
0.
1
);
background
:
rgba
(
0
,
0
,
0
,
0.
6
);
}
.store-list-item-icon
{
width
:
20px
;
display
:
inline-block
;
text-align
:
center
;
display
:
inline-block
;
margin-right
:
15px
;
}
.store-list-item-size
{
display
:
inline-block
;
width
:
70px
;
text-align
:
right
;
float
:
right
;
}
.
store-list-item-action
s
{
display
:
inline-block
;
width
:
100px
;
text-align
:
center
;
float
:
right
;
.
info
s
{
padding
:
20px
;
display
:
none
;
border-left
:
1px
solid
#ddd
;
border-right
:
1px
solid
#ddd
;
}
</style>
<script>
$
(
function
()
{
$
(
".store-list-item"
).
click
(
function
()
{
if
(
$
(
this
).
data
(
"item-type"
)
==
"D"
)
return
true
;
$
(
this
).
next
(
".infos"
).
stop
().
slideToggle
();
return
false
;
});
/* less js way, but at least works, tho redirection is bad */
$
(
'form input[type="submit"]'
).
click
(
function
()
{
var
current_dir
=
$
(
"form"
).
find
(
'[name="current_dir"]'
).
val
();
$
.
get
(
$
(
"form"
).
data
(
"action"
)
+
"?current_dir="
+
current_dir
,
function
(
result
)
{
$
(
"form"
).
get
(
0
).
setAttribute
(
"action"
,
result
[
'url'
]);
$
(
"form"
).
submit
();
});
return
false
;
});
/* this does not work
$('form input[type="submit"]').click(function() {
var current_dir = $("form").find('[name="current_dir"]').val();
$.get($("form").data("action") + "?current_dir=" + current_dir, function(result) {
$.ajax({
method: "POST",
url: result['url'],
data: $("form").serialize(),
success: function(re) {
console.log(re);
}
});
});
return false;
}); */
});
</script>
{% endblock %}
...
...
circle/dashboard/urls.py
View file @
7fe4e4d1
...
...
@@ -37,7 +37,7 @@ from .views import (
get_vm_screenshot
,
ProfileView
,
toggle_use_gravatar
,
UnsubscribeFormView
,
UserKeyDelete
,
UserKeyDetail
,
UserKeyCreate
,
StoreList
StoreList
,
store_download
,
store_upload
,
)
urlpatterns
=
patterns
(
...
...
@@ -172,5 +172,9 @@ urlpatterns = patterns(
name
=
"dashboard.views.userkey-create"
),
url
(
r"^store/list/$"
,
StoreList
.
as_view
(),
name
=
"dashboard.views.store-list"
)
name
=
"dashboard.views.store-list"
),
url
(
r"^store/download/$"
,
store_download
,
name
=
"dashboard.views.store-download"
),
url
(
r"^store/upload/$"
,
store_upload
,
name
=
"dashboard.views.store-upload"
),
)
circle/dashboard/views.py
View file @
7fe4e4d1
...
...
@@ -2940,8 +2940,54 @@ class StoreList(LoginRequiredMixin, TemplateView):
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
StoreList
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
directory
=
self
.
request
.
GET
.
get
(
"directory"
,
"/"
)
directory
=
"/"
if
not
len
(
directory
)
else
directory
files
=
store_api
.
listfolder
(
"test"
,
"/"
)
dirs_first
=
sorted
(
files
,
key
=
lambda
k
:
k
[
'TYPE'
]
)
context
[
'
root'
]
=
dirs_first
context
[
'root'
]
=
self
.
clean_directory_list
(
directory
)
context
[
'up_url'
]
=
self
.
create_up_directory
(
directory
)
context
[
'
current'
]
=
directory
return
context
def
create_up_directory
(
self
,
directory
):
cut
=
-
2
if
directory
.
endswith
(
"/"
)
else
-
1
return
"/"
.
join
(
directory
.
split
(
"/"
)[:
cut
])
+
"/"
def
clean_directory_list
(
self
,
directory
):
from
datetime
import
datetime
from
sizefield.utils
import
filesizeformat
content
=
store_api
.
listfolder
(
"test"
,
directory
)
for
d
in
content
:
d
[
'human_readable_date'
]
=
datetime
.
fromtimestamp
(
float
(
d
[
'MTIME'
]))
d
[
'human_readable_size'
]
=
(
"directory"
if
d
[
'TYPE'
]
==
"D"
else
filesizeformat
(
float
(
d
[
'SIZE'
])))
d
[
'path'
]
=
d
[
'DIR'
]
if
len
(
d
[
'path'
])
==
1
and
d
[
'path'
][
0
]
==
"."
:
d
[
'path'
]
=
"/"
else
:
d
[
'path'
]
=
"/"
+
d
[
'path'
]
+
"/"
d
[
'path'
]
+=
d
[
'NAME'
]
if
d
[
'TYPE'
]
==
"D"
:
d
[
'path'
]
+=
"/"
return
sorted
(
content
,
key
=
lambda
k
:
k
[
'TYPE'
])
@require_GET
def
store_download
(
request
):
path
=
request
.
GET
.
get
(
"path"
)
url
=
store_api
.
requestdownload
(
"test"
,
path
)
return
redirect
(
url
)
@require_GET
def
store_upload
(
request
):
current_dir
=
request
.
GET
.
get
(
"current_dir"
)
url
=
store_api
.
requestupload
(
"test"
,
current_dir
)
return
HttpResponse
(
json
.
dumps
({
'url'
:
url
}),
content_type
=
"application/json"
,
)
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