install django-batchimport

15 views
Skip to first unread message

Michael

unread,
Mar 25, 2009, 10:21:40 AM3/25/09
to django-batchimport-users
Hi There,

Django-batchimport looks nice and I would like to use it to test with
importing product feeds (CSV) into my postgresdb.

I am not a real python programmer but I have developped several sites
in django. The installation is going just fine (I have python 2.5 +
django 1.0).

When I installed django-batchimport I had to add sample_project to the
import lines into the forms.py (from sample_project.batchimport.util
import... in stead of batchimport.util import...)

When I visit my local url http://test/batchimport/import_start/ the
template shows well but I cannot select any models (the models are
present in the admin). I have the idea (with 'all my knowledge') that
the settings are not imported in my batchimport_settings.py.

Do you recognize the problem and could you help me further with the
installation?

Keyton Weissinger

unread,
Mar 25, 2009, 11:54:03 AM3/25/09
to django-batch...@googlegroups.com
Hi Michael,

Great to hear from you. I'm sure we can get you squared away. The
error doesn't sound familiar but we can certainly look at it. Is the
data or app proprietary? Would it be possible to share with me a
sample of the data and your models file?

One thought off the top of my head. Are your models in a file/module
called models(.py)?

You don't happen to be at PyCon do you? We could meet to discuss...

Keyton
--
Sent from my mobile device

Michael

unread,
Mar 25, 2009, 3:24:20 PM3/25/09
to django-batchimport-users
No PyCon for me... I'm just a django novice so may be in the next
years. First I want to learn more about django (and python). Your
application seems really nice. We are working on a platform to show
shop products imported from CSV files into our db and a registration
platform for personal (also import CSV).

Well here is some info. I have the idea that I do something wrong in
the batchimport/forms.py or in the batchimport/batchimport_settings.py
(below the .py info I point out the changes I have made. The project
lives in django_projects/sample_project. As far as I can see I have
made no changes to the util.py. I hope this info makes it more clear.

settings.py
------------------------
# Django settings for batchimport project.
import os, sys
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
DJANGO_PROJECTS_DIR, PROJECT_NAME = os.path.split(PROJECT_DIR)

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_...@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'postgresql' # 'postgresql_psycopg2',
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'secret' # Or path to database file if
using sqlite3.
DATABASE_USER = 'secret' # Not used with sqlite3.
DATABASE_PASSWORD = 'secret' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost.
Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not
used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as
your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as
not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/web/media/sample_project'

# URL that handles the media served from MEDIA_ROOT. Make sure to use
a
# trailing slash if there is a path component (optional in other
cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/sample_project/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure
to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/admin_media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'SECRET'

# List of callables that know how to import templates from various
sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'sample_project.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/
django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(DJANGO_PROJECTS_DIR, 'templates'),
"/home/web/django_templates/sample_project"
)

#BATCH_IMPORT_IMPORTABLE_MODELS = (
# 'sample_project.sample_app',
#)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'sample_project.batchimport',
'sample_project.sample_app',
)

batchimport/forms.py
--> I have added sample_project to initial of ImportOptionsForm
------------------------------
from django import forms

from sample_project.batchimport.util import get_model_list,
get_column_choice_list, get_model_fields

from sample_project.batchimport.batchimport_settings import *





import_model_list = get_model_list()



class UploadImportFileForm(forms.Form):

model_for_import = forms.ChoiceField(import_model_list, label='What
are you importing?')

import_file = forms.FileField(label='Select your XLS file:')



class ImportOptionsForm(forms.Form):

show_successful_imports = forms.BooleanField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_SHOW_SUCCESSFUL_IMPORTS,
required=False)

show_successful_updates = forms.BooleanField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_SHOW_SUCCESSFUL_UPDATES,
required=False)

show_errors = forms.BooleanField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_SHOW_ERRORS,
required=False)

stop_on_first_error = forms.BooleanField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_STOP_ON_FIRST_ERROR,
required=False)

update_dupes = forms.BooleanField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_UPDATE_DUPS,
required=False)

