initial commit
This commit is contained in:
commit
b7c87e12b0
10
LICENSE
Normal file
10
LICENSE
Normal file
@ -0,0 +1,10 @@
|
||||
Copyright (c) 2009, Sunlight Foundation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Sunlight Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
65
README.rst
Normal file
65
README.rst
Normal file
@ -0,0 +1,65 @@
|
||||
|
||||
|
||||
---------------
|
||||
Creating Themes
|
||||
---------------
|
||||
|
||||
A theme is represented by a single django template, currently kept at templates/themes/themename.html
|
||||
|
||||
Required Elements
|
||||
-----------------
|
||||
|
||||
The theme must include a content block that will be filled by the page, the theme should also include "idea_form.html" if you wish to use the generic idea submission form.
|
||||
|
||||
Example dynamic content block:
|
||||
<!-- content -->
|
||||
<div>
|
||||
<h2 id="secondLogo"><a href="http://mysite.com/subsite/">{{subsite.name}}</a></h2>
|
||||
<div id="featureBox">
|
||||
<p>project description</p>
|
||||
</div>
|
||||
|
||||
<div id="ltColumn">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
<div id="rtColumn">
|
||||
<h3>Submit New Idea</h3>
|
||||
{% include "idea_form.html" %}
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
|
||||
Styling the Theme
|
||||
-----------------
|
||||
|
||||
Obviously the styling/design of the static portions of the theme is entirely within the hands of the designer.
|
||||
There are however a few dynamic sections which typically will need some form of styling.
|
||||
|
||||
index
|
||||
.....
|
||||
|
||||
The 'content' block of the index contains two divs: 'div#ideas' and 'div#pagination'.
|
||||
|
||||
'div#ideas' contains an list where each li is a pair of div.btnVote and div.voteContent. When a div.btnVote has been voted up it will have the additional class 'voted' to allow for additional styling.
|
||||
|
||||
'div.btnVote' contains the link 'a.vote_link' for voting and 'div.votes_counted' for displaying the current vote total.
|
||||
|
||||
'div.voteContent' contains an <h3> with the idea title, a div.commentMeta with the idea's submitter/date, and a <p> with the description.
|
||||
|
||||
|
||||
idea
|
||||
....
|
||||
|
||||
The content block of the idea page contains two divs: 'div#idea' and 'div#comments'.
|
||||
|
||||
'div#idea' contains a single pair of 'div.btnVote' and 'div.voteContent' (see `index`_ for description of these elements)
|
||||
|
||||
'div#comments' contains an <h3> with the number of comments, then an ordered list where each <li> has the following elements:
|
||||
|
||||
* div.commentMeta which contains span.commentMetaAuthor and span.commentMetaDate
|
||||
* div.commentContent which contains a <p> with the comment itself
|
||||
|
||||
(TODO: comment form)
|
0
brainstorm/__init__.py
Normal file
0
brainstorm/__init__.py
Normal file
12
brainstorm/admin.py
Normal file
12
brainstorm/admin.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.contrib import admin
|
||||
from brainstorm.models import Subsite, Idea
|
||||
|
||||
class SubsiteAdmin(admin.ModelAdmin):
|
||||
list_display = ('slug', 'name')
|
||||
|
||||
class IdeaAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'user', 'subsite')
|
||||
list_filter = ('subsite',)
|
||||
|
||||
admin.site.register(Subsite, SubsiteAdmin)
|
||||
admin.site.register(Idea, IdeaAdmin)
|
30
brainstorm/feeds.py
Normal file
30
brainstorm/feeds.py
Normal file
@ -0,0 +1,30 @@
|
||||
from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
|
||||
from brainstorm.models import Subsite
|
||||
|
||||
class SubsiteFeed(Feed):
|
||||
|
||||
description_template = 'feedback/idea_rss_description.html'
|
||||
|
||||
def get_object(self, bits):
|
||||
return Subsite.objects.get(slug__exact=bits[0])
|
||||
|
||||
def title(self, obj):
|
||||
return '%s' % obj.name
|
||||
|
||||
def link(self, obj):
|
||||
if not obj:
|
||||
raise FeedDoesNotExist
|
||||
return obj.get_absolute_url()
|
||||
|
||||
def description(self, obj):
|
||||
return 'Latest ideas submitted for %s' % obj.name
|
||||
|
||||
def items(self, obj):
|
||||
return obj.ideas.order_by('-submit_date')[:30]
|
||||
|
||||
def item_author_name(self, item):
|
||||
return item.user
|
||||
|
||||
def item_pubdate(self, item):
|
||||
return item.submit_date
|
||||
|
40
brainstorm/models.py
Normal file
40
brainstorm/models.py
Normal file
@ -0,0 +1,40 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.comments.models import Comment
|
||||
import secretballot
|
||||
|
||||
class Subsite(models.Model):
|
||||
slug = models.SlugField(max_length=50, primary_key=True)
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
theme = models.CharField(max_length=100)
|
||||
|
||||
ideas_per_page = models.IntegerField(default=10)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('subsite', args=[self.slug])
|
||||
|
||||
class Idea(models.Model):
|
||||
|
||||
title = models.CharField(max_length=100)
|
||||
description = models.TextField()
|
||||
|
||||
submit_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
user = models.ForeignKey(User, null=True, related_name='ideas')
|
||||
subsite = models.ForeignKey(Subsite, related_name='ideas')
|
||||
|
||||
comments = generic.GenericRelation(Comment, object_id_field='object_pk')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('idea', args=[self.subsite_id, self.id])
|
||||
|
||||
secretballot.enable_voting_on(Idea)
|
39
brainstorm/templates/brainstorm/idea.html
Normal file
39
brainstorm/templates/brainstorm/idea.html
Normal file
@ -0,0 +1,39 @@
|
||||
{% extends subsite.theme %}
|
||||
{% load comments %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="idea">
|
||||
{% include "brainstorm/idea_vote.html" %}
|
||||
</div>
|
||||
|
||||
{% get_comment_list for idea as comments %}
|
||||
<a name="comments"></a>
|
||||
<div id="comments">
|
||||
<h3>{{ comments|length }} Comments</h3>
|
||||
<ol>
|
||||
{% for comment in comments %}
|
||||
<a name="c{{comment.id}}"><li></a>
|
||||
<div class="commentMeta">
|
||||
<span class="commentMetaAuthor">
|
||||
{% if comment.user_url %}<a href="{{comment.user_url}}">{% endif %}
|
||||
{{comment.user_name}}
|
||||
{% if comment.user_url %}</a>{% endif %}
|
||||
</span>
|
||||
<span class="commentMetaDate">{{comment.submit_date|date:"m/d P"}}</span>
|
||||
</div>
|
||||
<div class="commentContent">
|
||||
<p>{{comment.comment|urlize}}</p>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
|
||||
{% get_comment_form for idea as comment_form %}
|
||||
<form method="post" action="{% comment_form_target %}">
|
||||
{{ comment_form.as_p }}
|
||||
<button class="btnSubmit" type="submit">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
13
brainstorm/templates/brainstorm/idea_form.html
Normal file
13
brainstorm/templates/brainstorm/idea_form.html
Normal file
@ -0,0 +1,13 @@
|
||||
<form action="{% url new_idea subsite.slug %}" method="post">
|
||||
<p>
|
||||
<label for="title">Title</label>
|
||||
<input type="text" id="title" name="title" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="description">Description</label>
|
||||
<textarea id="description" name="description"></textarea>
|
||||
</p>
|
||||
<button class="btnSubmit" type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
{{obj.description|urlize}}
|
15
brainstorm/templates/brainstorm/idea_vote.html
Normal file
15
brainstorm/templates/brainstorm/idea_vote.html
Normal file
@ -0,0 +1,15 @@
|
||||
{% if not idea.user_vote %}
|
||||
<div class="btnVote">
|
||||
<a class="vote_link" href="{% url vote_up idea.id %}">Vote</a>
|
||||
{% else %}
|
||||
<div class="btnVote voted">
|
||||
<a class="vote_link" href="{% url unvote idea.id %}">Voted</a>
|
||||
{% endif %}
|
||||
<div class="votesCounted">{{idea.vote_total}} Votes</div>
|
||||
</div>
|
||||
<div class="voteContent">
|
||||
<h3><a href="{{idea.get_absolute_url}}">{{idea.title}}</a></h3>
|
||||
<div class="commentMeta">Submitted on {{idea.submit_date|date:"m/d P"}} by {{idea.user|default_if_none:"anonymous"}} (<a href="{{idea.get_absolute_url}}#comments">{{idea.comments.count}} comments</a>)</div>
|
||||
|
||||
<p>{{idea.description|urlize}}</p>
|
||||
</div>
|
23
brainstorm/templates/brainstorm/index.html
Normal file
23
brainstorm/templates/brainstorm/index.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends subsite.theme %}
|
||||
|
||||
{% block content %}
|
||||
<div id="ideas">
|
||||
<ul>
|
||||
{% for idea in ideas.object_list %}
|
||||
<li>{% include "brainstorm/idea_vote.html" %}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div id="pagination">
|
||||
{% if ideas.has_previous %}
|
||||
<a href="?page={{ideas.previous_page_number}}">previous</a>
|
||||
{% endif %}
|
||||
|
||||
page {{ideas.number}} / {{ideas.paginator.num_pages}}
|
||||
|
||||
{% if ideas.has_next %}
|
||||
<a href="?page={{ideas.next_page_number}}">next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
34
brainstorm/urls.py
Normal file
34
brainstorm/urls.py
Normal file
@ -0,0 +1,34 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from brainstorm.models import Idea
|
||||
from brainstorm.feeds import SubsiteFeed
|
||||
|
||||
feeds = {
|
||||
'latest': SubsiteFeed,
|
||||
}
|
||||
|
||||
# feeds live at rss/latest/site-name/
|
||||
urlpatterns = patterns('',
|
||||
url(r'^rss/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
|
||||
{'feed_dict': feeds}),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('brainstorm.views',
|
||||
url(r'^(?P<slug>[\w-]+)/$', 'idea_list', {'ordering': 'most_popular'}, name='subsite'),
|
||||
url(r'^(?P<slug>[\w-]+)/latest/$', 'idea_list', {'ordering': 'latest'}, name='subsite_latest'),
|
||||
url(r'^(?P<slug>[\w-]+)/(?P<id>\d+)/$', 'idea_detail', name='idea'),
|
||||
url(r'^(?P<slug>[\w-]+)/new_idea/$', 'new_idea', name='new_idea'),
|
||||
)
|
||||
|
||||
urlpatterns = patterns('secretballot.views',
|
||||
url(r'^vote_up/(?P<object_id>\d+)/$', 'vote',
|
||||
{'content_type': ContentType.objects.get_for_model(Idea), 'vote': 1},
|
||||
name='vote_up'),
|
||||
url(r'^vote_down/(?P<object_id>\d+)/$', 'vote',
|
||||
{'content_type': ContentType.objects.get_for_model(Idea), 'vote': -1},
|
||||
name='vote_down'),
|
||||
url(r'^unvote/(?P<object_id>\d+)/$', 'vote',
|
||||
{'content_type': ContentType.objects.get_for_model(Idea), 'vote': 0},
|
||||
name='unvote'),
|
||||
) + urlpatterns
|
||||
|
52
brainstorm/views.py
Normal file
52
brainstorm/views.py
Normal file
@ -0,0 +1,52 @@
|
||||
from django.template import RequestContext
|
||||
from django.core.paginator import Paginator, InvalidPage, EmptyPage
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.decorators.http import require_POST
|
||||
from brainstorm.models import Subsite, Idea
|
||||
|
||||
def idea_list(request, slug, ordering='-total_upvotes'):
|
||||
subsite = get_object_or_404(Subsite, pk=slug)
|
||||
ordering_db = {'most_popular': '-total_upvotes',
|
||||
'latest': '-submit_date'}[ordering]
|
||||
paginator = Paginator(Idea.objects.from_request(request).filter(subsite=subsite).order_by(ordering_db),
|
||||
subsite.ideas_per_page)
|
||||
|
||||
try:
|
||||
page = int(request.GET.get('page', '1'))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
try:
|
||||
ideas = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
ideas = paginator.page(paginator.num_pages)
|
||||
|
||||
return render_to_response('brainstorm/index.html',
|
||||
{'subsite':subsite, 'ideas': ideas,
|
||||
'ordering': ordering},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
def idea_detail(request, slug, id):
|
||||
subsite = get_object_or_404(Subsite, pk=slug)
|
||||
idea = get_object_or_404(Idea.objects.from_request(request),
|
||||
subsite=slug, pk=id)
|
||||
|
||||
return render_to_response('brainstorm/idea.html',
|
||||
{'subsite':subsite, 'idea': idea},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_POST
|
||||
def new_idea(request, slug):
|
||||
subsite = get_object_or_404(Subsite, pk=slug)
|
||||
title = request.POST['title']
|
||||
description = request.POST['description']
|
||||
if request.user.is_anonymous():
|
||||
user = None
|
||||
else:
|
||||
user = request.user
|
||||
|
||||
idea = Idea.objects.create(title=title, description=description,
|
||||
user=user, subsite=subsite)
|
||||
return HttpResponseRedirect(idea.get_absolute_url())
|
Loading…
Reference in New Issue
Block a user