Skip to content

Commit

Permalink
Updated example database. Added base fixtures. Added a few new fields…
Browse files Browse the repository at this point in the history
… for example reasons.
  • Loading branch information
nowells committed Sep 6, 2009
1 parent 76c64a8 commit 7b57b1f
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions examples/complaints/models.py
Expand Up @@ -4,6 +4,7 @@
from pluggables.models import PluggableModel

class Complaint(PluggableModel):
name = models.CharField(max_length=50)
description = models.TextField()

def __unicode__(self):
Expand Down
Binary file modified examples/db/database.db
Binary file not shown.
7 changes: 7 additions & 0 deletions examples/sillywalks/admin.py
@@ -0,0 +1,7 @@
from django.contrib import admin
from sillywalks.models import SillyWalk

class SillyWalkAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}

admin.site.register(SillyWalk, SillyWalkAdmin)
31 changes: 31 additions & 0 deletions examples/sillywalks/fixtures/test_data.json
@@ -0,0 +1,31 @@
[
{
"pk": 1,
"model": "sillywalks.sillywalk",
"fields": {
"description": "Nothing is better than the original!",
"slug": "ministry-of-silly-walks",
"video_url": "http://www.youtube.com/v/9ZlBUglE6Hc&hl=en&fs=1",
"title": "Ministry of Silly Walks"
}
},
{
"pk": 2,
"model": "sillywalks.sillywalk",
"fields": {
"description": "Silly walk thru Derry-Londonderry - a tribute to the legend, John Cleese. Music: \"Blaze Away\" Performed by the Britannia Band (L'derry).",
"slug": "ministry-of-silly-walks-derry-style",
"video_url": "http://www.youtube.com/v/m99n93dL5Mc&hl=en&fs=1",
"title": "Ministry of Silly Walks - Derry Style!"
}
},
{
"pk": 1,
"model": "complaints.complaint",
"fields": {
"pluggable_url": "KGRwMQpTJ3ByZWZpeCcKcDIKUydzaWxseXdhbGtzJwpwMwpzUydwYXJlbnRfa3dhcmdzJwpwNAooZHA1ClMnd2Fsa19zbHVnJwpwNgpWbWluaXN0cnktb2Ytc2lsbHktd2Fsa3MtZGVycnktc3R5bGUKcDcKc3NTJ3BhcmVudF9hcmdzJwpwOAoodHMu",
"name": "Nowell Strite",
"description": "Nice try buddy, but nothing is as good as the original."
}
}
]
1 change: 1 addition & 0 deletions examples/sillywalks/forms.py
Expand Up @@ -4,3 +4,4 @@
class SillyWalkForm(forms.ModelForm):
class Meta:
model = SillyWalk
exclude = ('slug',)
12 changes: 8 additions & 4 deletions examples/sillywalks/models.py
@@ -1,12 +1,16 @@
from django.db import models
from django.contrib import admin
from django.template.defaultfilters import slugify

class SillyWalk(models.Model):
name = models.SlugField(unique=True)
title = models.CharField(max_length=100)
slug = models.SlugField(unique=True)
description = models.TextField()
video_url = models.URLField()

def __unicode__(self):
return self.name
return self.title

