Skip to content

Commit

Permalink
spike for elections app and 3rd party apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Burón committed Nov 9, 2011
1 parent ced0aef commit 361ac88
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 8 deletions.
Empty file added elections/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions elections/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin

from models import Election, Candidate

class CandidateAdmin(admin.ModelAdmin):
list_display = ('name', 'created_at',)
list_filter = ('last_name',)
date_hierarchy = 'created_at'

admin.site.register(Election)
admin.site.register(Candidate, CandidateAdmin)
35 changes: 35 additions & 0 deletions elections/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.db import models

# Create your models here.

class Election(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField()
owner = models.ForeignKey('auth.User')

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)


def __unicode__(self):
return u"%s" % self.name


class Candidate(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
slug = models.SlugField()
election = models.ForeignKey('Election')

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

@property
def name(self):
return u"%(first_name)s %(last_name)s" % {
'first_name': self.first_name,
'last_name': self.last_name
}

def __unicode__(self):
return self.name
10 changes: 10 additions & 0 deletions elections/templates/elections/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>

<title>{% block title%}Candidator{% endblock title %}</title>
<body>

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

</body>
</html>
9 changes: 9 additions & 0 deletions elections/templates/elections/election_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "elections/base.html" %}

{% block title %}
{{ block.super }} Election
{% endblock title %}

{% block content %}
<a href="{% url election_detail pk=object.pk %}">permalink {{ election.name }}</a>
{% endblock content %}
9 changes: 9 additions & 0 deletions elections/templates/elections/election_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "elections/base.html" %}

{% block content %}
<ul>
{% for election in object_list %}
<li>{{ election }}</li>
{% endfor %}
</ul>
{% endblock content %}
16 changes: 16 additions & 0 deletions elections/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""

from django.test import TestCase


class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
9 changes: 9 additions & 0 deletions elections/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf.urls.defaults import patterns, url
from django.views.generic import DetailView, ListView

from models import Election

urlpatterns = patterns('',
url(r'^election/(?P<pk>\d+)/$', DetailView.as_view(model=Election), name='election_detail'),
url(r'^$', ListView.as_view(model=Election), name='election_list'),
)
1 change: 1 addition & 0 deletions elections/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your views here.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Django==1.3
South==0.7.3
distribute==0.6.19
django-debug-toolbar==0.8.5
django-grappelli==2.3.5
wsgiref==0.1.2
35 changes: 31 additions & 4 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# ('Your Name', '[email protected]'),
)

INTERNAL_IPS = ('127.0.0.1',)

MANAGERS = ADMINS

DATABASES = {
Expand All @@ -30,7 +32,7 @@
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
TIME_ZONE = 'America/Santiago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
Expand Down Expand Up @@ -68,7 +70,7 @@
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"

# Additional locations of static files
STATICFILES_DIRS = (
Expand Down Expand Up @@ -106,6 +108,7 @@
ROOT_URLCONF = 'candidator.urls'

TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates'),
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
Expand All @@ -119,9 +122,14 @@
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
'grappelli',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'django.contrib.admindocs',
'debug_toolbar',
'profiles',
'smart_profile',
'elections',
)

# A sample logging configuration. The only tangible logging
Expand All @@ -146,3 +154,22 @@
},
}
}

DEBUG_TOOLBAR_PANELS = (
'debug_toolbar.panels.version.VersionDebugPanel',
'debug_toolbar.panels.timer.TimerDebugPanel',
'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
'debug_toolbar.panels.headers.HeaderDebugPanel',
'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
'debug_toolbar.panels.template.TemplateDebugPanel',
'debug_toolbar.panels.sql.SQLDebugPanel',
'debug_toolbar.panels.signals.SignalDebugPanel',
'debug_toolbar.panels.logger.LoggingPanel',
)

DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
'HIDE_DJANGO_SQL': False,
}

AUTH_PROFILE_MODULE = 'smart_profile.Profile'
Empty file added smart_profile/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions smart_profile/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from models import Profile

admin.site.register(Profile)
22 changes: 22 additions & 0 deletions smart_profile/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

# Create your models here.

class Profile(models.Model):
name = models.CharField(max_length=255)
biography = models.TextField()

user = models.ForeignKey('auth.User')

@models.permalink
def get_absolute_url(self):
return ('profiles_profile_detail', (), { 'username': self.user.username })


def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)
16 changes: 16 additions & 0 deletions smart_profile/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""

from django.test import TestCase


class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
1 change: 1 addition & 0 deletions smart_profile/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your views here.
9 changes: 9 additions & 0 deletions templates/profiles/profile_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<body>

<body>
{% for profile in object_list %}
<li><a href="{{ profile.get_absolute_url }}">{{ profile.user.username }}</a></li>
{% empty %}
<li>No hay usuarios</li>
{% endfor %}
</body>
13 changes: 9 additions & 4 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'candidator.views.home', name='home'),
# url(r'^candidator/', include('candidator.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
(r'^grappelli/', include('grappelli.urls')),
url(r'^admin/', include(admin.site.urls)),

(r'^profiles/', include('profiles.urls')),

url(r'^elections/', include('elections.urls')),
)

0 comments on commit 361ac88

Please sign in to comment.