start_row = forms.IntegerField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_START_ROW,
required=False)

end_row = forms.IntegerField
(initial=sample_project.batchimport.batchimport_settings.BATCH_IMPORT_END_ROW,
required=False)

def __init__(self, model_for_import, save_file_name, *args,
**kwargs):

super(ImportOptionsForm, self).__init__(*args, **kwargs)

self.process_options = {}



# Initialize several lists to be used later...

self.model_field_names = []

self.relation_info_dict = {}



# Get a list of columns from the uploaded spreadsheet.

# This will be either a list of example values or a list

# of column headers.

xls_column_option_list = get_column_choice_list(save_file_name)



# Get a list of field names from the selected model

# for import.

self.mapping_only = False



model_list = []

if 'relation' in model_for_import:

import_model_info_list = model_for_import.split('%')

model_list.append(import_model_info_list[0])

if len(import_model_info_list) > 1:

model_list.append(import_model_info_list[2])

self.mapping_only = True

else:

model_list = [model_for_import]



for model_name in model_list:



# In this field_tuple_list is the following for each field in the
current model:

# - field.name: The name of the field.

# - related_model_app_name: Name of the app for any

# related model name (if there is one).

# - related_model_name: Name of the related model

# itself (again, if there is one).

# - related_model_field_name_list: List of fields on the

# related model (for mapping the current model's

# field to the related model).

model_field_tuple_list = get_model_fields(model_name,
self.mapping_only)



# Iterate over this field_tuple_list and create a form field

# for each of the following FOR EACH FIELD in the model:

# - xls_columns_available (list of columns from the spreadsheet)

# - default_value_field (default value if none is in the
spreadsheet)

# - related_field_mapping (list of fields on the related model)

# - id_field (to specify whether this field is in the group of

# fields for this model that together can be used to uniquely

# identify an instance of the model.

for field_tuple in model_field_tuple_list:

base_field_name = field_tuple[0]

full_field_name = model_name + '.' + base_field_name



# XLS column name list for this field.

xls_column_field_name = full_field_name + '-xls_column'

self.model_field_names.append(xls_column_field_name)

initial_value = self._get_initial_value(xls_column_option_list,
base_field_name)

self.fields[xls_column_field_name] = forms.ChoiceField
(xls_column_option_list, label='Spreadsheet column:', required=False,
initial=initial_value)



# ID selection checkmark (see template for example)

is_id_field_name = full_field_name + '-is_id_field'

self.model_field_names.append(is_id_field_name)

if not self.mapping_only:

self.fields[is_id_field_name] = forms.BooleanField
(required=False,initial=True)

else:

self.fields[is_id_field_name] = forms.BooleanField
(required=False,initial=False)



if not self.mapping_only:

related_model_app_name = field_tuple[1]

related_model_name = field_tuple[2]

field_mapping_list = field_tuple[3]



# Get list of fields on the related model as needed.

related_field_choice_list = []

if field_mapping_list:

for related_field_name in field_mapping_list:

related_field_choice_list.append((related_field_name,
related_field_name))

self.relation_info_dict[full_field_name] =
(related_model_app_name,

related_model_name,

related_field_choice_list)



# Default value form field.

default_value_field_name = full_field_name + '-default_value'

self.model_field_names.append(default_value_field_name)

self.fields[default_value_field_name] = forms.CharField
(label="Default value", max_length=100, required=False)



# List of fields on the related model on which to map this field.

mapping_choice_field_name = full_field_name + '-mapping_choice'

self.model_field_names.append(mapping_choice_field_name)

self.fields[mapping_choice_field_name] = forms.ChoiceField
(related_field_choice_list, label='Related model field mapping',
required=False)

self.import_info_dict = self.get_import_info_dict()



def get_import_info_dict(self):

import_info_dict = {}

for field_name in self.model_field_names:

field_name_parts = field_name.split('.')

model_name = field_name_parts[-2]

base_field_name = field_name_parts[-1].split('-')[0]

