Login

Tag "name"

Snippet List

Resolve URLs to view name and args/kwargs

This is an expanded version of ["Resolve URLs to view name"](http://djangosnippets.org/snippets/1378/) without the monkey-patching. Simply pass in a URL such as '/events/rsvp/some_conference/' and you'll get back the view name or function (if name isn't available) and the arguments to it, eg 'events_rsvp', [], {'event_slug':'some_conference'}. Example (blatantly copied from previous snippet): === urlconf ==== urlpatterns = patterns('' (r'/some/url', 'app.views.view'), url(r'/some/other/(?P<url>\w+)', 'app.views.other.view', name='this_is_a_named_view'), url(r'/yet/another/(?P<url>\w+)/(\d+)', 'app.views.yetanother.view', name='one_with_args'), ) === example usage in interpreter === >>> from some.where import resolve_to_name >>> print resolve_to_name('/some/url') ('app.views.view',[],{}) >>> print resolve_to_name('/some/other/url') ('this_is_a_named_view',[],{'url':'url'}) >>> print resolve_to_name('/yet/another/url/5') ('one_with_args',[5],{'url':'url'}) From [fahhem.com](http://fahhem.com/) and [Recrec Labs](http://recreclabs.com/)

  • url
  • resolve
  • name
  • args
  • kwargs
Read More

Resolve URLs to view name

This snippet suplies a resolve_to_name function that takes in a path and resolves it to a view name or view function name (given that the path is actually defined in your urlconf). Example: === urlconf ==== urlpatterns = patterns('' (r'/some/url', 'app.views.view'), (r'/some/other/url', 'app.views.other.view', {}, 'this_is_a_named_view'), ) === example usage in interpreter === >>> from some.where import resolve_to_name >>> print resolve_to_name('/some/url') 'app.views.view' >>> print resolve_to_name('/some/other/url') 'this_is_a_named_view'

  • view
  • url
  • resolve
  • name
Read More

Username genrator

This function generate an username based on the user's full name. First it tries to use the first name first letter plus the last name, second it tires the first name plus the last name first latter, and at last it tries to use the first name with a sequential number at the end. The username generated are all lowercase and ASCII only characters.

  • auth
  • username
  • name
Read More

3 snippets posted so far.