Code Monkey home page Code Monkey logo

django-excel's Introduction

django-excel - Let you focus on data, instead of file formats

image

image

image

image

image

image

image

image

image

image

Support the project

If your company has embedded pyexcel and its components into a revenue generating product, please support me on github, patreon or bounty source to maintain the project and develop it further.

If you are an individual, you are welcome to support me too and for however long you feel like. As my backer, you will receive early access to pyexcel related contents.

And your issues will get prioritized if you would like to become my patreon as pyexcel pro user.

With your financial support, I will be able to invest a little bit more time in coding, documentation and writing interesting posts.

Known constraints

Fonts, colors and charts are not supported.

Nor to read password protected xls, xlsx and ods files.

Introduction

Here is a typical conversation between the developer and the user:

User: "I have uploaded an excel file"
      "but your application says un-supported file format"
Developer: "Did you upload an xlsx file or a csv file?"
User: "Well, I am not sure. I saved the data using "
      "Microsoft Excel. Surely, it must be in an excel format."
Developer: "OK. Here is the thing. I were not told to support"
           "all available excel formats in day 1. Live with it"
           "or delay the project x number of days."

django-excel is based on pyexcel and makes it easy to consume/produce information stored in excel files over HTTP protocol as well as on file system. This library can turn the excel data into a list of lists, a list of records(dictionaries), dictionaries of lists. And vice versa. Hence it lets you focus on data in Django based web development, instead of file formats.

The idea originated from the common usability problem: when an excel file driven web application is delivered for non-developer users (ie: team assistant, human resource administrator etc). The fact is that not everyone knows (or cares) about the differences between various excel formats: csv, xls, xlsx are all the same to them. Instead of training those users about file formats, this library helps web developers to handle most of the excel file formats by providing a common programming interface. To add a specific excel file format type to you application, all you need is to install an extra pyexcel plugin. Hence no code changes to your application and no issues with excel file formats any more. Looking at the community, this library and its associated ones try to become a small and easy to install alternative to Pandas.

The highlighted features are:

  1. excel data import into and export from databases
  2. turn uploaded excel file directly into Python data structure
  3. pass Python data structures as an excel file download
  4. provide data persistence as an excel file in server side
  5. supports csv, tsv, csvz, tsvz by default and other formats are supported via the following plugins:
A list of file formats supported by external plugins
Package name Supported file formats Dependencies

pyexcel-io

csv, csvz1, tsv, tsvz2

pyexcel-xls

xls, xlsx(read only), xlsm(read only)

xlrd, xlwt

pyexcel-xlsx xlsx openpyxl

pyexcel-ods3

ods

pyexcel-ezodf, lxml

pyexcel-ods ods odfpy
Dedicated file reader and writers
Package name Supported file formats Dependencies
pyexcel-xlsxw xlsx(write only) XlsxWriter
pyexcel-libxlsxw xlsx(write only) libxlsxwriter
pyexcel-xlsxr xlsx(read only) lxml
pyexcel-xlsbr xlsb(read only) pyxlsb
pyexcel-odsr read only for ods, fods lxml
pyexcel-odsw write only for ods loxun
pyexcel-htmlr html(read only) lxml,html5lib
pyexcel-pdfr pdf(read only) camelot

Plugin shopping guide

Since 2020, all pyexcel-io plugins have dropped the support for python version lower than 3.6. If you want to use any python verions, please use pyexcel-io and its plugins version lower than 0.6.0.

Except csv files, xls, xlsx and ods files are a zip of a folder containing a lot of xml files

The dedicated readers for excel files can stream read

In order to manage the list of plugins installed, you need to use pip to add or remove a plugin. When you use virtualenv, you can have different plugins per virtual environment. In the situation where you have multiple plugins that does the same thing in your environment, you need to tell pyexcel which plugin to use per function call. For example, pyexcel-ods and pyexcel-odsr, and you want to get_array to use pyexcel-odsr. You need to append get_array(..., library='pyexcel-odsr').

Other data renderers
Package name Supported file formats Dependencies Python versions

pyexcel-text

write only:rst, mediawiki, html, latex, grid, pipe, orgtbl, plain simple read only: ndjson r/w: json

tabulate

2.6, 2.7, 3.3, 3.4 3.5, 3.6, pypy

pyexcel-handsontable handsontable in html handsontable same as above

pyexcel-pygal

svg chart

pygal

2.7, 3.3, 3.4, 3.5 3.6, pypy

pyexcel-sortable sortable table in html csvtotable same as above

pyexcel-gantt

gantt chart in html

frappe-gantt

except pypy, same as above

Footnotes

This library makes information processing involving various excel files as easy as processing array, dictionary when processing file upload/download, data import into and export from SQL databases, information analysis and persistence. It uses pyexcel and its plugins:

  1. to provide one uniform programming interface to handle csv, tsv, xls, xlsx, xlsm and ods formats.
  2. to provide one-stop utility to import the data in uploaded file into a database and to export tables in a database as excel files for file download.
  3. to provide the same interface for information persistence at server side: saving a uploaded excel file to and loading a saved excel file from file system.

Tested Django Versions

image

image

image

image

image

image

image

Installation

You can install django-excel via pip:

$ pip install django-excel

or clone it and install it:

$ git clone https://github.com/pyexcel-webwares/django-excel.git
$ cd django-excel
$ python setup.py install

Setup

You will need to update your settings.py:

FILE_UPLOAD_HANDLERS = ("django_excel.ExcelMemoryFileUploadHandler",
                        "django_excel.TemporaryExcelFileUploadHandler")

Usage

Here is the example viewing function codes:

from django.shortcuts import render_to_response
from django.http import HttpResponseBadRequest
from django import forms
from django.template import RequestContext
import django_excel as excel

class UploadFileForm(forms.Form):
    file = forms.FileField()

def upload(request):
    if request.method == "POST":
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            filehandle = request.FILES['file']
            return excel.make_response(filehandle.get_sheet(), "csv")
        else:
            return HttpResponseBadRequest()
    else:
        form = UploadFileForm()
    return render_to_response('upload_form.html',
                              {'form': form},
                              context_instance=RequestContext(request))