if not model_name in import_info_dict.keys():

import_info_dict[model_name] = {}

model_field_dict = import_info_dict[model_name]

if not base_field_name in model_field_dict.keys():

model_field_dict[base_field_name] = []

field_list = model_field_dict[base_field_name]

field_list.append(self[field_name])

return import_info_dict



def get_process_options_dict(self):

if not self.process_options:

process_options = {}

process_options['show_successful_imports'] = self
['show_successful_imports']

process_options['show_successful_updates'] = self
['show_successful_updates']

process_options['show_errors'] = self['show_errors']

process_options['stop_on_first_error'] = self
['stop_on_first_error']

process_options['update_dupes'] = self['update_dupes']

process_options['start_row'] = self['start_row']

process_options['end_row'] = self['end_row']

self.process_options = process_options

return self.process_options



def _get_initial_value(self, xls_column_option_list, field_name):

if field_name[-1] == '*':

field_name = ''.join(field_name[:-1])

choice_index = -1

for item in xls_column_option_list:

choice = item[1]

if field_name.lower() == choice.lower():

choice_index = item[0]

break

return str(choice_index)

batchimport/batchimport_settings.py
--> If I add a model in the empty list of
BATCH_IMPORT_IMPORTABLE_MODELS it appears in the html form of /
import_start/ but when I try to upload I get the message: 'NoneType'
object has no attribute '_meta' (AttributeError at /batchimport/
import_options/ -- Exception Location: /home/web/django_projects/
sample_project/batchimport/util.py in get_model_fields, line 155)
-----------------------------------------------
"""

The batchimport_settings.py module initializes itself with defaults
but

allows for the values to be overridden via the django project's
settings

file.



NOTE: These values should be considered CONSTANTS even though I'm kind

of cheating and using them as variables to initialize them here.



"""



import sample_project.settings



def get_setting(setting_name, default):

"""

A simple setting retrieval function to pull settings from the

main settings.py file.



"""

setting = default

print setting_name

print default

try:

setting=getattr(settings, setting_name)

except (AttributeError, NameError):

pass

return setting



# INITIALIZE BATCHIMPORT SETTINGS...



BATCH_IMPORT_START_TEMPLATE = get_setting
('BATCH_IMPORT_START_TEMPLATE', 'batchimport/start.html')

BATCH_IMPORT_OPTIONS_TEMPLATE = get_setting
('BATCH_IMPORT_OPTIONS_TEMPLATE', 'batchimport/options.html')

BATCH_IMPORT_EXECUTE_TEMPLATE = get_setting
('BATCH_IMPORT_EXECUTE_TEMPLATE', 'batchimport/processing.html')

BATCH_IMPORT_RESULTS_TEMPLATE = get_setting
('BATCH_IMPORT_RESULTS_TEMPLATE', 'batchimport/results.html')



# Specify the list of models in your application which are importable

# in batch. If you do not provide a list, the system will use
introspection

# to get a list of ALL models in your application (via
INSTALLED_APPS).

BATCH_IMPORT_IMPORTABLE_MODELS = get_setting
('BATCH_IMPORT_IMPORTABLE_MODELS', [])



# Specify where the uploaded Microsoft Excel file will be saved to the

# system.

# NOTE: This must be a absolute path.

# NOTE: Django must have read/write access to this location.

BATCH_IMPORT_TEMPFILE_LOCATION = get_setting
('BATCH_IMPORT_TEMPFILE_LOCATION', '/tmp/')



# By default, the system does not allow you to import data for fields

# that are not EDITABLE (i.e. in their model field declarations,
you've

# set editable=False). You can override this behavior here:

BATCH_IMPORT_UNEDITABLE_FIELDS = get_setting
('BATCH_IMPORT_UNEDITABLE_FIELDS', False)



# Sometimes you will want to override the value coming in from the XLS

# file with a constant or a dynamically generated value.

# The following setting is a dictionary of values (or callables) per

# each fully specified model field.

# NOTE: You must import the item into your settings file if it is a

