Commits

Colin Copeland committed 8248567

basic models

Comments (0)

Files changed (7)

+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-simple-events
+====================
+
+Development by `Caktus Consulting Group <http://www.caktusgroup.com/>`_.

events/managers.py

+import datetime
+
+from django.db import models
+from django.db.models import Q
+
+
+class EventManager(models.Manager):
+    def upcoming(self):
+        """
+        QuerySet of next n upcoming events
+        """
+        today = datetime.date.today()
+        return self.get_query_set().filter(
+            Q(begin_date__gte=today) | Q(end_date__gte=today)
+        ).order_by('begin_date')
+
+
+class PublishedEventManager(EventManager):
+    def get_query_set(self):
+        return super(PublishedEventManager, self).get_query_set().filter(
+            is_published=True,
+        )
+from django import models
+
+from events.managers import EventManager, PublishedEventManager
+
+
+class Event(models.Model):
+    name = models.CharField(max_length=255, unique_for_date='begin_date')
+    slug = models.SlugField(max_length=255, unique_for_date='begin_date')
+    categories = models.ManyToManyField(EventCategory, blank=True,
+                                        verbose_name='category')
+    begin_date = models.DateTimeField()
+    end_date = models.DateTimeField(null=True, blank=True)
+    show_date = models.BooleanField(default=True,
+                                    help_text="Events with hidden dates will continue to display chronologically, but the event date won't be shown")
+    description = models.TextField()
+    location = models.CharField(max_length=255, blank=True)
+    address = models.TextField(blank=True)
+    is_published = models.BooleanField(default=True,
+                                       help_text='Indicates whether or not to display this event on the web site')
+    attachments = models.ManyToManyField(Attachment, blank=True,
+                                         related_name='events')
+
+    objects = EventManager()
+    published = PublishedEventManager()
+
+    def get_absolute_url(self):
+        args = [self.begin_date.year, self.begin_date.month, self.slug]
+        return reverse('view_event', args=args)
+
+    def display_date(self):
+        if not self.show_date:
+            return ''
+        if not self.end_date:
+            return self.begin_date.strftime("%B %d, %Y")
+        else:
+            return mark_safe("%s &mdash; %s" % (
+                self.begin_date.strftime("%B %d, %Y"),
+                self.end_date.strftime("%B %d, %Y")
+           ))
+
+    def is_upcoming(self):
+        now = datetime.datetime.now()
+        upcoming_start_date = self.begin_date > now
+        upcoming_end_date = self.end_date and (self.end_date > now) or False
+        return upcoming_start_date or upcoming_end_date
+    is_upcoming.boolean = True
+
+    def __unicode__(self):
+        return self.name
+from django.conf.urls.defaults import *
+from django.views.generic.date_based import archive_month
+
+from events.models import Event
+from events import views
+
+
+urlpatterns = patterns('',
+    url(r'^events/category/(?P<category_slug>[\w-]+)/$',
+        'list_events_for_category', name='list_events_for_category'),
+    url(r'^events/$', 'list_events', name='list_events'),
+    url(r'^events/overview/$', 'describe_events', name='describe_events'),
+    url(r'^events/(?P<year>\d{4})/(?P<month>\d+)/$', archive_month, {
+            'date_field': 'begin_date',
+            'queryset': Event.published.all(),
+            'month_format': '%m',
+            'template_name': 'academy/events/archive/month.html',
+        }, name='list_past_events'),
+    url(r'^events/(?P<year>\d{4})/(?P<month>\d+)/(?P<event_slug>[\w-]+)/$',
+        'view_event', name='view_event'),
+    url(r'^events/(?P<year>\d{4})/(?P<month>\d+)/(?P<event_slug>[\w-]+)/export/$',
+        'export_event', name='export_event'),
+    url(r'^events/archive/$', 'event_archive_list',
+        name='event_archive_list'),
+    url(r'^events/archive/(?P<category_slug>[\w-]+)/$', 'event_archive_view',
+        name='event_archive_view'),
+)

events/views.py

Empty file added.
+from setuptools import setup, find_packages
+
+packages = find_packages()
+setup(
+    name='django-simple-events',
+    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 event model',
+    long_description=open('README.rst').read(),
+)