Skip to main content

A configurable Django app for exporting Tolstoy-compatible product CSV feeds.

Project description

Django Tolstoy Export

A configurable Django app for exporting Tolstoy-compatible product CSV feeds.

It is designed to be installed in INSTALLED_APPS and configured from Django settings. The package does not require Django Oscar, but it works well with Oscar-style products, images, stockrecords, and request strategies.

Installation

pip install django-tolstoy-export
INSTALLED_APPS = [
    # ...
    "tolstoy_export",
]

Add the URLs if you want the package-provided export endpoint:

from django.urls import include, path

urlpatterns = [
    path("feeds/", include("tolstoy_export.urls")),
]

The CSV will be available at /feeds/tolstoy-csv/.

Settings

Configure the exported model, Tolstoy columns, queryset shaping, and languages:

TOLSTOY_EXPORT = {
    "MODEL": "catalogue.Product",
    "FILENAME": "tolstoy_export_feed.csv",
    "LANGUAGES": ["en", "el"],
    "INCLUDE_LANGUAGE_IN_ID": True,
    "PUBLIC_FIELD": "is_public",
    "CURRENCY_CODE": "EUR",
    "CURRENCY_SYMBOL": "€",
    "FIELDS": {
        "id": "upc",
        "title": "title",
        "descriptionHtml": "db_field_description",
        "url": "get_absolute_url",
        "imageUrl": "images",
        "images": "images",
        "price": "price",
        "compareAtPrice": "compare_at_price",
        "inventory": "stockrecords.0.num_in_stock",
    },
    "QUERYSET_FILTERS": {
        "is_public": True,
    },
    "QUERYSET_EXCLUDES": {
        "stockrecords__num_in_stock": 0,
    },
    "SELECT_RELATED": ("parent",),
    "PREFETCH_RELATED": ("images", "stockrecords"),
    "ORDER_BY": ("id",),
}

Use "LANGUAGES": "__all__" to export every language in Django's LANGUAGES setting. Use None or omit it to export only the currently active language.

Field Mapping

FIELDS maps Tolstoy CSV column names to fields or attributes on your model.

Supported values:

  • "db_field_name" for a direct model field;
  • "parent.description" for dotted relation paths;
  • "stockrecords.0.num_in_stock" for list/queryset indexes;
  • "get_absolute_url" for a no-argument model method;
  • ["upc", "id"] for fallback fields;
  • a callable, or an import path to a callable.

The Tolstoy columns are:

id,title,descriptionHtml,url,imageUrl,images,price,compareAtPrice,currencyCode,currencySymbol,inventory

imageUrl is the first image. images is exported as a comma-separated list of additional image URLs. A mapped value can be a URL string, image object with original.url, list, tuple, queryset, or related manager.

Custom View

You can also call the response helper directly:

from tolstoy_export.django import tolstoy_csv_response


def export_tolstoy_csv(request):
    return tolstoy_csv_response(request)

Per-view overrides are useful when you want two exports from the same settings:

def export_single_language_tolstoy_csv(request):
    return tolstoy_csv_response(
        request,
        include_all_languages=False,
        include_language_in_id=False,
        require_public=False,
    )

Generic CSV Writer

For non-view usage:

from io import StringIO
from tolstoy_export import write_products_csv

output = StringIO()
write_products_csv(
    output,
    products,
    request=request,
    languages=["en", "el"],
    include_language_in_id=True,
    fields={
        "id": "sku",
        "title": "name",
        "descriptionHtml": "description",
        "url": "get_absolute_url",
    },
)
csv_text = output.getvalue()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_tolstoy_export-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_tolstoy_export-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file django_tolstoy_export-0.1.0.tar.gz.

File metadata

  • Download URL: django_tolstoy_export-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.6

File hashes

Hashes for django_tolstoy_export-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f55166a47bf602426c38bc04d6af286c1428512154865933a97a416c1462bcf
MD5 b481191c62ffe6556904a512263ba35e
BLAKE2b-256 5a00960f85747ef1f7b960a16f3b2bd1c96c08d2f013dc46712f848f6021a33d

See more details on using hashes here.

File details

Details for the file django_tolstoy_export-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_tolstoy_export-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57d914a898dfcc37df62cf0228a7d6aaefe59d1cf4c4111df7cef8c4cc339573
MD5 ffa36ef0a24a6573fbfd655aa62b991b
BLAKE2b-256 444c53d1f045b290969affb85ae6b1fc4cb4c702dcf4f29a25f4430bc1b2db6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page