# callable.

BATCH_IMPORT_VALUE_OVERRIDES = get_setting
('BATCH_IMPORT_VALUE_OVERRIDES', {})





# The system can show you individual imports, updates,

# or errors individually using the following boolean options.

# Note that True is assumed for all three if no setting is

# present.

BATCH_IMPORT_SHOW_SUCCESSFUL_IMPORTS = get_setting
('BATCH_IMPORT_SHOW_SUCCESSFUL_IMPORTS', True)

BATCH_IMPORT_SHOW_SUCCESSFUL_UPDATES = get_setting
('BATCH_IMPORT_SHOW_SUCCESSFUL_UPDATES', True)

BATCH_IMPORT_SHOW_ERRORS = get_setting('BATCH_IMPORT_SHOW_ERRORS',
True)



# Whether the system should stop on the first error

# or process the entire uploaded spreadsheet and show

# errors afterwards.

BATCH_IMPORT_STOP_ON_FIRST_ERROR = get_setting
('BATCH_IMPORT_STOP_ON_FIRST_ERROR', False)



# Whether or not to update duplicates or simply

# ignore them. Note that duplicates are determined

# based on the user's specification of model fields

# as identification fields. If these are not set, a duplicate

# must match at all column/fields.

BATCH_IMPORT_UPDATE_DUPS = get_setting('BATCH_IMPORT_UPDATE_DUPS',
False)



# If no options are set for start/end row, defaults are used that

# assume (1) the spreadsheet has a header row (indicating that data

# starts on row #2 and (2) the entire spreadsheet is to be processed.

BATCH_IMPORT_START_ROW = get_setting('BATCH_IMPORT_START_ROW', 2)

BATCH_IMPORT_END_ROW = get_setting('BATCH_IMPORT_END_ROW', -1)


On Mar 25, 4:54 pm, Keyton Weissinger <key...@gmail.com> wrote:
> Hi Michael,
>
> Great to hear from you. I'm sure we can get you squared away. The
> error doesn't sound familiar but we can certainly look at it. Is the
> data or app proprietary? Would it be possible to share with me a
> sample of the data and your models file?
>
> One thought off the top of my head. Are your models in a file/module
> called models(.py)?
>
> You don't happen to be at PyCon do you? We could meet to discuss...
>
> Keyton
>

Keyton Weissinger

unread,
Mar 26, 2009, 6:54:07 AM3/26/09
to django-batch...@googlegroups.com
Hi Michael,

Good news potentially. I believe I may know what the problem is. In
your CSV data (XLS file) you are uploading, do the columns have
headers? If not, try that and let me know what happens. At the last
minute I added some code to help you auto-select the spreadsheet
column from the model's field names and I believe that there is a bug
that breaks if you DON'T have headers. I will get the code patched
probably late today or this weekend, but in the mean time you may be
able to work around the problem by simply adding a header row to your
data.

If it's not that, we'll have to go deeper. No worries. It just may be
this weekend before I can dig much and I would definitely want to see
your models file and get some sample data (fake is of course fine --
even preferred) so I can set up a project locally and try it and see
what's happening.

One other thing I keep meaning to update on the site: If you're data
contains dates, you'll need to format them in Excel to be in the
format: YYYY-mm-dd You can do this using the format options for the
cells though I believe you have to use custom formatting and put this
string in as your format: YYYY-mm-dd

Let me know what happens. Sorry you won't make it to PyCon. This is my
first one but I've been to loads of other tech conferences. So far
this one is definitely my favorite and everyone (speakers and
attendees alike) are all extremely nice and approachable.

Best,
Keyton

RichardH

unread,
Mar 26, 2009, 7:33:36 AM3/26/09
to django-batchimport-users
Hi Keyton,
Great to meet up on the first day of Pycon2009.
A thought on one of your comments below. I don't think the actual
formatting of the date matters. Your _do_batch_import code checks the
ctype to identify the data type and picks up whether it is a date or
not. This looks like it will work whatever the formatting of the date
string.
Regards,
Richard

