Anonymous avatar Anonymous committed e5110bb

Preparing for 0.2 release

Comments (0)

Files changed (5)

docs/overview.txt

 Development
 ===========
 
-The `latest released version`_ of this application is 0.1, and is
+The `latest released version`_ of this application is 0.2, and is
 quite stable; it's already been deployed on a number of sites. You can
 also obtain the absolute freshest code from `a Subversion checkout`_,
 but be warned that the code in SVN may not always be
 backwards-compatible, and may well contain bugs that haven't yet been
 fixed.
 
-This document covers the 0.1 release of django-registration; new
+This document covers the 0.2 release of django-registration; new
 features introduced in Subversion will be added to the documentation
 at the time of the next packaged release.
 
-.. _latest released version: http://django-registration.googlecode.com/files/registration-0.1.tar.gz
+.. _latest released version: http://django-registration.googlecode.com/files/registration-0.2.tar.gz
 .. _a Subversion checkout: http://django-registration.googlecode.com/svn/trunk/registration/
 
 
+Changes from previous versions
+==============================
+
+Several new features were added between version 0.1 and version 0.2;
+for details, see the CHANGELOG.txt file distributed with the packaged
+0.2 release.
+
+One important change to note before upgrading an installation of
+version 0.1 is a change to the ``RegistrationProfile`` model; the
+field ``key_generated`` has been removed, since it was redundant with
+the field ``date_joined`` on Django's bundled ``User`` model. Since
+this field became a ``NOT NULL`` column in the database, you will need
+to either drop the ``NOT NULL`` constraint or, preferably, simply drop
+the column. Consult your database's documentation for the correct way
+to handle this.
+
+
 Dependencies
 ============
 
         template to customize the text of the email. This method
         returns the new ``User`` object, in case you want to do
         something with it afterwards.
+	
+	To enable creation of a site-specific user profile (e.g., the
+	model specified in the ``AUTH_PROFILE_MODULE`` setting), pass
+	the optional keyword argument ``profile_callback``; the value
+	of this argument should be a function which, given a ``User``,
+	will create and save an instance of the site-specific profile
+	with appropriate default values.
+
+    ``create_profile`` Given a ``User`` object, creates, saves and
+        returns a ``RegistrationProfile`` for that ``User``,
+        generating the activation key from a combinatino og the
+        ``User``'s username and a random salt.
 
     ``delete_inactive_users``
         Clears out accounts which were never activated; it does this
 override this by passing the keyword argument ``success_url`` into the
 view.
 
+To enable creation of a site-specific user profile, pass the optional
+keyword argument ``profile_callback`` to this view; see the
+``create_inactive_user`` method of the manager on
+``RegistrationProfile`` (documented above) for details.
+
 URLs
 ====
 

registration/forms.py

 
 """
 
+
 import re
+
 from django import newforms as forms
 from django.contrib.auth.models import User
 
+
 # I put this on all required fields, because it's easier to pick up
 # on them with CSS or JavaScript if they have a class of "required"
 # in the HTML. Your mileage may vary.
 attrs_dict = { 'class': 'required' }
 
+
 username_re = re.compile(r'^\w+$')
 
+
 class RegistrationForm(forms.Form):
     """
     Form for registering a new user account.

registration/models.py

 """
 A registration profile model and associated manager.
 
-The RegistrationProfile model and especially its custom manager
+The ``RegistrationProfile`` model and especially its custom manager
 implement nearly all the logic needed to handle user registration and
 account activation, so before implementing something in a view or
 form, check here to see if they can take care of it for you.
 
-Also, be sure to see the note on RegistrationProfile about use of the
+Also, be sure to see the note on ``RegistrationProfile`` about use of the
 ``AUTH_PROFILE_MODULE`` setting.
 
 """
 
+
 import datetime, random, re, sha
+
 from django.db import models
 from django.template import Context, loader
 from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
 from django.conf import settings
 
+
 SHA1_RE = re.compile('^[a-f0-9]{40}$')
 
