Giter VIP home page Giter VIP logo

image-sitemaps's Introduction

image-sitemaps

Google image sitemaps for Django. More informations about image sitemaps on Google Webmaster Tools.

Installation

You can get image-sitemaps from pypi with:

pip install django-image-sitemaps

The development version can be installed with:

pip install -e git+git://github.com/akarzim/image-sitemaps#egg=image-sitemaps

image-sitemaps introduce a new XML template therefore you should add it to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
    ...
    'imagesitemaps',
    ...
)

Usage

Create a new file named sitemaps.py in your app directory and declare your ImageSitemap classes :

# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
import imagesitemaps

class ImageSitemap(imagesitemaps.ImageSitemap):
    """ generic data for all ours image sitempas (use it as you used to with Django Sitemap) """  
    changefreq = 'weekly'
    priority = 0.5

    def lastmod(self, obj):
        return obj.modified

class ProductImageSitemap(ImageSitemap):
    """ a specific image sitemap for ours Product class """
    
    def items(self):
        """ Django Sitemap's items method """
        return Product.objects.all()

    def images(self, obj):
        """ this method allows you to define multiple images for an object """
        return obj.images()

    def image_loc(self, img):
        """ this required method define the image location """
        return img.doc.url

    def image_caption(self, img):
        """ this optional method define the image caption """
        return unicode(img)


    def location(self, obj):
       """ Django Sitemap's location method """
        return reverse(
            'webstore_product',
            kwargs={
                'slug_product': obj.slug,
            }
        )

Then you have to add this data at the end of your Django root urls.py :

from myapp.sitemaps import ProductImageSitemap

imagesitemaps = {
    'products': ProductImageSitemap,
}

urlpatterns += patterns('imagesitemaps.views',
    url(r'^sitemap-image\.xml$', 'index', {'sitemaps': imagesitemaps, 'template_name': 'image_sitemap.xml'}),
    url(r'^sitemap-image-(?P<section>.+)\.xml$', 'sitemap', {'sitemaps': imagesitemaps, 'template_name': 'image_sitemap.xml'}),
)

Image tag definitions

Tag Required Description
<image:image> Yes Encloses all information about a single image. Each URL (<loc> tag) can include up to 1,000 <image:image> tags.
<image:loc> Yes The URL of the image.

In some cases, the image URL may not be on the same domain as your main site. This is fine, as long as both domains are verified in Webmaster Tools. If, for example, you use a content delivery network (CDN) to host your images, make sure that the hosting site is verified in Webmaster Tools OR that you submit your Sitemap using robots.txt. In addition, make sure that your robots.txt file doesn’t disallow the crawling of any content you want indexed.

<image:caption> Optional The caption of the image.
<image:geo_location> Optional The geographic location of the image. For example, <image:geo_location>Limerick, Ireland</image:geo_location>.
<image:title> Optional The title of the image.
<image:license> Optional A URL to the license of the image.

If we want to declare a new tag in our image sitemap (i.e. <image:license>), we just have to define a new method starting with image_ in our ImageSitemap class :

class ProductImageSitemap(ImageSitemap):
    ...
    def image_license(self, license):
        """ this optional method define the image license """
        return u"http://creativecommons.org/licenses/by-nd/3.0/legalcode"

image-sitemaps's People

Contributors

akarzim avatar bodyhealer avatar petrdlouhy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

image-sitemaps's Issues

Package has a problem with django 3.2

I have been used this package with django 2.2 and its worked fine but after updating to django 3.2 its get stuck to this problem,

<---------- Error ----------->
AttributeError at /sitemap-products.xml

'ProductImageSitemap' object has no attribute '_Sitemap__get'

-- | --

Django Version: 3.2
AttributeError
'ProductImageSitemap' object has no attribute '_Sitemap__get'
/home2/virtualenv/3.7/lib/python3.7/site-packages/imagesitemaps/init.py, line 46, in get_urls

<---------- my code ----------->

class ImageSitemap(imagesitemaps.ImageSitemap):
""" generic data for all ours image sitempas (use it as you used to with Django Sitemap) """
changefreq = 'weekly'
priority = 0.8

def lastmod(self, obj):
    return obj.modified

class ProductImageSitemap(ImageSitemap):
""" A specific image sitemap for ours Product class """

def items(self):
    """ Django Sitemap's items method """
    return Product.objects.filter(is_publish="Publish")

def images(self, obj):
    """ this method allows you to define multiple images for an object """
    return obj.gallery_product.all()[0:1]

def image_loc(self, img):
    """ this required method define the image location """
    return "https://*****.com/"+img.image.url

def image_caption(self, img):
    """ this optional method define the image caption """
    return str(img.name)

Install django-image-sitemaps through pip is not working

The command:

pip install -vvvv django-image-sitemaps

Outputs:

Collecting django-image-sitemaps
  1 location(s) to search for versions of django-image-sitemaps:
  * https://pypi.python.org/simple/django-image-sitemaps/
  Getting page https://pypi.python.org/simple/django-image-sitemaps/
  Looking up "https://pypi.python.org/simple/django-image-sitemaps/" in the cache
  Current age based on date: 490
  Freshness lifetime from max-age: 600
  Freshness lifetime from request max-age: 600
  The response is "fresh", returning cached response
  600 > 490
  Analyzing links from page https://pypi.python.org/simple/django-image-sitemaps/
    Skipping link https://pypi.python.org/packages/2c/61/4a708c6b64ce6ce25f6c3ddab3a187d97dc07ad97254c8c00614cec8f147/django_image_sitemaps-1.05-py2.7.egg#md5=5a769b32b1731126e2135e7c2f1a1de9 (from https://pypi.python.org/simple/django-image-sitemaps/); unsupported archive format: .egg
    Skipping link https://pypi.python.org/packages/38/3d/b1e408273d596dd3d87ad0d949c59dd5adc60469df3df411edaa5f91ad1a/django_image_sitemaps-1.02-py2.7.egg#md5=d506ed012849424a21627cf1189c2bfe (from https://pypi.python.org/simple/django-image-sitemaps/); unsupported archive format: .egg
    Skipping link https://pypi.python.org/packages/77/39/594b778df7bc0ca98845beecbe5a3154a39631bc6da8c96b8c857d94e339/django_image_sitemaps-1.03-py2.7.egg#md5=cc7e83345538aa03bebe1e656db7dbae (from https://pypi.python.org/simple/django-image-sitemaps/); unsupported archive format: .egg
    Skipping link https://pypi.python.org/packages/7e/39/5491d592319a4924c5d0816afe2a9d5caec9e96fbd5166ea6d26381e608b/django_image_sitemaps-1.04-py2.7.egg#md5=2cfb9fe02cf27cb9dec081cfd8f36c57 (from https://pypi.python.org/simple/django-image-sitemaps/); unsupported archive format: .egg
  Could not find a version that satisfies the requirement django-image-sitemaps (from versions: )
Cleaning up...
No matching distribution found for django-image-sitemaps
Exception information:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 310, in run
    wb.build(autobuilding=True)
  File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 750, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 522, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 268, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/local/lib/python2.7/site-packages/pip/index.py", line 491, in find_requirement
    'No matching distribution found for %s' % req
DistributionNotFound: No matching distribution found for django-image-sitemaps

Cannot be install on django 3

Hello,
on django 3 cannot be install,

error: bash: pip: command not found

please help to fix this error

thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.