def download(request):
    sheet = excel.pe.Sheet([[1, 2],[3, 4]])
    return excel.make_response(sheet, "csv")

Development guide

Development steps for code changes

  1. git clone https://github.com/pyexcel/django-excel.git
  2. cd django-excel

Upgrade your setup tools and pip. They are needed for development and testing only:

  1. pip install --upgrade setuptools pip

Then install relevant development requirements:

  1. pip install -r rnd_requirements.txt # if such a file exists
  2. pip install -r requirements.txt
  3. pip install -r tests/requirements.txt

Once you have finished your changes, please provide test case(s), relevant documentation and update CHANGELOG.rst.

Note

As to rnd_requirements.txt, usually, it is created when a dependent library is not released. Once the dependecy is installed (will be released), the future version of the dependency in the requirements.txt will be valid.

How to test your contribution

Although nose and doctest are both used in code testing, it is adviable that unit tests are put in tests. doctest is incorporated only to make sure the code examples in documentation remain valid across different development releases.

On Linux/Unix systems, please launch your tests like this:

$ make

On Windows systems, please issue this command:

> test.bat

Before you commit

Please run:

$ make format

so as to beautify your code otherwise travis-ci may fail your unit test.

License

New BSD License


  1. zipped csv file

  2. zipped tsv file

django-excel's People

Contributors

chfw avatar minhlongdo avatar oonid avatar thebrahma 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  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

django-excel's Issues

Filename extension issue

In the following code :

class ExcelMixin(webio.ExcelInput):
     def _get_file_extension(self):
        extension = self.name.split(".")[1]
        return extension

you are considering that the filename will have only one dot. This is not always the case and I would recommend you take the last ( [-1] ) and not the second ( [1] ) element.
Otherwise for a file named tutu.12.xlsx, this will fail with error

NotImplementedError at /import/
Cannot read content of file type 12 from stream

This is very simple to correct and shouldn't lead to any side effect.

urls.py cannot work after fresh install, then Page not found after hot-fix

Environment: Windows10, Python 3.6, Django 2.0.6

// logs with command: manage.py runserver
'''
Performing system checks...

Unhandled exception in thread started by <function check_errors..wrapper at 0x03BED7C8>
Traceback (most recent call last):
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\urls\conf.py", line 17, in include
urlconf_module, app_name = arg
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\core\management\base.py", line 364, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\core\management\base.py", line 351, in run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\core\checks\registry.py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\urls\resolvers.py", line 399, in check
for pattern in self.url_patterns:
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\utils\functional.py", line 36, in get
res = instance.dict[self.name] = self.func(instance)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\urls\resolvers.py", line 540, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\utils\functional.py", line 36, in get
res = instance.dict[self.name] = self.func(instance)
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\urls\resolvers.py", line 533, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Program Files (x86)\Python36-32\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "D:\github\django-excel\mysite\urls.py", line 6, in
url(r'^admin/', include(admin.site.urls), name='admin'),
File "C:\Users\Jim Fang\AppData\Roaming\Python\Python36\site-packages\django\urls\conf.py", line 27, in include
'provide the namespace argument to include() instead.' % len(arg)
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.
'''

Blank xls file output

My outputted xls files are all empty/blank, i.e. 0 kB. No indicator as to why this might be happening. I followed the sample code:

def export_data(request, atype):
if atype == "sheet":
return excel.make_response_from_a_table(City, 'xls', file_name="cities")

Lots of cities in the db. Running Django 1.9.4, django-excel 0.0.6 and pyexcel 0.4.3. How can I debut this issue?

Unable to make response from array in Django 1.9

Versions

Django 1.9
Django-excel version 0.0.5

What I did

I tried the make_response_from_array(rows, "xls") where rows is a list of list

What I expected

To simply work

What I got

OSError about no file name and no content

Question: how to change file name and sheet name?

hello, I'm giving a try to the library but I can't find any hint on how to change

  1. the response filename (in chrome the file is named download with no extension)
  2. the sheet name (it's pyexcel_sheet1)

how can I customize these two aspects?
thanks in advance!


here is my view's code:

def exportExcel(request):
    qs = MyModel.objects.all()
    column_names = ['a', 'b']
    sheet = excel.pe.get_sheet(query_sets=qs, column_names=column_names)
    sheet.row[0] = ["a", "b"]
    return excel.make_response(sheet, 'xls')

Docs: From forms.FileField() to ExcelInMemoryUploadedFile ?

I do not understand this:

UploadFileForm is html widget for file upload form in the html page. Then look down at filehandle. It is an instance of either ExcelInMemoryUploadedFile

Source: http://django-excel.readthedocs.io/en/latest/

You use an ordinary forms.FileField(). I guess the matching config in settings.py is needed.

Please make this part more newbee friendly.

What could be added here?

UploadFileForm is html widget for file upload form in the html page. *** here ** Then look down at filehandle. It is an instance of either ExcelInMemoryUploadedFile

Use verbose name

Is ther anyway to use verbose name in Django model instead of field names when customizing export file's column_names?

Depreciated usage. please use dest_file_name

I've an issue (I receive "Depreciated usage. please use dest_file_name" warning) that seems related to some comments in https://github.com/chfw/django-excel/issues/1. It should not be generated by code:

import django_excel as excel
import pyexcel.ext.xls
from .models import MyModel

qs = MyModel.objects.all()
column_names = ['field1', 'field2']
sheet = excel.pe.get_sheet(query_sets=qs, column_names=column_names)
sheet.row[0] = ["field1", "field2"]
sheet.name = 'test'
response = excel.make_response(sheet, 'xls', 200)
response['Content-Disposition'] = 'attachment;      
filename="export_test_{:%d_%m_%Y}.xls"'.format(datetime.datetime.now())

and this is my pip freeze (the relevant parts of it, more precisely):

Django==1.8.4
django-excel==0.0.2
future==0.15.2
openpyxl==2.2.6
pyexcel==0.1.7
pyexcel-io==0.0.6
pyexcel-webio==0.0.3
pyexcel-xls==0.0.7
pyexcel-xlsx==0.0.6
pytz==2015.4
six==1.9.0
Unidecode==0.4.18
virtualenv==13.0.3
xlrd==0.9.4
xlwt==1.0.0
xlwt-future==0.8.0

not a big deal but I'd like to solve it before it becomes an error :)

If changing initializer row number, it will report error

In the initializer, if change the row index that has the field names, let's say the default is "0", if changed to "1" or "2" which means in Excel, the field row is not the first row anymore. It will report errors like C:\Python27\lib\site-packages\pyexcel_io\djangobook.py" in __init__for name in self.column_names]
Exception Value: ''

Export issue

For the given polls app, url"polls/downland/csv" export nothing, neither for any other format

It seems that in make_response function the pos attribute of file_content is not set back to 0, which make each response return nothing

Update/Skipping row during data import into database

Currently, it was only possible to import data into an empty database or partial database. However, it is more often that the database is the case and hence developer needs a bit extra logic to cope with existing data: 1) update existing items 2) skipping them. Let's give the choice to the developer.

