Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Event display and managment views #25

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ class Common(Configuration):

TIME_ZONE = 'America/Chicago'

USE_TZ = True

USE_I18N = False

USE_L10N = False

USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

Expand Down
4 changes: 1 addition & 3 deletions events/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import timedelta

from django.db import models
Expand Down Expand Up @@ -28,8 +27,7 @@ def get_occurrences(self, start, end, category=None):

if category:
qs = qs.filter(Q(category=category) | Q(category__parent=category))
else:
qs = qs.filter(start__lt=end)

# get all occurrences for those events that don't already have a
# persistent match and that lie in this period.
all_occurrences = []
Expand Down
5 changes: 5 additions & 0 deletions events/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now, utc
from django_extensions.db.models import TimeStampedModel, TitleSlugDescriptionModel

from .meta import Location
Expand Down Expand Up @@ -41,6 +42,10 @@ def clean(self):
# REVIEW: would be nice if this was a part of the field validators
raise ValidationError("Start time must be earlier than end time.")

@property
def has_past(self):
return self.end.replace(tzinfo=utc) < now()

class Meta:
abstract = True
ordering = ('start', )
23 changes: 23 additions & 0 deletions events/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .base import (
UpcomingOccurrencesViewBase,
EventsListViewBase,
EventDetailViewBase,
EventCreateViewBase,
EventUpdateViewBase,
EventDetailViewBase,
OccurrenceDetailViewBase,
OccurrenceDeleteViewBase,
OccurrenceUpdateViewBase)


__all__ = (
'UpcomingOccurrencesViewBase',
'EventsListViewBase',
'EventDetailViewBase',
'EventCreateViewBase',
'EventUpdateViewBase',
'EventDetailViewBase',
'OccurrenceDetailViewBase',
'OccurrenceDeleteViewBase',
'OccurrenceUpdateViewBase',
)
Empty file added events/views/admin.py
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ geopy==1.11.0

# Time related
arrow==0.7.0
pytz==2015.4

# static file related
whitenoise==2.0.6
Expand Down
24 changes: 24 additions & 0 deletions twd/templates/twd/home.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<div class="container">
<div class="row">
<div class="col-md-offset-3 col-md-6">
<!-- Developers, what do they know? Is it working? let's find out! -->
<div class="card card-inverse card-success text-center m-t">
<div class="card-block">
<h4 class="card-title">
Expand All @@ -12,6 +13,29 @@
<p class="card-text">If you're seeing this, things are probably working!</p>
</div>
</div>
<!-- Events -->
<h3>Upcoming Events</h3>
<p>Events from <strong>{{ start|date }}</strong> to <strong>{{ until|date }}</strong></p>
{% for event_occ in get_upcoming_events() %}
<div class="card m-t {{ event_occ.slug|default('un-persisted') }} {{ event_occ.event.slug }}">
{% if event_occ.has_past -%}
<div class="card-header">
event past
</div>
{%- endif %}
<div class="card-block">
<h4 class="card-title">{{ event_occ.title }}</h4>
<p class="card-text">
<small class="text-muted"><time datetime="{{ event_occ.start }}">{{ event_occ.start|date }}</time></small>
<small>in</small>
<small class="text-muted">{{ event_occ.start|timeuntil }}</small>
{% if event_occ.location %}
<small class="pull-right">{{ event_occ.location.name }}</small></p>
{% endif %}
<p class="card-text">{{ event_occ.description }}</p>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions twd/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import arrow
from django.utils.timezone import datetime, now
from django.views.generic import TemplateView

from events import views as base_views

from events.models import Event


class UpcomingOccurrencesView(base_views.UpcomingOccurrencesViewBase):
template_name = 'events/upcoming_events.jinja'
Expand All @@ -14,6 +18,24 @@ class EventsListView(base_views.EventsListViewBase):
class HomePageView(TemplateView):
template_name = 'twd/home.jinja'

def dispatch(self, *args, **kwargs):
self.start_from = arrow.utcnow().replace(weeks=-1).naive
self.until = arrow.utcnow().replace(months=1).naive
return super().dispatch(*args, **kwargs)

def get_context_data(self):
context = super().get_context_data()
context.update({
'get_upcoming_events': self.get_upcoming_events,
'start': self.start_from,
'until': self.until
})
return context

def get_upcoming_events(self):
"""Grab all occurrences from a week ago to a month in the future"""
return Event.objects.get_occurrences(self.start_from, self.until)


# Event/Occurrence Views
class EventDetailView(base_views.EventDetailViewBase):
Expand Down