Re: Can't get ThreadLocals (user in threadlocal storage) working.

2008-04-24 Thread Hilbert Schraal

Yeah! I found the solution. Instead of:

  'XXX.cms.middleware.session.ThreadLocals',

I need to do:

  'cms.middleware.session.ThreadLocals',

So, specify the middleware class without the project name.

The strange thing is that the middleware itself works when the project
is specified, however the model class methods seem to run in a
different thread. There must be an explanation for this somewhere deep
down Django. Does someone know why?

cheers,
Hilbert

On 22 apr, 11:14, Hilbert Schraal <[EMAIL PROTECTED]> wrote:
> Thanks for the tip. I fiddled around with the imports, but no
> results :(
>
> On 20 apr, 21:33, Doug B <[EMAIL PROTECTED]> wrote:
>
> > Its been a while, but I had problems getting this to work at first
> > too.  It turned out to be how I was importing the module that
> > contained thread locals.  I needed to specify the project as well as
> > the app when doing the import.
>
> > I couldn't just do from myapp import mymiddleware, I had to do from
> > myproject.myapp import mymiddleware.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can't get ThreadLocals (user in threadlocal storage) working.

2008-04-22 Thread Hilbert Schraal

Thanks for the tip. I fiddled around with the imports, but no
results :(

On 20 apr, 21:33, Doug B <[EMAIL PROTECTED]> wrote:
> Its been a while, but I had problems getting this to work at first
> too.  It turned out to be how I was importing the module that
> contained thread locals.  I needed to specify the project as well as
> the app when doing the import.
>
> I couldn't just do from myapp import mymiddleware, I had to do from
> myproject.myapp import mymiddleware.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can't get ThreadLocals (user in threadlocal storage) working.

2008-04-22 Thread Hilbert Schraal

check, that was a bit stupid :)

On 21 apr, 15:16, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Sun, Apr 20, 2008 at 10:45 AM, Hilbert Schraal
>
> <[EMAIL PROTECTED]> wrote:
> >  # Make this unique, and don't share it with anybody.
> >  SECRET_KEY = '[EMAIL PROTECTED]@d(5w+m)kpcjffne(pvb+#6w2s_pz*5)b%$f'
>
> As an aside, note the comment: "don't share it with anybody" It's good
> that you cleaned the passwords out of your settings before pasting,
> but you should always clean this too.
>
> -Gul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can't get ThreadLocals (user in threadlocal storage) working.

2008-04-22 Thread Hilbert Schraal

Some extra info. I printed the _thread_locals variable in the
get_current_user() method and in the process_request() method. They
are different:

middleware: 
get_current_user: 


Here's the threadlocals.py:
import logging

try:
from threading import local
except ImportError:
from django.utils._threading_local import local

_thread_locals = local()
def get_current_user():
print "get_current_user: %s " % _thread_locals
return getattr(_thread_locals, 'user', None)

class ThreadLocals(object):
"""Middleware that gets various objects from the
request object and saves them in thread local storage."""
def process_request(self, request):
print "middleware: %s" % _thread_locals
_thread_locals.user = getattr(request, 'user', None)


and this is how I use it (the TemplateManager is used as the object
manager of a model class - objects=TemplateManager() - and I want to
use the user for filtering):

from cms.middleware import threadlocals

class TemplateManager(models.Manager):
def get_query_set(self):
threadlocals.get_current_user()
return super(TemplateManager, self).get_query_set()


Looks pretty much the same as the cookbook example I think...

On 20 apr, 16:45, Hilbert Schraal <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I've followed the CookBook (http://code.djangoproject.com/wiki/
> CookBookThreadlocalsAndUser) to have the user available in my model. I
> have added the ThreadLocals class to my code and added it to the
> middleware class setting. It gets called en sets values that look
> valid.
>
> However, when I call the get_current_user() method, it always returns
> None. I tried this using 'manage.py runserver' and using mod_python.
>
> I use Django 0.96.1 on Ubuntu Hardy (Python 2.5.2) and Debian (Python
> 2.4.4). Here's my settings.py (I replaced the project name with XXX).
>
> Anyone got a clue?
> Thanks,
> Hilbert
>
> # Django settings for XXX project.
> import logging
>
> #--
> #
> # Below are the settings that most likely change per
> environment   #
> #--
> #
>
> #DEBUG needs to be 'False' on environments other than development
> # NOTE: with DEBUG = True, some settings are overridden ot the bottom
> of this file.
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
>
> # logging configuratie
> LOG_LEVEL = logging.DEBUG
> LOG_FILE = '/tmp/XXX.log'
>
> DATABASE_ENGINE = 'mysql'   # 'postgresql_psycopg2',
> 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
> DATABASE_NAME = XXX # Or path to database file if using
> sqlite3.
> DATABASE_USER = XXX # Not used with sqlite3.
> DATABASE_PASSWORD = XXX # 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.
>
> # location of the cache. Needs to be an absolute path
> CACHE_BACKEND = 'file:///tmp/django_cache'
>
> # Absolute path to the directory that holds media.
> # Example: "/home/media/media.lawrence.com/"
> MEDIA_ROOT = '/home/schraal/XXX-media/'
>
> 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.
> "/home/schraal/XXX/cms/templates",
> )
>
> #--
> #
> # DO NOT CHANGE THE SETTINGS BELOW HERE, UNLESS YOU KNOW WHAT YOU'RE
> DOING #
> #--
> #
>
> CACHE_MIDDLEWARE_SECONDS = 300
> CACHE_MIDDLEWARE_KEY_PREFIX = 'XXX'
> CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
>
> ADMINS = (
> # ('Your Name', '[EMAIL PROTECTED]'),
> )
>
> MANAGERS = ADMINS
>
> # Local time zone for this installation. Choices can be found here:
> #http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATE...
> # although not all variations may be possible on all operating
> systems.
> # If running in a Windows environment this must be set to the same as
> your
> # system time zone.
> TIME_ZONE = 'Europe/Amsterdam'
>
> # Language code for this installation. All choices can be found here:
> #http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
> #http://blogs.law.harvard.edu/tech

