From 0bfd3d45128b45b47310c3825e85f9fddec9e349 Mon Sep 17 00:00:00 2001 From: Lincoln de Sousa Date: Wed, 8 Oct 2008 15:11:08 -0300 Subject: [PATCH] making an entry be available with its slug --- urls.py | 2 ++ views.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 views.py diff --git a/urls.py b/urls.py index 22476cb..b625832 100644 --- a/urls.py +++ b/urls.py @@ -20,6 +20,7 @@ from django.conf import settings from diario.settings import DIARIO_NUM_LATEST from diario.models import Entry from contents.models import Menu +from ema.views import get_entry_by_slug MEDIA = {'document_root': settings.INSTANCE('media')} @@ -54,6 +55,7 @@ urlpatterns = patterns('', date_field='pub_date'), name='diario-entry'), + (r'^([-\w]+)/$', get_entry_by_slug), (r'^', include('ema.eventos.urls')), # static media diff --git a/views.py b/views.py new file mode 100644 index 0000000..36d9af4 --- /dev/null +++ b/views.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2008 Lincoln de Sousa +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +from diario.views.entries import entry_detail +from diario.models import Entry +from django.views.generic.date_based import object_detail +from ema.contents.models import Menu + +def get_entry_by_slug(request, slug): + theone = Entry.objects.get(slug=slug) + return entry_detail(request, + year=str(theone.pub_date.year), + month=str(theone.pub_date.month), + day=str(theone.pub_date.day), + date_field='pub_date', + slug=slug, + slug_field='slug', + month_format='%m', + queryset=Entry.published_on_site.all(), + template_object_name='entry', + extra_context={'menus': Menu.objects.all()}) -- 2.20.1