david / django-roa (http://welldev.org/)

Turn your models into remote resources that you can access through Django's ORM. ROA stands for Resource Oriented Architecture.

Clone this repository (size: 560.7 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-roa
commit 118: 7e9e0615c76f
parent 117: 2beb9c5c8529
branch: default
Add a new setting, ROA_HEADERS, to specify headers sent to the server by restkit (Content-Type for instance).
David Larlet / david
12 months ago

Changed (Δ332 bytes):

raw changeset »

django_roa/db/models.py (3 lines added, 3 lines removed)

django_roa/db/query.py (4 lines added, 3 lines removed)

examples/django_roa_client/settings.py (4 lines added, 0 lines removed)

Up to file-list django_roa/db/models.py:

@@ -19,7 +19,7 @@ from django_roa.db.exceptions import ROA
19
19
logger = logging.getLogger("django_roa")
20
20
21
21
ROA_MODEL_NAME_MAPPING = getattr(settings, 'ROA_MODEL_NAME_MAPPING', [])
22
22
ROA_HEADERS = getattr(settings, 'ROA_HEADERS', {})
23
23
24
24
class ROAModelBase(ModelBase):
25
25
    def __new__(cls, name, bases, attrs):
@@ -325,7 +325,7 @@ class ROAModel(models.Model):
325
325
            
326
326
            if force_update or pk_set and not self.id is None:
327
327
                record_exists = True
328
                resource = Resource(self.get_resource_url_detail())
328
                resource = Resource(self.get_resource_url_detail(), headers=ROA_HEADERS)
329
329
                try:
330
330
                    logger.debug(u"""Modifying : "%s" through %s
331
331
                                  with payload "%s" and GET args "%s" """ % (
@@ -338,7 +338,7 @@ class ROAModel(models.Model):
338
338
                    raise ROAException(e)
339
339
            else:
340
340
                record_exists = False
341
                resource = Resource(self.get_resource_url_list())
341
                resource = Resource(self.get_resource_url_list(), headers=ROA_HEADERS)
342
342
                try:
343
343
                    logger.debug(u"""Creating  : "%s" through %s
344
344
                                  with payload "%s" and GET args "%s" """ % (

Up to file-list django_roa/db/query.py:

@@ -14,6 +14,7 @@ logger = logging.getLogger("django_roa")
14
14
15
15
ROA_MODEL_NAME_MAPPING = getattr(settings, 'ROA_MODEL_NAME_MAPPING', [])
16
16
ROA_ARGS_NAMES_MAPPING = getattr(settings, 'ROA_ARGS_NAMES_MAPPING', {})
17
ROA_HEADERS = getattr(settings, 'ROA_HEADERS', {})
17
18
18
19
19
20
class Query(object):
@@ -151,7 +152,7 @@ class RemoteQuerySet(query.QuerySet):
151
152
        An iterator over the results from applying this QuerySet to the
152
153
        remote web service.
153
154
        """
154
        resource = Resource(self.model.get_resource_url_list())
155
        resource = Resource(self.model.get_resource_url_list(), headers=ROA_HEADERS)
155
156
156
157
        try:
157
158
            parameters = self.query.parameters
@@ -188,7 +189,7 @@ class RemoteQuerySet(query.QuerySet):
188
189
        # a staticmethod for get_resource_url_count and avoid to set it
189
190
        # for all model without relying on get_resource_url_list
190
191
        instance = clone.model()
191
        resource = Resource(instance.get_resource_url_count())
192
        resource = Resource(instance.get_resource_url_count(), headers=ROA_HEADERS)
192
193
        
193
194
        try:
194
195
            parameters = clone.query.parameters
@@ -216,7 +217,7 @@ class RemoteQuerySet(query.QuerySet):
216
217
        # for all model without relying on get_resource_url_list
217
218
        instance = clone.model()
218
219
        instance.id = id
219
        resource = Resource(instance.get_resource_url_detail())
220
        resource = Resource(instance.get_resource_url_detail(), headers=ROA_HEADERS)
220
221
        
221
222
        try:
222
223
            parameters = clone.query.parameters

Up to file-list examples/django_roa_client/settings.py:

@@ -51,6 +51,10 @@ SERIALIZATION_MODULES = {
51
51
## ROA custom settings
52
52
ROA_MODELS = True   # set to False if you'd like to develop/test locally
53
53
ROA_FORMAT = 'django' # json or xml
54
# specify the headers sent to the ws from restkit
55
ROA_HEADERS = {
56
    'Content-Type': 'application/x-www-form-urlencoded',
57
} 
54
58
ROA_DJANGO_ERRORS = True # useful to ease debugging if you use test server
55
59
56
60
ROA_URL_OVERRIDES_LIST = {