Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Moved to django-markup. Made some changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
myles committed Sep 8, 2010
1 parent b2da820 commit e5abc0f
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README
Expand Up @@ -9,9 +9,9 @@ Requirements
* Django_ >= 1.1
* `Django Taggit`_ >= 0.4.0
* `Python DateUtil`_ >= 1.5
* `Asgard Utilities`_ == trunk
* `Django Markup`_ >= 0.3.0

.. _Django: http://djangoproject.org/
.. _Django Taggit: http://pypi.python.org/pypi/django-taggit
.. _Asgard Utilities: http://github.com/asgardproject/asgard-utils
.. _Django Markup: http://pypi.python.org/pypi/django-markup
.. _DateUtil: http://labix.org/python-dateutil
3 changes: 2 additions & 1 deletion events/__init__.py
@@ -1 +1,2 @@
__version__ = '0.1.0'
VERSION = (0, 2, 0)
__version__ = ".".join(map(str, VERSION))
2 changes: 1 addition & 1 deletion events/feeds.py
@@ -1,7 +1,7 @@
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
from django.contrib.syndication.views import Feed, FeedDoesNotExist

from events.models import Event

Expand Down
13 changes: 13 additions & 0 deletions events/fixtures/auth.json
@@ -0,0 +1,13 @@
[
{
"pk": 1,
"model": "auth.user",
"fields": {
"username": "myles",
"password": "no-no-no",
"first_name": "Myles",
"last_name": "Braithwaite",
"email": "me@mylesbraithwaite.com"
}
}
]
31 changes: 22 additions & 9 deletions events/fixtures/events.json
Expand Up @@ -6,12 +6,11 @@
"title": "The care and feeding of portable media players under Linux",
"slug": "gtalug-meeting",
"author": 1,
"start_date": "2009-08-11",
"start_date": "2010-08-19",
"start_time": "19:30",
"end_time": "21:00",
"body": "<p>So, you have a portable media player that plays music, shows photos, and can play videos, how do you keep that player fed with media from your Linux box? Colin McGregor will give an introductory talk that will look at:</p><ul><li>Ripping CDs into MP3 files.</li><li>Converting audio tapes into MP3 files</li><li>Putting photos onto your player</li><li>Putting videos onto your player</li><li>Where and how to get free, legal, content on-line</li></ul><p>This will be an updated version of a well received talk Colin McGregor did earlier this year for NewTLUG.</p>",
"body_html": "<p>So, you have a portable media player that plays music, shows photos, and can play videos, how do you keep that player fed with media from your Linux box? Colin McGregor will give an introductory talk that will look at:</p><ul><li>Ripping CDs into MP3 files.</li><li>Converting audio tapes into MP3 files</li><li>Putting photos onto your player</li><li>Putting videos onto your player</li><li>Where and how to get free, legal, content on-line</li></ul><p>This will be an updated version of a well received talk Colin McGregor did earlier this year for NewTLUG.</p>",
"body_markup_choices": "html",
"markup": "none",
"published": "2009-08-10",
"date_added": "2009-08-10",
"date_modified": "2009-08-10"
Expand All @@ -24,12 +23,11 @@
"title": "GTALUG Soup",
"slug": "gtalug-soup",
"author": 1,
"start_date": "2009-08-11",
"start_date": "2010-08-19",
"start_time": "18:00",
"end_time": "19:00",
"body": "There will be an informal get together of Linux fans at the Pho Hung restaurant 350 Spadina Ave. to talk about Linux related topics over Vietnamese style food.",
"body_html": "<p>There will be an informal get together of Linux fans at the Pho Hung restaurant 350 Spadina Ave. to talk about Linux related topics over Vietnamese style food.</p>",
"body_markup_choices": "plain",
"markup": "linebreaks",
"published": "2009-08-10",
"date_added": "2009-08-10",
"date_modified": "2009-08-10"
Expand All @@ -42,12 +40,27 @@
"title": "GTALUG Beer",
"slug": "gtalug-beer",
"author": 1,
"start_date": "2009-08-11",
"start_date": "2010-08-19",
"start_time": "21:30",
"end_time": "23:30",
"body": "A large group of Linux fans will move to a nearby pub for further informal socializing.",
"body_html": "<p>A large group of Linux fans will move to a nearby pub for further informal socializing.</p>",
"body_markup_choices": "plain",
"markup": "none",
"published": "2009-08-10",
"date_added": "2009-08-10",
"date_modified": "2009-08-10"
}
},
{
"pk": 4,
"model": "events.event",
"fields": {
"title": "Vacation",
"slug": "vacation",
"author": 1,
"start_date": "2010-08-10",
"end_date": "2010-08-20",
"body": "I am going to be on vacation from 10th to 20th August.",
"markup": "none",
"published": "2009-08-10",
"date_added": "2009-08-10",
"date_modified": "2009-08-10"
Expand Down
10 changes: 5 additions & 5 deletions events/managers.py
@@ -1,4 +1,4 @@
from datetime import datetime
import datetime
import operator

from django.db.models import Manager, Q
Expand All @@ -12,9 +12,9 @@ def upcoming(self, **kwargs):
"""
Upcoming events.
"""
TODAY = datetime.now()
TODAY = datetime.date.today()
return self.get_query_set().filter(private=False,
start_date__gte=TODAY.date(), **kwargs).order_by('start_date')
start_date__gte=TODAY, **kwargs).order_by('start_date', 'start_time')

def public(self, **kwargs):
"""
Expand All @@ -27,7 +27,7 @@ def published(self, **kwargs):
Published events.
"""
return self.get_query_set().filter(private=False,
published__lte=datetime.now(), **kwargs)
published__lte=datetime.datetime.now(), **kwargs)