This feature was mentioned in the following conversation:

#12

'TUPLE' OBJECT IS NOT CALLABLE

Hi,

I've just changed an upgraded my environments to a new computer (including getting the latest of all packages I have). For a reason I cannot figure out, the uploading module of my application fails @ the below function. From what I know of this error it's usually linked to a comma, but here it might have to do with the code inside the package? I have to say that I am stuck. Every bit of help appreciated.
Thank you!

Jo

FUNCTION:

def import_data_pos(request):
    if request.method == "POST":
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            request.FILES['file'].save_book_to_database(models=[(Sales, ['sale', 'product_id', 'store_id', 'sale_date'], None, 0)])
            return HttpResponse("OK", status=200)
        else:
            return HttpResponseBadRequest()
    else:
        form = UploadFileForm()
    return render_to_response('upload_pos.html', {'form': form, 'title': 'Import excel data into database example', 'header': 'Please upload sample-data.xls:'},context_instance=RequestContext(request))

ERROR OUTPUT:

TYPEERROR AT /UPLOAD/POS 'TUPLE' OBJECT IS NOT CALLABLE 
REQUEST METHOD: POST 
REQUEST URL: HTTP://127.0.0.1:8000/UPLOAD/POS 
DJANGO VERSION: 1.7.9 
PYTHON EXECUTABLE: /USR/BIN/PYTHON PYTHON VERSION: 2.7.10 
PYTHON PATH: ['/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS', 
'/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PIP-7.1.0-PY2.7.EGG', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON27.ZIP', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7/PLAT-DARWIN', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7/PLAT-MAC', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7/PLAT-MAC/LIB-SCRIPTPACKAGES', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/EXTRAS/LIB/PYTHON',
 '/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7/LIB-TK', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7/LIB-OLD', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/LIB/PYTHON2.7/LIB-DYNLOAD', 
'/SYSTEM/LIBRARY/FRAMEWORKS/PYTHON.FRAMEWORK/VERSIONS/2.7/EXTRAS/LIB/PYTHON/PYOBJC', '/LIBRARY/PYTHON/2.7/SITE-PACKAGES'] 
SERVER TIME: MON, 24 AUG 2015 00:21:14 +0000 
INSTALLED APPLICATIONS: ('DJANGO.CONTRIB.ADMIN', 'DJANGO.CONTRIB.AUTH', 'DJANGO.CONTRIB.CONTENTTYPES', 'DJANGO.CONTRIB.SESSIONS', 'DJANGO.CONTRIB.MESSAGES', 'DJANGO.CONTRIB.STATICFILES', 'DJANGO.CONTRIB.HUMANIZE', 'STORES', 'USERS', 'CALENDAR', 'EASY_THUMBNAILS', 'GEOPY') 
INSTALLED MIDDLEWARE: ('DJANGO.CONTRIB.SESSIONS.MIDDLEWARE.SESSIONMIDDLEWARE', 'DJANGO.MIDDLEWARE.COMMON.COMMONMIDDLEWARE', 'DJANGO.MIDDLEWARE.CSRF.CSRFVIEWMIDDLEWARE', 'DJANGO.CONTRIB.AUTH.MIDDLEWARE.AUTHENTICATIONMIDDLEWARE', 'DJANGO.CONTRIB.AUTH.MIDDLEWARE.SESSIONAUTHENTICATIONMIDDLEWARE', 'DJANGO.CONTRIB.MESSAGES.MIDDLEWARE.MESSAGEMIDDLEWARE', 'DJANGO.MIDDLEWARE.CLICKJACKING.XFRAMEOPTIONSMIDDLEWARE') 
TRACEBACK: FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/DJANGO/CORE/HANDLERS/BASE.PY" IN GET_RESPONSE 
111. RESPONSE = WRAPPED_CALLBACK(REQUEST, *CALLBACK_ARGS, **CALLBACK_KWARGS) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/DJANGO/CONTRIB/AUTH/DECORATORS.PY" IN _WRAPPED_VIEW 
21. RETURN VIEW_FUNC(REQUEST, *ARGS, **KWARGS) FILE "/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS/STORES/VIEWS.PY" IN IMPORT_DATA_POS 
473. REQUEST.FILES['FILE'].SAVE_BOOK_TO_DATABASE(MODELS=[(SALES, ['SALE', 'PRODUCT_ID', 'STORE_ID', 'SALE_DATE'], NONE, 0)]) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/DJANGO_EXCEL/__INIT__.PY" IN SAVE_BOOK_TO_DATABASE 
41. BOOK.SAVE_TO_DJANGO_MODELS(MODELS, **KEYWORDS) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL/BOOK.PY" IN SAVE_TO_DJANGO_MODELS 
209. SELF.SAVE_TO(OUT_SOURCE) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL/BOOK.PY" IN SAVE_TO 
178. SOURCE.WRITE_DATA(SELF) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL/SOURCES/DATABASE.PY" IN WRITE_DATA 
185. W.WRITE_BOOK_READER_TO_DB(BOOK) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL/WRITERS.PY" IN WRITE_BOOK_READER_TO_DB 
171. SELF.WRITER.WRITE(THE_DICT) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL_IO/BASE.PY" IN WRITE 
258. SHEET.WRITE_ARRAY(SHEET_DICTS[NAME]) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL_IO/BASE.PY" IN WRITE_ARRAY 
222. SELF.WRITE_ROW(R) FILE "/LIBRARY/PYTHON/2.7/SITE-PACKAGES/PYEXCEL_IO/DJANGOBOOK.PY" IN WRITE_ROW 
87. ZIP(SELF.COLUMN_NAMES, SELF.INITIALIZER(NEW_ARRAY)) EXCEPTION TYPE: TYPEERROR AT /UPLOAD/POS EXCEPTION VALUE: 'TUPLE' OBJECT IS NOT CALLABLE 
REQUEST INFORMATION: GET: NO GET DATA POST: CSRFMIDDLEWARETOKEN = U'EDXAVDGPGODYAGO9RP4WALZOVSQFG841' 
FILES: FILE = <EXCELINMEMORYUPLOADEDFILE: UPLOAD - 2015 7.XLSX (APPLICATION/VND.OPENXMLFORMATS-OFFICEDOCUMENT.SPREADSHEETML.SHEET)> 
COOKIES: CSRFTOKEN = 'EDXAVDGPGODYAGO9RP4WALZOVSQFG841' SESSIONID = 'YHER3T87T2N9XLWQTBLD5UL40IDMQGIN' META: WSGI.MULTIPROCESS = FALSE RUN_MAIN = 'TRUE' HTTP_REFERER = 'HTTP://127.0.0.1:8000/UPLOAD/POS' VERSIONER_PYTHON_PREFER_32_BIT = 'NO' SERVER_SOFTWARE = 'WSGISERVER/0.1 PYTHON/2.7.10' TERM_PROGRAM_VERSION = '343.7' REQUEST_METHOD = 'POST' LOGNAME = 'JOSEPHSARTRE' USER = 'JOSEPHSARTRE' HTTP_ORIGIN = 'HTTP://127.0.0.1:8000' PATH = '/USERS/JOSEPHSARTRE/TMP/BIN:/LIBRARY/POSTGRESQL/9.4/BIN:/USR/LOCAL/BIN:/USR/BIN:/BIN:/USR/SBIN:/SBIN' QUERY_STRING = '' HOME = '/USERS/JOSEPHSARTRE' PS1 = '(TMP)\\H:\\W \\U\\$ ' TERM_PROGRAM = 'APPLE_TERMINAL' LANG = 'EN_US.UTF-8' VIRTUAL_ENV = '/USERS/JOSEPHSARTRE/TMP' SHELL = '/BIN/BASH' TZ = 'UTC' HTTP_COOKIE = 'SESSIONID=YHER3T87T2N9XLWQTBLD5UL40IDMQGIN; CSRFTOKEN=EDXAVDGPGODYAGO9RP4WALZOVSQFG841' SERVER_NAME = '1.0.0.127.IN-ADDR.ARPA' VERSIONER_PYTHON_VERSION = '2.7' SHLVL = '1' XPC_FLAGS = '0X0' WSGI.URL_SCHEME = 'HTTP' _ = '/USR/BIN/PYTHON' SERVER_PORT = '8000' CONTENT_LENGTH = '15919' TERM_SESSION_ID = '49019DDC-B0BC-4FD0-9A97-9C94AD82D0FB' SSH_AUTH_SOCK = '/PRIVATE/TMP/COM.APPLE.LAUNCHD.TKIJ05EY4R/LISTENERS' HTTP_X_REQUESTED_WITH = 'XMLHTTPREQUEST' XPC_SERVICE_NAME = '0' TERM = 'XTERM-256COLOR' WSGI.INPUT = <SOCKET._FILEOBJECT OBJECT AT 0X108168E50> APPLE_PUBSUB_SOCKET_RENDER = '/PRIVATE/TMP/COM.APPLE.LAUNCHD.ZKJIGVD3VD/RENDER' HTTP_HOST = '127.0.0.1:8000' SCRIPT_NAME = U'' WSGI.MULTITHREAD = TRUE HTTP_CONNECTION = 'CLOSE' HTTP_CACHE_CONTROL = 'NO-CACHE' TMPDIR = '/VAR/FOLDERS/XQ/W33S_YFX3291N7X9JW3MCQCW0000GN/T/' HTTP_ACCEPT = 'APPLICATION/JSON' WSGI.VERSION = HTTP_USER_AGENT = 'MOZILLA/5.0 (MACINTOSH; INTEL MAC OS X 10_10_5) APPLEWEBKIT/537.36 (KHTML, LIKE GECKO) CHROME/44.0.2403.157 SAFARI/537.36' GATEWAY_INTERFACE = 'CGI/1.1' WSGI.RUN_ONCE = FALSE CSRF_COOKIE = U'EDXAVDGPGODYAGO9RP4WALZOVSQFG841' WSGI.ERRORS = <OPEN FILE '<STDERR>', MODE 'W' AT 0X105DE81E0> REMOTE_ADDR = '127.0.0.1' HTTP_ACCEPT_LANGUAGE = 'EN-US,EN;Q=0.8,FR;Q=0.6' __CF_USER_TEXT_ENCODING = '0X1F5:0X0:0X0' PWD = '/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS' SERVER_PROTOCOL = 'HTTP/1.0' DJANGO_SETTINGS_MODULE = 'STRIKERS.SETTINGS' CONTENT_TYPE = 'MULTIPART/FORM-DATA; BOUNDARY=----WEBKITFORMBOUNDARYPJQ0AFYSBL4UJ3SW' WSGI.FILE_WRAPPER = '' REMOTE_HOST = '' HTTP_ACCEPT_ENCODING = 'GZIP, DEFLATE' PATH_INFO = U'/UPLOAD/POS' SETTINGS: USING SETTINGS MODULE STRIKERS.SETTINGS USE_L10N = TRUE USE_THOUSAND_SEPARATOR = FALSE CSRF_COOKIE_SECURE = FALSE LANGUAGE_CODE = 'EN-US' ROOT_URLCONF = 'STRIKERS.URLS' MANAGERS = BASE_DIR = '/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS' TEST_NON_SERIALIZED_APPS = [] DEFAULT_CHARSET = 'UTF-8' SESSION_SERIALIZER = 'DJANGO.CONTRIB.SESSIONS.SERIALIZERS.JSONSERIALIZER' STATIC_ROOT = '/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS/STATIC_FILES' ALLOWED_HOSTS = ['*'] MESSAGE_STORAGE = 'DJANGO.CONTRIB.MESSAGES.STORAGE.FALLBACK.FALLBACKSTORAGE' EMAIL_SUBJECT_PREFIX = '[DJANGO] ' SEND_BROKEN_LINK_EMAILS = FALSE STATICFILES_FINDERS = SESSION_CACHE_ALIAS = 'DEFAULT' SESSION_COOKIE_DOMAIN = NONE SESSION_COOKIE_NAME = 'SESSIONID' THUMBNAIL_ALIASES = {'': {'AVATAR': {'CROP': TRUE, 'SIZE': (50, 50)}, 'ICON': {'CROP': TRUE, 'SIZE': (25, 25)}}} ADMIN_FOR = TIME_INPUT_FORMATS = DATABASES = {'DEFAULT': {'ENGINE': 'DJANGO.DB.BACKENDS.SQLITE3', 'AUTOCOMMIT': TRUE, 'ATOMIC_REQUESTS': FALSE, 'NAME': '/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS/DB.SQLITE3', 'CONN_MAX_AGE': 0, 'TIME_ZONE': 'UTC', 'OPTIONS': {}, 'HOST': '', 'USER': '', 'TEST': {'COLLATION': NONE, 'CHARSET': NONE, 'NAME': NONE, 'MIRROR': NONE}, 'PASSWORD': U'********************', 'PORT': ''}} FILE_UPLOAD_DIRECTORY_PERMISSIONS = NONE FILE_UPLOAD_PERMISSIONS = NONE FILE_UPLOAD_HANDLERS = DEFAULT_CONTENT_TYPE = 'TEXT/HTML' APPEND_SLASH = TRUE LOCALE_PATHS = '/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS/LOCALE' DATABASE_ROUTERS = [] DEFAULT_TABLESPACE = '' YEAR_MONTH_FORMAT = 'F Y' STATICFILES_STORAGE = 'DJANGO.CONTRIB.STATICFILES.STORAGE.STATICFILESSTORAGE' CACHES = {'DEFAULT': {'BACKEND': 'DJANGO.CORE.CACHE.BACKENDS.LOCMEM.LOCMEMCACHE'}} SERVER_EMAIL = 'ROOT@LOCALHOST' SESSION_COOKIE_PATH = '/' SILENCED_SYSTEM_CHECKS = [] MIDDLEWARE_CLASSES = USE_I18N = TRUE THOUSAND_SEPARATOR = ',' SECRET_KEY = U'********************' LANGUAGE_COOKIE_NAME = 'DJANGO_LANGUAGE' DEFAULT_INDEX_TABLESPACE = '' TRANSACTIONS_MANAGED = FALSE LOGGING_CONFIG = 'LOGGING.CONFIG.DICTCONFIG' TEMPLATE_LOADERS = FIRST_DAY_OF_WEEK = 0 WSGI_APPLICATION = 'STRIKERS.WSGI.APPLICATION' TEMPLATE_DEBUG = TRUE X_FRAME_OPTIONS = 'SAMEORIGIN' CSRF_COOKIE_NAME = 'CSRFTOKEN' FORCE_SCRIPT_NAME = NONE USE_X_FORWARDED_HOST = FALSE SIGNING_BACKEND = 'DJANGO.CORE.SIGNING.TIMESTAMPSIGNER' SESSION_COOKIE_SECURE = FALSE CSRF_COOKIE_DOMAIN = NONE FILE_CHARSET = 'UTF-8' DEBUG = TRUE LANGUAGE_COOKIE_DOMAIN = NONE DEFAULT_FILE_STORAGE = 'DJANGO.CORE.FILES.STORAGE.FILESYSTEMSTORAGE' INSTALLED_APPS = LANGUAGES = COMMENTS_ALLOW_PROFANITIES = FALSE STATICFILES_DIRS = 'STATIC' PREPEND_WWW = FALSE SECURE_PROXY_SSL_HEADER = NONE LANGUAGE_COOKIE_AGE = NONE SESSION_COOKIE_HTTPONLY = TRUE DEBUG_PROPAGATE_EXCEPTIONS = FALSE INTERNAL_IPS = MONTH_DAY_FORMAT = 'F J' LOGIN_URL = '/LOGIN/' SESSION_EXPIRE_AT_BROWSER_CLOSE = FALSE TIME_FORMAT = 'P' AUTH_USER_MODEL = 'AUTH.USER' DATE_INPUT_FORMATS = AUTHENTICATION_BACKENDS = 'DJANGO.CONTRIB.AUTH.BACKENDS.MODELBACKEND' EMAIL_HOST_PASSWORD = U'********************' PASSWORD_RESET_TIMEOUT_DAYS = U'********************' SESSION_FILE_PATH = NONE CACHE_MIDDLEWARE_ALIAS = 'DEFAULT' SESSION_SAVE_EVERY_REQUEST = FALSE NUMBER_GROUPING = 0 SESSION_ENGINE = 'DJANGO.CONTRIB.SESSIONS.BACKENDS.DB' CSRF_FAILURE_VIEW = 'DJANGO.VIEWS.CSRF.CSRF_FAILURE' CSRF_COOKIE_PATH = '/' LOGIN_REDIRECT_URL = '/ACCOUNTS/PROFILE/' DECIMAL_SEPARATOR = '.' IGNORABLE_404_URLS = MIGRATION_MODULES = {} TEMPLATE_STRING_IF_INVALID = '' LOGOUT_URL = '/ACCOUNTS/LOGOUT/' EMAIL_USE_TLS = FALSE FIXTURE_DIRS = EMAIL_HOST = 'LOCALHOST' DATE_FORMAT = 'N J, Y' MEDIA_ROOT = '/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS/MEDIA' DEFAULT_EXCEPTION_REPORTER_FILTER = 'DJANGO.VIEWS.DEBUG.SAFEEXCEPTIONREPORTERFILTER' ADMINS = FORMAT_MODULE_PATH = NONE DEFAULT_FROM_EMAIL = 'WEBMASTER@LOCALHOST' MEDIA_URL = '/MEDIA/' DATETIME_FORMAT = 'N J, Y, P' TEMPLATE_DIRS = DISALLOWED_USER_AGENTS = ALLOWED_INCLUDE_ROOTS = LOGGING = {} SHORT_DATE_FORMAT = 'M/D/Y' TEMPLATES = [{'DIRS': ['/USERS/JOSEPHSARTRE/DOCUMENTS/SITES/KAM/PRODUCTION/150802STRIKERS/TEMPLATES'], 'APP_DIRS': TRUE, 'OPTIONS': {'CONTEXT_PROCESSORS': ['DJANGO.CONTRIB.AUTH.CONTEXT_PROCESSORS.AUTH', 'DJANGO.TEMPLATE.CONTEXT_PROCESSORS.DEBUG', 'DJANGO.TEMPLATE.CONTEXT_PROCESSORS.I18N', 'DJANGO.TEMPLATE.CONTEXT_PROCESSORS.MEDIA', 'DJANGO.TEMPLATE.CONTEXT_PROCESSORS.STATIC', 'DJANGO.TEMPLATE.CONTEXT_PROCESSORS.TZ', 'DJANGO.CONTRIB.MESSAGES.CONTEXT_PROCESSORS.MESSAGES']}, 'BACKEND': 'DJANGO.TEMPLATE.BACKENDS.DJANGO.DJANGOTEMPLATES'}] TEST_RUNNER = 'DJANGO.TEST.RUNNER.DISCOVERRUNNER' CACHE_MIDDLEWARE_KEY_PREFIX = U'********************' TIME_ZONE = 'UTC' FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440 EMAIL_BACKEND = 'DJANGO.CORE.MAIL.BACKENDS.SMTP.EMAILBACKEND' EMAIL_USE_SSL = FALSE TEMPLATE_CONTEXT_PROCESSORS = SESSION_COOKIE_AGE = 1209600 SETTINGS_MODULE = 'STRIKERS.SETTINGS' USE_ETAGS = FALSE LANGUAGES_BIDI = FILE_UPLOAD_TEMP_DIR = NONE CSRF_COOKIE_AGE = 31449600 STATIC_URL = '/STATIC/' EMAIL_PORT = 25 USE_TZ = TRUE SHORT_DATETIME_FORMAT = 'M/D/Y P' PASSWORD_HASHERS = U'********************' ABSOLUTE_URL_OVERRIDES = {} LANGUAGE_COOKIE_PATH = '/' CACHE_MIDDLEWARE_SECONDS = 600 CSRF_COOKIE_HTTPONLY = FALSE DATETIME_INPUT_FORMATS = EMAIL_HOST_USER = '' PROFANITIES_LIST = U'********************' YOU'RE SEEING THIS ERROR BECAUSE YOU HAVE DEBUG = TRUE IN YOUR DJANGO SETTINGS FILE. CHANGE THAT TO FALSE, AND DJANGO WILL DISPLAY A STANDARD 500 PAGE.

Data is not created in models and no error message shown

Hi I am trying to upload an excel file to update my model however the data is not updated neither any error message displayed.

@login_required
def productbulk(request):
    if request.method == "POST":
        form = productupload(request.POST, request.FILES)
        def choice_func(row):
            q = request.user
            row[0] = q
            return row
        if form.is_valid():
            request.FILES['select_excel_file'].save_book_to_database(
                models=[productmodel],
                initializers=[choice_func],
                mapdicts=[
                    
                    ['user','product_name','uom','description','HSN_code','price','discount_rate','sgst_rate','cgst_rate','igst_rate']]
            )
            return HttpResponseRedirect(reverse('productbulk'),messages.add_message(request, messages.SUCCESS,'Product added Succesfully'))   
    else:
        form = productupload()
    return render(request,'productbulk.html',{'form': form})

get_params method should seek at 0 on the file stream

continuing with #26, explicit seeking at 0 on the file stream could help avoid #37.

def get_params(self, **keywords):
    extension = self.name.split(".")[-1]
    keywords['file_type'] = extension
    self.file.seek(0) # <--
    content = self.file.read()
    if content:
        keywords['file_content'] = content
    else:
        raise IOError("No content was uploaded.")
    return keywords

Create a file in memory (not an uploaded file) and save to FileField default_storage

