Thursday, March 1, 2012

Re: subprocess

On Thu, Mar 1, 2012 at 11:42 AM, Sébastien Billion
<sebastien.billion@gmail.com> wrote:
> Hi,
>
> You can try something like that:
>
> p = subprocess.Popen(args=[("%s %s") % (script_name,command_args1)],

Sorry to pick on something seemingly inconsequential, but this really
riles me. If you launch a subprocess using a string like "command arg1
arg2 arg3", then you force the OS to do additional work to spawn the
process via the shell. at which point the shell then has to re-parse
the arguments that you passed to it.

So, what's the big deal?

If command_args1 was the string 'hello world', then the suggested
approach would not work. The argument would be split into two separate
arguments by the shell. You already know which argument you want and
where you want it, so just pass them through appropriately with a
list.

The only 'benefit' going through a shell is that you can rely on the
shell searching $PATH to find the 'right' executable. As I've
intimated, this isn't much of a benefit.

OP:

Are you showing us precisely the code that runs? WFM…

>>> import sys
>>> import subprocess
>>> p=subprocess.Popen([sys.executable, 'hello.py', 'sdfg'], stdout=subprocess.PIPE)
>>> p.communicate()
('hello\n', None)


Cheers

Tom

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: subprocess

Hi,

You can try something like that:

p = subprocess.Popen(args=[("%s %s") % (script_name,command_args1)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
output = p.stdout.readlines()
p.wait()

2012/3/1 dummyman dummyman <tempovan@gmail.com>
Hi ,

i am using django  s view function to invoke python script to run in background.
now i want to pass command line args to the script

here is wat i did

subprocess.Popen([sys.executable,"script_name","command_args1"])

i got the error 

execv requires arg 2 to be a string

please help me 

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

UnicodeEncodeError in file uploads

Hi there,
for quite some time I got a Django project up and running on an Apache
web server. I got absolutely no problems with e.g. German umlauts. I
followed all instructions on how to set up django, apache and mysql.
But unfortunately uploading of files containing non-ASCII characters
raises a UnicodeEncodeError. In my code there is no need for any
conversion to ASCII: I'm simply using a ImageFileField in my model and
want to save the file.

I have absolutely no idea where to look for the problem. Any
suggestions???
The code is available on launchpad:
http://bazaar.launchpad.net/~andi-hasenkopf/aintnowiki/trunk/revision/75
Here is the DEBUG output:

UnicodeEncodeError at /photobook/upload/hdd/

'ascii' codec can't encode character u'\xf6' in position 30: ordinal
not in range(128)

Request Method: POST
Request URL: https://www-elektronenmikroskopie.uni-regensburg.de/photobook/upload/hdd/
Django Version: 1.3.1
Exception Type: UnicodeEncodeError
Exception Value:

'ascii' codec can't encode character u'\xf6' in position 30: ordinal
not in range(128)

Exception Location: /usr/lib/python2.6/genericpath.py in exists, line
18
Python Executable: /usr/bin/python
Python Version: 2.6.5
Python Path:

['/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/pymodules/python2.6',
'/usr/lib/pymodules/python2.6/gtk-2.0',
'/usr/local/lib/python2.6/dist-packages',
'/var/aintnowiki/',
'/var/']

Server time: Thu, 1 Mar 2012 10:47:41 +0100
Unicode error hint

The string that could not be encoded/decoded was: mps/höle_in
Traceback Switch to copy-and-paste view

/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py in get_response

response = callback(request,
*callback_args, **callback_kwargs)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py
in _wrapped_view

response = view_func(request, *args,
**kwargs)

...
▶ Local vars
/var/aintnowiki/wiki/decorators.py in _wrapped_view_func

return view_func(request, *args, **kwargs)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py in _wrapped_view

return view_func(request, *args, **kwargs)

...
▶ Local vars
/var/aintnowiki/stampit/views.py in upload_hdd

photo.save()

...
▶ Local vars
/var/aintnowiki/stampit/models.py in save

super(Photo,self).save(*args,**kwargs)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/db/models/base.py in
save

self.save_base(using=using, force_insert=force_insert,
force_update=force_update)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/db/models/base.py in
save_base

for f in meta.local_fields if not
isinstance(f, AutoField)]

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/db/models/fields/
files.py in pre_save

file.save(file.name, file, save=False)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/db/models/fields/
files.py in save

self.name = self.storage.save(name, content)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/core/files/
storage.py in save

name = self.get_available_name(name)

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/core/files/
storage.py in get_available_name

while self.exists(name):

...
▶ Local vars
/usr/local/lib/python2.6/dist-packages/django/core/files/
storage.py in exists

return os.path.exists(self.path(name))

...
▶ Local vars
/usr/lib/python2.6/genericpath.py in exists

st = os.stat(path)

...
▶ Local vars

Request information
GET

No GET data
POST
Variable Value
Upload

u'Upload!'

csrfmiddlewaretoken

u'd652017af517ec5684f7702df836b489'

tags

u''

description

u''

title

u'test'

FILES
Variable Value
local_image

<InMemoryUploadedFile: höle_in_membrane.jpg (image/jpeg)>

COOKIES
Variable Value
csrftoken

'd652017af517ec5684f7702df836b489'

sessionid

'a52f7d9254d313ffcfafd1e37d622b8b'

META
Variable Value
mod_wsgi.reload_mechanism

'0'

mod_wsgi.listener_port

'443'

HTTP_REFERER

'https://www-elektronenmikroskopie.uni-regensburg.de/photobook/upload/
hdd/
'

mod_wsgi.listener_host

''

SERVER_SOFTWARE

'Apache/2.2.14 (Ubuntu)'

SCRIPT_NAME

u''

SERVER_SIGNATURE

'<address>Apache/2.2.14 (Ubuntu) Server at www-
elektronenmikroskopie.uni-regensburg.de Port 443</address>\n'

REQUEST_METHOD

'POST'

PATH_INFO

u'/photobook/upload/hdd/'

SERVER_PROTOCOL

'HTTP/1.1'

QUERY_STRING

''

PATH

'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/
X11R6/bin'

SSL_TLS_SNI

'www-elektronenmikroskopie.uni-regensburg.de'

CONTENT_LENGTH

'56064'

HTTP_USER_AGENT

'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:10.0.2) Gecko/20100101
Firefox/10.0.2'

HTTP_CONNECTION

'keep-alive'

HTTP_COOKIE

'csrftoken=d652017af517ec5684f7702df836b489;
sessionid=a52f7d9254d313ffcfafd1e37d622b8b'

SERVER_NAME

'www-elektronenmikroskopie.uni-regensburg.de'

REMOTE_ADDR

'132.199.99.54'

GEOIP_COUNTRY_NAME

'Germany'

wsgi.url_scheme

'https'

PATH_TRANSLATED

'/var/aintnowiki/apache/django.wsgi/photobook/upload/hdd/'

SERVER_PORT

'443'

wsgi.multiprocess

True

SERVER_ADDR

'132.199.99.155'

DOCUMENT_ROOT

'/var/www'

mod_wsgi.process_group

''

SCRIPT_FILENAME

'/var/aintnowiki/apache/django.wsgi'

SERVER_ADMIN

'webmaster@hasenkopf2000.net'

SCRIPT_URI

'https://www-elektronenmikroskopie.uni-regensburg.de/photobook/upload/
hdd/
'

wsgi.input

<mod_wsgi.Input object at 0x7fe9c4397b30>

HTTP_DNT

'1'

HTTP_HOST

'www-elektronenmikroskopie.uni-regensburg.de'

SCRIPT_URL

'/photobook/upload/hdd/'

HTTPS

'1'

wsgi.multithread

False

mod_wsgi.callable_object

'application'

REQUEST_URI

'/photobook/upload/hdd/'

HTTP_ACCEPT

'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'

wsgi.version

(1, 0)

GATEWAY_INTERFACE

'CGI/1.1'

wsgi.run_once

False

wsgi.errors

<mod_wsgi.Log object at 0x7fe9c3e25990>

REMOTE_PORT

'51326'

HTTP_ACCEPT_LANGUAGE

'en-us,en;q=0.5'

mod_wsgi.version

(2, 8)

GEOIP_COUNTRY_CODE

'DE'

CONTENT_TYPE

'multipart/form-data;
boundary=---------------------------102201031114817323861166079304'

mod_wsgi.application_group

'pc101100593x.uni-regensburg.de|'

mod_wsgi.script_reloading

'1'

wsgi.file_wrapper

''

CSRF_COOKIE

'd652017af517ec5684f7702df836b489'

HTTP_ACCEPT_ENCODING

'gzip, deflate'

Settings
Using settings module aintnowiki.settings
Setting Value
GRAPPELLI_INDEX_DASHBOARD

'aintnowiki.dashboard.CustomIndexDashboard'

SERVER_EMAIL

'root@localhost'

USE_L10N

False

USE_THOUSAND_SEPARATOR

False

LANGUAGE_CODE

'en-us'

ROOT_URLCONF

'aintnowiki.urls'

MANAGERS

(('Andreas Hasenkopf', 'webmaster@hasenkopf2000.net'),)

DEFAULT_CHARSET

'utf-8'

STATIC_ROOT

'/var/aintnowiki/media/static/'

TEST_DATABASE_CHARSET

None

PRODUCTIVE_ENVIRON

True

MESSAGE_STORAGE

'django.contrib.messages.storage.user_messages.LegacyFallbackStorage'

DATABASE_HOST

''

IGNORABLE_404_STARTS

('/cgi-bin/', '/_vti_bin', '/_vti_inf')

SEND_BROKEN_LINK_EMAILS

False

URL_VALIDATOR_USER_AGENT

'Django/1.3.1 (http://www.djangoproject.com)'

STATICFILES_FINDERS

('django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder')

FILEBROWSER_DIRECTORY

'uploads/'

SESSION_COOKIE_DOMAIN

None

SESSION_COOKIE_NAME

'sessionid'

FILEBROWSER_IMAGE_GENERATOR_PORTRAIT

[('tiny_', 64), ('smaller_', 128)]

COMMENTS_MODERATORS_GROUP

None

TIME_INPUT_FORMATS

('%H:%M:%S', '%H:%M')

DATABASES

{'default': {'ENGINE': 'django.db.backends.mysql',
'HOST': '',
'NAME': 'temwiki',
'OPTIONS': {},
'PASSWORD': '********************',
'PORT': '',
'TEST_CHARSET': None,
'TEST_COLLATION': None,
'TEST_MIRROR': None,
'TEST_NAME': None,
'TIME_ZONE': 'Europe/Berlin',
'USER': 'temwiki'}}

HOST_ADDR

'http://www-elektronenmikroskopie.uni-regensburg.de/'

FILE_UPLOAD_PERMISSIONS

None

FILE_UPLOAD_HANDLERS

('django.core.files.uploadhandler.MemoryFileUploadHandler',
'django.core.files.uploadhandler.TemporaryFileUploadHandler')

DEFAULT_CONTENT_TYPE

'text/html'

APPEND_SLASH

True

FIRST_DAY_OF_WEEK

0

DATABASE_ROUTERS

[]

ANW_MAIN

'wiki'

YEAR_MONTH_FORMAT

'F Y'

STATICFILES_STORAGE

'django.contrib.staticfiles.storage.StaticFilesStorage'

CACHES

{'default': {'BACKEND':
'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': ''}}

STAMPIT_DEFAULT_PHOTOS_PER_PAGE

8

FILEBROWSER_URL_ADMIN

'/admin/filebrowser/'

SESSION_COOKIE_PATH

'/'

FILEBROWSER_IMAGE_CROP_GENERATOR

[('cropped_', 64, 64), ('croppedthumbnail_', 128, 128)]

USE_X_FORWARDED_HOST

False

WIKI_THEME

'tem'

IGNORABLE_404_ENDS

('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico',
'.php')

HTTPS_SUPPORT

True

MIDDLEWARE_CLASSES

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

USE_I18N

True

THOUSAND_SEPARATOR

','

SECRET_KEY

'********************'

FILEBROWSER_DEBUG

True

LANGUAGE_COOKIE_NAME

'django_language'

FILE_UPLOAD_TEMP_DIR

None

TRANSACTIONS_MANAGED

False

LOGGING_CONFIG

'django.utils.log.dictConfig'

TEMPLATE_LOADERS

('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader')

TEMPLATE_DEBUG

True

AUTHENTICATION_BACKENDS

('django.contrib.auth.backends.ModelBackend',)

TEST_DATABASE_COLLATION

None

FORCE_SCRIPT_NAME

None

CACHE_BACKEND

'locmem://'

SESSION_COOKIE_SECURE

False

TINYMCE_SPELLCHECKER

True

CSRF_COOKIE_DOMAIN

None

FILE_CHARSET

'utf-8'

DEBUG

True

SESSION_FILE_PATH

None

DEFAULT_FILE_STORAGE

'django.core.files.storage.FileSystemStorage'

INSTALLED_APPS

['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'grappelli.dashboard',
'grappelli',
'filebrowser',
'django.contrib.admin',
'tinymce',
'tagging',
'dajaxice',
'dajax',
'aintnowiki.wiki',
'aintnowiki.stampit',
'aintnowiki.captcha',
'aintnowiki.users',
'aintnowiki.tem_status']

LANGUAGES_BIDI

('he', 'ar', 'fa')

DATABASE_ENGINE

''

DATABASE_NAME

''

COMMENTS_FIRST_FEW

0

FILEBROWSER_PATH_TINYMCE

'/var/aintnowiki/media/js/tiny_mce/'

PREPEND_WWW

False

SESSION_COOKIE_HTTPONLY

False

DATABASE_PORT

''

STAMPIT_DEFAULT_FRAME

None

DEBUG_PROPAGATE_EXCEPTIONS

False

TINYMCE_FILEBROWSER

True

MONTH_DAY_FORMAT

'F j'

LOGIN_URL

'/users/login/'

SESSION_EXPIRE_AT_BROWSER_CLOSE

False

TINYMCE_JS_URL

'/media/js/tiny_mce/tiny_mce_src.js'

TIME_FORMAT

'P'

WIKI_PAGELOCK_TIMEOUT

1800

FILEBROWSER_URL_WWW

'http://www-elektronenmikroskopie.uni-regensburg.de/media/uploads'

DATE_INPUT_FORMATS

('%Y-%m-%d',
'%m/%d/%Y',
'%m/%d/%y',
'%b %d %Y',
'%b %d, %Y',
'%d %b %Y',
'%d %b, %Y',
'%B %d %Y',
'%B %d, %Y',
'%d %B %Y',
'%d %B, %Y')

CSRF_COOKIE_NAME

'csrftoken'

EMAIL_HOST_PASSWORD

'********************'

PASSWORD_RESET_TIMEOUT_DAYS

'********************'

CACHE_MIDDLEWARE_ALIAS

'default'

SESSION_SAVE_EVERY_REQUEST

False

ADMIN_MEDIA_PREFIX

'/media/static/grappelli/'

NUMBER_GROUPING

0

WIKI_CAT_PAGES_PER_VIEW

15

SESSION_ENGINE

'django.contrib.sessions.backends.db'

CSRF_FAILURE_VIEW

'aintnowiki.users.views.my403'

COMMENTS_SKETCHY_USERS_GROUP

None

LOGIN_REDIRECT_URL

'/accounts/profile/'

WIKI_DEFAULT_PUBLIC_WRITE

False

FILEBROWSER_IMAGE_GENERATOR_LANDSCAPE

[('tiny_', 64), ('smaller_', 128)]

LOGGING

{'disable_existing_loggers': False,
'handlers': {'mail_admins': {'class':
'django.utils.log.AdminEmailHandler',
'level': 'ERROR'}},
'loggers': {'django.request': {'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True}},
'version': 1}

CACHE_MIDDLEWARE_KEY_PREFIX

''

LOCALE_PATHS

()

TEMPLATE_STRING_IF_INVALID

''

DISALLOWED_USER_AGENTS

()

COMMENTS_ALLOW_PROFANITIES

False

LOGOUT_URL

'/accounts/logout/'

EMAIL_USE_TLS

False

TEMPLATE_DIRS

('/var/aintnowiki/templates',
'/var/aintnowiki/filebrowser/templates',
'/var/aintnowiki/tinymce/templates')

FIXTURE_DIRS

()

EMAIL_HOST

'localhost'

DATE_FORMAT

'N j, Y'

MEDIA_ROOT

'/var/aintnowiki/media/'

ADMINS

(('Andreas Hasenkopf', 'webmaster@hasenkopf2000.net'),)

FORMAT_MODULE_PATH

None

DEFAULT_FROM_EMAIL

'webmaster@localhost'

WIKI_DEFAULT_PUBLIC_READ

True

STATICFILES_DIRS

()

MEDIA_URL

'http://www-elektronenmikroskopie.uni-regensburg.de/media/'

DATETIME_FORMAT

'N j, Y, P'

EMAIL_SUBJECT_PREFIX

'[Django] '

SITE_ID

1

DAJAXICE_DEBUG

True

ALLOWED_INCLUDE_ROOTS

()

FILEBROWSER_URL_TINYMCE

'/media/js/tiny_mce/'

DECIMAL_SEPARATOR

'.'

SHORT_DATE_FORMAT

'm/d/Y'

DATABASE_USER

''

TEST_DATABASE_NAME

None

TEST_RUNNER

'django.test.simple.DjangoTestSuiteRunner'

TIME_ZONE

'Europe/Berlin'

FILE_UPLOAD_MAX_MEMORY_SIZE

2621440

EMAIL_BACKEND

'django.core.mail.backends.smtp.EmailBackend'

DEFAULT_TABLESPACE

''

TEMPLATE_CONTEXT_PROCESSORS

('django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages')

FILEBROWSER_PATH_SERVER

'/var/aintnowiki/media/uploads'

SESSION_COOKIE_AGE

1209600

SETTINGS_MODULE

'aintnowiki.settings'

USE_ETAGS

False

TINYMCE_COMPRESSOR

False

LANGUAGES

(('ar', 'Arabic'),
('az', 'Azerbaijani'),
('bg', 'Bulgarian'),
('bn', 'Bengali'),
('bs', 'Bosnian'),
('ca', 'Catalan'),
('cs', 'Czech'),
('cy', 'Welsh'),
('da', 'Danish'),
('de', 'German'),
('el', 'Greek'),
('en', 'English'),
('en-gb', 'British English'),
('es', 'Spanish'),
('es-ar', 'Argentinian Spanish'),
('es-mx', 'Mexican Spanish'),
('es-ni', 'Nicaraguan Spanish'),
('et', 'Estonian'),
('eu', 'Basque'),
('fa', 'Persian'),
('fi', 'Finnish'),
('fr', 'French'),
('fy-nl', 'Frisian'),
('ga', 'Irish'),
('gl', 'Galician'),
('he', 'Hebrew'),
('hi', 'Hindi'),
('hr', 'Croatian'),
('hu', 'Hungarian'),
('id', 'Indonesian'),
('is', 'Icelandic'),
('it', 'Italian'),
('ja', 'Japanese'),
('ka', 'Georgian'),
('km', 'Khmer'),
('kn', 'Kannada'),
('ko', 'Korean'),
('lt', 'Lithuanian'),
('lv', 'Latvian'),
('mk', 'Macedonian'),
('ml', 'Malayalam'),
('mn', 'Mongolian'),
('nl', 'Dutch'),
('no', 'Norwegian'),
('nb', 'Norwegian Bokmal'),
('nn', 'Norwegian Nynorsk'),
('pa', 'Punjabi'),
('pl', 'Polish'),
('pt', 'Portuguese'),
('pt-br', 'Brazilian Portuguese'),
('ro', 'Romanian'),
('ru', 'Russian'),
('sk', 'Slovak'),
('sl', 'Slovenian'),
('sq', 'Albanian'),
('sr', 'Serbian'),
('sr-latn', 'Serbian Latin'),
('sv', 'Swedish'),
('ta', 'Tamil'),
('te', 'Telugu'),
('th', 'Thai'),
('tr', 'Turkish'),
('uk', 'Ukrainian'),
('ur', 'Urdu'),
('vi', 'Vietnamese'),
('zh-cn', 'Simplified Chinese'),
('zh-tw', 'Traditional Chinese'))

DEFAULT_INDEX_TABLESPACE

''

INTERNAL_IPS

()

STATIC_URL

'/media/static/'

EMAIL_PORT

25

SHORT_DATETIME_FORMAT

'm/d/Y P'

WIKI_MAINPAGE

'welcome'

TINYMCE_DEFAULT_CONFIG

{'body_id': 'pages_body',
'content_css': 'http://www-elektronenmikroskopie.uni-regensburg.de/
media/themes/tem/css/theme.css
',
'height': '30em',
'plugins':
'autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template',
'relative_urls': 'true',
'skin': 'o2k7',
'skin_variant': 'silver',
'theme': 'advanced',
'theme_advanced_buttons1':
'bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,attribs,styleprops',
'theme_advanced_buttons2':
'fontselect,fontsizeselect,|,tablecontrols,',
'theme_advanced_buttons3':
'cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,',
'theme_advanced_buttons4':
'visualchars,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,preview,fullscreen,code,spellchecker',
'theme_advanced_resizing': 'true',
'theme_advanced_statusbar_location': 'bottom',
'theme_advanced_toolbar_align': 'left',
'theme_advanced_toolbar_location': 'top',
'width': '100%'}

ABSOLUTE_URL_OVERRIDES

{}

DATABASE_OPTIONS

{}

CACHE_MIDDLEWARE_SECONDS

600

BANNED_IPS

()

DAJAXICE_NOTIFY_EXCEPTIONS

True

DATETIME_INPUT_FORMATS

('%Y-%m-%d %H:%M:%S',
'%Y-%m-%d %H:%M',
'%Y-%m-%d',
'%m/%d/%Y %H:%M:%S',
'%m/%d/%Y %H:%M',
'%m/%d/%Y',
'%m/%d/%y %H:%M:%S',
'%m/%d/%y %H:%M',
'%m/%d/%y')

DATABASE_PASSWORD

'********************'

ADMIN_FOR

()

PROFANITIES_LIST

'********************'

EMAIL_HOST_USER

''

COMMENTS_BANNED_USERS_GROUP

None

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

EuroPython 2012: Call for Proposal is Open!

Hi all,
I'm Francesco and I am writing on behalf of EuroPython Staff
(www.europython.eu). We are happy to announce that the Call for
Proposals is now officially open!

DEADLINE FOR PROPOSALS: MARCH 18TH, 23:59:59 CET

For those who have never been at EuroPython (or similar conferences)
before, the Call for Proposals is the period in which the organizers
ask the community to submit proposals for talks to be held at the
conference.

EuroPython is a conference run by the community for the community: the
vast majority of talks that are presented at the conference will be
proposed, prepared and given by members of the Python community
itself.

And not only that: the process that selects the best talks among all
the proposals will also be public and fully driven by the community:
it's called Community Voting, and will begin right after the Call for
Proposals ends.


CFP: Talks, Hands-On Trainings and Posters
------------------------------------------

We're looking for proposals on every aspect of Python: programming
from novice to advanced levels, applications and frameworks, or how
you have been involved in introducing Python into your organisation.

There are three different kind of contribution that you can present at
EuroPython:
- Regular talk. These are standard "talk with slides", allocated in
slots of 45, 60 or 90 minutes, depending on your preference and
scheduling constraints. A Q&A session is held at the end of the talk.
- Hands-on training. These are advanced training sessions for a
smaller audience (10-20 people), to dive into the subject with all
details. These sessions are 4-hours long, and the audience will be
strongly encouraged to bring a laptop to experiment. They should be
prepared with less slides and more source code.
- Posters. Posters are a graphical way to describe a project or a
technology, printed in large format; posters are exhibited at the
conference, can be read at any time by participants, and can be
discussed face to face with their authors during the poster session.
We will take care of printing the posters too, so don't worry about
logistics.

More details about Call for Proposal are online here:
https://ep2012.europython.eu/call-for-proposals/


Don't wait for the last day
---------------------------

If possible, please avoid submitting your proposals on the last day.
It might sound a strange request, but last year about 80% of the
proposals were submitted in the last 72 hours. This creates a few
problems for organizers because we can't have a good picture of the
size of the conference until that day.

Remember that proposals are fully editable at any time, even after the
Call for Proposals ends. You just need to login on the website, go to
the proposal page (linked from your profile page), and click the Edit
button.

First-time speakers are especially welcome; EuroPython is a community
conference and we are eager to hear about your experience. If you have
friends or colleagues who have something valuable to contribute, twist
their arms to tell us about it!

Please also forward this Call for Proposals to anyone that you feel
may be interested.

All the best,

Francesco

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

humanized date range and translation

Hello,

I am working on a Django application for handling events with schedules. Basically an event has a starting and ending date and contains sessions, each with a date and starting and ending time (current code is at https://gitorious.org/django-seminar/). The application is internationalized.

I want to present the date range of an event in a humanized form, using formulations that depend on the particular range at hand, like
  • May 4th, 2012
  • from May 3rd to 5th, 2012 (not sure this is the proper phrasing in English, btw)
  • from April 23rd to May 2nd, 2012
  • from December 27th, 2012 to January 4th, 2013
Obviously, I want this to be translated properly. What would be a proper way to do this?
I came up with two ideas for solving the question, but neither one is fully satisfactory:
  1. use a combination of translatable format strings, like "from %(begin)s to %(end)s" (one for each case) plus one or two translatable strftime format for each case, but that makes for a dozen techincal messages to translate;
  2. use a Python function for formatting, one for each language, stored in a module like locale.en.formats, and use the proper function depending on the context, but that requires some complicated machinery, unless some infrastructure already exists for that.
As a related point, I want to format single dates within this range in a humanized fashion that depends on the context (when presenting a schedule, or in selection lists in forms). For instance, if the date range is from Monday, May 7h to Friday, May 11th, I want to simpy say "Tuesday" or "Tuesday 8th" instead of "May 8th, 2012", since the month and year are known from the context. This, too, combines translation and context dependent formatting.

I am probably not the first one to face this situation. How do people usually cope with this?

--
Emmanuel

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/wO7QKgUZn1cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: using django templates to generate and replace a file

Thanks Kurtis,

It seems so obvious now! :-)

I can do ...

t = Template(open('users.template').read())
c = Context([get the users from db])
open('users.cfg','w').write(t.render(c))

Thanks for your speedy response! It seems I couldn't see the wood for
the trees
-Paul

On Feb 29, 8:24 pm, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> Hey,
>
> I just thought I'd give you a quick reply. First, you can save the rendered
> output of a template using this:
>
> https://docs.djangoproject.com/en/1.3/ref/templates/api/#rendering-a-...
>
> Then, take that String and write over that 'users.cfg' file. For example,
>
> http://docs.python.org/tutorial/inputoutput.html
>
> Hopefully that helps a little bit. I'm not sure if I understand the problem
> right but I figured I'd give it a shot.
>
> Good luck!
> - Kurtis
>
> On Wed, Feb 29, 2012 at 4:27 PM, Paul Bunker <paulmarkbun...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Hi Django Users,
>
> > I'd like to use the django template system to generate a file
> > 'users.cfg' that gets read some dispatching software. Is it possible
> > to get django  to generate this file and replace the existing one?
>
> > Thanks
> > -Paul
>
> > --
> > 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
> > django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Django TypeError-/SEARCH/

Hi guys, I want to create a search form for my django site. So after
creating it, I input the keyword I want to search, after clicking on
"Search" I'm getting:

TypeError at /search/
Related Field has invalid lookup: icontains
Request Method: GET
Request URL: http://127.0.0.1:8000/search/?q=lordme
Django Version: 1.3.1
Exception Type: TypeError
Exception Value: Related Field has invalid lookup: icontains
Exception Location: C:\Python27\lib\site-packages\django\db\models
\fields\related.py in get_prep_lookup, line 141
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2

Below are my codes:

Models:
#I just paste this in models.

def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
''' Splits the query string in invidual keywords, getting rid of
unecessary spaces
and grouping quoted words together.
Example:

>>> normalize_query(' some random words "with quotes "
and spaces')
['some', 'random', 'words', 'with quotes', 'and', 'spaces']

'''
return [normspace(' ', (t[0] or t[1]).strip()) for t in
findterms(query_string)]

def get_query_set(query_string, search_fields):
''' Returns a query, that is a combination of Q objects. That
combination
aims to search keywords within a model by testing the given
search fields.

'''
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each
field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
or_query = q
else:
or_query = or_query | q
if query is None:
query = or_query
else:
query = query & or_query
return query

Views:

from myweb.meekapp.models import get_query_set
def search(request):
query_string = ''
found_entries = None
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']

entry_query = get_query_set(query_string, ['user'])

found_entries =
UserProfile.objects.filter(entry_query).order_by('-pub_date')


return render_to_response('search_form.html',
{ 'query_string': query_string,
'found_entries': found_entries },
context_instance=RequestContext(request))
Template:

<html>
<head>
<title>Search</title>
</head>
<body>
<form action="" method="get">
<input type="text" name="q">
<input type="submit" value="Search">
</form>
</body>
</html>

What am I missing?

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.