Re: Sitemap questions (probably dumb ones)

2007-06-16 Thread David Larlet

2007/6/16, John DeRosa <[EMAIL PROTECTED]>:
>
> David Larlet wrote:
> >
> > Any thoughts about this implementation?
>
> I think you could get rid of FakeObject() completely:
>
> class MainSitemap(Sitemap):
>  priority = 0.8
>
>  def items(self):
>  return ["/", "/archives/", "/foo/bar/", ...]
>
>  def location(self, obj):
>  return obj
>
>
> OTOH, if your code works now, you could also leave it alone. :-)  And
> FakeObject could be a convenient central container for calculating
> information that the other methods need, if your site grows in complexity.
>

You're absolutely right, thanks for your comment and suggestion which
works perfectly too! Maybe this usage need to be documented? It
doesn't seemed evident for me at first sight and someone just ask the
same think on IRC yesterday.

David

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sitemap questions (probably dumb ones)

2007-06-15 Thread David Larlet

2007/6/15, John DeRosa <[EMAIL PROTECTED]>:
>
> David Larlet wrote:
> > 2007/6/13, John DeRosa <[EMAIL PROTECTED]>:
> >> David Larlet wrote:
> >>> 2006/12/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>  I've been playing with the sitemap stuff and am finding it to be quite
>  slick. I do, however, have some questions about some unusual cases.
> 
>  1)It works beautifully for listing all the detail pages that make up a
>  list view, but what about the page that takes the list view? In my
>  case, For example, I've got all my guitar pages in there, but not the
>  "guitars" page itself.
> >> An list of objects returned in a sitemap can be for any page on your
> >> site.  The object will have an URL associated with it, as well as a
> >> frequency of change and priority, etc.  So you can make a list of
> >> objects that are entirely arbitrary, and as long as the URL returned for
> >> each object corresponds to a page on your site (i.e., as long as the URL
> >> returns a page on an HttpGet), everything works as you'd expect.
> >>
> > Is it possible that you just paste an example? Because I've tried with
> > a DummyModel with a get_absolute_url function and it doesn't work...
>
> Ah, that's your problem!  You need to define the method location(), not
> get_absolute_url()!
>
> See http://www.djangoproject.com/documentation/0.96/sitemaps/.
>
> An example:
>
> sitemap_classes.py:
> ***
> class BrowseTopicSitemap(Sitemap):
>  """Browse topic page."""
>  changefreq = "weekly"
>  priority = 0.9
>
>  def items(self):
>  """Return a list of objects represent the browse topic page.
>
>  The caller doesn't care what type of object these are; all that
> matters
>  is that these objects get passed to the location(), lastmod(),
>  changefreq() and priority() methods.
>  """
>  # Return a list containing the most recent topic on the site.
>  return
> [Topic.objects.filter(visible=True).order_by("-creation_time")[0]]
>
>  def location(self, obj):
>  """Return the absolute URL for the browse topic page "object"."""
>  return "/browse/"
>
>  def lastmod(self, obj):
>  """Etc..."""
>  
>  return result
>
>
> def sitemap_dict():
>  """Return the current sitemap dict."""
>  # Prepare mapping info for the static mapping sections.  Each of these
>  # sections aren't very large.
>  class_list = [("index", IndexSitemap),
>("browse", BrowseTopicSitemap),
>("author", AuthorSitemap),
>
>  ]
>
>
> *
>
>
> In the URL config:
> 
> urlpatterns += patterns('',
>  (r'^sitemap.xml$', "django.contrib.sitemaps.views.index",
>  sitemap_dict()),
>  (r'^sitemap-(?P.+).xml$',
> "django.contrib.sitemaps.views.sitemap",
>  sitemap_dict()),
>  )
> 
>
>
> John
>

Thanks for your suggestion, I've just done that:

class FakeObject(object):
def __init__(self, url):
self.url = url

class MainSitemap(Sitemap):
priority = 0.8

def items(self):
return [FakeObject('/'),
FakeObject('/archives/'),
...
]

def location(self, obj):
return obj.url

sitemaps = {
'index': MainSitemap(),
...
}

Any thoughts about this implementation?

David

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sitemap questions (probably dumb ones)

2007-06-15 Thread John DeRosa

David Larlet wrote:
> 2007/6/13, John DeRosa <[EMAIL PROTECTED]>:
>> David Larlet wrote:
>>> 2006/12/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
 I've been playing with the sitemap stuff and am finding it to be quite
 slick. I do, however, have some questions about some unusual cases.

 1)It works beautifully for listing all the detail pages that make up a
 list view, but what about the page that takes the list view? In my
 case, For example, I've got all my guitar pages in there, but not the
 "guitars" page itself.