If I was to create a file-like csv object in memory like so:

output_stream = io.StringIO()
sheet = pyexcel.get_sheet(records=data)
sheet.save_to_memory(file_type='csv', stream=output_stream)

What can I do to save the file like object in output_stream to a file on my default_storage backend with Django?

class Example(models.Model):
    model_file = models.FileField(upload_to='', max_length=255, blank=True, null=True)

I've tried something like:

self.model_file.save(filename, ContentFile(output_stream.read()))

But I get the following error:
"TypeError: ('data must be bytes, received', <class 'str'>)"

Custom Export with Foreignkey

def export_data(request, atype):
....
elif atype == "custom":
question = Question.objects.get(slug='ide')
query_sets = Choice.objects.filter(question=question)
column_names = ['choice_text', 'id', 'votes']
sheet = excel.pe.get_sheet(query_sets=query_sets, column_names=column_names)
sheet.row[0] = ["X", "Y", "Z"] # please put verbose_name list here
return excel.make_response(sheet, 'xls')

while that code works fine, but it failed when I tried to include question it self

def export_data(request, atype):
....
elif atype == "custom":
question = Question.objects.get(slug='ide')
query_sets = Choice.objects.filter(question=question)
column_names = ['question','choice_text', 'votes']
sheet = excel.pe.get_sheet(query_sets=query_sets, column_names=column_names)
sheet.row[0] = ["Question", "Choice", "Votes"] # please put verbose_name list here
return excel.make_response(sheet, 'xls')

