djangosnippets.org: Latest snippets tagged with 'rails'https://djangosnippets.org/tags/rails/2009-10-14T12:36:32.402420-05:00Rails-like environments using Django
2009-10-14T12:36:32.402420-05:00ElfSternberghttps://djangosnippets.org/snippets/1761/<p>This is a replacement for settings.py, which moves the actual settings files into a directory called "env" and establishes different versions for different settings of the environment variable DJANGO_ENV. At runtime, the specified development environment can be found and loaded into the local context of settings.py, which is then picked …</p>
Freely redistributableRails-like MVC Controllers for Django
2008-11-18T17:04:29.064200-06:00sciyoshihttps://djangosnippets.org/snippets/1204/<p><a href="http://sciyoshi.com/blog/2008/nov/18/rails-mvc-controllers-django/">See the blog entry</a></p>
<p>Allows using controllers for views.</p>
<p>This allows for nice subclassing to override behavior of views. <code>Controller.urls</code> (see below) works fine for subclasses as well.</p>
<p>Similar to <a href="http://www.djangosnippets.org/snippets/1165/">snippet #1165</a> except that it won't break reverse URL resolving and regex validation in URLs.</p>
<p>In <code>views.py</code>:</p>
<pre><code>import mvc …</code></pre>
Freely redistributableCookie based flash errors and notices (a la Rails)
2008-09-17T20:35:16.519274-05:00alexkhttps://djangosnippets.org/snippets/1064/<p>This is a light-weight flash implementation. Instead of hitting the database it uses cookies. The messages are shown to the user only once, after that the cookies are deleted.</p>
<p>I tested it on Google App Engine, but it should work on vanilla Django as well, there's no GAE specific code. …</p>
Freely redistributableExtended rails flash implementation
2007-07-20T09:25:39.273826-05:00miracle2khttps://djangosnippets.org/snippets/331/<p>This is an extendend version of the Rails Flash implementation by Sean Patrick Hogan that supports different message types.</p>
<p><strong>Setting a flash message:</strong></p>
<pre><code>request.flash.error = 'Item could not be saved'
request.flash['error'] = 'Item could not be saved'
request.flash['foo'] = 'bar'
</code></pre>
<p><strong>Displaying a flash in the view:</strong></p>
<pre><code><!-- show the error …</code></pre>
Freely redistributable