Commits

Anonymous committed 314a916

Cleaned up templates and views and moved them into projects added previous into managers to pair with upcoming

  • Participants
  • Parent commits 8248567

Comments (0)

Files changed (10)

File events/__init__.py

Empty file added.

File events/admin.py

+from django.contrib import admin
+from django.core.urlresolvers import reverse
+
+from events.forms import EventAdminForm
+from events import models
+
+class EventCategoryAdmin(admin.ModelAdmin):
+    list_display = ('name', 'slug', )
+    search_fields = ('name',)
+    prepopulated_fields = {'slug': ('name',)}
+admin.site.register(models.EventCategory, EventCategoryAdmin)
+
+
+class AttachmentAdmin(admin.ModelAdmin):
+    list_display = ('file', 'name', 'slug', 'order')
+    search_fields = ('file', 'name', 'slug')
+admin.site.register(models.Attachment, AttachmentAdmin)
+
+
+class EventAdmin(admin.ModelAdmin):
+    list_display = ('name', 'begin_date', 'is_upcoming',
+                    'is_published', 'show_date',)
+    list_filter = ('begin_date', 'is_published',
+                   'show_date',)
+    search_fields = (
+        'name',
+        'description',
+    )
+    ordering = ('-begin_date',)
+    date_hierarchy = 'begin_date'
+    prepopulated_fields = {'slug': ('name',)}
+    fieldsets = (
+        (None, {
+            'fields': (
+                'name',
+                'slug',
+                'begin_date',
+                'end_date',
+                'description',
+                'location',
+                'address',
+                'is_published',
+                'show_date',
+            ),
+        }),
+        ('Attachments', {
+            'fields': (
+                'attachments',
+            ),
+        }),
+        ('Categories', {
+            'fields': (
+                'categories',
+            ),
+        }),
+    )
+    form = EventAdminForm
+admin.site.register(models.Event, EventAdmin)

File events/forms.py

+from django import forms
+from django.db.models import get_model
+
+class EventAdminForm(forms.ModelForm):
+    class Meta:
+        model = get_model('events', 'event')

File events/managers.py

         return self.get_query_set().filter(
             Q(begin_date__gte=today) | Q(end_date__gte=today)
         ).order_by('begin_date')
+        
+    def previous(self):
+        """
+        QuerySet of next n upcoming events
+        """
+        today = datetime.date.today()
+        return self.get_query_set().filter(
+            Q(begin_date__lt=today) | Q(end_date__lt=today)
+        ).order_by('begin_date')
 
 
 class PublishedEventManager(EventManager):

File events/models.py

-from django import models
+import datetime
+from django.db import models
+from django.core.urlresolvers import reverse
+from django.utils.safestring import mark_safe
 
 from events.managers import EventManager, PublishedEventManager
 
 
+class EventCategory(models.Model):
+    name = models.CharField(max_length=255, unique=True)
+    slug = models.SlugField(max_length=255, unique=True)
+
+    class Meta:
+        verbose_name_plural = 'Categories'
+    
+    def __unicode__(self):
+        return self.name
+
+
+ORDER_CHOICES = [(x, x) for x in range(-10, 11)]
+
+class Attachment(models.Model):
+    file = models.FileField(upload_to='attachments/')
+    name = models.CharField(max_length=255, blank=True)
+    slug = models.SlugField(max_length=255, blank=True)
+    order = models.SmallIntegerField(blank=True, choices=ORDER_CHOICES)
+
+
 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')

File events/templates/events/list.html

+{% extends "base.html" %}
+{% block title %}Events{% endblock %}
+{% block content %}    
+    {% if upcoming_events %}
+        <h2 class='no-bottom'>Upcoming {{ current_category }} Events and Meetings
+        {% if perms.events.change_event %}
+            <a class='edit' href='{% url admin:events_event_changelist %}'>(Edit)</a>
+        {% endif %}
+        {% if current_category %}: {{ current_category }}{% endif %}</h2>
+        <ul class='events'>
+            {% for event in upcoming_events %}
+                <li>
+                    <h2 class='no-bottom'><a href='{% url view_event event.begin_date.year,event.begin_date.month,event.slug %}'>{{ event }}</a></h2>
+                        <p class='date'>
+                            {{ event.display_date }}{% if event.show_date %}.{% endif %}
+                        </p>
+                    <div class='description'>{{ event.description|safe|truncatewords_html:40 }}</div>
+                </li>
+            {% endfor %}
+        </ul>
+    {% endif %}
+    
+    {% if previous_events %}
+        <h2 class='no-bottom'>Previous {{ current_category }} Events and Meetings
+        {% if perms.events.change_event %}
+            <a class='edit' href='{% url admin:events_event_changelist %}'>(Edit)</a>
+        {% endif %}
+        {% if current_category %}: {{ current_category }}{% endif %}</h2>
+        <ul class='events'>
+            {% for event in previous_events %}
+                <li>
+                    <h2 class='no-bottom'><a href='{% url view_event event.begin_date.year,event.begin_date.month,event.slug %}'>{{ event }}</a></h2>
+                        <p class='date'>
+                            {{ event.display_date }}{% if event.show_date %}.{% endif %}
+                        </p>
+                    <div class='description'>{{ event.description|safe|truncatewords_html:40 }}</div>
+                </li>
+            {% endfor %}
+        </ul>
+    {% endif %}
+{% endblock %}

