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
8a470f03
Commit
8a470f03
authored
Jan 30, 2011
by
tom christie tom@tomchristie.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor changes to examples and docs
parent
f6e53432
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
docs/index.rst
+10
-0
examples/objectstore/views.py
+11
-0
examples/pygments_api/views.py
+9
-2
No files found.
docs/index.rst
View file @
8a470f03
...
@@ -13,6 +13,16 @@ Features:
...
@@ -13,6 +13,16 @@ Features:
*
Optional
support
for
forms
as
input
validation
.
*
Optional
support
for
forms
as
input
validation
.
*
Modular
architecture
-
Easy
to
extend
and
modify
.
*
Modular
architecture
-
Easy
to
extend
and
modify
.
Requirements
------------
*
Python
2.6
*
Django
1.2
..
note
::
Support
for
a
wider
range
of
Python
&
Django
versions
is
planned
,
but
right
now
django
-
rest
-
framework
is
only
tested
against
these
versions
.
Installation
&
Setup
Installation
&
Setup
--------------------
--------------------
...
...
examples/objectstore/views.py
View file @
8a470f03
...
@@ -8,6 +8,16 @@ import os
...
@@ -8,6 +8,16 @@ import os
import
uuid
import
uuid
OBJECT_STORE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'objectstore'
)
OBJECT_STORE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'objectstore'
)
MAX_FILES
=
20
def
remove_oldest_files
(
dir
,
max_files
):
"""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."""
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
ctime_sorted_paths
=
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
[
os
.
remove
(
path
)
for
path
in
ctime_sorted_paths
[
max_files
:]]
class
ObjectStoreRoot
(
Resource
):
class
ObjectStoreRoot
(
Resource
):
...
@@ -25,6 +35,7 @@ class ObjectStoreRoot(Resource):
...
@@ -25,6 +35,7 @@ class ObjectStoreRoot(Resource):
key
=
str
(
uuid
.
uuid1
())
key
=
str
(
uuid
.
uuid1
())
pathname
=
os
.
path
.
join
(
OBJECT_STORE_DIR
,
key
)
pathname
=
os
.
path
.
join
(
OBJECT_STORE_DIR
,
key
)
pickle
.
dump
(
content
,
open
(
pathname
,
'wb'
))
pickle
.
dump
(
content
,
open
(
pathname
,
'wb'
))
remove_oldest_files
(
OBJECT_STORE_DIR
,
MAX_FILES
)
return
Response
(
status
.
HTTP_201_CREATED
,
content
,
{
'Location'
:
self
.
reverse
(
StoredObject
,
key
=
key
)})
return
Response
(
status
.
HTTP_201_CREATED
,
content
,
{
'Location'
:
self
.
reverse
(
StoredObject
,
key
=
key
)})
...
...
examples/pygments_api/views.py
View file @
8a470f03
...
@@ -16,10 +16,11 @@ import operator
...
@@ -16,10 +16,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
=
5
MAX_FILES
=
20
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."""
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
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
)]
...
@@ -74,4 +75,10 @@ class PygmentsInstance(Resource):
...
@@ -74,4 +75,10 @@ class PygmentsInstance(Resource):
return
Resource
(
status
.
HTTP_404_NOT_FOUND
)
return
Resource
(
status
.
HTTP_404_NOT_FOUND
)
return
open
(
pathname
,
'r'
)
.
read
()
return
open
(
pathname
,
'r'
)
.
read
()
def
delete
(
self
,
request
,
auth
,
unique_id
):
"""Delete the highlighted snippet."""
pathname
=
os
.
path
.
join
(
HIGHLIGHTED_CODE_DIR
,
unique_id
)
if
not
os
.
path
.
exists
(
pathname
):
return
Resource
(
status
.
HTTP_404_NOT_FOUND
)
return
os
.
remove
(
pathname
)
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