commit b7c87e12b0dac39a61b7db79d2d64fae163a8174 Author: James Turk Date: Wed Feb 25 11:41:50 2009 -0500 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5aee4cd --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..5066131 --- /dev/null +++ b/README.rst @@ -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: + +
+ +
+

project description

+
+ +
+ {% block content %} + {% endblock %} +
+ +
+

Submit New Idea

+ {% include "idea_form.html" %} +
+
+
+ + +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

with the idea title, a div.commentMeta with the idea's submitter/date, and a

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

with the number of comments, then an ordered list where each
  • has the following elements: + +* div.commentMeta which contains span.commentMetaAuthor and span.commentMetaDate +* div.commentContent which contains a

    with the comment itself + +(TODO: comment form) diff --git a/brainstorm/__init__.py b/brainstorm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/brainstorm/admin.py b/brainstorm/admin.py new file mode 100644 index 0000000..adf3b55 --- /dev/null +++ b/brainstorm/admin.py @@ -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) diff --git a/brainstorm/feeds.py b/brainstorm/feeds.py new file mode 100644 index 0000000..2f0000a --- /dev/null +++ b/brainstorm/feeds.py @@ -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 + diff --git a/brainstorm/models.py b/brainstorm/models.py new file mode 100644 index 0000000..bbd35e9 --- /dev/null +++ b/brainstorm/models.py @@ -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) diff --git a/brainstorm/templates/brainstorm/idea.html b/brainstorm/templates/brainstorm/idea.html new file mode 100644 index 0000000..3c74ea2 --- /dev/null +++ b/brainstorm/templates/brainstorm/idea.html @@ -0,0 +1,39 @@ +{% extends subsite.theme %} +{% load comments %} + +{% block content %} + +

    + {% include "brainstorm/idea_vote.html" %} +
    + +{% get_comment_list for idea as comments %} + +
    +

    {{ comments|length }} Comments

    +
      + {% for comment in comments %} +
    1. +
      + + {% if comment.user_url %}{% endif %} + {{comment.user_name}} + {% if comment.user_url %}{% endif %} + + {{comment.submit_date|date:"m/d P"}} +
      +
      +

      {{comment.comment|urlize}}

      +
      +
    2. + {% endfor %} +
    + +{% get_comment_form for idea as comment_form %} +
    + {{ comment_form.as_p }} + +
    +
    + +{% endblock content %} diff --git a/brainstorm/templates/brainstorm/idea_form.html b/brainstorm/templates/brainstorm/idea_form.html new file mode 100644 index 0000000..885cc1a --- /dev/null +++ b/brainstorm/templates/brainstorm/idea_form.html @@ -0,0 +1,13 @@ +
    +

    + + +

    +

    + + +

    + +
    + + diff --git a/brainstorm/templates/brainstorm/idea_rss_description.html b/brainstorm/templates/brainstorm/idea_rss_description.html new file mode 100644 index 0000000..973dbd1 --- /dev/null +++ b/brainstorm/templates/brainstorm/idea_rss_description.html @@ -0,0 +1 @@ +{{obj.description|urlize}} diff --git a/brainstorm/templates/brainstorm/idea_vote.html b/brainstorm/templates/brainstorm/idea_vote.html new file mode 100644 index 0000000..527e122 --- /dev/null +++ b/brainstorm/templates/brainstorm/idea_vote.html @@ -0,0 +1,15 @@ + {% if not idea.user_vote %} +
    + Vote + {% else %} +
    + Voted + {% endif %} +
    {{idea.vote_total}} Votes
    +
    +
    +

    {{idea.title}}

    +
    Submitted on {{idea.submit_date|date:"m/d P"}} by {{idea.user|default_if_none:"anonymous"}} ({{idea.comments.count}} comments)
    + +

    {{idea.description|urlize}}

    +
    diff --git a/brainstorm/templates/brainstorm/index.html b/brainstorm/templates/brainstorm/index.html new file mode 100644 index 0000000..b88d681 --- /dev/null +++ b/brainstorm/templates/brainstorm/index.html @@ -0,0 +1,23 @@ +{% extends subsite.theme %} + +{% block content %} +
    +
      + {% for idea in ideas.object_list %} +
    • {% include "brainstorm/idea_vote.html" %}
    • + {% endfor %} +
    +
    + +{% endblock %} + diff --git a/brainstorm/urls.py b/brainstorm/urls.py new file mode 100644 index 0000000..67953a9 --- /dev/null +++ b/brainstorm/urls.py @@ -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.*)/$', 'django.contrib.syndication.views.feed', + {'feed_dict': feeds}), +) + +urlpatterns += patterns('brainstorm.views', + url(r'^(?P[\w-]+)/$', 'idea_list', {'ordering': 'most_popular'}, name='subsite'), + url(r'^(?P[\w-]+)/latest/$', 'idea_list', {'ordering': 'latest'}, name='subsite_latest'), + url(r'^(?P[\w-]+)/(?P\d+)/$', 'idea_detail', name='idea'), + url(r'^(?P[\w-]+)/new_idea/$', 'new_idea', name='new_idea'), +) + +urlpatterns = patterns('secretballot.views', + url(r'^vote_up/(?P\d+)/$', 'vote', + {'content_type': ContentType.objects.get_for_model(Idea), 'vote': 1}, + name='vote_up'), + url(r'^vote_down/(?P\d+)/$', 'vote', + {'content_type': ContentType.objects.get_for_model(Idea), 'vote': -1}, + name='vote_down'), + url(r'^unvote/(?P\d+)/$', 'vote', + {'content_type': ContentType.objects.get_for_model(Idea), 'vote': 0}, + name='unvote'), +) + urlpatterns + diff --git a/brainstorm/views.py b/brainstorm/views.py new file mode 100644 index 0000000..bd9f925 --- /dev/null +++ b/brainstorm/views.py @@ -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())