would return me Unexpected data type

but if I were to replace column_names to
`
column_names = ['question__question_text','choice_text', 'votes']

`
it would returns me :

'Choice' object has no attribute 'question__question_text'

is there anyway to do this?

thanks!

export xls file type error

  • xls
    make_response(sheet, "xls", file_name=filename)
    OSError: No content, file name. Nothing is given

  • xlsx
    make_response(sheet, "xlsx", file_name=filename)
    Success

Working fine on development but not on production

@chfw Thanks a lot for this wonderful package. It made my day.
However the issue I am facing now is that it works perfectly fine on my local machine (OS-Seira) but when deployed on production server (Ubuntu), it does not work.

Do we need to have MS excel installed on server? As only difference I see is that on my local machine I have installed MS excel.

import_sheet foreign key

get this error if has foreign key in model "Cannot assign "5": "Choice.question" must be a "Question" instance."

custom export with colnames

i want to export foreignkey fieds, and i want to change the header,
so i wrote some code like this:
query_sets = Asset.object.all()
column_names = ['name', 'manager__firstname']
sheet_header = ['name', 'manager']
return excel.make_response_from_query_sets(query_sets, column_names, 'xls', file_name="custom", colnames=sheet_header)

but it comes out two headers( column_names and sheet_header) like this:
|name | manager |
|name | manager__firstname|
|pen | aaa |
....more asset list...