On Mar 26, 5:54 am, Keyton Weissinger <key...@gmail.com> wrote:
> Hi Michael,
>
> Good news potentially. I believe I may know what the problem is. In
> your CSV data (XLS file) you are uploading, do the columns have
> headers? If not, try that and let me know what happens. At the last
> minute I added some code to help you auto-select the spreadsheet
> column from the model's field names and I believe that there is a bug
> that breaks if you DON'T have headers. I will get the code patched
> probably late today or this weekend, but in the mean time you may be
> able to work around the problem by simply adding a header row to your
> data.
>
> If it's not that, we'll have to go deeper. No worries. It just may be
> this weekend before I can dig much and I would definitely want to see
> your models file and get some sample data (fake is of course fine --
> even preferred) so I can set up a project locally and try it and see
> what's happening.
>
> One other thing I keep meaning to update on the site: If you're data
> contains dates, you'll need to format them in Excel to be in the
> format: YYYY-mm-dd You can do this using the format options for the
> cells though I believe you have to use custom formatting and put this
> string in as your format: YYYY-mm-dd
>
> Let me know what happens. Sorry you won't make it to PyCon. This is my
> first one but I've been to loads of other tech conferences. So far
> this one is definitely my favorite and everyone (speakers and
> attendees alike) are all extremely nice and approachable.
>
> Best,
> KeytonOn Wed, Mar 25, 2009 at 2:24 PM, Michael <folderpla...@gmail.com> wrote:
>
> > No PyCon for me... I'm just a django novice so may be in the next
> > years. First I want to learn more about django (and python). Your
> > application seems really nice. We are working on a platform to show
> > shop products imported from CSV files into our db and a registration
> > platform for personal (also import CSV).
>
> > Well here is some info. I have the idea that I do something wrong in
> > the batchimport/forms.py or in the batchimport/batchimport_settings.py
> > (below the .py info I point out the changes I have made. The project
> > lives in django_projects/sample_project. As far as I can see I have
> > made no changes to the util.py. I hope this info makes it more clear.
>
> > settings.py
> > ------------------------
> > # Django settings for batchimport project.
> > import os, sys
> > PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
> > DJANGO_PROJECTS_DIR, PROJECT_NAME = os.path.split(PROJECT_DIR)
>
> > DEBUG = True
> > TEMPLATE_DEBUG = DEBUG
>
> > ADMINS = (
> >    # ('Your Name', 'your_em...@domain.com'),
> > )
>
> > MANAGERS = ADMINS
>
> > DATABASE_ENGINE = 'postgresql'           # 'postgresql_psycopg2',
> > 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
> > DATABASE_NAME = 'secret'             # Or path to database file if
> > using sqlite3.
> > DATABASE_USER = 'secret'             # Not used with sqlite3.
> > DATABASE_PASSWORD = 'secret'         # Not used with sqlite3.
> > DATABASE_HOST = ''             # Set to empty string for localhost.
> > Not used with sqlite3.
> > DATABASE_PORT = ''             # Set to empty string for default. Not
> > used with sqlite3.
>
> > # Local time zone for this installation. Choices can be found here:
> > #http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
> > # although not all choices may be available on all operating systems.
> > # If running in a Windows environment this must be set to the same as
> > your
> > # system time zone.
> > TIME_ZONE = 'America/Chicago'
>
> > # Language code for this installation. All choices can be found here:
> > #http://www.i18nguy.com/unicode/language-identifiers.html

Keyton Weissinger

unread,
Mar 26, 2009, 7:59:01 AM3/26/09
to django-batch...@googlegroups.com
Same here absolutely. I mentioned this issue with the dates as a
result of a problem I had. Xlrd is able to pull the dates, no problem
but when I tried to load a model instance with them (as DateField as I
recall) django didn't like it. Let's discuss in person today. I want
to make sure I have this thing right.

Keyton

Michael

unread,
Mar 26, 2009, 11:00:58 AM3/26/09
to django-batchimport-users
Hi Keyton,

Thanks for your quick reply.

I don't think that that is the issue here (you are a few steps
ahead.....). My problem is that in the first step I cannot upload any
XLS/CSV file because I cannot select any models in the form. My models
are shown in the admin so I guess somehow the models aren't imported
in my form (probably because I have the wrong import settings in my
forms.py / batchimport_settings.py.

From what I understand is that all the available models are imported
if I don't specify BATCH_IMPORT_IMPORTABLE_MODELS. I didn specify any
models so the available models should appear in my form, but they
aren't....

Greetings Michael.


On Mar 26, 11:54 am, Keyton Weissinger <key...@gmail.com> wrote:
> Hi Michael,
>
> Good news potentially. I believe I may know what the problem is. In
> your CSV data (XLS file) you are uploading, do the columns have
> headers? If not, try that and let me know what happens. At the last
> minute I added some code to help you auto-select the spreadsheet
> column from the model's field names and I believe that there is a bug
> that breaks if you DON'T have headers. I will get the code patched
> probably late today or this weekend, but in the mean time you may be
> able to work around the problem by simply adding a header row to your
> data.
>
> If it's not that, we'll have to go deeper. No worries. It just may be
> this weekend before I can dig much and I would definitely want to see
> your models file and get some sample data (fake is of course fine --
> even preferred) so I can set up a project locally and try it and see
> what's happening.
>
> One other thing I keep meaning to update on the site: If you're data
> contains dates, you'll need to format them in Excel to be in the
> format: YYYY-mm-dd You can do this using the format options for the
> cells though I believe you have to use custom formatting and put this
> string in as your format: YYYY-mm-dd
>
> Let me know what happens. Sorry you won't make it to PyCon. This is my
> first one but I've been to loads of other tech conferences. So far
> this one is definitely my favorite and everyone (speakers and
> attendees alike) are all extremely nice and approachable.
>
> Best,
> KeytonOn Wed, Mar 25, 2009 at 2:24 PM, Michael <folderpla...@gmail.com> wrote:
>
> > No PyCon for me... I'm just a django novice so may be in the next
> > years. First I want to learn more about django (and python). Your
> > application seems really nice. We are working on a platform to show
> > shop products imported from CSV files into our db and a registration
> > platform for personal (also import CSV).
>
> > Well here is some info. I have the idea that I do something wrong in
> > the batchimport/forms.py or in the batchimport/batchimport_settings.py
> > (below the .py info I point out the changes I have made. The project
> > lives in django_projects/sample_project. As far as I can see I have
> > made no changes to the util.py. I hope this info makes it more clear.
>
> > settings.py
> > ------------------------
> > # Django settings for batchimport project.
> > import os, sys
> > PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
> > DJANGO_PROJECTS_DIR, PROJECT_NAME = os.path.split(PROJECT_DIR)
>
> > DEBUG = True
> > TEMPLATE_DEBUG = DEBUG
>
> > ADMINS = (
> >    # ('Your Name', 'your_em...@domain.com'),
> > )
>
> > MANAGERS = ADMINS
>
> > DATABASE_ENGINE = 'postgresql'           # 'postgresql_psycopg2',
> > 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
> > DATABASE_NAME = 'secret'             # Or path to database file if
> > using sqlite3.
> > DATABASE_USER = 'secret'             # Not used with sqlite3.
> > DATABASE_PASSWORD = 'secret'         # Not used with sqlite3.
> > DATABASE_HOST = ''             # Set to empty string for localhost.
> > Not used with sqlite3.
> > DATABASE_PORT = ''             # Set to empty string for default. Not
> > used with sqlite3.
>
> > # Local time zone for this installation. Choices can be found here:
> > #http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
> > # although not all choices may be available on all operating systems.
> > # If running in a Windows environment this must be set to the same as
> > your
> > # system time zone.
> > TIME_ZONE = 'America/Chicago'
>
> > # Language code for this installation. All choices can be found here:
> > #http://www.i18nguy.com/unicode/language-identifiers.html

Keyton Weissinger

unread,
Mar 26, 2009, 11:22:36 AM3/26/09
to django-batch...@googlegroups.com
Hmm. A couple ideas. The way I'm getting an initial list of models if
you don't put a shorter list in the BATCH_IMPORT settings, is like
this:

mod = __import__(app+'.models')
if 'models' in dir(mod):

This loads the module called "models". Obviously, it assumes that your
models are in a file called models.py.

I'm concerned that the system is not properly instantiating your
module properly.

As for adding the project name everywhere this is sort of a no-no. If
your project is on the PYTHONPATH then the modules are already on the
path as they are all python modules (have __init__.py files in them).
Adding the project name to the beginning of these imports makes the
app less reusable.

So I would change that back.If your project stops working we have
other issues we can look at.

Assuming it does work still, do this:

Go to a command line and from your project folder enter the following:
python manage.py shell

You should see the python shell.

Enter the following:
from sample_app import models

If you get an error here that will tell us something.

If no error, do this:
dir(models)

You should see a list of stuff in this module (including your models).

Do those things and let me know what you learn...

Sorry you're having issues. We'll resolve. Have no fear...

Keyton

Michael

unread,
Mar 26, 2009, 12:02:50 PM3/26/09
to django-batchimport-users
No errors here and the models show up in the dir(models)... I think I
don't have my project added to the PYTHON PATH the right way so I'm
the one that should be sorry. I have added django to the site-packages
of Python and I had no problems with the other django projects. But
this is my first time that I try to install a 'reusable app' in one of
my projects...

I will try a new install and will add the project to the PYTHON PATH
and will let you know whether it works... Thanks for your efforts so
far!
> ...
>
> read more »

Michael

unread,
Mar 27, 2009, 9:07:16 AM3/27/09
to django-batchimport-users
Yep. Wrong settings in Apache... I added

PythonPath "['/home/web/django_projects','/home/web/django_projects/
sample_project'] + sys.path"

and now the models are shown is the form at /import_start/. When I
upload the sample_parents.xls file and click on submit I get
redericted to /import_options/. If I make no changes and click on
submit I get the python error below. Could it be that I have tot
change the location of /temp/ or add this path to var/www ?

I am getting really excited about this app. I see great
possibilities....

MOD_PYTHON ERROR

ProcessId: 8809
Interpreter: 'test'

ServerName: 'test'
DocumentRoot: '/var/www'

URI: '/batchimport/import_execute/'
Location: '/'
Directory: None
Filename: '/var/www/batchimport'
PathInfo: '/import_execute/'

Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'

Traceback (most recent call last):

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1229, in _process_target
result = _execute_target(config, req, object, arg)

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1128, in _execute_target
result = object(arg)

File "/usr/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 228, in handler
return ModPythonHandler()(req)

File "/usr/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 205, in __call__
response = middleware_method(request, response)

File "/usr/lib/python2.5/site-packages/django/contrib/sessions/
middleware.py", line 35, in process_response
request.session.save()

File "/usr/lib/python2.5/site-packages/django/contrib/sessions/
backends/db.py", line 56, in save
sid = transaction.savepoint()

File "/usr/lib/python2.5/site-packages/django/db/transaction.py",
line 188, in savepoint
connection._savepoint(sid)

File "/usr/lib/python2.5/site-packages/django/db/backends/
__init__.py", line 43, in _savepoint
self.connection.cursor().execute(self.ops.savepoint_create_sql
(sid))

ProgrammingError: ERROR: current transaction is aborted, commands
ignored until end of transaction block

SAVEPOINT s1238340720_x1
> ...
>
> read more »

Keyton Weissinger

unread,
Mar 27, 2009, 9:37:14 AM3/27/09
to django-batch...@googlegroups.com
Hi Michael.

Do me a favor. Try it just running django from the command line
(rather than from within django). That way we can isolate the issue a
bit.

What OS etc are you using (python ver, django ver, etc)?

Keyton
Reply all
Reply to author
Forward
0 new messages