Skip to content

Commit 509a976

Browse files
committed
* Created views with a homepage view that utilizes the meetup API wrapper
* Wired view into urls.py, caching the view * Added cache settings for redis in production, and in-memory locally * Populated index template with data from API wrapper * Added django-redis-cache dependency * Updated pythonkc-meetups dependency
1 parent d780851 commit 509a976

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

pythonkc_site/requirements/project.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ Django==1.3
22
gondor==1.0b1.post12
33
psycopg2==2.4.1
44
South==0.7.3
5-
pythonkc-meetups==0.0.2
5+
pythonkc-meetups==0.0.3
6+
django-redis-cache==0.8.3

pythonkc_site/settings.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,32 @@
148148
}
149149
}
150150

151+
151152
try:
152153
from local_settings import *
153154
except ImportError:
154155
pass
156+
157+
158+
try:
159+
# NOTE The GONDOR_REDIS_* settings are placed in local_settings by the
160+
# Gondor runtime.
161+
CACHES = {
162+
'default': {
163+
'BACKEND': 'redis_cache.RedisCache',
164+
'LOCATION': '{0}:{1}'.format(GONDOR_REDIS_HOST, GONDOR_REDIS_PORT),
165+
'OPTIONS': { # optional
166+
'DB': 1,
167+
'PASSWORD': GONDOR_REDIS_PASSWORD,
168+
}
169+
}
170+
}
171+
except NameError: # If we're not in the Gondor runtime, use memory.
172+
CACHES = {
173+
'default': {
174+
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
175+
}
176+
}
177+
178+
179+
from meetup_api_key import MEETUP_API_KEY

pythonkc_site/templates/index.html

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
<article>
2121
<header>
2222
<time>
23-
<h1>[upcoming date]</h1>
24-
<p>[upcoming time]</p>
23+
<h1>{{ next_event.time|date:"F j, Y" }}</h1>
24+
<p>{{ next_event.time|date:"g:i a" }}</p>
2525
</time>
2626
</header>
27-
<h2>[Event title]</h2>
28-
<p>[Event descriptiopn]</p>
29-
<p class="rsvp">RSVP at</p>
27+
<h2>{{ next_event.name|safe }}</h2>
28+
<p>{{ next_event.description|safe }}</p>
29+
<p class="rsvp"><a href="{{ next_event.event_url }}">RSVP</a></p>
3030
<div id="map_canvas" style="width:100%; height:100%"></div>
3131
</article>
3232
</div>
@@ -43,14 +43,17 @@ <h1>Past Events</h1>
4343
{% for event in past_events %}
4444
<article>
4545
<header>
46-
<h1><time datetime>{Date goes here}</time></h1>
46+
<h1><time datetime>{{ event.time|date:"F j, Y" }}</time></h1>
4747
</header>
4848

49-
<h2>{}</h2>
50-
<p>{summary}</p>
49+
<h2>{{ event.name|safe }}</h2>
50+
<p>{{ event.description|safe }}</p>
5151
<div class="attendees">
52-
{% for attendee in attendees %}
53-
<img src="" height="" width="" class="attendee" />
52+
{% for attendee in event.attendees %}
53+
{% if attendee.photo.thumb_url %}
54+
<img src="{{ attendee.photo.thumb_url}}" height="" width="" class="attendee"
55+
alt="{{ attendee.name }}" />
56+
{% endif %}
5457
{% endfor %}
5558
</div>
5659

@@ -76,7 +79,7 @@ <h2>{}</h2>
7679
pykc.map;
7780

7881
pykc.mapInit = function() {
79-
var latlng = new google.maps.LatLng(-34.397, 150.644);
82+
var latlng = new google.maps.LatLng({{ next_event.venue.lat }}, {{ next_event.venue.lon }});
8083
var opts = {
8184
zoom: 8,
8285
center: latlng,

pythonkc_site/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from django.conf.urls.defaults import include
22
from django.conf.urls.defaults import patterns
33
from django.conf.urls.defaults import url
4-
from django.views.generic.simple import direct_to_template
4+
from django.views.decorators.cache import cache_page
5+
from pythonkc_site.views import PythonKCHome
56

67
# Uncomment the next two lines to enable the admin:
78
# from django.contrib import admin
89
# admin.autodiscover()
910

1011
urlpatterns = patterns('',
11-
url(r'^/?$', direct_to_template, {'template': 'index.html'}),
12+
url(r'^/?$', cache_page(60 * 5)(PythonKCHome.as_view())),
1213
# Examples:
1314
# url(r'^$', 'pythonkc_site.views.home', name='home'),
1415
# url(r'^pythonkc_site/', include('pythonkc_site.foo.urls')),

pythonkc_site/views.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
from django.conf import settings
5+
from django.views.generic.base import TemplateView
6+
from pythonkc_meetups import PythonKCMeetups
7+
8+
9+
try:
10+
api_key = settings.MEETUP_API_KEY
11+
except AttributeError:
12+
raise ImproperlyConfigured('MEETUP_API_KEY is required in settings')
13+
14+
15+
meetups = PythonKCMeetups(api_key, http_timeout=6)
16+
num_past_events = getattr(settings, 'MEETUP_SHOW_PAST_EVENTS', 3)
17+
18+
19+
class PythonKCHome(TemplateView):
20+
template_name = 'index.html'
21+
22+
def get_context_data(self, **kwargs):
23+
# NOTE Insteading of individually caching next/past events, we're
24+
# simply going to cache this whole page until things get more
25+
# complicated (see urls.py for caching decoration).
26+
27+
def get_next_event():
28+
upcoming_events = meetups.get_upcoming_events()
29+
return upcoming_events[0] if upcoming_events else None
30+
31+
def get_past_events():
32+
return meetups.get_past_events()[:num_past_events]
33+
34+
return {
35+
'next_event': get_next_event(),
36+
'past_events': get_past_events()
37+
}

0 commit comments

Comments
 (0)