Skip to content

Instantly share code, notes, and snippets.

@andybak
Last active August 29, 2015 13:57
Show Gist options
  • Save andybak/9766998 to your computer and use it in GitHub Desktop.
Save andybak/9766998 to your computer and use it in GitHub Desktop.
from datetime import datetime
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import Http404, HttpResponsePermanentRedirect
from cms.models import Page
unique = True
can_use_extra_url = True
uses_extra_content = True
changeform_content = "List of <a href='/admin/news/news/'>Activities Items</a> will appear here"
def get_type_object():
from alban_way.models import Activity
return Activity
def get_related_instance(request, extra_url=None):
from alban_way.models import Activity
try:
activities = Activity.objects.filter(name=extra_url)
return news[0] #TODO uniqueness?
except IndexError:
return None
def render(request, context):
from alban_way.models import Activity
page = context['page']
extra_url = context['page'].extra_url
if extra_url:
template = 'activity.html'
news_item = get_related_instance(request, extra_url=extra_url[0])
if not(news_item):
raise Http404
context.update ({
'activity': activity
})
else:
template = 'activities.html'
context.update ({
'activities': Activity.objects.all(),
})
return render_to_response(template, context, RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment