Commits

Colin Copeland committed 95a185a

add basic committee app

Comments (0)

Files changed (11)

+Copyright (c) 2008-2010, Caktus Consulting Group, LLC
+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 the Caktus Consulting Group, LLC 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 HOLDER 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.
+-*- restructuredtext -*-
+
+django-committees
+=================
+
+Development by `Caktus Consulting Group <http://www.caktusgroup.com/>`_.

committees/__init__.py

Empty file added.

committees/admin.py

+from django.contrib import admin
+from django.core.urlresolvers import reverse
+
+from committees.models import Committee, CommitteeMember, CommitteeType
+
+
+class CommitteeTypeAdmin(admin.ModelAdmin):
+    list_display = ('name', 'slug', 'order',)
+    search_fields = ('name',)
+    prepopulated_fields = {'slug': ('name',)}
+admin.site.register(CommitteeType, CommitteeTypeAdmin)
+
+
+class CommitteeMemberAdmin(admin.TabularInline):
+    model = CommitteeMember
+    raw_id_fields = ('contact',)
+
+
+class CommitteeAdmin(admin.ModelAdmin):
+    inlines = (CommitteeMemberAdmin,)
+    list_display = ('name', 'slug', 'type')
+    list_filter = ('type',)
+    prepopulated_fields = {'slug': ('name',)}
+    search_fields = (
+        'name',
+        'members__first_name',
+        'members__last_name',
+        'members__email',
+    )
+    ordering = ('name',)
+admin.site.register(Committee, CommitteeAdmin)

committees/models.py

+from django.db import models
+
+
+class Profile(models.Model):
+    first_name = models.CharField(max_length=50)
+    last_name = models.CharField(max_length=50)
+    slug = models.SlugField(unique=True)
+    email = models.EmailField(blank=True)
+    description = models.TextField(blank=True)
+
+    class Meta:
+        ordering = ('last_name', 'first_name')
+    
+    def __unicode__(self):
+        return '%s %s' % (self.first_name, self.last_name,)
+
+
+class CommitteeType(models.Model):
+    name = models.CharField(max_length=255)
+    slug = models.SlugField(max_length=255, unique=True)
+    order = models.SmallIntegerField(
+        null=True,
+        blank=True,
+        choices=[(x, x) for x in range(-10, 11)],
+    )
+
+    class Meta:
+        ordering = ('order',)
+
+    def __unicode__(self):
+        return self.name
+
+
+class Committee(models.Model):
+    type = models.ForeignKey(CommitteeType, related_name='committees')
+    name = models.CharField(max_length=255)
+    slug = models.SlugField(max_length=255, unique=True)
+    description = models.TextField(blank=True)
+
+    class Meta:
+        ordering = ('type__order', 'name')
+
+    def __unicode__(self):
+        return self.name
+
+
+class CommitteeMember(models.Model):
+    committee = models.ForeignKey(Committee, related_name='members')
+    profile = models.ForeignKey(Profile, related_name='committee_members')
+    position = models.CharField(max_length=100, blank=True)
+    order = models.SmallIntegerField(
+        null=True,
+        blank=True,
+        choices=[(x, x) for x in range(-10, 11)],
+    )
+
+    class Meta:
+        ordering = ('order', 'contact__last_name', 'contact__first_name',)
+
+    def __unicode__(self):
+        position = ''
+        if self.position:
+            position = " (%s)" % self.position
+        return "%s%s" % (self.contact, position)

committees/templates/committees/list.html

+{% extends "base.html" %}
+
+{% block title %}Committees{% endblock %}
+
+{% block content %}
+    <h1>Committees{% if perms.academy.change_committee %} <a class='edit' href='{% url admin:academy_committee_changelist %}'>(Edit)</a>{% endif %}</h1>
+    {% regroup committees by type as type_list %}
+    <ul id='committees'>
+    {% for type in type_list %}
+        <li><h2>{{ type.grouper }}</h2></li>
+        <ul>
+            {% for committee in type.list %}
+            <li>
+                <a title='{{ committee.name }}' href='{% url view_committee committee.slug %}'>{{ committee }}</a>
+            </li>
+            {% endfor %}
+        </ul>
+    {% endfor %}
+    </ul>
+{% endblock %}

committees/templates/committees/profile.html

+{% extends "base.html" %}
+
+{% block title %}{{ profile }}{% endblock %}
+
+{% block content %}
+    
+    <h1>{{ profile }}{% if perms.crm.change_profile %} <a class='edit' href='{% url edit_person profile.id %}'>(Edit)</a>{% endif %}</h1>
+    
+    <h2>Committees</h2>
+    
+    <ul>
+    {% for member in profile.committee_members.all %}
+        <li><a href='{% url view_committee member.committee.slug %}'>{{ member.committee }}</a></li>
+    {% endfor %}
+    </ul>
+    
+{% endblock %}

committees/templates/committees/view.html

+{% extends "base.html" %}
+
+{% block title %}{{ committee }}{% endblock %}
+
+{% block content %}
+    <h1>{% if committee.label %}{{ committee.label|safe }}{% else %}{{ committee }}{% endif %}{% if perms.academy.change_committee %} <a class='edit' href='{% url admin:academy_committee_change committee.id %}'>(Edit)</a>{% endif %}</h1>
+    {% if committee.description %}
+        {{ committee.description }}
+    {% else %}
+        Description to be entered here.
+    {% endif %}
+    
+    <h2>Members</h2>
+    <ul>
+        {% for member in committee.members.select_related.all %}
+        <li><a href='{% url view_profile member.profile.slug %}'>{{ member }}</a></li>
+        {% endfor %}
+    </ul>
+{% endblock %}

committees/urls.py

+from django.conf.urls.defaults import *
+
+from committees import views
+
+
+urlpatterns = patterns('',
+    url(r'^profile/(?P<profile_slug>[\w-]+)/$', views.view_profile,
+        name='view_profile'),
+    url(r'^$', views.list_committees, name='list_committees'),
+    url(r'^(?P<committee_slug>[\w-]+)/$', views.view_committee,
+        name='view_committee'),
+)

committees/views.py

+from django.db import transaction
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
+
+from committees.models import Committee, Profile
+
+
+def list_committees(request):
+    context = {
+        'committees': Committee.objects.select_related().all(),
+    }
+    return render_to_response('committees/list.html', context,
+                              context_instance=RequestContext(request))
+
+
+def view_committee(request, committee_slug):
+    context = {
+        'committee': get_object_or_404(Committee, slug=committee_slug)
+    }
+    return render_to_response('committees/view.html', context,
+                              context_instance=RequestContext(request))
+
+
+def view_profile(request, profile_slug):
+    context = {
+        'profile': get_object_or_404(Profile, slug=profile_slug)
+    }
+    return render_to_response('committees/profile.html', context,
+                              context_instance=RequestContext(request))
+from setuptools import setup, find_packages
+
+packages = find_packages()
+setup(
+    name='django-committees',
+    version='0.0.1',
+    author='Caktus Consulting Group',
+    author_email='solutions@caktusgroup.com',
+    packages=find_packages(),
+    include_package_data=True,
+    exclude_package_data={
+        '': ['*.sql', '*.pyc',],
+    },
+    url='',
+    license='LICENSE.txt',
+    description='Simple Django app to model committees and members',
+    long_description=open('README.rst').read(),
+)