Created
July 8, 2012 22:13
-
-
Save lucassimon/3073137 to your computer and use it in GitHub Desktop.
Gerar sitemap.xml com django de paginas estaticas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
__author__ = 'lucas' | |
""" | |
Description: | |
Version: | |
Data: 01/05/12 | |
packages: , | |
""" | |
from django.conf.urls import patterns, url | |
from views import HomePageView,AboutPageView | |
urlpatterns = patterns( | |
'core.views', | |
url(r'^$',HomePageView.as_view(),name='homepage'), | |
url(r'^sobre-nos/$',AboutPageView.as_view(),name='aboutus'), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.core.urlresolvers import reverse | |
from django.contrib.sitemaps import Sitemap | |
from news.models import New | |
from events.models import Event | |
__author__ = 'lucas' | |
""" | |
Description: Sitemap de todo o sistema | |
Version: 0.1 | |
Data: 08/07/12 | |
packages: , | |
""" | |
class NewsSitemap(Sitemap): | |
""" | |
Classe responsavel por gerar o xml dos itens de novidades | |
""" | |
#Se for um atributo, seu valor deve ser uma string representando a frequência de mudança para | |
#objeto retornado por items(). | |
changefreq = 'weekly' | |
#Se for um atributo, seu valor deve ser ou uma string ou uma float representando a prioridade de | |
# objeto retornado por items(). | |
priority = 0.5 | |
def items(self): | |
""" | |
Obrigatório. Um método que retorna uma lista de objetos. | |
O framework não se preocupa com o tipo de objetos que eles são; | |
tudo que importa é que estes objetos são passados para os métodos | |
""" | |
return New.objects.filter(isactive__exact=1) | |
def lastmod(self, obj): | |
""" | |
Se for um método, deve receber um argumento -- um objeto retornado pelo items() -- | |
e retornar a data/hora da última modificação deste objeto, | |
como um objeto Python datetime.datetime. | |
""" | |
return obj.created_at | |
# changefreq can be callable too | |
def changefreq(self, obj): | |
""" | |
Se for um método, ele deve receber um argumento -- um objeto retornado por items() -- | |
e retornar a frequencia de mudança deste objeto, como uma string Python. | |
""" | |
return "weekly" | |
class EventsSitemap(Sitemap): | |
""" | |
Classe responsavel por gerar o xml dos itens de novidades | |
""" | |
#Se for um atributo, seu valor deve ser uma string representando a frequência de mudança para | |
#objeto retornado por items(). | |
changefreq = 'daily' | |
#Se for um atributo, seu valor deve ser ou uma string ou uma float representando a prioridade de | |
# objeto retornado por items(). | |
priority = 0.8 | |
def items(self): | |
""" | |
Obrigatório. Um método que retorna uma lista de objetos. | |
O framework não se preocupa com o tipo de objetos que eles são; | |
tudo que importa é que estes objetos são passados para os métodos | |
""" | |
return Event.objects.all() | |
def lastmod(self, obj): | |
""" | |
Se for um método, deve receber um argumento -- um objeto retornado pelo items() -- | |
e retornar a data/hora da última modificação deste objeto, | |
como um objeto Python datetime.datetime. | |
""" | |
return obj.start | |
# changefreq can be callable too | |
def changefreq(self, obj): | |
""" | |
Se for um método, ele deve receber um argumento -- um objeto retornado por items() -- | |
e retornar a frequencia de mudança deste objeto, como uma string Python. | |
""" | |
return "weekly" | |
class ViewSitemap(Sitemap): | |
"""Reverse static views for XML sitemap.""" | |
def items(self): | |
# Return list of url names for views to include in sitemap | |
return ['/', 'aboutus'] | |
def location(self, item): | |
return reverse(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import patterns, include, url | |
from django.contrib.staticfiles.urls import staticfiles_urlpatterns | |
# Uncomment the next two lines to enable the admin: | |
from django.contrib import admin | |
admin.autodiscover() | |
from sitemap import NewsSitemap,ViewSitemap, EventsSitemap | |
sitemaps = { | |
'pages': ViewSitemap, | |
'news': NewsSitemap, | |
'events': EventsSitemap, | |
} | |
urlpatterns = patterns('', | |
# Examples: | |
# url(r'^$', 'serpentedonilo.views.home', name='home'), | |
# url(r'^serpentedonilo/', include('serpentedonilo.foo.urls')), | |
# Uncomment the admin/doc line below to enable admin documentation: | |
#url(r'^admin/doc/', include('django.contrib.admindocs.urls')), | |
# Uncomment the next line to enable the admin: | |
url(r'^admin/', include(admin.site.urls)), | |
url(r'^', include('core.urls', namespace='core')), | |
url(r'^', include('news.urls', namespace='news')), | |
url(r'^', include('events.urls', namespace='events')), | |
url(r'^', include('inscriptions.urls', namespace='inscriptions')), | |
(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}) | |
) | |
urlpatterns += staticfiles_urlpatterns() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment