diff options
| author | Tom Christie | 2011-12-29 13:31:12 +0000 |
|---|---|---|
| committer | Tom Christie | 2011-12-29 13:31:12 +0000 |
| commit | 07349597ab936dc9887caa70b5d7d2860c897b12 (patch) | |
| tree | db1fdb8934e4d8dc8d3afe8d1e9fd076e3a4e27d /examples | |
| parent | 1bdc5eacc6290c486796eb5ab8fa29092137dab6 (diff) | |
| download | django-rest-framework-07349597ab936dc9887caa70b5d7d2860c897b12.tar.bz2 | |
whitespace fixes
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/blogpost/resources.py | 8 | ||||
| -rw-r--r-- | examples/blogpost/tests.py | 44 | ||||
| -rw-r--r-- | examples/mixin/urls.py | 2 | ||||
| -rw-r--r-- | examples/objectstore/urls.py | 4 | ||||
| -rw-r--r-- | examples/objectstore/views.py | 2 | ||||
| -rw-r--r-- | examples/permissionsexample/models.py | 2 | ||||
| -rw-r--r-- | examples/permissionsexample/views.py | 16 | ||||
| -rw-r--r-- | examples/pygments_api/forms.py | 2 | ||||
| -rw-r--r-- | examples/pygments_api/tests.py | 2 | ||||
| -rw-r--r-- | examples/pygments_api/urls.py | 2 | ||||
| -rw-r--r-- | examples/pygments_api/views.py | 4 | ||||
| -rw-r--r-- | examples/resourceexample/views.py | 2 | ||||
| -rw-r--r-- | examples/runtests.py | 4 | ||||
| -rw-r--r-- | examples/sandbox/views.py | 4 | ||||
| -rw-r--r-- | examples/settings.py | 6 |
15 files changed, 52 insertions, 52 deletions
diff --git a/examples/blogpost/resources.py b/examples/blogpost/resources.py index 9b91ed73..5a3c1ce2 100644 --- a/examples/blogpost/resources.py +++ b/examples/blogpost/resources.py @@ -12,16 +12,16 @@ class BlogPostResource(ModelResource): ordering = ('-created',) def comments(self, instance): - return reverse('comments', kwargs={'blogpost': instance.key}) + return reverse('comments', kwargs={'blogpost': instance.key}) class CommentResource(ModelResource): """ - A Comment is associated with a given Blog Post and has a *username* and *comment*, and optionally a *rating*. + A Comment is associated with a given Blog Post and has a *username* and *comment*, and optionally a *rating*. """ model = Comment fields = ('username', 'comment', 'created', 'rating', 'url', 'blogpost') ordering = ('-created',) - + def blogpost(self, instance): - return reverse('blog-post', kwargs={'key': instance.blogpost.key})
\ No newline at end of file + return reverse('blog-post', kwargs={'key': instance.blogpost.key}) diff --git a/examples/blogpost/tests.py b/examples/blogpost/tests.py index e55f0f90..5aa4f89f 100644 --- a/examples/blogpost/tests.py +++ b/examples/blogpost/tests.py @@ -15,68 +15,68 @@ from blogpost import models, urls # class AcceptHeaderTests(TestCase): # """Test correct behaviour of the Accept header as specified by RFC 2616: -# +# # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1""" -# +# # def assert_accept_mimetype(self, mimetype, expect=None): # """Assert that a request with given mimetype in the accept header, # gives a response with the appropriate content-type.""" # if expect is None: # expect = mimetype -# +# # resp = self.client.get(reverse(views.RootResource), HTTP_ACCEPT=mimetype) -# +# # self.assertEquals(resp['content-type'], expect) -# -# +# +# # def dont_test_accept_json(self): # """Ensure server responds with Content-Type of JSON when requested.""" # self.assert_accept_mimetype('application/json') -# +# # def dont_test_accept_xml(self): # """Ensure server responds with Content-Type of XML when requested.""" # self.assert_accept_mimetype('application/xml') -# +# # def dont_test_accept_json_when_prefered_to_xml(self): # """Ensure server responds with Content-Type of JSON when it is the client's prefered choice.""" # self.assert_accept_mimetype('application/json;q=0.9, application/xml;q=0.1', expect='application/json') -# +# # def dont_test_accept_xml_when_prefered_to_json(self): # """Ensure server responds with Content-Type of XML when it is the client's prefered choice.""" # self.assert_accept_mimetype('application/json;q=0.1, application/xml;q=0.9', expect='application/xml') -# +# # def dont_test_default_json_prefered(self): # """Ensure server responds with JSON in preference to XML.""" # self.assert_accept_mimetype('application/json,application/xml', expect='application/json') -# +# # def dont_test_accept_generic_subtype_format(self): # """Ensure server responds with an appropriate type, when the subtype is left generic.""" # self.assert_accept_mimetype('text/*', expect='text/html') -# +# # def dont_test_accept_generic_type_format(self): # """Ensure server responds with an appropriate type, when the type and subtype are left generic.""" # self.assert_accept_mimetype('*/*', expect='application/json') -# +# # def dont_test_invalid_accept_header_returns_406(self): # """Ensure server returns a 406 (not acceptable) response if we set the Accept header to junk.""" # resp = self.client.get(reverse(views.RootResource), HTTP_ACCEPT='invalid/invalid') # self.assertNotEquals(resp['content-type'], 'invalid/invalid') # self.assertEquals(resp.status_code, 406) -# +# # def dont_test_prefer_specific_over_generic(self): # This test is broken right now # """More specific accept types have precedence over less specific types.""" # self.assert_accept_mimetype('application/xml, */*', expect='application/xml') # self.assert_accept_mimetype('*/*, application/xml', expect='application/xml') -# -# +# +# # class AllowedMethodsTests(TestCase): # """Basic tests to check that only allowed operations may be performed on a Resource""" -# +# # def dont_test_reading_a_read_only_resource_is_allowed(self): # """GET requests on a read only resource should default to a 200 (OK) response""" # resp = self.client.get(reverse(views.RootResource)) # self.assertEquals(resp.status_code, 200) -# +# # def dont_test_writing_to_read_only_resource_is_not_allowed(self): # """PUT requests on a read only resource should default to a 405 (method not allowed) response""" # resp = self.client.put(reverse(views.RootResource), {}) @@ -171,7 +171,7 @@ from blogpost import models, urls class TestRotation(TestCase): - """For the example the maximum amount of Blogposts is capped off at views.MAX_POSTS. + """For the example the maximum amount of Blogposts is capped off at views.MAX_POSTS. Whenever a new Blogpost is posted the oldest one should be popped.""" def setUp(self): @@ -193,7 +193,7 @@ class TestRotation(TestCase): view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource) view(request) self.assertEquals(len(models.BlogPost.objects.all()),models.MAX_POSTS) - + def test_fifo_behaviour(self): '''It's fine that the Blogposts are capped off at MAX_POSTS. But we want to make sure we see FIFO behaviour.''' for post in range(15): @@ -201,11 +201,11 @@ class TestRotation(TestCase): request = self.factory.post('/blog-post', data=form_data) view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource) view(request) - request = self.factory.get('/blog-post') + request = self.factory.get('/blog-post') view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource) response = view(request) response_posts = json.loads(response.content) response_titles = [d['title'] for d in response_posts] response_titles.reverse() self.assertEquals(response_titles, ['%s' % i for i in range(models.MAX_POSTS - 5, models.MAX_POSTS + 5)]) -
\ No newline at end of file + diff --git a/examples/mixin/urls.py b/examples/mixin/urls.py index 1d25f6c7..a3da3b2c 100644 --- a/examples/mixin/urls.py +++ b/examples/mixin/urls.py @@ -1,4 +1,4 @@ -from djangorestframework.compat import View # Use Django 1.3's django.views.generic.View, or fall back to a clone of that if Django < 1.3 +from djangorestframework.compat import View # Use Django 1.3's django.views.generic.View, or fall back to a clone of that if Django < 1.3 from djangorestframework.mixins import ResponseMixin from djangorestframework.renderers import DEFAULT_RENDERERS from djangorestframework.response import Response diff --git a/examples/objectstore/urls.py b/examples/objectstore/urls.py index 2c685f59..0a3effa7 100644 --- a/examples/objectstore/urls.py +++ b/examples/objectstore/urls.py @@ -1,7 +1,7 @@ from django.conf.urls.defaults import patterns, url from objectstore.views import ObjectStoreRoot, StoredObject - + urlpatterns = patterns('objectstore.views', - url(r'^$', ObjectStoreRoot.as_view(), name='object-store-root'), + url(r'^$', ObjectStoreRoot.as_view(), name='object-store-root'), url(r'^(?P<key>[A-Za-z0-9_-]{1,64})/$', StoredObject.as_view(), name='stored-object'), ) diff --git a/examples/objectstore/views.py b/examples/objectstore/views.py index 19999aa9..2a222529 100644 --- a/examples/objectstore/views.py +++ b/examples/objectstore/views.py @@ -39,7 +39,7 @@ class ObjectStoreRoot(View): 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): """ Create a new stored object, with a unique key. diff --git a/examples/permissionsexample/models.py b/examples/permissionsexample/models.py index 232085ad..790bbaf8 100644 --- a/examples/permissionsexample/models.py +++ b/examples/permissionsexample/models.py @@ -1 +1 @@ -#for fixture loading
\ No newline at end of file +#for fixture loading diff --git a/examples/permissionsexample/views.py b/examples/permissionsexample/views.py index f95c2c84..54a1fdd5 100644 --- a/examples/permissionsexample/views.py +++ b/examples/permissionsexample/views.py @@ -6,33 +6,33 @@ class PermissionsExampleView(View): """ A container view for permissions examples. """ - + def get(self, request): return [{'name': 'Throttling Example', 'url': reverse('throttled-resource')}, {'name': 'Logged in example', 'url': reverse('loggedin-resource')},] - + class ThrottlingExampleView(View): """ A basic read-only View that has a **per-user throttle** of 10 requests per minute. - + If a user exceeds the 10 requests limit within a period of one minute, the throttle will be applied until 60 seconds have passed since the first request. """ - + permissions = ( PerUserThrottling, ) throttle = '10/min' - + def get(self, request): """ Handle GET requests. """ return "Successful response to GET request because throttle is not yet active." - + class LoggedInExampleView(View): """ - You can login with **'test', 'test'.** + You can login with **'test', 'test'.** """ permissions = (IsAuthenticated, ) def get(self, request): - return 'Logged in or not?'
\ No newline at end of file + return 'Logged in or not?' diff --git a/examples/pygments_api/forms.py b/examples/pygments_api/forms.py index 8488db06..30a59a84 100644 --- a/examples/pygments_api/forms.py +++ b/examples/pygments_api/forms.py @@ -13,7 +13,7 @@ class PygmentsForm(forms.Form): code = forms.CharField(widget=forms.Textarea, label='Code Text', - max_length=1000000, + max_length=1000000, help_text='(Copy and paste the code text here.)') title = forms.CharField(required=False, help_text='(Optional)', diff --git a/examples/pygments_api/tests.py b/examples/pygments_api/tests.py index 6eb69da5..98139ce2 100644 --- a/examples/pygments_api/tests.py +++ b/examples/pygments_api/tests.py @@ -46,4 +46,4 @@ class TestPygmentsExample(TestCase): self.assertEquals(locations, response_locations)
-
\ No newline at end of file + diff --git a/examples/pygments_api/urls.py b/examples/pygments_api/urls.py index 905e31c5..e0d44ece 100644 --- a/examples/pygments_api/urls.py +++ b/examples/pygments_api/urls.py @@ -2,6 +2,6 @@ from django.conf.urls.defaults import patterns, url from pygments_api.views import PygmentsRoot, PygmentsInstance urlpatterns = patterns('', - url(r'^$', PygmentsRoot.as_view(), name='pygments-root'), + url(r'^$', PygmentsRoot.as_view(), name='pygments-root'), url(r'^([a-zA-Z0-9-]+)/$', PygmentsInstance.as_view(), name='pygments-instance'), ) diff --git a/examples/pygments_api/views.py b/examples/pygments_api/views.py index e50029f6..884cff3a 100644 --- a/examples/pygments_api/views.py +++ b/examples/pygments_api/views.py @@ -72,10 +72,10 @@ class PygmentsRoot(View): linenos = 'table' if self.CONTENT['linenos'] else False options = {'title': self.CONTENT['title']} if self.CONTENT['title'] else {} formatter = HtmlFormatter(style=self.CONTENT['style'], linenos=linenos, full=True, **options) - + with open(pathname, 'w') as outfile: highlight(self.CONTENT['code'], lexer, formatter, outfile) - + remove_oldest_files(HIGHLIGHTED_CODE_DIR, MAX_FILES) return Response(status.HTTP_201_CREATED, headers={'Location': reverse('pygments-instance', args=[unique_id])}) diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py index 990c7834..e6b5eeb8 100644 --- a/examples/resourceexample/views.py +++ b/examples/resourceexample/views.py @@ -34,7 +34,7 @@ class AnotherExampleView(View): if int(num) > 2: return Response(status.HTTP_404_NOT_FOUND) return "GET request to AnotherExampleResource %s" % num - + def post(self, request, num): """ Handle POST requests, with form validation. diff --git a/examples/runtests.py b/examples/runtests.py index fdd35839..a62d9a9a 100644 --- a/examples/runtests.py +++ b/examples/runtests.py @@ -8,7 +8,7 @@ from coverage import coverage def main(): """Run the tests for the examples and generate a coverage report.""" - + # Discover the list of all modules that we should test coverage for project_dir = os.path.dirname(__file__) cov_files = [] @@ -18,7 +18,7 @@ def main(): continue cov_files.extend([os.path.join(path, file) for file in files if file.endswith('.py')]) TestRunner = get_runner(settings) - + cov = coverage() cov.erase() cov.start() diff --git a/examples/sandbox/views.py b/examples/sandbox/views.py index ecf62165..f7a3542d 100644 --- a/examples/sandbox/views.py +++ b/examples/sandbox/views.py @@ -14,8 +14,8 @@ class Sandbox(View): bash: curl -X GET http://api.django-rest-framework.org/ # (Use default renderer) bash: curl -X GET http://api.django-rest-framework.org/ -H 'Accept: text/plain' # (Use plaintext documentation renderer) - The examples provided: - + The examples provided: + 1. A basic example using the [Resource](http://django-rest-framework.org/library/resource.html) class. 2. A basic example using the [ModelResource](http://django-rest-framework.org/library/modelresource.html) class. 3. An basic example using Django 1.3's [class based views](http://docs.djangoproject.com/en/dev/topics/class-based-views/) and djangorestframework's [RendererMixin](http://django-rest-framework.org/library/renderers.html). diff --git a/examples/settings.py b/examples/settings.py index c47011fd..4438bb84 100644 --- a/examples/settings.py +++ b/examples/settings.py @@ -51,7 +51,7 @@ MEDIA_ROOT = 'media/' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com", "http://example.com/media/" -# NOTE: None of the djangorestframework examples serve media content via MEDIA_URL. +# NOTE: None of the djangorestframework examples serve media content via MEDIA_URL. MEDIA_URL = '' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a @@ -90,10 +90,10 @@ TEMPLATE_DIRS = ( ) # for loading initial data -##SERIALIZATION_MODULES = { +##SERIALIZATION_MODULES = { # 'yml': "django.core.serializers.pyyaml" -#} +#} INSTALLED_APPS = ( |
