Opened 16 years ago

Closed 14 years ago

Last modified 14 years ago

#11358 closed (fixed)

Flatpage sitemap shows all pages, even private pages

Reported by: Dennis Burke Owned by: Karen Tracey
Component: Contrib apps Version: 1.0
Severity: Keywords: sprintSep2010
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I tried searching trac for this issue, but wasn't able to turn up anything relevant.

Flatpages allow you to make a page visible only to logged in users, but the flatpage sitemap reveals the url. Would it be possible to add a .filter(registration_required=False) to the queryset that populates the flatpage sitemap?

in django.contrib.sitemaps:

class FlatPageSitemap(Sitemap):
    def items(self):
        from django.contrib.sites.models import Site
        current_site = Site.objects.get_current()
        return current_site.flatpage_set.filter(registration_required=False)

Attachments (2)

11358.patch (1.3 KB ) - added by Mark Lavin 14 years ago.
Patch against [13710] for change and doc change
11358_with_test.patch (3.7 KB ) - added by Mark Lavin 14 years ago.
Patch against [13714] to add tests and doc change

Download all attachments as: .zip

Change History (15)

comment:1 by kmpm, 15 years ago

You almost answered it yourself.
I don't know if its worth doing a modification to sitemaps just for this.
Save your class but with another name like "FlatPagePublicSitemap" in a file called "sitemaps.py" for example.
Include ( from sitemaps include FlatPagePublicSitemap ) and use that class in your urls.py instead of the ordinary FlagPageSitemap.

Is that a good enough solution for you?

comment:2 by Dennis Burke, 15 years ago

Yeah, this solution is fine. Should be made a little more explicit in the Documentation? Or should we hope that google helps direct people seeking this solution here?

comment:3 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

A sitemap exists for the benefit of public spiders and crawlers, so there isn't much point having a sitemap that includes private pages.

comment:4 by Mark Lavin, 14 years ago

Owner: changed from nobody to Mark Lavin

by Mark Lavin, 14 years ago

Attachment: 11358.patch added

Patch against [13710] for change and doc change

comment:5 by Mark Lavin, 14 years ago

Has patch: set

comment:6 by Malcolm Tredinnick, 14 years ago

The code change looks fine, however I'd like a small tweak in the documentation: rather then explaining the effect in code (registration_required=False), try to do it in English (e.g. "pages which are visible to all users, including those not logged in" or something a little more concise). It can disrupt the reading flow to have to switch to understanding that flatpages model has an attribute called registration_required and so on.

Are there any existing sitemap tests? If so, they might need to be updated here. If not, have a think about if there's some way to test them even a little bit. It might be hard to do so, but shouldn't be impossible (using test.Client to pull back a sample of the sitemap and examine the contents, perhaps?)

by Mark Lavin, 14 years ago

Attachment: 11358_with_test.patch added

Patch against [13714] to add tests and doc change

comment:7 by Mark Lavin, 14 years ago

Keywords: sprintSep2010 added

comment:8 by Mark Lavin, 14 years ago

Owner: changed from Mark Lavin to nobody
Triage Stage: AcceptedReady for checkin

comment:9 by Karen Tracey, 14 years ago

Owner: changed from nobody to Karen Tracey

comment:10 by Karen Tracey, 14 years ago

Resolution: fixed
Status: newclosed

(In [13734]) Fixed #11358: Don't include private flatpages in sitemap. Thanks dburke and mlavin.

comment:11 by Luke Plant, 14 years ago

Is there a reason this wasn't backported? I'm trying to backport another patch, and I've got a conflict because this hasn't been backported to 1.2.X.

in reply to:  11 comment:12 by Karen Tracey, 14 years ago

Replying to lukeplant:

Is there a reason this wasn't backported? I'm trying to backport another patch, and I've got a conflict because this hasn't been backported to 1.2.X.

Hectic sprint day oversight, I think. On first read I think I thought this was more of a feature than a bugfix...on re-looking at it it seems to be more of a bugfix, so should probably be backported.

comment:13 by Luke Plant, 14 years ago

I backported it now - [13985]

Note: See TracTickets for help on using tickets.
Back to Top