Can't get ThreadLocals (user in threadlocal storage) working.

2008-04-20 Thread Hilbert Schraal

Hi All,

I've followed the CookBook (http://code.djangoproject.com/wiki/
CookBookThreadlocalsAndUser) to have the user available in my model. I
have added the ThreadLocals class to my code and added it to the
middleware class setting. It gets called en sets values that look
valid.

However, when I call the get_current_user() method, it always returns
None. I tried this using 'manage.py runserver' and using mod_python.

I use Django 0.96.1 on Ubuntu Hardy (Python 2.5.2) and Debian (Python
2.4.4). Here's my settings.py (I replaced the project name with XXX).

Anyone got a clue?
Thanks,
Hilbert

# Django settings for XXX project.
import logging


#--
#
# Below are the settings that most likely change per
environment   #
#--
#

#DEBUG needs to be 'False' on environments other than development
# NOTE: with DEBUG = True, some settings are overridden ot the bottom
of this file.
DEBUG = True
TEMPLATE_DEBUG = DEBUG

# logging configuratie
LOG_LEVEL = logging.DEBUG
LOG_FILE = '/tmp/XXX.log'

DATABASE_ENGINE = 'mysql'   # 'postgresql_psycopg2',
'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = XXX # Or path to database file if using
sqlite3.
DATABASE_USER = XXX # Not used with sqlite3.
DATABASE_PASSWORD = XXX # 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.

# location of the cache. Needs to be an absolute path
CACHE_BACKEND = 'file:///tmp/django_cache'

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

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.
"/home/schraal/XXX/cms/templates",
)

#--
#
# DO NOT CHANGE THE SETTINGS BELOW HERE, UNLESS YOU KNOW WHAT YOU'RE
DOING #
#--
#

CACHE_MIDDLEWARE_SECONDS = 300
CACHE_MIDDLEWARE_KEY_PREFIX = 'XXX'
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

ADMINS = (
# ('Your Name', '[EMAIL PROTECTED]'),
)

MANAGERS = ADMINS

# Local time zone for this installation. Choices can be found here:
# 
http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
# although not all variations may be possible on all operating
systems.
# If running in a Windows environment this must be set to the same as
your
# system time zone.
TIME_ZONE = 'Europe/Amsterdam'

# Language code for this installation. All choices can be found here:
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
# http://blogs.law.harvard.edu/tech/stories/storyReader$15
LANGUAGE_CODE = 'nl'

DATETIME_FORMAT = 'd-m-Y H:i'

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

APPEND_SLASH = True

# URL that handles the media served from MEDIA_ROOT.
# Example: "http://media.lawrence.com;
MEDIA_URL = ''

# 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 = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '[EMAIL PROTECTED]@d(5w+m)kpcjffne(pvb+#6w2s_pz*5)b%$f'

# 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',
)

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.cache.CacheMiddleware',
'XXX.cms.middleware.session.ThreadLocals',
)

ROOT_URLCONF = 'rvucms.urls'

INSTALLED_APPS = (
'XXX.cms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'XXX.upload'
)

logging.basicConfig(level=LOG_LEVEL,
format='%(asctime)s %(levelname)s %(message)s',
  

Admin i18n problems using Apache + mod_python

2008-04-03 Thread Hilbert Schraal

Hi all,

I'm deploying django 0.96.1 on Apache + mod_python on debian etch. In
the setting.py I have:

LANGUAGES = (
('nl', 'Dutch'),
)

LANGUAGE_CODE = 'nl'

USE_I18N = True


On development using 'manage.py runserver' I have the admin app
translated in Dutch. Behind Apache + mod_python the admin app always
shows up in English. I even have set my language preference in my
browser to Dutch, to no avail.


Does anyone have a clue? I haven't been able to find a ticket or
mailinglist item about this particular problem.

thanks,
Hilbert
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---