Re: sitemaps and prepend_www

2011-04-26 Thread Gert Van Gool
Usually you would create a ticket on trac [1] which describes your problem
and reasoning.
And you can attach a patch file to it. This way, it will go through the
normal triaging and feature requests.

[1] http://code.djangoproject.com/newticket
-- Gert

Mobile: +32 498725202
Twitter: @gvangool 
Web: http://gert.selentic.net



On Fri, Apr 22, 2011 at 13:14, Nikolay Panov wrote:

> Hi,
>
> I cannot use www in current_site.domain since .domain is used in many
> places (e.g. emails) where www is not required. BTW, I'm using
> PREPEND_WWW=True setting, since it makes url looks better.
> Now, google webmaster tools rejecting all links in sitemap of my
> project because lack of 'www'.
>
> My question is: why we cannot have something like:
>
> --- django_old/contrib/sitemaps/__init__.py   2008-11-19
> 08:44:26.0 +0300
> +++ django_new/contrib/sitemaps/__init__.py 2010-11-24
> 18:57:34.0 +0300
> @@ -1,4 +1,5 @@
>  from django.core import urlresolvers, paginator
> +from django.conf import settings
>  import urllib
>
>  PING_URL = "http://www.google.com/webmasters/tools/ping";
> @@ -29,7 +30,10 @@
>
> from django.contrib.sites.models import Site
> current_site = Site.objects.get_current()
> -url = "http://%s%s"; % (current_site.domain, sitemap_url)
> +domain = current_site.domain
> +if settings.PREPEND_WWW and not domain.startswith('www.'):
> +domain = 'www.' + domain
> +url = "http://%s%s"; % (domain, sitemap_url)
> params = urllib.urlencode({'sitemap':url})
> urllib.urlopen("%s?%s" % (ping_url, params))
>
> @@ -62,9 +66,12 @@
> def get_urls(self, page=1):
> from django.contrib.sites.models import Site
> current_site = Site.objects.get_current()
> +domain = current_site.domain
> +if settings.PREPEND_WWW and not domain.startswith('www.'):
> +domain = 'www.' + domain
> urls = []
> for item in self.paginator.page(page).object_list:
> -loc = "http://%s%s"; % (current_site.domain,
> self.__get('location', item))
> +loc = "http://%s%s"; % (domain, self.__get('location', item))
> url_info = {
> 'location':   loc,
> 'lastmod':self.__get('lastmod', item, None),
> and
>
> --- django_old/contrib/sitemaps/views.py  2008-11-19
> 08:44:26.0 +0300
> +++ django_new/contrib/sitemaps/views.py2010-11-24
> 18:57:58.0 +0300
> @@ -4,6 +4,8 @@
>  from django.core import urlresolvers
>  from django.utils.encoding import smart_str
>  from django.core.paginator import EmptyPage, PageNotAnInteger
> +from django.conf import settings
> +
>
>  def index(request, sitemaps):
> current_site = Site.objects.get_current()
> @@ -15,10 +17,13 @@
> else:
> pages = site.paginator.num_pages
> sitemap_url =
> urlresolvers.reverse('django.contrib.sitemaps.views.sitemap',
> kwargs={'section': section})
> -sites.append('%s://%s%s' % (protocol, current_site.domain,
> sitemap_url))
> +domain = current_site.domain
> +if settings.PREPEND_WWW and not domain.startswith('www.'):
> +domain = 'www.' + domain
> +sites.append('%s://%s%s' % (protocol, domain, sitemap_url))
> if pages > 1:
> for page in range(2, pages+1):
> -sites.append('%s://%s%s?p=%s' % (protocol,
> current_site.domain, sitemap_url, page))
> +sites.append('%s://%s%s?p=%s' % (protocol, domain,
> sitemap_url, page))
> xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
> return HttpResponse(xml, mimetype='application/xml')
>
>
> This fix works well for me, but it will be great to have this into
> official django repo.
>
> Have a nice day,
>Nikolay.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To post to this group, send email to django-developers@googlegroups.com.
> To unsubscribe from this group, send email to
> django-developers+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-developers?hl=en.
>
>

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



sitemaps and prepend_www

2011-04-22 Thread Nikolay Panov
Hi,

I cannot use www in current_site.domain since .domain is used in many
places (e.g. emails) where www is not required. BTW, I'm using
PREPEND_WWW=True setting, since it makes url looks better.
Now, google webmaster tools rejecting all links in sitemap of my
project because lack of 'www'.

My question is: why we cannot have something like:

--- django_old/contrib/sitemaps/__init__.py   2008-11-19
08:44:26.0 +0300
+++ django_new/contrib/sitemaps/__init__.py 2010-11-24
18:57:34.0 +0300
@@ -1,4 +1,5 @@
 from django.core import urlresolvers, paginator
+from django.conf import settings
 import urllib

 PING_URL = "http://www.google.com/webmasters/tools/ping";
@@ -29,7 +30,10 @@

 from django.contrib.sites.models import Site
 current_site = Site.objects.get_current()
-url = "http://%s%s"; % (current_site.domain, sitemap_url)
+domain = current_site.domain
+if settings.PREPEND_WWW and not domain.startswith('www.'):
+domain = 'www.' + domain
+url = "http://%s%s"; % (domain, sitemap_url)
 params = urllib.urlencode({'sitemap':url})
 urllib.urlopen("%s?%s" % (ping_url, params))

@@ -62,9 +66,12 @@
 def get_urls(self, page=1):
 from django.contrib.sites.models import Site
 current_site = Site.objects.get_current()
+domain = current_site.domain
+if settings.PREPEND_WWW and not domain.startswith('www.'):
+domain = 'www.' + domain
 urls = []
 for item in self.paginator.page(page).object_list:
-loc = "http://%s%s"; % (current_site.domain,
self.__get('location', item))
+loc = "http://%s%s"; % (domain, self.__get('location', item))
 url_info = {
 'location':   loc,
 'lastmod':self.__get('lastmod', item, None),
and

--- django_old/contrib/sitemaps/views.py  2008-11-19
08:44:26.0 +0300
+++ django_new/contrib/sitemaps/views.py2010-11-24
18:57:58.0 +0300
@@ -4,6 +4,8 @@
 from django.core import urlresolvers
 from django.utils.encoding import smart_str
 from django.core.paginator import EmptyPage, PageNotAnInteger
+from django.conf import settings
+

 def index(request, sitemaps):
 current_site = Site.objects.get_current()
@@ -15,10 +17,13 @@
 else:
 pages = site.paginator.num_pages
 sitemap_url =
urlresolvers.reverse('django.contrib.sitemaps.views.sitemap',
kwargs={'section': section})
-sites.append('%s://%s%s' % (protocol, current_site.domain,
sitemap_url))
+domain = current_site.domain
+if settings.PREPEND_WWW and not domain.startswith('www.'):
+domain = 'www.' + domain
+sites.append('%s://%s%s' % (protocol, domain, sitemap_url))
 if pages > 1:
 for page in range(2, pages+1):
-sites.append('%s://%s%s?p=%s' % (protocol,
current_site.domain, sitemap_url, page))
+sites.append('%s://%s%s?p=%s' % (protocol, domain,
sitemap_url, page))
 xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
 return HttpResponse(xml, mimetype='application/xml')


This fix works well for me, but it will be great to have this into
official django repo.

Have a nice day,
   Nikolay.

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