i've found no way to salve this problem without modify django-excel.
what should i do?
thanks .

Question - additional field

Hi everyone,

I still consider myself a newbie on django but i've been trying to toy around with django-excel which is working awesomely so far.

I would like to go a bit further and add a field (charfield) in my form that I would like to insert at the same time as the excel import and that will be the same for all rows.

Any directions you guys could point me to?
Thanks!

Joseph

Import empty rows

Why is it possible to import empty rows?
zrzut ekranu 2015-06-02 o 14 35 52

zrzut ekranu 2015-06-02 o 14 32 30

They should not be skipped?

Question

Hello First of all, I am gratefully using djang-excel, I can not speak English well.

First, can I store only certain columns in the database?

In the code below, I want to store only the test2 column in the database.

<Current code>
<views>

request.FILES['file'].save_book_to_database(
				models=[UserSub],
				initializers=[None],
				mapdicts=[{'test1': 'number', 'test2': 'subject'}],
				keyword=[0]
			)

<models>
class UserSub(models.Model):
    number=models.CharField(max_length=10)
    subject=models.CharField(max_length=15)

    def __str__(self):
        return self.subject

'tuple' object has no attribute '_meta'

Return this error till .xls uploading, here is a code...

def form_valid(self, form):
        self.request.FILES['file'].save_book_to_database(
            models=[
                (Question, ['title', 'answer_1', 'answer_2', 'answer_3', 'answer_4', 'correct'], None, 0)
            ]
        )
        return super(QuestionList, self).form_valid(form)

Anybody, help!

Insert tuple value for ModelFields with choices set

I have a modelField, a.k. an IntergerField(choices=((1, 'nice option 1'),(2, 'nice option 2'))

It now displays a 1 or 2, but it would be really nice if it could show 'nice option 1' or 'nice option 2' instead.

Hyperlinking

Hello Sir,
I have deployed django-excel in production. Its working perfectly, thanks.
Is there any method for giving hyperlinks?

Thank you

Question

In polls.py

def import_data(request):
if request.method == "POST":
form = UploadFileForm(request.POST, request.FILES)
def choice_func(row):
print row[0]
q = Question.objects.filter(slug=row[0])[0]
row[0] = q
return row
if form.is_valid():
request.FILES['file'].save_book_to_database(
models=[
(Question, ['question_text', 'pub_date', 'slug'], None, 0),
(Choice, ['question', 'choice_text', 'votes'], choice_func, 0)
]
)
return HttpResponse("OK", status=200)
else:
return HttpResponseBadRequest()
else:

what does choice_fun do exactly?I didn't understand slug in Choice model.

Need to format an exported date

Using make_response(), I am exporting a column date which is a DateField like this :
2017-10-05T14:27:25.436299+00:00

I want to format this field to be more readable, like this:
10/05/2017

Is it possible to format my date in my exporting view?

Here is my view :

def export_client_download(request, atype):
    if request.user.groups.filter(name="Admin").exists():
        if atype == "clients":
            query_sets = Profile.objects.filter(user__groups__name='Clients')
            columns_names = [
                'user__id',
                'user__last_name',
                'user__first_name',
                'user__email',
                'simulationNb',
                'user__date_joined'
            ]
            sheet = excel.pe.get_sheet(query_sets=query_sets, column_names=columns_names)
            sheet.row[0] = [
                'ID',
                'Last name',
                'First Name',
                'Email',
                'Numbers',
                'Date'
            ]
            return excel.make_response(sheet, 'xls', file_name="clients")

Question

def import_data(request):
if request.method == "POST":
form = UploadFileForm(request.POST,
request.FILES)
def choice_func(row):
q = Question.objects.filter(slug=row[0])[0]
row[0] = q
return row
if form.is_valid():
request.FILES['file'].save_book_to_database(
models=[Question, Choice],
initializers=[None, choice_func],
mapdicts=[
['question_text', 'pub_date', 'slug'],
['question', 'choice_text', 'votes']]
)
return HttpResponse("OK", status=200)
else:
return HttpResponseBadRequest()

In this part of the code ,
How do I modify the code if both sheets were merged in the excel file i.e., If I had one excel sheet with only 7 columns:question_text,published date,choice 1,choice 2 , choice 3,choice 4,right answer
Assuming 1)question model has a field right_answer 2) no slug field in Question 3)no votes filed in Choice model.

Since all choices are in the same row ,I thought i won't need slug field.

Thank You

Test requirements

I did pip install -r test_requirements.txt

i get an error saying sh1.11 is only supported for linux. download pbs 0.110 for windows.
I downloaded pbs using pip install pbs and ran the above command-
I still get the same error. Does this mean django-excel isn't compatible with windows. How can I finish downloading the rest of the needed dependencies?
Please help.
Thank you

