Grigoriy Petukhov avatar Grigoriy Petukhov committed db744d7

Move wrap_url into AuthKey manager

Comments (0)

Files changed (4)

 Installation of django-urlauth
 ==============================
 
-If you have ``easy_install`` or ``pip`` then run::
+pip install django-urlauth
 
-    easy_install django-urlauth
+configuration
+=============
 
-or
-
-    pip django-urlauth
-
-Also you can download package and run the following command iside package directory::
-
-    python setup.py install
-
-After installing django-urlauth package to the system you have to setup your site. See "index.rst" file in the "docs/" directory for site setup instructions.
+* Add `urlauth` to INSTALLED_APPS
+* Put `urlauth.middleware.AuthKeyMiddleware' to MIDDLEWARES
+* Put "from urlauth.settings import * to settings.py
             data_files.append(os.path.join(prefix, f))
 
 setup(
-    version = '0.1.5',
+    version = '0.1.6',
     description = 'Django application for user authentication with key in hypertext link',
     author = 'Grigoriy Petukhov',
     author_email = 'lorien@lorien.name',

urlauth/models.py

         key.save()
         return key.id
 
+    def wrap_url(self, url, **kwargs):
+        """
+        Create new authorization key, append it to the url and return modified url.
+        """
+
+        key_id = self.create_key(**kwargs)
+        clue = '?' in url and '&' or '?'
+        parts = url.rsplit('#', 1)
+        if len(parts) > 1:
+            url, hash = parts
+            hash = '#%s' % hash
+        else:
+            hash = ''
+        url = '%s%s%s=%s%s' % (url, clue, settings.URLAUTH_AUTHKEY_NAME, key_id, hash)
+        return url
+
 
 class AuthKey(models.Model):
     id = models.CharField(max_length=40, primary_key=True)
 from base64 import b64encode, b64decode
 from urllib import urlencode
 from cgi import parse_qs
+import logging
 
 from django.conf import settings
 
     """
     Create new authorization key and append it to the url.
     """
-
-    if not 'uid' in kwargs:
-        raise Exception('wrap_url function requires uid name argument')
-
-    key_id = AuthKey.objects.create_key(**kwargs)
-    clue = '?' in url and '&' or '?'
-    parts = url.rsplit('#', 1)
-    if len(parts) > 1:
-        url, hash = parts
-        hash = '#%s' % hash
-    else:
-        hash = ''
-    url = '%s%s%s=%s%s' % (url, clue, settings.URLAUTH_AUTHKEY_NAME, key_id, hash)
-    return url
+    
+    logging.error('urlauth.util.wrap_url is deprecated. Use AuthKey.objects.wrap_url instead.')
+    return AuthKey.objects.wrap_url(url, **kwargs)
 
 
 def load_key(hash):
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.