aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortom christie tom@tomchristie.com2011-01-30 16:51:06 +0000
committertom christie tom@tomchristie.com2011-01-30 16:51:06 +0000
commit8a470f031eeccf45625c3e3e18a8743021b38d41 (patch)
tree754d555139f250a8aacca5d6c73bcee95e8fe794
parentf6e534321a0bbb683aeeb3120c528a8ad9a33647 (diff)
downloaddjango-rest-framework-8a470f031eeccf45625c3e3e18a8743021b38d41.tar.bz2
Minor changes to examples and docs
-rw-r--r--docs/index.rst10
-rw-r--r--examples/objectstore/views.py11
-rw-r--r--examples/pygments_api/views.py11
3 files changed, 30 insertions, 2 deletions
diff --git a/docs/index.rst b/docs/index.rst
index a7058ed4..7a871a5c 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -13,6 +13,16 @@ Features:
* Optional support for forms as input validation.
* 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
--------------------
diff --git a/examples/objectstore/views.py b/examples/objectstore/views.py
index 2eaadd3c..4681fe70 100644
--- a/examples/objectstore/views.py
+++ b/examples/objectstore/views.py
@@ -8,6 +8,16 @@ import os
import uuid
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):
@@ -25,6 +35,7 @@ class ObjectStoreRoot(Resource):
key = str(uuid.uuid1())
pathname = os.path.join(OBJECT_STORE_DIR, key)
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)})
diff --git a/examples/pygments_api/views.py b/examples/pygments_api/views.py
index 96322115..d9082ada 100644
--- a/examples/pygments_api/views.py
+++ b/examples/pygments_api/views.py
@@ -16,10 +16,11 @@ import operator
# We need somewhere to store the code that we highlight
HIGHLIGHTED_CODE_DIR = os.path.join(settings.MEDIA_ROOT, 'pygments')
-MAX_FILES = 5
+MAX_FILES = 20
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)]
ctime_sorted_paths = [item[0] for item in sorted([(path, os.path.getctime(path)) for path in filepaths],
key=operator.itemgetter(1), reverse=True)]
@@ -74,4 +75,10 @@ class PygmentsInstance(Resource):
return Resource(status.HTTP_404_NOT_FOUND)
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)