Skip to content

Instantly share code, notes, and snippets.

View pydanny's full-sized avatar

Daniel Roy Greenfeld pydanny

View GitHub Profile
"""
How to get the csrf_protect around a generic view. Which you need if you are working with comments.
"""
from django.conf.urls.defaults import *
from django.views.decorators.csrf import csrf_protect
from django.views.generic.list_detail import object_detail
from myapp.blog.models import Cartwheel
Sure! I'm perfect for the job!
But I think it would be in the customer's best interest if they switched to Python and
Django. It works in both Microsoft and Linux environments. We used it extensively at
NASA, Microsoft supports it strongly, and Google App Engine has critical elements
powered by Django technology.
So please tell the customer I would be interested in working with them to improve the
lot of their developers, managers, customers, and investors by switching to this
premier technology.
url(
regex = '^g/(?P<slug>[-\w]+)/(?P<feature_id>\d+)/(?P<bogus_slug>[-\w]+)/$',
view = grid_detail_feature,
name = 'grid',
),
/grids/g/cms/45/508-asdasda
>>> f = Feature.objects.get(id=1)
>>> f
<Feature: cms : 508 compliant?>
>>> f.grid
<Grid: CMS>
>>> f.title
u'508 compliant?'
>>> f.description
u'See http://webaim.org/standards/508/checklist'
>>> f.package
@pydanny
pydanny / perms.rst
Created March 19, 2011 18:36
Same packaginator permissions

perms

Just pseudocode!

SETTINGS:

PACKAGE_EDITOR_LEVEL = None # default
@pydanny
pydanny / DEVIL_test.py
Created April 15, 2011 06:31
Generic IDS from fixtures in tests is the DEVIL!
# Test form post for existing grid package
response = self.client.post(url, {
'package': 2,
})
self.assertContains(response,
'&#39;Supertester&#39; is already in this grid.')
# Test form post for new grid package
count = GridPackage.objects.count()
response = self.client.post(url, {
'package': 4,
@pydanny
pydanny / eggshell.py
Created June 15, 2011 18:38
The eggshell code sample
""" Note - I make this simple because complex shell tools are hard to code
and harder to document. Inspired by Kenneth Reitz's Requests library. """
from eggshell import shell
# Get the location of this script
shell.pwd
# Get the contents of this directory
directory = shell.ls(shell.pwd)
from django.template import Context
from django.template.loader import get_template
def model_generator(model_names):
template = get_template('startcbv/models.py')
c = Context({'model_names': model_names})
return template.render(c)
from django.db import models
{% for model_name in model_names %}
class {{ model_name}}(models.Model):
""" TODO - maybe put in created/modified timestamp fields?
pass
{% endfor %}
from django.conf.urls.defaults import patterns, url
from blarg.profiles import views
urlpatterns = patterns('',
url(regex=r'^$',
view=views.profile_list,
name='profile_list',
),