Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 759fe470169937708d1ee4f46574767fe8f0ef47 0 parents
Joe Bergantine authored
3  .gitignore
@@ -0,0 +1,3 @@
+*.pyc
+.DS_Store
+dist
0  events/__init__.py
No changes.
27 events/admin.py
@@ -0,0 +1,27 @@
+from django.contrib import admin
+
+from sorl.thumbnail.admin import AdminImageMixin
+
+from events.models import Event
+
+
+class EventAdmin(AdminImageMixin, admin.ModelAdmin):
+
+ # use objects instead of the default manager
+ def queryset(self, request):
+ # use our manager, rather than the default one
+ qs = self.model.objects.get_query_set()
+
+ # we need this from the superclass method
+ # provide an altenrative so we don't try to get *None
+ ordering = self.ordering or ()
+ if ordering:
+ qs = qs.order_by(*ordering)
+ return qs
+
+ list_display = ('__unicode__', 'start_date', 'end_date',)
+ list_filter = ('start_date', 'end_date',)
+ prepopulated_fields = {'slug': ['name']}
+ search_fields = ['name', 'start_date', 'end_date', 'description']
+
+admin.site.register(Event, EventAdmin)
22 events/feeds.py
@@ -0,0 +1,22 @@
+from django.template.defaultfilters import striptags
+from django.contrib.syndication.views import Feed
+
+from events.models import Event
+
+
+class UpcomingEvents(Feed):
+ title = 'Events'
+ link = '/events/'
+ description = 'Upcoming events'
+
+ def items(self):
+ return Event.upcoming.all()[:30]
+
+ def item_pubdate(self, item):
+ return item.created
+
+ def item_title(self, item):
+ return striptags(item.name)
+
+ def item_description(self, item):
+ return item.description_html
0  events/fixtures/__init__.py
No changes.
52 events/migrations/0001_initial.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Event'
+ db.create_table('events_event', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=250)),
+ ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50)),
+ ('start_date', self.gf('django.db.models.fields.DateField')()),
+ ('end_date', self.gf('django.db.models.fields.DateField')()),
+ ('url', self.gf('django.db.models.fields.URLField')(max_length=200, blank=True)),
+ ('description', self.gf('django.db.models.fields.TextField')()),
+ ('description_html', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ('image', self.gf('sorl.thumbnail.fields.ImageField')(max_length=100, blank=True)),
+ ('image_alt_text', self.gf('django.db.models.fields.TextField')(max_length=250)),
+ ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+ ('updated', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
+ ))
+ db.send_create_signal('events', ['Event'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'Event'
+ db.delete_table('events_event')
+
+
+ models = {
+ 'events.event': {
+ 'Meta': {'ordering': "['start_date', 'end_date', 'name']", 'object_name': 'Event'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ 'description_html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'end_date': ('django.db.models.fields.DateField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '100', 'blank': 'True'}),
+ 'image_alt_text': ('django.db.models.fields.TextField', [], {'max_length': '250'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
+ 'start_date': ('django.db.models.fields.DateField', [], {}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['events']
0  events/migrations/__init__.py
No changes.
56 events/models.py
@@ -0,0 +1,56 @@
+import datetime
+import markdown
+
+from django.core.urlresolvers import reverse
+from django.db import models
+
+from sorl.thumbnail import ImageField
+
+
+class UpcomingEventManager(models.Manager):
+
+ def get_query_set(self):
+ dr = datetime.date.today() + datetime.timedelta(weeks=12)
+ return super(UpcomingEventManager, self).get_query_set().filter(
+ start_date__gte=datetime.date.today(), start_date__lte=dr)
+
+
+class Event(models.Model):
+ name = models.CharField(max_length=250,
+ help_text='Maximum 250 characters.')
+ slug = models.SlugField(unique=True,
+ help_text='Suggested value automatically generated from title. '\
+ 'Must be unique.')
+
+ start_date = models.DateField()
+ end_date = models.DateField()
+
+ url = models.URLField(blank=True)
+
+ description = models.TextField(help_text="Use Markdown to mark this up.")
+ description_html = models.TextField(editable=False, blank=True)
+
+ image = ImageField(upload_to='events', blank=True,
+ help_text='80px X 80px')
+ image_alt_text = models.TextField(max_length=250, help_text=''\
+ 'Describe the image as you would to someone over the phone. '\
+ 'Max length 250 characters.')
+
+ created = models.DateTimeField(auto_now_add=True, editable=False)
+ updated = models.DateTimeField(auto_now=True, editable=False)
+
+ def save(self, *args, **kwargs):
+ self.description_html = markdown.markdown(self.description)
+ super(Event, self).save(*args, **kwargs)
+
+ def get_absolute_url(self):
+ return reverse('events')
+
+ class Meta:
+ ordering = ['start_date', 'end_date', 'name']
+
+ def __unicode__(self):
+ return self.name
+
+ upcoming = UpcomingEventManager() # default manager
+ objects = models.Manager()
67 events/templates/event_list.html
@@ -0,0 +1,67 @@
+{% extends "base.html" %}
+
+{% load nav %}
+{% load categories %}
+{% load authors %}
+
+{# meta data #}
+{% block metadescription %}{% endblock %}
+{% block metakeywords %}{% endblock %}
+{% block pagetitle %}{% endblock %}
+
+{% block fb_title %}{% endblock %}
+{% block fb_type %}{% endblock %}
+{% block fb_image %}{% endblock %}
+{% block fb_url %}{% endblock %}
+{% block fb_description %}{% endblock %}
+
+{# page specific includes (stylesheets, javascripts) #}
+{% block additional_head_items %}{% endblock additional_head_items %}
+
+{# body id #}
+{% block bodyid %}{{ block.super }}{% endblock %}{# for 'base' body id use {{ block.super }} #}
+
+{# body class #}
+{% block bodyclass %}{{ block.super }}{% endblock %}{# for 'base' body class use {{ block.super }} #}
+
+{% block nav %}
+ {% nav "events" %}
+ {{ block.super }}
+{% endblock %}
+
+{# content #}
+{% block content %}
+ {% regroup object_list|dictsort:"start_date" by start_date|date:"F, Y" as monthly_list %}
+ <dl>
+ {% for item in monthly_list %}
+ <dt>{{ item.grouper }}</dt>
+ <dd>
+ {% for object in item.list %}
+ <article id="{{ object.slug }}">
+ {% thumbnail object.image "80x80" crop="center" as im %}
+ <img src="{{ im.url }}" alt="" />
+ {% endthumbnail %}
+
+ {% if object.start_date == object.end_date %}
+ <time datetime="{{ object.start_date|date:"Y-m-d" }}">{{ object.start_date|date:"n/d" }}</time>
+ {% else %}
+ {% if object.start_date|date:"m" = object.end_date|date:"m" %}
+ <time datetime="{{ object.start_date|date:"Y-m-d" }}">{{ object.start_date|date:"n/d" }}</time> <abbr title="through">-</abbr> <time datetime="{{ object.end_date|date:"Y-m-d" }}">{{ object.end_date|date:"d" }}</time>
+ {% else %}
+ <time datetime="{{ object.start_date|date:"Y-m-d" }}">{{ object.start_date|date:"n/d" }}</time> <abbr title="through">-</abbr> <time datetime="{{ object.end_date|date:"Y-m-d" }}">{{ object.end_date|date:"n/d" }}</time>
+ {% endif %}
+ {% endif %}
+
+ <h1>{% if object.url %}<a href="{{ object.url }}" title="Website for {{ object.name|safe }}.">{% endif %}{{ object.name|safe }}{% if object.url %}</a>{% endif %}</h1>
+ <div class="wysiwyg">{{ object.description_html|safe }}</div>
+ </article>
+ {% endfor %}
+ </dd>
+ {% endfor %}
+ </dl>
+{% endblock content %}
+
+{# javascript #}
+{% block javascript %}
+ {{ block.super }}
+{% endblock %}
22 events/tests.py
@@ -0,0 +1,22 @@
+from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.test.client import Client
+
+from events.models import Event
+
+class EventTest(TestCase):
+ fixtures = ['events.json']
+
+ def setUp(self):
+ self.client = Client()
+
+ def test_add_event(self):
+
+ self.assertEqual(Event.objects.all().count(), 5)
+ self.assertEqual(Event.upcoming.all().count(), 2)
+ self.assertEqual(Event.upcoming.all()[0].name, 'Current Event')
+ self.assertEqual(Event.upcoming.all()[1].name, 'Near Future Event')
+
+ r = self.client.get(reverse('events'))
+ self.assertEqual(r.status_code, 200)
+ self.assertTemplateUsed(r, 'events/event_list.html')
10 events/urls.py
@@ -0,0 +1,10 @@
+from django.conf.urls.defaults import patterns, url
+
+from events.feeds import UpcomingEvents
+from events.views import event_list
+
+
+urlpatterns = patterns('',
+ url(r'^feed/$', UpcomingEvents(), '', 'events_feed'),
+ url(r'^$', event_list, {}, 'events'),
+)
17 events/views.py
@@ -0,0 +1,17 @@
+from django.http import Http404
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.views.decorators.cache import never_cache
+
+from events.models import Event
+
+
+@never_cache
+def event_list(request):
+ object_list = Event.upcoming.all
+ if not object_list:
+ raise Http404
+
+ return render_to_response('events/event_list.html',
+ {'object_list': object_list},
+ context_instance=RequestContext(request))
17 readme.md
@@ -0,0 +1,17 @@
+## Installation
+
+[Install sorl-thumbnail](http://sorl-thumbnail.readthedocs.org/en/latest/installation.html).
+
+Add ``'events',`` to the ``INSTALLED_APPS`` tuple in ``settings.py``.
+
+Add ``'sorl.thumbnail',`` to the ``INSTALLED_APPS`` tuple in ``settings.py``.
+
+Sync the database to finish installing sorl-thumbnail.
+
+Add the following to the ``patterns()`` method in the project's primary ``urls.py`` file:
+
+ url(r'^events/', include('events.urls')),
+
+The RSS feed can now be referred to in the ``<head>`` of your HTML templates:
+
+ <link rel="feed alternate" type="application/rss+xml" title="Events" href="{% url events_feed %}" />
1  requirements.txt
@@ -0,0 +1 @@
+sorl-thumbnail
Please sign in to comment.
Something went wrong with that request. Please try again.