From 361ac88f3279453dc48d9cdc670079dbd6ce2a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Bur=C3=B3n?= Date: Wed, 9 Nov 2011 18:09:14 -0300 Subject: [PATCH] spike for elections app and 3rd party apps --- elections/__init__.py | 0 elections/admin.py | 11 ++++++ elections/models.py | 35 +++++++++++++++++++ elections/templates/elections/base.html | 10 ++++++ .../templates/elections/election_detail.html | 9 +++++ .../templates/elections/election_list.html | 9 +++++ elections/tests.py | 16 +++++++++ elections/urls.py | 9 +++++ elections/views.py | 1 + requirements.txt | 1 + settings.py | 35 ++++++++++++++++--- smart_profile/__init__.py | 0 smart_profile/admin.py | 4 +++ smart_profile/models.py | 22 ++++++++++++ smart_profile/tests.py | 16 +++++++++ smart_profile/views.py | 1 + templates/profiles/profile_list.html | 9 +++++ urls.py | 13 ++++--- 18 files changed, 193 insertions(+), 8 deletions(-) create mode 100644 elections/__init__.py create mode 100644 elections/admin.py create mode 100644 elections/models.py create mode 100644 elections/templates/elections/base.html create mode 100644 elections/templates/elections/election_detail.html create mode 100644 elections/templates/elections/election_list.html create mode 100644 elections/tests.py create mode 100644 elections/urls.py create mode 100644 elections/views.py create mode 100644 smart_profile/__init__.py create mode 100644 smart_profile/admin.py create mode 100644 smart_profile/models.py create mode 100644 smart_profile/tests.py create mode 100644 smart_profile/views.py create mode 100644 templates/profiles/profile_list.html diff --git a/elections/__init__.py b/elections/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/elections/admin.py b/elections/admin.py new file mode 100644 index 0000000..658f6f2 --- /dev/null +++ b/elections/admin.py @@ -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) diff --git a/elections/models.py b/elections/models.py new file mode 100644 index 0000000..ecdbbe1 --- /dev/null +++ b/elections/models.py @@ -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 diff --git a/elections/templates/elections/base.html b/elections/templates/elections/base.html new file mode 100644 index 0000000..26d58ca --- /dev/null +++ b/elections/templates/elections/base.html @@ -0,0 +1,10 @@ + + +{% block title%}Candidator{% endblock title %} + + +{% block content %} +{% endblock content %} + + + diff --git a/elections/templates/elections/election_detail.html b/elections/templates/elections/election_detail.html new file mode 100644 index 0000000..f0d0ba7 --- /dev/null +++ b/elections/templates/elections/election_detail.html @@ -0,0 +1,9 @@ +{% extends "elections/base.html" %} + +{% block title %} +{{ block.super }} Election +{% endblock title %} + +{% block content %} +permalink {{ election.name }} +{% endblock content %} diff --git a/elections/templates/elections/election_list.html b/elections/templates/elections/election_list.html new file mode 100644 index 0000000..5d3cf39 --- /dev/null +++ b/elections/templates/elections/election_list.html @@ -0,0 +1,9 @@ +{% extends "elections/base.html" %} + +{% block content %} + +{% endblock content %} diff --git a/elections/tests.py b/elections/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/elections/tests.py @@ -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) diff --git a/elections/urls.py b/elections/urls.py new file mode 100644 index 0000000..b9314ec --- /dev/null +++ b/elections/urls.py @@ -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\d+)/$', DetailView.as_view(model=Election), name='election_detail'), + url(r'^$', ListView.as_view(model=Election), name='election_list'), +) diff --git a/elections/views.py b/elections/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/elections/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/requirements.txt b/requirements.txt index b37614c..355a96a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/settings.py b/settings.py index fa89f24..28e4b6f 100644 --- a/settings.py +++ b/settings.py @@ -10,6 +10,8 @@ # ('Your Name', 'your_email@example.com'), ) +INTERNAL_IPS = ('127.0.0.1',) + MANAGERS = ADMINS DATABASES = { @@ -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 @@ -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 = ( @@ -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. @@ -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 @@ -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' diff --git a/smart_profile/__init__.py b/smart_profile/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smart_profile/admin.py b/smart_profile/admin.py new file mode 100644 index 0000000..4f4e99f --- /dev/null +++ b/smart_profile/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from models import Profile + +admin.site.register(Profile) diff --git a/smart_profile/models.py b/smart_profile/models.py new file mode 100644 index 0000000..b72cdb5 --- /dev/null +++ b/smart_profile/models.py @@ -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) diff --git a/smart_profile/tests.py b/smart_profile/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/smart_profile/tests.py @@ -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) diff --git a/smart_profile/views.py b/smart_profile/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/smart_profile/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/templates/profiles/profile_list.html b/templates/profiles/profile_list.html new file mode 100644 index 0000000..200e64d --- /dev/null +++ b/templates/profiles/profile_list.html @@ -0,0 +1,9 @@ + + + +{% for profile in object_list %} +
  • {{ profile.user.username }}
  • +{% empty %} +
  • No hay usuarios
  • +{% endfor %} + diff --git a/urls.py b/urls.py index 70e56b2..1c04107 100644 --- a/urls.py +++ b/urls.py @@ -1,8 +1,8 @@ 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: @@ -10,8 +10,13 @@ # 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')), )