admin.site.register(SillyWalk)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(SillyWalk, self).save(*args, **kwargs)
2 changes: 1 addition & 1 deletion examples/sillywalks/templates/sillywalks/edit.html
Expand Up @@ -7,7 +7,7 @@
<div class="item_container">
<form method="post" action="." class="uniForm">
{{ form|as_uni_form }}
<input type="submit" value="Complain" />
<input type="submit" value="Submit" />
</form>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion examples/sillywalks/templates/sillywalks/index.html
Expand Up @@ -5,7 +5,7 @@
<div><a href="{% url sillywalks_create %}">Create a New Walk</a></div>
{% for sillywalk in sillywalks %}
<div class=item_container>
<h2><a href="{% url sillywalks_view sillywalk.name %}">{{ sillywalk.name }}</a></h2>
<h2><a href="{% url sillywalks_view sillywalk.slug %}">{{ sillywalk.title }}</a></h2>
<p>{{ sillywalk.description|safe }}</p>
</div>
{% empty %}
Expand Down
2 changes: 1 addition & 1 deletion examples/sillywalks/templates/sillywalks/view.html
Expand Up @@ -3,7 +3,7 @@
{% block body_content %}
{{ block.super }}
<div class=item_container>
<h2>{{ sillywalk.name }}</h2>
<h2>{{ sillywalk.title }}</h2>
<p>{{ sillywalk.description|safe }}</p>
<div class="video_container"><object width="425" height="344"><param name="movie" value="{{ sillywalk.video_url }}"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="{{ sillywalk.video_url }}" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></div>
{% block pluggable_content %}{% endblock %}
Expand Down
6 changes: 3 additions & 3 deletions examples/sillywalks/urls.py
Expand Up @@ -11,9 +11,9 @@
url('^$', 'django.views.generic.simple.direct_to_template', {'template': 'index.html'}, name='index'),
url('^sillywalks/$', views.index, name='sillywalks_index'),
url('^sillywalks/create/$', views.edit, name='sillywalks_create'),
url('^sillywalks/(?P<walk_name>[\w\-_]+)/$', views.view, name='sillywalks_view'),
url('^sillywalks/(?P<walk_name>[\w\-_]+)/edit/$', views.view, name='sillywalks_edit'),
url('^sillywalks/(?P<walk_name>[\w\-_]+)/complaints/', include(views.complaints)),
url('^sillywalks/(?P<walk_slug>[\w\-_]+)/$', views.view, name='sillywalks_view'),
url('^sillywalks/(?P<walk_slug>[\w\-_]+)/edit/$', views.view, name='sillywalks_edit'),
url('^sillywalks/(?P<walk_slug>[\w\-_]+)/complaints/', include(views.complaints)),
url('^complaints/', include(Complaints())),
)

Expand Down
18 changes: 9 additions & 9 deletions examples/sillywalks/views.py
Expand Up @@ -13,20 +13,20 @@ def index(request):
'sillywalks': sillywalks,
}, context_instance=RequestContext(request))

def view(request, walk_name):
return complaints.index(request, walk_name=walk_name)
def view(request, walk_slug):
return complaints.index(request, walk_slug=walk_slug)

def edit(request, walk_name=None):
def edit(request, walk_slug=None):
try:
sillywalk = SillyWalk.objects.get(name=walk_name)
sillywalk = SillyWalk.objects.get(slug=walk_slug)
except SillyWalk.DoesNotExist:
sillywalk = None

if request.method == 'POST':
form = SillyWalkForm(request.POST, instance=sillywalk)
if form.is_valid():
sillywalk = form.save()
return HttpResponseRedirect(reverse('sillywalks_view', args=[sillywalk.name]))
return HttpResponseRedirect(reverse('sillywalks_view', args=[sillywalk.slug]))
else:
form = SillyWalkForm(instance=sillywalk)

Expand All @@ -36,17 +36,17 @@ def edit(request, walk_name=None):
}, context_instance=RequestContext(request))

class SillyWalkComplaints(Complaints):
def pluggable_config(self, request, walk_name=None):
def pluggable_config(self, request, walk_slug=None):
return {'base_template': 'sillywalks/view.html'}

def pluggable_view_context(self, request, walk_name):
def pluggable_view_context(self, request, walk_slug):
try:
sillywalk = SillyWalk.objects.get(name=walk_name)
sillywalk = SillyWalk.objects.get(slug=walk_slug)
except SillyWalk.DoesNotExist:
raise Http404
return sillywalk

def pluggable_template_context(self, request, walk_name):
def pluggable_template_context(self, request, walk_slug):
return {'sillywalk': request.pluggable.view_context}

complaints = SillyWalkComplaints('sillywalks')

0 comments on commit 7b57b1f

Please sign in to comment.