Giter VIP home page Giter VIP logo

joshourisman / django-tablib Goto Github PK

View Code? Open in Web Editor NEW
103.0 103.0 48.0 116 KB

django-tablib is a helper library for Django that allows Django models to be used to generate tablib datasets with introspection of the fields on the models if no headers are provided. If headers are provided they can reference any attribute, fields, properties, or methods on the model.

License: MIT License

Python 97.27% HTML 2.73%

django-tablib's People

Contributors

acdha avatar akaihola avatar anrie avatar beniwohli avatar bradmontgomery avatar chive avatar czpython avatar fabricesalvaire avatar fdanielsen avatar gregmuellegger avatar jazztpt avatar jezdez avatar johbo avatar johnthedebs avatar joshourisman avatar renyi avatar shanx avatar skevy avatar stefanfoulis avatar twz915 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-tablib's Issues

ModelDataset evaluates queryset during import

Specifically, DatasetMetaclass evaluates the queryset twice:

if not opts.model and not opts.queryset:
    raise NoObjectsException("You must set a model or non-empty "
                             "queryset for each Dataset subclass")
if opts.queryset:
    queryset = opts.queryset
    model = queryset.model
    new_class.queryset = queryset
    new_class.model = model

This can lead to hard to debug problems, e.g. when the database tables don't exist yet. Instead, these if-conditions could specifically check if the queryset is not None:

if not opts.model and opts.queryset is None:
    raise NoObjectsException("You must set a model or non-empty "
                             "queryset for each Dataset subclass")
if opts.queryset is not None:
    queryset = opts.queryset
    model = queryset.model
    new_class.queryset = queryset
    new_class.model = model

Django 1.8 compatibility

Hello,

Was wondering if a new release is coming with Django 1.8 compatibility from the develop branch?

Allow exporting change list verbatim

Example which does not work because values in "headers" are expected to be model fields:

class SomeModelAdmin(TablibAdmin):
    list_display = ['id', 'name']
    formats = ['xls', 'csv']
    headers = list_display

    def name(self, obj):
        return "{0} {1}".format(obj.first_name, obj.last_name)

The fields could be rendered similarly to the way the change list fields are rendered.

tablib.ext namepace

This isn't an issue, but a discussion. If there's a better place to do this, let me know.

I'm hoping to add the tablib.ext (or tablibext) namespace to Tablib soon, where new modules (tablib-modname) can install themselves and extend the functionality of Tablib.

Since you are the only extension at this time, I'd like to get your feedback on a few things.

  1. Would you move your module to the new namespace?

    Here's what I had in mind;

    from tablibext.django import ModelDataset
    from tablibext.django.admin import TablibAdmin
    
  2. Are there any features that you think would be useful?

    I plan on adding a way for extensions to add new available formats to Dataset, as well as new methods. Are there other features/abilities that you would find useful?

I really appreciate the feedback.

Error importing admin in 3.0.1

In 3.0.1 when you

from django_tablib.views import export

you get this error:

Exception Type:     ImportError
Exception Value:    

No module named admin

Exception Location:     /home/wrnpro/virtualenv/local/lib/python2.7/site-packages/django_tablib/__init__.py in <module>, line 3

This was not the case in 3.0.0

does django-tablib works in django1.6?

I use the source django-tablib 3.0.2.tar.gz
and then
python setup.py install
It show an error
SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/django_tablib/models.py', 80, 41, ' self.fields = {field: Field() for field in included}\n'))

DateTimeFields come back in UTC

It looks like when USE_TZ is true the time zone conversions are not applied to excel export. I am using the generic export view. Am I missing something?

Set .title base on model name

Perhaps you could set the title to the model name. That way when people use multiple sheets in a databook the sheet names are something sensible.

cheers, Oliver

business_data = SimpleDataset(Business.objects.all(), headers=None)
discount_data = SimpleDataset(Discount.objects.all(), headers=None)

business_data.title = "Businesses"
discount_data.title = "Discounts"

book = tablib.Databook((business_data, discount_data))

Updates Django when installing with pip

I have an old project which uses Django 1.4 and won't work with 1.5. If I add django-tablib to the project using pip install django-tablib, it automatically updates Django to version 1.5.1.

