apache2 / mod_wsgi / django production Ошибка NoneType для импорта satchmo - PullRequest
0 голосов
/ 27 октября 2011

Я пытаюсь (очень тяжело) развернуть свое приложение Django в apache2 / mod_wsgi, однако я сталкиваюсь с ошибкой, которая возникает только в производственной среде. Я был бы очень благодарен за любые предложения о том, что делать дальше. Ошибка:

'NoneType' object has no attribute 'objects'

Трассировка стека указывает на эту функцию:

/ var / webapps / MYAPP / Releases / Current / Apps / Product / models.py в by_site

"""
Base model used for products.  Stores hierarchical categories
as well as individual product level information which includes
options.
"""
from decimal import Context, Decimal, ROUND_FLOOR
from django import forms
from django.conf import settings
from django.contrib.sites.models import Site
from django.core import urlresolvers
from django.core.cache import cache
from django.db import models
from django.db.models import Q
from django.utils.translation import get_language, ugettext, ugettext_lazy as _
from l10n.utils import moneyfmt, lookup_translation
from livesettings import config_value, SettingNotSet, config_value_safe
from prices import get_product_quantity_price, get_product_quantity_adjustments
from product import active_product_types
from product.prices import PriceAdjustmentCalc
from satchmo_utils import get_flat_list
from satchmo_utils.fields import CurrencyField
from satchmo_utils.thumbnail.field import ImageWithThumbnailField
from satchmo_utils.unique_id import slugify
import config   #This import is required to make sure livesettings picks up the config values
import datetime
import keyedcache
import logging
import operator
import signals

log = logging.getLogger('product.models')

dimension_units = (('cm','cm'), ('in','in'))

weight_units = (('kg','kg'), ('lb','lb'))

DISCOUNT_SHIPPING_CHOICES = (
('NONE', _('None')),
('FREE', _('Free Shipping')),
('FREECHEAP', _('Cheapest shipping option is free')),
('APPLY', _('Apply the discount above to shipping'))
)

SHIP_CLASS_CHOICES = (
('DEFAULT', _('Default')),
('YES', _('Shippable')),
('NO', _('Not Shippable'))
)

STANDARD_COMPARISON_MEASURES = (
#Weight
('g', '100'),
('kg', '1'),
('mg', '100'),
#Volume
('L', '1'),
('ml', '100'),
#Length
('mm', '100'),
('cm', '100'),
('m', '1'),
('inches', '100'),
#Electricity
('W', '1'),
('V', '1'),
#Each / Pack
('other', '1'),
)

def default_dimension_unit():
val = config_value_safe('PRODUCT','MEASUREMENT_SYSTEM', (None, None))[0]
if val == 'metric':
    return 'cm'
else:
    return 'in'

def default_weight_unit():
val = config_value_safe('PRODUCT','MEASUREMENT_SYSTEM', (None, None))[0]
if val == 'metric':
    return 'kg'
else:
    return 'lb'

class CategoryManager(models.Manager):
def active(self):
    return self.filter(is_active=True)

def by_site(self, site=None, **kwargs):
    """Get all categories for this site"""
    if not site:
        site = Site.objects.get_current()                  <<<<<<<< Line causing error... apparently 

    site = site.id

    return self.active().filter(site__id__exact = site, **kwargs)

def get_by_site(self, site=None, **kwargs):
    if not site:
        site = Site.objects.get_current()              
    return self.active().get(site = site, **kwargs)

def root_categories(self, site=None, **kwargs):
    """Get all root categories."""

    if not site:
        site = Site.objects.get_current()

    return self.active().filter(parent__isnull=True, site=site, **kwargs)

def search_by_site(self, keyword, site=None, include_children=False):
    """Search for categories by keyword.
    Note, this does not return a queryset."""

    if not site:
        site = Site.objects.get_current()

    cats = self.active().filter(
        Q(name__icontains=keyword) |
        Q(meta__icontains=keyword) |
        Q(description__icontains=keyword),
        site=site)

    if include_children:
        # get all the children of the categories found
        cats = [cat.get_active_children(include_self=True) for cat in cats]

    # sort properly
    if cats:
        fastsort = [(c.ordering, c.name, c) for c in get_flat_list(cats)]
        fastsort.sort()
        # extract the cat list
        cats = zip(*fastsort)[2]
    return cats

Это добавляется в модуль satchimo, 'product'. Он был скопирован и настроен в MYAPP / приложениях. Устанавливается в settings.py как apps.product.

Мой файл modwsgi находится в MYAPP / deploy /:

import os
import sys

# redirect sys.stdout to sys.stderr for bad libraries like geopy that uses
# print statements for optional import exceptions.
sys.stdout = sys.stderr

from os.path import abspath, dirname, join
from site import addsitedir

sys.path.insert(0, '/var/webapps/MYAPP/releases/current/apps')
sys.path.insert(0, '/var/webapps/MYAPP/releases/current')
sys.path.insert(0, abspath(join(dirname(__file__), "..", "..")))

from django.conf import settings
os.environ["DJANGO_SETTINGS_MODULE"] = "current.settings"

sys.path.insert(0, join(settings.PINAX_ROOT, "apps"))
sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

Другая информация

Django Версия: 1.3.1 Версия Python: 2.7.1 Python Path:

['/var/webapps/MYAPP/releases/current/apps',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages/pinax/apps',
 '/var/webapps/MYAPP/releases',
 '/var/webapps/MYAPP/releases/current',
 '/var/webapps/MYAPP/releases/current/apps',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages',
 '/var/webapps/MYAPPreleases/current/env/lib/python2.7/site-packages/PIL',
 '/usr/local/lib/python2.7/dist-packages/virtualenv-1.6.4-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7']
...