>> An list of objects returned in a sitemap can be for any page on your
>> site.  The object will have an URL associated with it, as well as a
>> frequency of change and priority, etc.  So you can make a list of
>> objects that are entirely arbitrary, and as long as the URL returned for
>> each object corresponds to a page on your site (i.e., as long as the URL
>> returns a page on an HttpGet), everything works as you'd expect.
>>
> Is it possible that you just paste an example? Because I've tried with
> a DummyModel with a get_absolute_url function and it doesn't work...

Ah, that's your problem!  You need to define the method location(), not 
get_absolute_url()!

See http://www.djangoproject.com/documentation/0.96/sitemaps/.

An example:

sitemap_classes.py:
***
class BrowseTopicSitemap(Sitemap):
 """Browse topic page."""
 changefreq = "weekly"
 priority = 0.9

 def items(self):
 """Return a list of objects represent the browse topic page.

 The caller doesn't care what type of object these are; all that 
matters
 is that these objects get passed to the location(), lastmod(),
 changefreq() and priority() methods.
 """
 # Return a list containing the most recent topic on the site.
 return 
[Topic.objects.filter(visible=True).order_by("-creation_time")[0]]

 def location(self, obj):
 """Return the absolute URL for the browse topic page "object"."""
 return "/browse/"

 def lastmod(self, obj):
 """Etc..."""
 
 return result


def sitemap_dict():
 """Return the current sitemap dict."""
 # Prepare mapping info for the static mapping sections.  Each of these
 # sections aren't very large.
 class_list = [("index", IndexSitemap),
   ("browse", BrowseTopicSitemap),
   ("author", AuthorSitemap),
   
 ]


*


In the URL config:

urlpatterns += patterns('',
 (r'^sitemap.xml$', "django.contrib.sitemaps.views.index",
 sitemap_dict()),
 (r'^sitemap-(?P.+).xml$', 
"django.contrib.sitemaps.views.sitemap",
 sitemap_dict()),
 )



John


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sitemap questions (probably dumb ones)

2007-06-15 Thread David Larlet

2007/6/13, John DeRosa <[EMAIL PROTECTED]>:
>
> David Larlet wrote:
> > 2006/12/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> >> I've been playing with the sitemap stuff and am finding it to be quite
> >> slick. I do, however, have some questions about some unusual cases.
> >>
> >> 1)It works beautifully for listing all the detail pages that make up a
> >> list view, but what about the page that takes the list view? In my
> >> case, For example, I've got all my guitar pages in there, but not the
> >> "guitars" page itself.
>
> An list of objects returned in a sitemap can be for any page on your
> site.  The object will have an URL associated with it, as well as a
> frequency of change and priority, etc.  So you can make a list of
> objects that are entirely arbitrary, and as long as the URL returned for
> each object corresponds to a page on your site (i.e., as long as the URL
> returns a page on an HttpGet), everything works as you'd expect.
>
Is it possible that you just paste an example? Because I've tried with
a DummyModel with a get_absolute_url function and it doesn't work...

Anyway, thanks for your help.

David

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sitemap questions (probably dumb ones)

2007-06-12 Thread David Larlet

2006/12/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> I've been playing with the sitemap stuff and am finding it to be quite
> slick. I do, however, have some questions about some unusual cases.
>
> 1)It works beautifully for listing all the detail pages that make up a
> list view, but what about the page that takes the list view? In my
> case, For example, I've got all my guitar pages in there, but not the
> "guitars" page itself.
>
> 2) what about pages that aren't directly tied to any particular view.
> My home page, for example, is built mostly from template tags, grabbing
> this and that from here and there.
>
> 3)What if there's some page that's completely outside of django? Create
> a dummy class returning the hardcoded URL? I've got a forum-archive
> subdomain django doesn't know anything about, since it only exists to
> archive the old php-based board.
>

I have exactly the same question about pages which  don't match a
django models and which are not FlatPages. For example /, /blog/,
/products/, etc. I can't find any example about that.

David

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Sitemap questions (probably dumb ones)

2006-12-07 Thread [EMAIL PROTECTED]

I've been playing with the sitemap stuff and am finding it to be quite
slick. I do, however, have some questions about some unusual cases.

1)It works beautifully for listing all the detail pages that make up a
list view, but what about the page that takes the list view? In my
case, For example, I've got all my guitar pages in there, but not the
"guitars" page itself.

2) what about pages that aren't directly tied to any particular view.
My home page, for example, is built mostly from template tags, grabbing
this and that from here and there.

3)What if there's some page that's completely outside of django? Create
a dummy class returning the hardcoded URL? I've got a forum-archive
subdomain django doesn't know anything about, since it only exists to
archive the old php-based board.

Thanks!


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---