File events/templates/events/view.html

+{% extends 'base.html' %}
+{% block title %}Event: {{ event.name }}{% endblock %}
+{% block content %}
+    
+    {% if not event.is_upcoming %}
+        <div id="archived-event">
+            This is an archived event. Please visit <strong><a href='{% url list_events %}'>Events and Meetings</a></strong> for current and upcoming events.
+        </div>
+    {% endif %}
+    
+    <h1>{{ event }}{% if perms.events.change_event %} <a class='edit' href='{% url admin:events_event_change event.id %}'>(Edit)</a>{% endif %}</h1>
+    
+    <p class='meta'>
+	{{ event.display_date }}
+        {% if event.location %}
+	at {{ event.location }}
+            {% if event.address %}
+                <a href='http://maps.google.com/maps?q={{ event.address|urlencode }}'>(map)</a>
+            {% else %}
+                {{ event.location}}
+            {% endif %}
+        {% endif %}
+    </p>
+    <div class='description'>{{ event.description|safe }}</div>
+
+    {% if event.attachments.all %}
+	<h2>Files</h2>
+	<ul class='events-attachments'>
+	{% for attachment in ordered_attachments %}
+	  <li><a href='{{ attachment.file.url }}'>{{ attachment.name }}</a></li>
+	{% endfor %}
+	</ul>
+    {% endif %}
+    
+{% endblock %}

File events/urls.py

 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, {
+urlpatterns = patterns('events.views',
+    url(r'^category/(?P<category_slug>[\w-]+)/$',
+            'list_events_for_category', 
+            name='list_events_for_category'
+        ),
+    url(r'^$', 'list_events', name='list_events'),
+    url(r'^(?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',
+            'template_name': 'events/archive/month.html',
         }, name='list_past_events'),
-    url(r'^events/(?P<year>\d{4})/(?P<month>\d+)/(?P<event_slug>[\w-]+)/$',
+    url(r'^(?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'),
 )

File events/views.py

+from django.db import transaction
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
+
+from events import models
+
+
+def list_events_for_category(request, category_slug):
+    current_category = get_object_or_404(models.EventCategory, slug=category_slug)
+    categories = models.EventCategory.objects.all()
+    upcoming_events = models.Event.published.upcoming()
+    upcoming_events = upcoming_events.filter(categories=current_category)
+    upcoming_events = upcoming_events.order_by('-begin_date')
+    previous_events = models.Event.published.previous().all()
+    previous_events = previous_events.filter(categories=current_category)
+    previous_events = previous_events.order_by('-begin_date')
+    
+    return render_to_response('events/list.html',
+        {
+            'upcoming_events': upcoming_events,
+            'previous_events': previous_events,
+            'current_category': current_category,
+            'categories' : categories,
+        },
+        context_instance=RequestContext(request),
+    )
+
+
+def list_events(request):
+    upcoming_events = \
+        models.Event.published.upcoming().order_by('-begin_date')
+    previous_events = \
+        models.Event.published.previous().order_by('-begin_date')
+    return render_to_response('events/list.html',  
+        {
+            'upcoming_events': upcoming_events,
+            'previous_events': previous_events,
+        },
+        context_instance=RequestContext(request),
+    )
+    
+    
+def view_event(request, year, month, event_slug):
+    event = get_object_or_404(
+        models.Event,
+        begin_date__year=year,
+        begin_date__month=month,
+        slug=event_slug,
+        is_published=True,
+    )
+
+    return render_to_response('events/view.html',
+        {
+            'event': event,
+            'ordered_attachments': event.attachments.order_by('order'),
+        },
+        context_instance=RequestContext(request),
+    )
     packages=find_packages(),
     include_package_data=True,
     exclude_package_data={
-        '': ['*.sql', '*.pyc'],
+        '': ['*.sql', '*.pyc',],
     },
     url='',
     license='LICENSE.txt',