Skip to content
Browse files

Readme upgrades

  • Loading branch information...
1 parent 0dec1ea commit c44881f1f96dcdb7f5f49929e8dcf96d6bac696d @oinopion committed May 17, 2012
Showing with 41 additions and 98 deletions.
  1. +41 −98 README.rst
View
139 README.rst
@@ -1,8 +1,11 @@
-Django has nice routing, but it's too low level. Regexps are powerful,
+Django Happy Urls
+=================
+
+Django has nice routing, but it's too low level. Regexps are powerful,
but but have cryptic syntax. This library strives to make writing DRY
urls a breeze.
-Consider a standard urls.py:
+Consider a standard urls.py::
urlpatterns = patterns('blog.entries.views',
url(r'^entries/$', 'recent_entries', name='entries_recent_entries'),
@@ -16,114 +19,54 @@ Consider a standard urls.py:
It has many issues:
- - you need to remember about the '^' and the '$'
- - you repeat the base url 'entries'
- - you repeat the entry_slug url
- - you need to remember arcane named group syntax
- - you repeat the [\w-]+ group
- - you associate name with urls conf
+- you need to remember about the '^' and the '$'
+- you repeat the base url 'entries'
+- you repeat the entry_slug url
+- you need to remember arcane named group syntax
+- you repeat the [\w-]+ group
+- you associate name with urls conf
-Better way of writing urls would be:
+Better way of writing urls would be::
urlpatterns = hurl.patterns('blog.entries.views', {
'': 'recent_entries',
'<entry_slug:str>': {
'': 'show_entry',
+ 'new': 'new_entry',
+ 'edit': 'edit_entry',
'delete': 'delete_entry',
- 'edit': 'delete_entry',
- 'new': 'delete_entry',
'comments': 'comments_list',
- 'comments/<:int>': 'comments_list',
- }),
- )
-
- urlpatterns = hurl.patterns('blog.entries.views', {
- '': 'recent_entries',
- '<entry_slug:str>': {
- '': 'show_entry',
- 'delete': 'delete_entry',
- 'edit': 'delete_entry',
- 'new': 'delete_entry',
- 'comments': include('apps.urls'),
+ 'comments/<:int>': 'comment_detail',
}),
)
-It conveys url structure more clearly
-
-Happy URLs
-
-# original:
-urlpatterns = patterns('',
- (r'^articles/2003/$', 'news.views.special_case_2003', {}, 'news_special_case_2003'),
- (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'),
- (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'),
- (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 'news.views.article_detail'),
-)
-
-# hurled:
-hurl = Hurl()
-hurl.matchers['year'] = r'\d{4}'
-hurl.matchers['month'] = r'\d{2}'
-hurl.matchers['month2'] = r'\d{1}'
-hurl.matchers['day'] = r'\d{2}'
+It conveys url structure more clearly, is much more readable and
+avoids repetition.
-urlpatterns = hurl.patterns('', 'articles', {
- '2003': 'news.views.special_case_2003',
- '<year>': 'news.views.year_archive',
- '<year>/<month>': 'news.views.month_archive',
- '<year>/<month>/<day>': 'news.views.article_detail',
-})
-
-
-
-
-
-ssl = get_satchmo_setting('SSL', default_value=False)
-
-urlpatterns = patterns('payment.views',
- (r'^$', 'contact.contact_info_view', {'SSL': ssl}, 'satchmo_checkout-step1'),
- (r'^success/$', 'checkout.success', {'SSL' : ssl}, 'satchmo_checkout-success'),
- (r'custom/charge/(?P<orderitem_id>\d+)/$', 'balance.charge_remaining', {}, 'satchmo_charge_remaining'),
- (r'custom/charge/$', 'balance.charge_remaining_post', {}, 'satchmo_charge_remaining_post'),
- (r'^balance/(?P<order_id>\d+)/$', 'balance.balance_remaining_order', {'SSL' : ssl}, 'satchmo_balance_remaining_order'),
- (r'^balance/$', 'balance.balance_remaining', {'SSL' : ssl}, 'satchmo_balance_remaining'),
- (r'^cron/$', 'cron.cron_rebill', {}, 'satchmo_cron_rebill'),
- (r'^mustlogin/$', 'contact.authentication_required', {'SSL' : ssl}, 'satchmo_checkout_auth_required'),
-)
-
-hurl.matchers['custom_charge'] = r'custom/charge/(?P<orderitem_id>\d+)'
-hurl.name_prefix = 'satchmo'
-hurl.default_data = {'SSL': ssl}
-
-urlpatterns = hurl.patterns('payment.views', {
- '': ('contact.contact_info_view', 'checkout-step1'),
- 'success': ('checkout.success', 'checkout-success'),
- r'<!custom/charge/(?P<orderitem_id>\d+)>': (balance.charge_remaining', 'charge_remaining', {}),
- 'balance': {
- '': ('balance.balance_remaining', 'balance_remaining'),
- '<order_id:int>': ('balance.balance_remaining_order', 'balance_remaining_order')
- },
- 'cron': ('cron.cron_rebill', 'cron_rebill', {}),
- 'mustlogin': ('contact.authentication_required', 'checkout_auth_required'),
-})
-
-urlpatterns = patterns('blog.entries.views',
- url(r'^$', 'recent_entries', name='entries_recent_entries'),
- url(r'^(?P<entry_slug>[\w-]+)/$', 'show_entry', name='entries_show_entry'),
- url(r'^(?P<entry_slug>[\w-]+)/delete/$', 'delete_entry', name='entries_delete_entry'),
- url(r'^(?P<entry_slug>[\w-]+)/new/$', 'new_entry', name='entries_delete_entry'),
- url(r'^(?P<entry_slug>[\w-]+)/comments/$', include('blog.comments.urls'))
-)
-
-urlpatterns = hurl.patterns('blog.entries.views', {
- '<entry_slug:str>': {
- '': 'show',
- 'delete': 'delete',
- 'new': 'new',
- 'comments': include('blog.comments.urls'),
- 'dupa': ('dupa_view', 'dupa_name', {}),
- }
-})
+More examples
+-------------
+Django tutorial::
+ # original:
+ urlpatterns = patterns('',
+ (r'^articles/2003/$', 'news.views.special_case_2003', {}, 'news_special_case_2003'),
+ (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive', {}, 'news_year_archive'),
+ (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive', {}, 'news_month_archive'),
+ (r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 'news.views.article_detail', {}, 'news_article_detail'),
+ )
+ # hurled:
+ hurl = Hurl(name_prefix='news')
+ hurl.matchers['year'] = r'\d{4}'
+ hurl.matchers['month'] = r'\d{2}'
+ hurl.matchers['day'] = r'\d{2}'
+
+ urlpatterns = hurl.patterns('news.views', {
+ 'articles': {
+ '2003': 'special_case_2003',
+ '<year>': 'year_archive',
+ '<year>/<month>': 'month_archive',
+ '<year>/<month>/<day>': 'article_detail',
+ }
+ })

0 comments on commit c44881f

Please sign in to comment.
Something went wrong with that request. Please try again.