From 8a470f031eeccf45625c3e3e18a8743021b38d41 Mon Sep 17 00:00:00 2001 From: tom christie tom@tomchristie.com Date: Sun, 30 Jan 2011 16:51:06 +0000 Subject: Minor changes to examples and docs --- examples/pygments_api/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'examples/pygments_api') 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) -- cgit v1.2.3