Commits

Chris Beaven  committed fd61fbb

PEP8 tidy up (and add the test template to setup.py package_data)

  • Participants
  • Parent commits b10997d

Comments (0)

Files changed (6)

File lockdown/forms.py

 
 
 class BasePreviewForm(forms.Form):
+
     def generate_token(self):
         """
         Generate a token which can be used to authenticate the user for future
         requests.
-        
+
         """
         return True
 
         """
         Authenticate the user from a stored token value. If the ``token_value``
         is ``None``, then no token was retrieved.
-         
+
         """
         return token_value is True
 
     def show_form(self):
         """
         Determine whether or not the form should be shown on locked pages.
-        
+
         """
         return True
 
     def clean_password(self):
         """
         Check that the password is valid.
-        
+
         """
         value = self.cleaned_data.get('password')
         if not value in self.valid_passwords:
     def generate_token(self):
         """
         Save the password as the authentication token.
-        
+
         It's acceptable to store the password raw, as it is stored server-side
         in the user's session.
-        
+
         """
         return self.cleaned_data['password']
 
     def authenticate(self, token_value):
         """
         Check that the password is valid.
-        
+
         This allows for revoking of a user's preview rights by changing the
         valid passwords.
-        
+
         """
         return token_value in self.valid_passwords
 
     def show_form(self):
         """
         Show the form if there are any valid passwords.
-         
+
         """
         return bool(self.valid_passwords)
 
 
 class AuthForm(AuthenticationForm, BasePreviewForm):
+
     def __init__(self, staff_only=None, superusers_only=None, *args,
                  **kwargs):
         from django.conf import settings as django_settings
     def generate_token(self):
         """
         Save the password as the authentication token.
-        
+
         It's acceptable to store the password raw, as it is stored server-side
         in the user's session.
-        
+
         """
         user = self.get_user()
         return '%s:%s' % (user.backend, user.pk)
     def authenticate(self, token_value):
         """
         Check that the password is valid.
-        
+
         This allows for revoking of a user's preview rights by changing the
         valid passwords.
-        
+
         """
         try:
             backend_path, user_id = token_value.split(':', 1)

File lockdown/middleware.py

 
 
 class LockdownMiddleware(object):
+
     def __init__(self, form=None, logout_key=None, session_key=None,
                  url_exceptions=None, **form_kwargs):
         if logout_key is None:

File lockdown/tests/forms.py

 from django import forms
 
+
 class CustomLockdownForm(forms.Form):
     answer = forms.IntegerField()
 

File lockdown/tests/tests.py

     """
     Base tests for lockdown functionality (whether via a decorator or
     middleware).
-    
+
     Subclasses should provide ``locked_url`` and ``locked_contents``
-    attributes. 
-    
+    attributes.
+
     """
 
     def test_lockdown_template_used(self):
 
 
 class AuthFormTests(LockdownTestCase):
+
     def test_using_form(self):
         url = '/auth/user/locked/view/'
         response = self.client.get(url)
         # Skip this test if auth isn't an installed app.
         if 'django.contrib.auth' not in django_settings.INSTALLED_APPS:
             return
-        
+
         url = '/auth/user/locked/view/'
         self.add_user()
 
         # Skip this test if auth isn't an installed app.
         if 'django.contrib.auth' not in django_settings.INSTALLED_APPS:
             return
-        
+
         url = '/auth/staff/locked/view/'
         self.add_user(username='user')
         self.add_user(username='staff', is_staff=True)
         # Skip this test if auth isn't an installed app.
         if 'django.contrib.auth' not in django_settings.INSTALLED_APPS:
             return
-        
+
         url = '/auth/superuser/locked/view/'
         self.add_user(username='staff', is_staff=True)
         self.add_user(username='superuser', is_staff=True, is_superuser=True)
 #!/usr/bin/env python
 
-import os, sys
+import os
+import sys
 
 from django.conf import settings
 
     sys.path.insert(0, parent)
     settings.configure(
         DATABASE_ENGINE='sqlite3',
-        INSTALLED_APPS = (
+        INSTALLED_APPS=(
             'django.contrib.sessions',
             'django.contrib.contenttypes',
             'django.contrib.auth',
-            'lockdown'
+            'lockdown',
         ),
         ROOT_URLCONF='lockdown.tests.urls',
     )
-from setuptools import setup
+from setuptools import setup, find_packages
 import subprocess
 import os.path
 
 try:
-    # don't get confused if our sdist is unzipped in a subdir of some 
+    # don't get confused if our sdist is unzipped in a subdir of some
     # other hg repo
     if os.path.isdir('.hg'):
         p = subprocess.Popen(['hg', 'parents', r'--template={rev}\n'],
             fh.close()
 except (OSError, IndexError):
     pass
-    
+
 try:
     hgrev = open('HGREV').read()
 except IOError:
     hgrev = ''
-    
+
 long_description = (open('README.txt').read() +
                     open('CHANGES.txt').read() +
                     open('TODO.txt').read())
 setup(
     name='django-lockdown',
     version='0.1.1.post%s' % hgrev,
-    description='Site-wide or per-view lockdown with customizable preview authorization',
+    description=('Site-wide or per-view lockdown with customizable preview '
+                 'authorization'),
     long_description=long_description,
     author='Carl Meyer',
     author_email='carl@dirtcircle.com',
     url='http://bitbucket.org/carljm/django-lockdown/',
-    packages=['lockdown'],
+    packages=find_packages(),
     classifiers=[
         'Development Status :: 3 - Alpha',
         'Environment :: Web Environment',
     ],
     zip_safe=False,
     test_suite='runtests.runtests',
-    package_data={'lockdown': ['templates/lockdown/*.html']}
+    package_data={'lockdown': ['templates/lockdown/*.html',
+                               'tests/templates/lockdown/*.html']},
 )