date format on export with TablibAdmin

Hi, I'm using TablibAdmin to export from the django admin (on google app engine with django-nonrel if that matters) and a user is complaining that they need the dates in "ISO" CCYY-MM-DD format rather than US "MM/DD/CCYY". I'm not sure if this is a tablib issue or a django issue or a django-tablib issue. Can you give me any hints on how to make this change?

Extra fields not exported

If you add extra fields to a queryset using .extra(select={'foo': '...'}), these are not exported if you send the queryset to django-tablib. It looks like tablib does not 'see' the extra fiedls, only the model fields.

UnicodeDecodeError

Hello @joshourisman . Thx for django-tablib :).

I'm getting an UnicodeDecodeError when generating HTML table. I have hacked a bit and here is what I found.

On https://github.com/joshourisman/django-tablib/blob/master/django_tablib/views.py#L20 when using hasattr you hide any exception that can happen in rendering of table, if you change to getattr this exceptions raise to developer. It's better to know where the problem of getting a 404 is :]. However, isn't better just keep a suported formats list or is intentional to render at this time?

After I have changed that line to use getattr I finally saw that at https://github.com/joshourisman/django-tablib/blob/master/django_tablib/base.py#L40 the BaseDaaset()._cleanval(value, str) encode the value in 'utf-8'. This is working for XLS an CSV tables, but not for HTML. I have checked that this value is unicode when enter in _cleanval method.

The data that is giving me headcache for you use in tests is:

Rua Maracá
Ap 4231

I'm sure that you can test with any accentuated character :).

[]'s

Changes to support Django 1.4 changes to ChangeList

Django 1.4 changes ChangeList to accept self.admin_site as a parameter. Also, 1.4 has ChangeList.get_query_set() take in request.

Simple code fix to support versioning.

IMPORT DJANGO:

import django

CHANGE get_tablib_queryset() AS FOLLOWS:

def get_tablib_queryset(self, request):
    if django.VERSION >= (1, 4):
        cl = ChangeList(request,
            self.model,
            self.list_display,
            self.list_display_links,
            self.list_filter,
            self.date_hierarchy,
            self.search_fields,
            self.list_select_related,
            self.list_per_page,
            self.list_editable,
            self.admin_site,
            self,
        )
        return cl.get_query_set(request)
    else:
        cl = ChangeList(request,
            self.model,
            self.list_display,
            self.list_display_links,
            self.list_filter,
            self.date_hierarchy,
            self.search_fields,
            self.list_select_related,
            self.list_per_page,
            self.list_editable,
            self,
        )
        return cl.get_query_set()

Add support for grappelli

The export buttons for django_tablib.admin.TablibAdmin are not rendered nicely when using django-tablib in combination with django-grappelli.

It would be possible to add some css classes to change_list.html in order to make this work.

The only issue I see here is being able to check if grappelli is installed , else the classes should not be defined.

Any thoughts on this ?

admin actions integration

hello,

Great app ;). Here is a snippet to integrate tab export inside admin actions, so that you can use django admin filters, and get an export only for instances in change list which are selected.

from django.http import Http404, HttpResponse, HttpResponseBadRequest
from django_tablib.datasets import SimpleDataset
from django_tablib.base import mimetype_map

def xls_export(modeladmin, request, queryset):
    dataset = SimpleDataset(queryset, headers=None)
    filename = 'export.xls'
    response = HttpResponse(
        getattr(dataset, 'xls'),
        mimetype=mimetype_map.get('xls', 'application/octet-stream')
        )
    response['Content-Disposition'] = 'attachment; filename=%s' % filename
    return response
xls_export.short_description = "Excel export"

and just add xls_export to the actions list in your ModelAdmin.

It seems to me

  • easier than using TablibAdmin (I have allready custom buttons, so that I would have to override change_list)
  • more efficient as you can pre-filter your export
  • more user friendly

Thx

Non-standard path for change_list.html

In TablibAdmin you've got:
change_list_template = 'tablib/change_list.html'

Shouldn't this default to (at least until this becomes a tablib extension)?:
change_list_template = 'django_tablib/change_list.html'

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.