Commits

Mikhail Korobov  committed c03c046

Allow customisible URLs (ex.: slugs). Fix #1.

  • Participants
  • Parent commits dfff96d

Comments (0)

Files changed (4)

 
 * ``queryset`` - Required. Albums will be attached to objects in this queryset.
 
+* ``object_regex`` - Optional, default is '\d+'. It should be a regular 
+expression for object used in URL.
+
+* ``lookup_field`` - Optional, default is 'pk'. It is a field name to lookup
+with data from URL. It may contain ``__`` and follow relations 
+(ex.: `userprofile__slug`) 
+
 * ``app_name`` - Optional, default value is 'album'. Used by url namespaces stuff.
 
 * ``extra_context`` - Optional. Extra context that will be passed to each view.
 	    username = 'obiwanus' 
 	    password = 'vasia'
 	    
-	    # fixtures with  to be loaded (at least with users, images and 
+	    # fixtures to be loaded (at least with users, images and 
 	    # objects with galleries)
 	    fixtures = ['my_fixtures']
 	    

File README.creole

 
 * ``queryset`` - Required. Albums will be attached to objects in this queryset.
 
+
+* ``object_regex`` - Optional, default is '\d+'. It should be a regular 
+expression for object used in URL.
+
+* ``lookup_field`` - Optional, default is 'pk'. It is a field name to lookup
+with data from URL. It may contain ``__`` and follow relations 
+(ex.: `userprofile__slug`) 
+
 * ``app_name`` - Optional, default value is 'album'. Used by url namespaces stuff.
 
 * ``extra_context`` - Optional. Extra context that will be passed to each view.
     username = 'obiwanus' 
     password = 'vasia'
 	    
-    # fixtures with  to be loaded (at least with users, images and 
+    # fixtures to be loaded (at least with users, images and 
     # objects with galleries)
     fixtures = ['my_fixtures']
 	    

File photo_albums/urls.py

 class PhotoAlbumSite(PluggableSite):
     
     def __init__(self, instance_name, queryset, app_name='album', 
+                 object_regex = r'\d+', lookup_field = 'pk',                 
                  extra_context=None, template_object_name = 'object',
                  has_edit_permission = lambda request, obj: True,
                  context_processors=None):
         
         super(PhotoAlbumSite, self).__init__(instance_name, queryset, app_name, 
+                                             object_regex, lookup_field,                                             
                                              extra_context, template_object_name,
                                              has_edit_permission, context_processors)
                 
                         
                         #album-level views
                         url(
-                            r'^(?P<object_id>\d+)/%s/$' % self.app_name,
+                            self.make_regex(r'/'),
                             'show_album', 
                             {'album_site': self},
                             name = 'show_album',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/edit$' % self.app_name,
+                            self.make_regex(r'/edit'),
                             'edit_album', 
                             {'album_site': self},
                             name = 'edit_album',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/upload_main/$' % self.app_name,
+                            self.make_regex(r'/upload_main/'),                            
                             'upload_main_image',
                             {'album_site': self},
                             name = 'upload_main_image',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/upload_images/$' % self.app_name,
+                            self.make_regex(r'/upload_images/'),
                             'upload_images',
                             {'album_site': self},
                             name = 'upload_images',
                         
                         #one image views
                         url(
-                            r'^(?P<object_id>\d+)/%s/(?P<image_id>\d+)/$' % self.app_name,
+                            self.make_regex(r'/(?P<image_id>\d+)/'),
                             'show_image',
                             {'album_site': self},
                             name = 'show_image',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/(?P<image_id>\d+)/edit$' % self.app_name,
+                            self.make_regex(r'/(?P<image_id>\d+)/edit'),
                             'edit_image',
                             {'album_site': self},
                             name = 'edit_image',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/(?P<image_id>\d+)/delete$' % self.app_name,
+                            self.make_regex(r'/(?P<image_id>\d+)/delete'),
                             'delete_image',
                             {'album_site': self},
                             name = 'delete_image',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/(?P<image_id>\d+)/set-as-main$' % self.app_name,
+                            self.make_regex(r'/(?P<image_id>\d+)/set-as-main'),
                             'set_as_main_image',
                             {'album_site': self},
                             name = 'set_as_main_image',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/(?P<image_id>\d+)/clear-main$' % self.app_name,
+                            self.make_regex(r'/(?P<image_id>\d+)/clear-main'),
                             'clear_main_image',
                             {'album_site': self},
                             name = 'clear_main_image',
                                                 
                         #reorder
                         url(
-                            r'^(?P<object_id>\d+)/%s/reorder/$' % self.app_name,
+                            self.make_regex(r'/reorder/'),
                             'edit_album', 
                             {'album_site': self, 'template_name': 'reorder_images.html'},
                             name = 'reorder_images',
                         ),
                         url(
-                            r'^(?P<object_id>\d+)/%s/set_image_order$' % self.app_name,
+                            self.make_regex(r'/set_image_order'),
                             'set_image_order', 
                             {'album_site': self},
                             name = 'set_image_order',
 
 setup(
       name='django-photo-albums',
-      version='0.13',
+      version='0.15',
       author='Mikhail Korobov',
       author_email='kmike84@gmail.com',
       url='http://bitbucket.org/kmike/django-photo-albums/',      
       license = 'MIT license',
       packages=['photo_albums'],
       requires = ['django (>=1.1)'],
-      install_requires=['django-generic-images >= 0.25', 'django-annoying > 0.5'],
+      install_requires=['django-generic-images >= 0.28', 'django-annoying > 0.5'],
       
       classifiers=(
           'Development Status :: 3 - Alpha',