Commits

depleater committed 839a87c

Fixed outstanding PEP8 violations.

Comments (0)

Files changed (8)

 # All configuration values have a default; values that are commented out
 # serve to show the default.
 
-import sys, os
+import sys
+import os
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, documentclass [howto/manual]).
 latex_documents = [
-  ('index', 'django-workflows.tex', u'django-workflows Documentation',
-   u'Kai Diefenbach', 'manual'),
+    ('index', 'django-workflows.tex', u'django-workflows Documentation', u'Kai Diefenbach', 'manual'),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
 setup(name='django-workflows',
       version=version,
       description="Generic workflow engine for Django.",
-      long_description=README,      
+      long_description=README,
       # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       classifiers=[
           'Development Status :: 4 - Beta',

workflows/__init__.py

 # workflows imports
 import workflows.utils
 
+
 class WorkflowBase(object):
     """Mixin class to make objects workflow aware.
     """
     def do_transition(self, transition, user):
         """Processes the passed transition (if allowed).
         """
-        return workflows.utils.do_transition(self, transition, user)
+        return workflows.utils.do_transition(self, transition, user)

workflows/admin.py

 from workflows.models import WorkflowModelRelation
 from workflows.models import WorkflowPermissionRelation
 
+
 class StateInline(admin.TabularInline):
     model = State
 
+
 class WorkflowAdmin(admin.ModelAdmin):
     inlines = [
         StateInline,
 admin.site.register(WorkflowObjectRelation)
 admin.site.register(WorkflowModelRelation)
 admin.site.register(WorkflowPermissionRelation)
-

workflows/models.py

 from permissions.models import Permission
 from permissions.models import Role
 
+
 class Workflow(models.Model):
     """A workflow consists of a sequence of connected (through transitions)
     states. It can be assigned to a model and / or model instances. If a
         try:
             wor = WorkflowObjectRelation.objects.get(content_type=ctype, content_id=obj.id)
         except WorkflowObjectRelation.DoesNotExist:
-            WorkflowObjectRelation.objects.create(content = obj, workflow=self)
+            WorkflowObjectRelation.objects.create(content=obj, workflow=self)
             workflows.utils.set_state(obj, self.initial_state)
         else:
             if wor.workflow != self:
                 wor.save()
                 workflows.utils.set_state(self.initial_state)
 
+
 class State(models.Model):
     """A certain state within workflow.
 
         for transition in self.transitions.all():
             permission = transition.permission
             if permission is None:
-               transitions.append(transition)
+                transitions.append(transition)
             else:
                 # First we try to get the objects specific has_permission
                 # method (in case the object inherits from the PermissionBase
                         transitions.append(transition)
         return transitions
 
+
 class Transition(models.Model):
     """A transition from a source to a destination state. The transition can
     be used from several source states.
     def __unicode__(self):
         return self.name
 
+
 class StateObjectRelation(models.Model):
     """Stores the workflow state of an object.
 
     content_type = models.ForeignKey(ContentType, verbose_name=_(u"Content type"), related_name="state_object", blank=True, null=True)
     content_id = models.PositiveIntegerField(_(u"Content id"), blank=True, null=True)
     content = generic.GenericForeignKey(ct_field="content_type", fk_field="content_id")
-    state = models.ForeignKey(State, verbose_name = _(u"State"))
+    state = models.ForeignKey(State, verbose_name=_(u"State"))
 
     def __unicode__(self):
         return "%s %s - %s" % (self.content_type.name, self.content_id, self.state.name)
     class Meta:
         unique_together = ("content_type", "content_id", "state")
 
+
 class WorkflowObjectRelation(models.Model):
     """Stores an workflow of an object.
 
     def __unicode__(self):
         return "%s %s - %s" % (self.content_type.name, self.content_id, self.workflow.name)
 
+
 class WorkflowModelRelation(models.Model):
     """Stores an workflow for a model (ContentType).
 
     def __unicode__(self):
         return "%s - %s" % (self.content_type.name, self.workflow.name)
 
+
 # Permissions relation #######################################################
-
 class WorkflowPermissionRelation(models.Model):
     """Stores the permissions for which a workflow is responsible.
 
     def __unicode__(self):
         return "%s %s" % (self.workflow.name, self.permission.name)
 
+
 class StateInheritanceBlock(models.Model):
     """Stores inheritance block for state and permission.
 
     def __unicode__(self):
         return "%s %s" % (self.state.name, self.permission.name)
 
+
 class StatePermissionRelation(models.Model):
     """Stores granted permission for state and role.
 
     role = models.ForeignKey(Role, verbose_name=_(u"Role"))
 
     def __unicode__(self):
-        return "%s %s %s" % (self.state.name, self.role.name, self.permission.name)
+        return "%s %s %s" % (self.state.name, self.role.name, self.permission.name)

workflows/tests.py

 from workflows.models import WorkflowObjectRelation
 from workflows.models import WorkflowPermissionRelation
 
+
 class WorkflowTestCase(TestCase):
     """Tests a simple workflow without permissions.
     """
         """
         self.assertEqual(self.w.__unicode__(), u"Standard")
 
+
 class PermissionsTestCase(TestCase):
     """Tests a simple workflow with permissions.
     """
         result = workflows.utils.do_transition(self.page_1, "Make pending", self.user)
         self.assertEqual(result, False)
 
-        wrong = Transition.objects.create(name="Wrong", workflow=self.w, destination = self.public)
+        wrong = Transition.objects.create(name="Wrong", workflow=self.w, destination=self.public)
 
         # name which does not exist
         result = workflows.utils.do_transition(self.page_1, wrong, self.user)
         self.assertEqual(result, False)
 
+
 class UtilsTestCase(TestCase):
     """Tests various methods of the utils module.
     """
         self.assertEqual(len(transitions), 1)
 
         # protect the transition with a permission
-        self.make_public.permission = view        
+        self.make_public.permission = view
         self.make_public.save()
 
         # user has no transition
         """
         result = workflows.utils.get_workflow(self.user)
         self.assertEqual(result, None)
-        
+
         # Set workflow for a user
         workflows.utils.set_workflow_for_object(self.user, self.w)
-        
-        # Get workflow for the user        
+
+        # Get workflow for the user
         result = workflows.utils.get_workflow_for_object(self.user)
         self.assertEqual(result, self.w)
 
         result = workflows.utils.get_workflow_for_object(page_1)
         self.assertEqual(result, self.w)
 
+
 class StateTestCase(TestCase):
     """Tests the State model
     """
         transitions = self.private.get_allowed_transitions(self.page_1, self.user)
         self.assertEqual(len(transitions), 1)
 
+
 class TransitionTestCase(TestCase):
     """Tests the Transition model
     """
         """
         self.assertEqual(self.make_private.__unicode__(), u"Make private")
 
+
 class RelationsTestCase(TestCase):
     """Tests various Relations models.
     """
         spr = StatePermissionRelation.objects.create(state=self.public, permission=self.view, role=self.owner)
         self.assertEqual(spr.__unicode__(), "Public Owner View")
 
+
 # Helpers ####################################################################
 
 def create_workflow(self):
     self.w = Workflow.objects.create(name="Standard")
 
-    self.private = State.objects.create(name="Private", workflow= self.w)
-    self.public = State.objects.create(name="Public", workflow= self.w)
+    self.private = State.objects.create(name="Private", workflow=self.w)
+    self.public = State.objects.create(name="Public", workflow=self.w)
 
-    self.make_public = Transition.objects.create(name="Make public", workflow=self.w, destination = self.public)
-    self.make_private = Transition.objects.create(name="Make private", workflow=self.w, destination = self.private)
+    self.make_public = Transition.objects.create(name="Make public", workflow=self.w, destination=self.public)
+    self.make_private = Transition.objects.create(name="Make private", workflow=self.w, destination=self.private)
 
     self.private.transitions.add(self.make_public)
     self.public.transitions.add(self.make_private)
     self.w.initial_state = self.private
     self.w.save()
 
+
 # Taken from "http://www.djangosnippets.org/snippets/963/"
 class RequestFactory(Client):
     """
         environ.update(request)
         return WSGIRequest(environ)
 
+
 def create_request():
     """
     """

workflows/urls.py

 
 # URL patterns for django-workflows
 
-urlpatterns = patterns('django-workflows.views',
-  # Add url patterns here
-)
+urlpatterns = patterns(
+    'django-workflows.views',
+    # Add url patterns here
+    )

workflows/utils.py

 # permissions imports
 import permissions.utils
 
+
 def get_objects_for_workflow(workflow):
     """Returns all objects which have passed workflow.
 
 
     return workflow.get_objects()
 
+
 def remove_workflow(ctype_or_obj):
     """Removes the workflow from the passed content type or object. After this
     function has been called the content type or object has no workflow
     else:
         remove_workflow_from_object(ctype_or_obj)
 
+
 def remove_workflow_from_model(ctype):
     """Removes the workflow from passed content type. After this function has
     been called the content type has no workflow anymore (the instances might
     else:
         wmr.delete()
 
+
 def remove_workflow_from_object(obj):
     """Removes the workflow from the passed object. After this function has
     been called the object has no *own* workflow anymore (it might have one
     # Set initial of object's content types workflow (if there is one)
     set_initial_state(obj)
 
+
 def set_workflow(ctype_or_obj, workflow):
     """Sets the workflow for passed content type or object. See the specific
     methods for more information.
     """
     return workflow.set_to(ctype_or_obj)
 
+
 def set_workflow_for_object(obj, workflow):
     """Sets the passed workflow to the passed object.
 
     obj
         The object which gets the passed workflow.
     """
-    if isinstance(workflow, Workflow) == False:
+    if not isinstance(workflow, Workflow):
         try:
             workflow = Workflow.objects.get(name=workflow)
         except Workflow.DoesNotExist:
 
     workflow.set_to_object(obj)
 
+
 def set_workflow_for_model(ctype, workflow):
     """Sets the passed workflow to the passed content type. If the content
     type has already an assigned workflow the workflow is overwritten.
         The content type to which the passed workflow should be assigned. Can
         be any Django model instance
     """
-    if isinstance(workflow, Workflow) == False:
+    if not isinstance(workflow, Workflow):
         try:
             workflow = Workflow.objects.get(name=workflow)
         except Workflow.DoesNotExist:
 
     workflow.set_to_model(ctype)
 
+
 def get_workflow(obj):
     """Returns the workflow for the passed object. It takes it either from
     the passed object or - if the object doesn't have a workflow - from the
     ctype = ContentType.objects.get_for_model(obj)
     return get_workflow_for_model(ctype)
 
+
 def get_workflow_for_object(obj):
     """Returns the workflow for the passed object.
 
     else:
         return wor.workflow
 
+
 def get_workflow_for_model(ctype):
     """Returns the workflow for the passed model.
 
     else:
         return wor.workflow
 
+
 def get_state(obj):
     """Returns the current workflow state for the passed object.
 
     else:
         return sor.state
 
+
 def set_state(obj, state):
     """Sets the state for the passed object to the passed state and updates
     the permissions for the object.
         sor.save()
     update_permissions(obj)
 
+
 def set_initial_state(obj):
     """Sets the initial state to the passed object.
     """
     if wf is not None:
         set_state(obj, wf.get_initial_state())
 
+
 def get_allowed_transitions(obj, user):
     """Returns all allowed transitions for passed object and user. Takes the
     current state of the object into account.
 
     return state.get_allowed_transitions(obj, user)
 
+
 def do_transition(obj, transition, user):
     """Processes the passed transition to the passed object (if allowed).
     """
     else:
         return False
 
+
 def update_permissions(obj):
     """Updates the permissions of the passed object according to the object's
     current workflow state.
     ct = ContentType.objects.get_for_model(obj)
     ps = [wpr.permission for wpr in WorkflowPermissionRelation.objects.filter(workflow=workflow)]
 
-    ObjectPermission.objects.filter(content_type = ct, content_id=obj.id, permission__in=ps).delete()
+    ObjectPermission.objects.filter(content_type=ct, content_id=obj.id, permission__in=ps).delete()
 
     # Grant permission for the state
     for spr in StatePermissionRelation.objects.filter(state=state):
 
     # Remove all inheritance blocks from the object
     ObjectPermissionInheritanceBlock.objects.filter(
-        content_type = ct, content_id=obj.id, permission__in=ps).delete()
+        content_type=ct, content_id=obj.id, permission__in=ps).delete()
 
     # Add inheritance blocks of this state to the object
     for sib in StateInheritanceBlock.objects.filter(state=state):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.