djangosnippets.org: Latest snippets posted by bradmontgomeryhttp://djangosnippets.org/users/bradmontgomery/2010-08-28T13:45:26.193133-05:00bradmontgomeryslug_and_slash_to_dash - modified slugify for urls
2010-08-28T13:45:26.193133-05:00bradmontgomeryhttp://djangosnippets.org/snippets/2177/<p>This filter converts slashes to spaces in a a sting and then slugify's the result. However, it ignores leading and trailing slashes. For example, it can take something like this:
</p>
<pre><code>/some/url/with-an-existing-slug/
</code></pre><p>And turn it into this:
</p>
<pre><code>some-url-with-an-existing-slug
</code></pre><p>The filter was originally written to use the <em>curent</em> url as the <code>disqus_identifier …</code></p>
Freely redistributableFlatpage Suggester Template tag for 404 templates
2010-02-02T10:13:41.545450-06:00bradmontgomeryhttp://djangosnippets.org/snippets/1908/<p>This template tag finds FlatPages with urls 'similar' to the given request_path. It takes the request_path from the page_not_found view (django.views.defaults), picks it apart, and attempts to match existing FlatPages that have a 'similar' URL.</p>
<p>For example, if the URL that resulted in a 404 was:</p>
<pre><code>/foo/bar/baz/whatever/
</code></pre>
<p>This tag would …</p>
Freely redistributableRow-Level, URL-based permissions for FlatPages
2009-06-17T09:52:13.706006-05:00bradmontgomeryhttp://djangosnippets.org/snippets/1569/<p>I'm using Django's FlatPages, but I want to be able to restrict admin access to Users based on a FlatPage url. For example, User John Doe should be able to edit any FlatPage objects whose URL begins with <code>/johndoe/</code> (such as <code>/johndoe/about/</code> or <code>/johndoe/projects/whatever/</code>).</p>
<p>For this to work, John …</p>
Freely redistributableSimple Flatpage Navigation Items
2009-06-12T16:11:55.255574-05:00bradmontgomeryhttp://djangosnippets.org/snippets/1566/<p>Flatpages are great for simple html content. However, I wanted some way to associate a navigation menu (just a snippet of HTML) with one or more FlatPage objects. Additionally, I wanted to be able to edit these throught the Admin. This was my solution.</p>
Freely redistributableSplitSelectDateTimeWidget
2008-11-19T11:36:18.726734-06:00bradmontgomeryhttp://djangosnippets.org/snippets/1206/<p>This class extends MultiWidget to create a widget that consists of HTML select elements for Django's forms.DateTimeFields. This results in a select elements with options for month, day, year, hour, minute, second, and (if using the twelve_hr option) meridiem.</p>
<pre><code># Default usage of SplitSelectDateTimeWidget
class TimeForm(Form):
dt = DateTimeField(widget=SplitSelectDateTimeWidget())
</code></pre>
<p>Another …</p>
Freely redistributableSelectTimeWidget
2008-11-18T13:52:32.467840-06:00bradmontgomeryhttp://djangosnippets.org/snippets/1202/<p>This snippet defines a Widget that is very similar to the <strong>SelectDateWidget</strong> located in django.forms.extras.widgets. The main difference however is that it works with Times instead of Dates.</p>
<p>The SelectTimeWidget supports both 24-hr and 12-hr formats, and flexible time increments for hours, minutes and seconds. Sample usage is illustrated below: …</p>
Freely redistributable