def search(self, search_terms):
"""
Expand All @@ -38,7 +38,7 @@ def search(self, search_terms):

for term in terms:
q_objects.append(Q(title__icontains=term))
q_objects.append(Q(body_html__icontains=term))
q_objects.append(Q(body__icontains=term))

qs = self.get_query_set().filter(
published__lte=datetime.now())
Expand Down
20 changes: 17 additions & 3 deletions events/models.py
Expand Up @@ -10,9 +10,12 @@

from taggit.managers import TaggableManager

from events.managers import EventManager
try:
from django_markup.fields import MarkupField
except ImportError:
MarkupField = False

from asgard.utils.db.fields import MarkupTextField
from events.managers import EventManager

class Event(models.Model):
title = models.CharField(_('title'), max_length=200)
Expand All @@ -31,7 +34,10 @@ class Event(models.Model):

tags = TaggableManager()

body = MarkupTextField(_('body'))
body = models.TextField(_('body'))

if MarkupField:
markup = MarkupField(default='none')

published = models.DateTimeField(_('published'), blank=True, null=True)
date_added = models.DateTimeField(_('date added'), auto_now_add=True)
Expand All @@ -53,6 +59,14 @@ class Meta:
def __unicode__(self):
return u"%s" % self.title

def save(self, *args, **kwargs):
if not self.end_date:
self.end_date = self.start_date
if not self.end_time:
self.end_time = self.start_time

super(Event, self).save(*args, **kwargs)

@permalink
def get_absolute_url(self):
return ('events_event_detail', None, {
Expand Down
4 changes: 2 additions & 2 deletions events/templates/events/detail.html
Expand Up @@ -7,7 +7,7 @@ <h2>{{ event.title }}</h2>
{% endblock %}

{% block content %}
{% load humanize %}
{% load humanize markup_tags %}

<table border="0">
<thead>
Expand All @@ -17,7 +17,7 @@ <h2>{{ event.title }}</h2>
</thead>
<tfoot>
<tr>
<td colspan="2">{{ event.body_html|safe }}</td>
<td colspan="2">{{ event.body|apply_markup:event.markup }}</td>
</tr>
</tfoot>
<tbody>
Expand Down
3 changes: 2 additions & 1 deletion events/templates/feeds/events_event_description.html
@@ -1 +1,2 @@
<div class="entry-content">{{ obj.body_html|safe }}</div>
{% load markup_tags %}
<div class="entry-content">{{ obj.body|apply_markup:obj.markup }}</div>
5 changes: 2 additions & 3 deletions events/tests.py
Expand Up @@ -2,14 +2,13 @@
from django.core.urlresolvers import reverse

from events.models import Event
from tagging.models import Tag

from django.test import TestCase

client = Client()

class EventsTestCase(TestCase):
fixtures = ['events',]
fixtures = ['auth', 'events',]

def setUp(self):
self.event = Event.objects.get(pk=3)
Expand Down Expand Up @@ -53,5 +52,5 @@ def testEventsSitemap(self):
self.assertEquals(response.status_code, 200)

def testEventsEventFeed(self):
response = client.get(reverse('feeds', args=['calendar']))
response = client.get(reverse('events_feed'))
self.assertEquals(response.status_code, 200)
1 change: 1 addition & 0 deletions events/testsettings.py
Expand Up @@ -14,6 +14,7 @@
'django.contrib.humanize',

'taggit',
'django_markup',

'events',
]
Expand Down
11 changes: 10 additions & 1 deletion events/urls.py
@@ -1,6 +1,15 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('events.views',
from events.feeds import EventsFeed

urlpatterns = patterns('',
url(r'feed/$',
view = EventsFeed(),
name = 'events_feed'
)
)

urlpatterns += patterns('events.views',
url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$',
view = 'detail',
name = 'events_event_detail',
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
@@ -1,4 +1,3 @@
python-dateutil
django-taggit

-e git+git://github.com/asgardproject/asgard-utils.git#egg=Asgard-Utils
django-markup

0 comments on commit e5abc0f

Please sign in to comment.