+
 class RegistrationManager(models.Manager):
     """
-    Custom manager for the RegistrationProfile model.
+    Custom manager for the ``RegistrationProfile`` model.
     
     The methods defined here provide shortcuts for account creation
     and activation (including generation and emailing of activation
     """
     def activate_user(self, activation_key):
         """
-        Given the activation key, makes a User's account active if the
+        Given the activation key, makes a ``User``'s account active if the
         activation key is valid and has not expired.
         
-        Returns the User if successful, or False if the account was
+        Returns the ``User`` if successful, or False if the account was
         not found or the key had expired.
         
         """
     
     def create_inactive_user(self, username, password, email, send_email=True, profile_callback=None):
         """
-        Creates a new User and a new RegistrationProfile for that
-        User, generates an activation key, and mails it.
+        Creates a new ``User`` and a new ``RegistrationProfile`` for that
+        ``User``, generates an activation key, and mails it.
         
         Pass ``send_email=False`` to disable sending the email.
 
         To enable creation of a custom user profile along with the
-        User (e.g., the model specified in the ``AUTH_PROFILE_MODULE``
-        setting), define a function which knows how to create and save
-        an instance of that model with appropriate default values, and
-        pass it as the keyword argument ``profile_callback``. This
-        function should accept one argument:
-        
-            user
-                The User object to which the profile will be related.
+        ``User`` (e.g., the model specified in the
+        ``AUTH_PROFILE_MODULE`` setting), define a function which
+        knows how to create and save an instance of that model with
+        appropriate default values, and pass it as the keyword
+        argument ``profile_callback``. This function should accept one
+        argument: the ``User`` to relate the profile to.
         
         """
         # Create the user.
         new_user.is_active = False
         new_user.save()
         
-        # Generate a salted SHA1 hash to use as a key.
-        salt = sha.new(str(random.random())).hexdigest()[:5]
-        activation_key = sha.new(salt+new_user.username).hexdigest()
-        
-        # And finally create the profile.
-        registration_profile = self.create(user=new_user,
-                                           activation_key=activation_key)
+        # And finally create the registration profile.
+        registration_profile = self.create_profile(new_user)
         
         # Create site-specific profile, if specified.
         if profile_callback is not None:
-            profile_callback(user=new_user)
+            profile_callback(new_user)
         
         if send_email:
             from django.core.mail import send_mail
             send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email])
         return new_user
     
+    def create_profile(self, user):
+        """
+        Given a ``User``, creates, saves and returns a
+        ``RegistrationProfile`` for that ``User``, generating the
+        activation key from a combination of the ``User``'s username
+        and a random salt.
+        
+        """
+        salt = sha.new(str(random.random())).hexdigest()[:5]
+        activation_key = sha.new(salt+new_user.username).hexdigest()
+        return self.create(user=user,
+                           activation_key=activation_key)
+        
     def delete_expired_users(self):
         """
         Removes unused profiles and their associated accounts.
 
         This is provided largely as a convenience for maintenance
-        purposes; if a RegistrationProfile's key expires without the
-        account being activated, then both the RegistrationProfile and
-        the associated User become clutter in the database, and (more
+        purposes; if a ``RegistrationProfile``'s key expires without the
+        account being activated, then both the ``RegistrationProfile`` and
+        the associated ``User`` become clutter in the database, and (more
         importantly) it won't be possible for anyone to ever come back
         and claim the username. For best results, set this up to run
         regularly as a cron job.
         
-        If you have a User whose account you want to keep in the
+        If you have a ``User`` whose account you want to keep in the
         database even though it's inactive (say, to prevent a
         troublemaker from accessing or re-creating his account), just
-        delete that User's RegistrationProfile and this method will
+        delete that ``User``'s ``RegistrationProfile`` and this method will
         leave it alone.
         
         """
             if profile.activation_key_expired():
                 user = profile.user
                 if not user.is_active:
-                    user.delete() # Removing the User will remove the RegistrationProfile, too.
+                    user.delete() # Removing the ``User`` will remove the ``RegistrationProfile``, too.
 
 
 class RegistrationProfile(models.Model):
     """
-    Simple profile model for a User, storing an activation key for the
+    Simple profile model for a ``User``, storing an activation key for the
     account.
     
     While it is possible to use this model as the value of the
     
     def activation_key_expired(self):
         """
-        Determines whether this Profile's activation key has expired,
-        based on the value of the setting ``ACCOUNT_ACTIVATION_DAYS``.
+        Determines whether this ``RegistrationProfile``'s activation
+        key has expired, based on the value of the setting
+        ``ACCOUNT_ACTIVATION_DAYS``.
         
         """
         expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)

registration/views.py

 
 """
 
+
 from django.conf import settings
 from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
 from django.template import RequestContext
+
 from registration.forms import RegistrationForm
 from registration.models import RegistrationProfile
 
+
 def activate(request, activation_key):
     """
-    Activates a user's account, if their key is valid and hasn't
+    Activates a ``User``'s account, if their key is valid and hasn't
     expired.
 
     Context::
                                 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
                               context_instance=RequestContext(request))
 
+
 def register(request, success_url='/accounts/register/complete/', profile_callback=None):
     """
     Allows a new user to register an account.
 from distutils.core import setup
 
 setup(name='registration',
-      version='0.1',
+      version='0.2',
       description='User-registration application for Django',
       author='James Bennett',
       author_email='james@b-list.org',
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.