Commits

Martin Skala committed c9702b7

Organizing imports and code clean up

  • Participants
  • Parent commits 66c0208

Comments (0)

Files changed (9)

django_roa/management/commands/inspectresources.py

-from django.core.management.base import NoArgsCommand, CommandError
+from django.core.management.base import NoArgsCommand
 
 class Command(NoArgsCommand):
     help = "Introspects the models and outputs a representation of resources."

django_roa/remoteauth/models.py

 from django.contrib.contenttypes.models import ContentType
 from django.contrib.auth.models import Permission as DjangoPermission, \
     User as DjangoUser, Group as DjangoGroup, \
-    UserManager as DjangoUserManager, Message as DjangoMessage, \
-    get_hexdigest, check_password
+    UserManager as DjangoUserManager, Message as DjangoMessage
 from django.utils.translation import ugettext_lazy as _
 from django.db import models
 

examples/django_roa_client/settings.py

 }
 
 ## ROA custom settings
-ROA_MODELS = True   # set to False if you'd like to develop/test locally
+ROA_MODELS = True # set to False if you'd like to develop/test locally
 ROA_FORMAT = 'django' # json or xml
 # specify the headers sent to the ws from restkit
 ROA_HEADERS = {

examples/django_roa_client/tests.py

 handle very well projects inside projects.
 """
 from datetime import time, date, datetime
-from decimal import Decimal
 
 from django.test import TestCase
 from django.conf import settings

examples/django_roa_server/emitters.py

 import logging
 
 from django.conf import settings
-from django.core import serializers
-from django.http import HttpResponse
-from django.utils import simplejson
 
 from piston.emitters import Emitter, DjangoEmitter
 

examples/django_roa_server/handlers.py

 import logging
 
-from django.conf import settings
 from django.contrib.auth.models import User, Message, Group, Permission
-from django.core.exceptions import ObjectDoesNotExist
-from django.core import serializers
 from django.db import models
-from django.http import Http404, HttpResponse, HttpResponseNotAllowed
+from django.http import Http404
 from django.shortcuts import get_object_or_404, _get_queryset
-from django.utils.encoding import smart_unicode
 
 from piston.handler import BaseHandler, AnonymousBaseHandler
 from piston.utils import rc
         if not self.has_model():
             return rc.NOT_IMPLEMENTED
         
+        logger.debug('Args: %s' % str(args))
+        logger.debug('Kwargs: %s' % str(kwargs))
+        
         if kwargs.values() != [None]:
             # Returns a single object
             return [self._get_object(self.model, *args, **kwargs)]
         
         # Initialization
         queryset = _get_queryset(self.model)
+        logger.debug('Before filters: %s' % str(queryset))
         
         # Filtering
         filters, excludes = {}, {}
                 excludes[k[8:]] = v
         queryset = queryset.filter(*filters.items()).exclude(*excludes.items())
         
+        logger.debug('Filters: %s' % str(filters))
+        logger.debug('Excludes: %s' % str(excludes))
+        logger.debug('After filters: %s' % str(queryset))
+        
         # Ordering (test custom parameters' name)
         if 'order' in request.GET:
             order_bys = request.GET['order'].split(',')
             return rc.NOT_IMPLEMENTED
         
         data = request.POST.copy()
-        keys = data.keys()
         
         values = {}
         for field in self.model._meta.local_fields:
                             field_value = float(field_value)
                     values[field.name] = field_value
 
-        object = self.model.objects.create(**values)
+        obj = self.model.objects.create(**values)
         
-        response = [self.model.objects.get(id=object.id)]
-        #response = [object]
-        logger.debug(u'Object "%s" created' % unicode(object))
+        response = [self.model.objects.get(id=obj.id)]
+        logger.debug(u'Object "%s" created' % unicode(obj))
         return response
 
     def update(self, request, *args, **kwargs):
         
         data = request.PUT.copy()
         logger.debug(u'Received: %s as PUT data' % data)
-        object = self._get_object(self.model, *args, **kwargs)
+        obj = self._get_object(self.model, *args, **kwargs)
         
         for field in self.model._meta.local_fields:
             field_name = field.name
                     field_value = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
                 else:
                     field_value = None
-                setattr(object, field.attname, field_value)
+                setattr(obj, field.attname, field_value)
             
             # Handle all other fields
             elif field_name in data:
                 elif isinstance(field, models.fields.CharField):
                     if field_value is None:
                         field_value = u''
-                setattr(object, field_name, field_value)
+                setattr(obj, field_name, field_value)
         
-        object.save()
+        obj.save()
         
-        response = [self.model.objects.get(id=object.id)]
-        #response = [object]
+        response = [self.model.objects.get(id=obj.id)]
         logger.debug(u'Object "%s" modified with %s' % (
-            unicode(object), unicode(data.items())))
+            unicode(obj), unicode(data.items())))
         return response
 
     def delete(self, request, *args, **kwargs):
             raise NotImplementedError
         
         try:
-            object = self._get_object(self.model, *args, **kwargs)
-            object.delete()
+            obj = self._get_object(self.model, *args, **kwargs)
+            obj.delete()
             logger.debug(u'Object "%s" deleted, remains %s' % (
-                unicode(object), 
-                [unicode(object) for object in self.model.objects.all()]))
+                unicode(obj), 
+                [unicode(obj) for obj in self.model.objects.all()]))
 
             return rc.DELETED
         except self.model.MultipleObjectsReturned:
         
         Useful when the slug is a combination of many fields.
         """
-        id, slug = kwargs['object_slug'].split('-', 1)
-        object = get_object_or_404(model, id=id, slug=slug)
-        return object
-    
+        pk, slug = kwargs['object_slug'].split('-', 1)
+        obj = get_object_or_404(model, id=pk)
+        return obj
+
 
 class RemotePageHandler(ROAHandler):
     model = RemotePage
 class RemotePageWithCustomSlugCountHandler(ROACountHandler):
     model = RemotePageWithCustomSlug
 
-    
+
 class RemotePageWithOverriddenUrlsHandler(ROAWithSlugHandler):
     model = RemotePageWithOverriddenUrls
 
 class RemotePageWithRelationsCountHandler(ROACountHandler):
     model = RemotePageWithRelations
 
-    
+
 class RemotePageWithRelationsThroughHandler(ROAHandler):
     model = RemotePageWithRelationsThrough
 
 class RemotePageWithRelationsThroughCountHandler(ROACountHandler):
     model = RemotePageWithRelationsThrough
 
-    
+
 class RemotePageWithNamedRelationsHandler(ROAHandler):
     model = RemotePageWithNamedRelations
 
 class RemotePageWithNamedRelationsCountHandler(ROACountHandler):
     model = RemotePageWithNamedRelations
 
-    
+
 class UserHandler(ROAHandler):
     model = User
 
 
 class PermissionHandler(ROAHandler):
     model = Permission
-    
+
 class GroupHandler(ROAHandler):
     model = Group

examples/django_roa_server/models.py

 from django.db import models
-from django.utils.translation import gettext_lazy as _
 
 class RemotePage(models.Model):
     title = models.CharField(max_length=50, blank=True, null=True)

examples/django_roa_server/urls.py

-from django.conf import settings
-from django.conf.urls.defaults import *
+from django.conf.urls.defaults import url, patterns
 
 from piston.resource import Resource
 from piston.authentication import HttpBasicAuthentication

examples/twitter_roa/settings.py

 }
 
 ## ROA custom settings
-ROA_MODELS = True   # set to False if you'd like to develop/test locally
+ROA_MODELS = True # set to False if you'd like to develop/test locally
 ROA_FORMAT = 'twitter' # json or xml
 ROA_DJANGO_ERRORS = True # useful to ease debugging if you use test server