Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
3acedec7
Commit
3acedec7
authored
Mar 22, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some examples
parent
b4a076c8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
11 deletions
+14
-11
.hgignore
+2
-2
examples/media/objectstore/.keep
+1
-0
examples/media/pygments/.keep
+1
-0
examples/objectstore/views.py
+8
-6
examples/pygments_api/views.py
+2
-3
No files found.
.hgignore
View file @
3acedec7
...
@@ -8,8 +8,8 @@ env
...
@@ -8,8 +8,8 @@ env
docs/build
docs/build
html
html
htmlcov
htmlcov
examples/media/pygments/*
examples/media/pygments/
[A-Za-z0-9]
*
examples/media/objectstore/*
examples/media/objectstore/
[A-Za-z0-9]
*
build/*
build/*
dist/*
dist/*
xmlrunner/*
xmlrunner/*
...
...
examples/media/objectstore/.keep
0 → 100644
View file @
3acedec7
Force media/objectstore directory to created
examples/media/pygments/.keep
0 → 100644
View file @
3acedec7
Force media/pygments directory to created
examples/objectstore/views.py
View file @
3acedec7
...
@@ -11,16 +11,16 @@ import uuid
...
@@ -11,16 +11,16 @@ import uuid
import
operator
import
operator
OBJECT_STORE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'objectstore'
)
OBJECT_STORE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'objectstore'
)
MAX_FILES
=
2
0
MAX_FILES
=
1
0
def
remove_oldest_files
(
dir
,
max_files
):
def
remove_oldest_files
(
dir
,
max_files
):
"""Remove the oldest files in a directory 'dir', leaving at most 'max_files' remaining.
"""Remove the oldest files in a directory 'dir', leaving at most 'max_files' remaining.
We use this to limit the number of resources in the sandbox."""
We use this to limit the number of resources in the sandbox."""
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)
if
not
file
.
startswith
(
'.'
)
]
ctime_sorted_paths
=
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
ctime_sorted_paths
=
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
[
os
.
remove
(
path
)
for
path
in
ctime_sorted_paths
[
max_file
:]]
[
os
.
remove
(
path
)
for
path
in
ctime_sorted_paths
[
max_file
s
:]]
class
ObjectStoreRoot
(
Resource
):
class
ObjectStoreRoot
(
Resource
):
...
@@ -29,9 +29,11 @@ class ObjectStoreRoot(Resource):
...
@@ -29,9 +29,11 @@ class ObjectStoreRoot(Resource):
allowed_methods
=
anon_allowed_methods
=
(
'GET'
,
'POST'
)
allowed_methods
=
anon_allowed_methods
=
(
'GET'
,
'POST'
)
def
get
(
self
,
request
,
auth
):
def
get
(
self
,
request
,
auth
):
"""Return a list of all the stored object URLs."""
"""Return a list of all the stored object URLs. (Ordered by creation time, newest first)"""
keys
=
sorted
(
os
.
listdir
(
OBJECT_STORE_DIR
))
filepaths
=
[
os
.
path
.
join
(
OBJECT_STORE_DIR
,
file
)
for
file
in
os
.
listdir
(
OBJECT_STORE_DIR
)
if
not
file
.
startswith
(
'.'
)]
return
[
reverse
(
'stored-object'
,
kwargs
=
{
'key'
:
key
})
for
key
in
keys
]
ctime_sorted_basenames
=
[
item
[
0
]
for
item
in
sorted
([(
os
.
path
.
basename
(
path
),
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
return
[
reverse
(
'stored-object'
,
kwargs
=
{
'key'
:
key
})
for
key
in
ctime_sorted_basenames
]
def
post
(
self
,
request
,
auth
,
content
):
def
post
(
self
,
request
,
auth
,
content
):
"""Create a new stored object, with a unique key."""
"""Create a new stored object, with a unique key."""
...
...
examples/pygments_api/views.py
View file @
3acedec7
...
@@ -19,11 +19,11 @@ import operator
...
@@ -19,11 +19,11 @@ import operator
# We need somewhere to store the code that we highlight
# We need somewhere to store the code that we highlight
HIGHLIGHTED_CODE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'pygments'
)
HIGHLIGHTED_CODE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'pygments'
)
MAX_FILES
=
2
0
MAX_FILES
=
1
0
def
list_dir_sorted_by_ctime
(
dir
):
def
list_dir_sorted_by_ctime
(
dir
):
"""Return a list of files sorted by creation time"""
"""Return a list of files sorted by creation time"""
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)
if
not
file
.
startswith
(
'.'
)
]
return
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
return
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
def
remove_oldest_files
(
dir
,
max_files
):
def
remove_oldest_files
(
dir
,
max_files
):
...
@@ -46,7 +46,6 @@ class PygmentsRoot(Resource):
...
@@ -46,7 +46,6 @@ class PygmentsRoot(Resource):
def
get
(
self
,
request
,
auth
):
def
get
(
self
,
request
,
auth
):
"""Return a list of all currently existing snippets."""
"""Return a list of all currently existing snippets."""
unique_ids
=
[
os
.
path
.
split
(
f
)[
1
]
for
f
in
list_dir_sorted_by_ctime
(
HIGHLIGHTED_CODE_DIR
)]
unique_ids
=
[
os
.
path
.
split
(
f
)[
1
]
for
f
in
list_dir_sorted_by_ctime
(
HIGHLIGHTED_CODE_DIR
)]
unique_ids
.
reverse
()
return
[
reverse
(
'pygments-instance'
,
args
=
[
unique_id
])
for
unique_id
in
unique_ids
]
return
[
reverse
(
'pygments-instance'
,
args
=
[
unique_id
])
for
unique_id
in
unique_ids
]
def
post
(
self
,
request
,
auth
,
content
):
def
post
(
self
,
request
,
auth
,
content
):
...
...
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