How to export with ManyToManyField

For the ManyToManyField, how to export it with a specified field?
For example:
Model: order, item, and order_to_item(many to many)
I'm going to use make_response_from_query_sets to generate the excel:
excel.make_response_from_query_sets( orders, column_names=['id', 'items__content'], file_type='xls', file_name="Order List"

But I get noting for the 'items__content' column.

how could I export sheet with model method as column

So I am trying to use django-excel to export a sheet of a certain model. Problem is there are some methods in this model that I also want to appear in the sheet. I tried to pass in those directly:

query_record = Equipment.objects.all().values('manufacturer','_latest_calibration_date',)
return excel.make_response_from_records(
                query_record, 'xls', file_name="sheet")

in which manufacturer is a charfield and _latest_calibration_date is a method, and this doesn't work. Trying to save the work of creating the sheet from scratch, I tried this a link that seems to maintain value of a field with a method, and do:

_latest_calibration_date = models.DateField(db_column = 'latest_calibration_date')

@property
def latest_calibration_date(self):
    return self._latest_calibration_date

@latest_calibration_date.setter
def latest_calibration_date(self):
    return Calibration.objects.filter(cal_asset__id = self.id).order_by('-id')[0].cal_date

Still, this gives me errors like this:

ProgrammingError at /calbase/export/sheet ('42S22', "[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'latest_calibration_date'. (207) (SQLExecDirectW)")

XLS and XLSX export wont work.

I am having problems exporting to XLS and XLSX.
For XLS I get the following error:
Unexpected data type <class 'django.contrib.auth.models.User'>

For XLSX I get the following error:
Cannot convert hf to Excel

I have installed pyexcel-xls and xlsx.

Export to CSV works without any problems.

The exported field has choices

There is a choices in the exported field. How do you display the corresponding value?

`class Introduction(models.Model):
INTRODUCTIO_STATUS_CHOICES = ( (0,'未确认'),(1,'已确认'),)
status = models.IntegerField(u"状态",choices = CARD_STATUS_CHOICES,default=1)
(...)

column_names = ['org__shop', 'staff_name', 'staff_mobile', 'invitation_name', 'invitation_mobile', 'sale_contract', 'car_model', 'bonus', 'remark', 'invitation_time', 'introductio_status', 'editor__truename', 'edit_time']
`

Import data with foreign key

Hello and first of all, thanks for this package !

I'm having issue when trying to import data with a foreign key field. The code doesnt raise any error, but nothing is saved in database. I've tried using custom initialize as in the documentation, however though I obtain correct values, no object is saved in database. When trying the same code with entities without foreign keys, everything goes fine.

Please find attached my function code. Thanks in advance for any help.
ps : here is what print(row) prints : (types and values are as expected)
['SCHNEIDER ELECTRIC', 'A9L16577', 'v8', 'Z130', 'B', 'aaa', 1, 'dummy', <Groupe: Serveurs>]
`
def import_xls(item, form):

    if form.is_valid():
        if request.FILES['file'].content_type.find('spreadsheet') == -1:
            messages.add_message(request, messages.ERROR, 'Le fichier n\'est pas un tableur !')
            return
        fields = []
        temp = item._meta.get_fields()
        for field in temp:
            if not field.name.startswith("article") and not field.name == 'id' and not isinstance(field,ManyToManyField)and not isinstance(field, ManyToManyRel):
                fields.append(field.name)
        if item == ArticleHW or item == ArticleSW: #no foreign keys, everything goes fine
            try:
                request.FILES['file'].save_to_database(model=item, mapdict=fields)
                messages.add_message(request, messages.SUCCESS, 'Enregistrement : Succès')
            except ValueError:
                messages.add_message(request, messages.ERROR, 'Erreur : Le nombre de champs ne correspond pas !')
        elif item == Equipement:
            try:
                def set_group(row):
                    group = Groupe.objects.get(id=int(row[8]))
                    row [8] = group
                    print(row)
                    return row
                #this is not saving 
                request.FILES['file'].save_to_database(model=item, mapdict=fields, initializer=set_group)           
                messages.add_message(request, messages.SUCCESS, 'Enregistrement : Succès')
            except ValueError as e:
                print(e)
                messages.add_message(request, messages.ERROR, 'Erreur : Le nombre de champs ne correspond pas !') `

Exception Value: string indices must be integers, not str

I am getting the above error when i run django-excel from inside a virtualnev in my work env..
Something is missing or is conflicting in pyexcel:-
/python2.7/site-packages/pyexcel_io-0.3.0-py2.7.egg/pyexcel_io/manager.py in pre_register, line 27

when i hit enter the 2nd time and again after that, i get:-
'module' object has no attribute '_compact'
python2.7/site-packages/pyexcel-0.4.2-py2.7.egg/pyexcel/sheets/sheet.py in , line 12

any quick help is appreciated?

Package requirement

I am working on the tutorial given at http://django-excel.readthedocs.org/en/latest/
I am doing so on Pycharm 5.0.2 on my Windows 7 system.
I get a message when i open the project on Pycharm saying 'Package requirement master.zip not satisfied'
There is an option to install the requirement and even though it says successful installation I still get the same error.
I had done both
pip install -r requirements.txt
pip install -r test_requirements.txt

How do I make master.zip available. Could I manually download it (if so , please mention a link) and also where(in which folder on my computer) should I save it?

Please help
Thank you.

Save too large excel file to django model

Excuse me,Do too large xlsx file possible effect save "save_book_to_database" function?
I try to upload a 6.8M xlsx file to save_book_to_database but my table is empty.

save_book_to_database not saving to database

Hi,

I'm not sure what I'm doing wrong.
view

    def put(self, request):
        print("file upload")
        file_obj = request.data['file']
        print(file_obj)
        file_obj.save_book_to_database(
            models=[Person, ['first_name', 'last_name'], None, 0]
        )
        return Response("OK", status=200)

model

class Person(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)

csv

first_name,last_name
testttt,jijodnf
we,wetet
wetbbty,wef

I get a 200 response but no data is added in the database?

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.