Permalink
Browse files

Add default value for VOCAB_FIELDS

This prevents an error if the setting has not been defined
  • Loading branch information...
1 parent 6d11335 commit c276cc56d051564d750079f47c068ad913a1cabe @bruth bruth committed May 8, 2013
Showing with 18 additions and 15 deletions.
  1. +10 −10 vocab/resources.py
  2. +3 −0 vocab/settings.py
  3. +5 −5 vocab/urls.py
View
@@ -1,17 +1,17 @@
from django.db.models import Q
+from django.core.urlresolvers import reverse
from avocado.models import DataField
-from django.conf import settings
from restlib2.http import codes
from restlib2.resources import Resource
from preserialize.serialize import serialize
-from django.core.urlresolvers import reverse
+from .settings import VOCAB_FIELDS
class ItemResource(Resource):
fields = (':pk', 'description->name', 'abbreviation', 'code', 'terminal',
'get_absolute_url->uri', 'children', 'ancestors')
def get(self, request, field_pk, pk):
- if not field_pk in [str(x) for x in settings.VOCAB_FIELDS]:
+ if not field_pk in [str(x) for x in VOCAB_FIELDS]:
return codes.NOT_FOUND
field = DataField.objects.get(pk=field_pk)
@@ -30,7 +30,7 @@ class ItemResourceCollection(Resource):
def get(self, request, field_pk):
uri = request.build_absolute_uri
- if not field_pk in [str(x) for x in settings.VOCAB_FIELDS]:
+ if not field_pk in [str(x) for x in VOCAB_FIELDS]:
return codes.NOT_FOUND
field = DataField.objects.get(pk=field_pk)
@@ -67,20 +67,20 @@ def get(self, request, field_pk):
return {
"_links": {
"items": {
- "href": uri(reverse("vocab:root",
+ "href": uri(reverse("vocab:root",
kwargs={'field_pk':field_pk})) + "values/",
"rel": "items"
},
"directory": {
- "href": uri(reverse("vocab:root",
+ "href": uri(reverse("vocab:root",
kwargs={'field_pk':field_pk})) + "directory/",
"rel": "directory"
},
"search": {
- "href": uri(reverse("vocab:root",
+ "href": uri(reverse("vocab:root",
kwargs={'field_pk':field_pk})) + "search/",
"rel": "search"
- }
- },
- "title": "Serrano Vocab Browser Hypermedia API",
+ }
+ },
+ "title": "Serrano Vocab Browser Hypermedia API",
}
View
@@ -0,0 +1,3 @@
+from django.conf import settings
+
+VOCAB_FIELDS = getattr(settings, 'VOCAB_FIELDS', ())
View
@@ -1,15 +1,15 @@
from django.conf.urls.defaults import url, patterns, include
-from django.conf import settings
+from .settings import VOCAB_FIELDS
-override_fields = '|'.join([str(f) for f in settings.VOCAB_FIELDS])
+override_fields = '|'.join([str(f) for f in VOCAB_FIELDS])
-urlpatterns = patterns('',
+urlpatterns = patterns('',
url(r'', include(patterns('',
- url(r'^fields/(?P<field_pk>{0})/values/(?P<pk>\d+)/$'.format(override_fields), 'vocab.resources.ItemResource',
+ url(r'^fields/(?P<field_pk>{0})/values/(?P<pk>\d+)/$'.format(override_fields), 'vocab.resources.ItemResource',
name="value"),
url(r'^fields/(?P<field_pk>{0})/directory/$'.format(override_fields), 'vocab.resources.ItemResourceCollection'),
url(r'^fields/(?P<field_pk>{0})/search/$'.format(override_fields), 'vocab.resources.ItemResourceCollection'),
- url(r'^fields/(?P<field_pk>{0})/$'.format(override_fields), 'vocab.resources.Resources',
+ url(r'^fields/(?P<field_pk>{0})/$'.format(override_fields), 'vocab.resources.Resources',
name='root')
), namespace="vocab"))
)

0 comments on commit c276cc5

Please sign in to comment.