Commits

Martin Skala committed e816f56

Code clean up

Comments (0)

Files changed (3)

django_roa/db/models.py

 
 ROA_MODEL_NAME_MAPPING = getattr(settings, 'ROA_MODEL_NAME_MAPPING', [])
 ROA_HEADERS = getattr(settings, 'ROA_HEADERS', {})
+ROA_FORMAT = getattr(settings, "ROA_FORMAT", 'json')
 
 DEFAULT_CHARSET = getattr(settings, 'DEFAULT_CHARSET', 'utf-8')
 
             pk_val = self._get_pk_val(meta)
             pk_set = pk_val is not None
             
-            ROA_FORMAT = getattr(settings, "ROA_FORMAT", 'json')
             get_args = {'format': ROA_FORMAT}
             get_args.update(getattr(settings, "ROA_CUSTOM_ARGS", {}))
             

django_roa/db/query.py

 ROA_MODEL_NAME_MAPPING = getattr(settings, 'ROA_MODEL_NAME_MAPPING', [])
 ROA_ARGS_NAMES_MAPPING = getattr(settings, 'ROA_ARGS_NAMES_MAPPING', {})
 ROA_HEADERS = getattr(settings, 'ROA_HEADERS', {})
+ROA_FORMAT = getattr(settings, "ROA_FORMAT", 'json')
 
 DEFAULT_CHARSET = getattr(settings, 'DEFAULT_CHARSET', 'utf-8')
 
             parameters[ROA_ARGS_NAMES_MAPPING.get('LIMIT_STOP', 'limit_stop')] = self.limit_stop
         
         # Format
-        ROA_FORMAT = getattr(settings, "ROA_FORMAT", 'json')
         parameters[ROA_ARGS_NAMES_MAPPING.get('FORMAT', 'format')] = ROA_FORMAT
         
         parameters.update(getattr(settings, 'ROA_CUSTOM_ARGS', {}))
         for local_name, remote_name in ROA_MODEL_NAME_MAPPING:
             response = response.replace(remote_name, local_name)
         
-        ROA_FORMAT = getattr(settings, "ROA_FORMAT", 'json')
         for res in serializers.deserialize(ROA_FORMAT, response):
             obj = res.object
             yield obj
             response = resource.get(**parameters)
         except Exception, e:
             raise ROAException(e)
-        
 
         response = force_unicode(response.body_string()).encode(DEFAULT_CHARSET)
 
         for local_name, remote_name in ROA_MODEL_NAME_MAPPING:
             response = response.replace(remote_name, local_name)
         
-        ROA_FORMAT = getattr(settings, "ROA_FORMAT", 'json')
         deserializer = serializers.get_deserializer(ROA_FORMAT)
         if hasattr(deserializer, 'deserialize_object'):
             result = deserializer(response).deserialize_object(response)

examples/twitter_roa/serializers.py

         # Handle each field
         for (field_name, field_value) in obj.iteritems():
             if isinstance(field_value, str):
-                field_value = smart_unicode(field_value, options.get("encoding", DEFAULT_CHARSET), strings_only=True)
+                field_value = smart_unicode(
+                                field_value, 
+                                options.get("encoding", DEFAULT_CHARSET),
+                                strings_only=True)
         
             try:
                 field = Model._meta.get_field(field_name)
-            except models.fields.FieldDoesNotExist:
+            except models.FieldDoesNotExist:
                 continue
         
             # Handle FK fields
             if field.rel and isinstance(field.rel, models.ManyToOneRel):
                 if field_value is not None:
-                    data[field.attname] = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value['id'])
+                    data[field.attname] = field.rel.to._meta.\
+                        get_field(field.rel.field_name).\
+                        to_python(field_value['id'])
                 else:
                     data[field.attname] = None
 
                 data[field.name] = field.to_python(field_value)
         
         yield base.DeserializedObject(Model(**data), m2m_data)
-