Re: Django in production on Windows

2010-12-08 Thread ashdesigner
Sam,

That's exactly what we arrived at: PyISAPIe doesn't work with IIS, so
I will install an Apache pack on Windows.

We've already launched a VMWare (Win VPS) with no IIS running on it,
and I lean to XAMPP as an appropriate Apache out-of-box pack to run on
the Win platform. What would you say? Will it do for development AND
production modes? Or shall I 'poke around' any other Apache distro?

p.s. The only thing I would avoid is dealing purely with Apache
configs: I need a distro to be set up and running asap, that's why I'm
thinking of XAMPP.

Anthony

On 8 дек, 06:54, Sam Lai  wrote:
> Eeek. Just had a poke around with getting Django running on IIS.
>
> Making it work with FastCGI will need a bit of work; doesn't work out
> of the box and isn't well documented as most of the focus has been on
> PHP.
>
> It does seem to work ok with PyISAPIe. I'd probably install Apache and
> use that instead though, either replacing IIS, or using IIS as a
> reverse proxy to Apache.
>
> On 8 December 2010 11:07, Sam Lai  wrote:
>
> > On 8 December 2010 02:50, shmengie <1st...@gmail.com> wrote:
> >>www.cygwin.comis one possible windows avenue that might work.  When I
> >> was hanging on to windows because I had to support it, I used cygwin
> >> religiously.  I found a lot about cygwin to be frustrating, but it was
> >> better than being w/out unix/linux all-together.
>
> > That isn't really going to help. The issue isn't *nix compatibility,
> > but connecting Django with IIS. FastCGI is the official way to go; the
> > other ISAPI modules are the next best thing.
>
> > I work with both platforms, and I've lost count the number of times
> > I've typed 'ls' into a Windows command prompt and have it error out :)
> > Luckily it works in PowerShell, which is one of the things that
> > Windows does that's better than *nix.
>
> >> Unless you absolutely positively must remain a Windows/Microsoft
> >> supporter, I recommend grabbing an old decommissioned box and slap
> >> Linux on it.  It's gotten a lot easier with the latest distributions.
> >> I use Ubuntu for most, but Cent-os might be just what you need, and
> >> I've heard good things about Mint, but haven't gone there.  If you can
> >> live without the Xwindows/GUI almost *any* machine will work and
> >> perform just fine.  W/Google and apt-get command line, you should be
> >> able to get a box up and running inside of a couple of hours.
>
> > It doesn't work like that in corporate environments. You can't just
> > set up a box and connect it to the network - the IT admins will scream
> > at you (at the very least). They need to be properly assessed,
> > configured, and most importantly maintained - an improperly
> > maintained/configured *nix box isn't secure either. And as OP doesn't
> > have any *nix admins, it isn't going to happen unless they hire or
> > outsource.
>
> >> I can imagine Linux is frightening, but it doesn't need to be.  For me
> >> it's like a big box of toys, you might have to do a fair amount of
> >> reading, but there's a lot of good documentation and Google can be
> >> your friend.  I prefer googling linux issues over Microsoft Technet
> >> issues.  Tech-net can be such a royal PITA.
>
> > It isn't utopia on the Linux side either - with the slight variations
> > between every Linux distro, often solutions you find don't exactly
> > work because of some annoying difference (versions, config paths,
> > location of files, default packages etc.).
>
> >> Argh, soo far off topic, my apologies.
>
> > So back to on to the topic -
>
> > Is the issue that FastCGI isn't up to scratch in terms of performance,
> > or is it not working at all?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to 
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group 
> >> athttp://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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: newbie question: @login_required, can't get it to work

2010-12-08 Thread Martin Melin
On Thu, Dec 9, 2010 at 8:04 AM, Charlietuna  wrote:
> Hi All,
>
> I'm a newbie. I would like to use the @login_required decorator, but I
> don't want to redirect to the standard default accounts/login. I would
> like to redirect to '/login/'
>
> The book says add the following to the end of the settings.py file.:
>
> import django.contrib.auth
> django.contrib.auth.LOGIN_URL = '/login/'

Not sure where you're getting this information from, but assuming
you're using the latest Django:

http://docs.djangoproject.com/en/dev/ref/settings/#std:setting-LOGIN_URL

i.e. you should be using settings.LOGIN_URL and not
django.contrib.auth.LOGIN_URL since at least 1.0

Cheers,
Martin Melin

>
> The server says: GET /accounts/login/?login/=/save/ HTTP/1.1  404 2273
> I assume that it is going the path:
>
> /account/login/login
>
> Any help would be appreciated!
>
> Thanks,
>
> Steve

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



Re: newbie question: @login_required, can't get it to work

2010-12-08 Thread robin nanola
on your settings.py you can just add  LOGIN_URL = '/login/'

On Thu, Dec 9, 2010 at 3:04 PM, Charlietuna  wrote:

> Hi All,
>
> I'm a newbie. I would like to use the @login_required decorator, but I
> don't want to redirect to the standard default accounts/login. I would
> like to redirect to '/login/'
>
> The book says add the following to the end of the settings.py file.:
>
> import django.contrib.auth
> django.contrib.auth.LOGIN_URL = '/login/'
>
>
> The server says: GET /accounts/login/?login/=/save/ HTTP/1.1  404 2273
> I assume that it is going the path:
>
> /account/login/login
>
> Any help would be appreciated!
>
> Thanks,
>
> Steve
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



newbie question: @login_required, can't get it to work

2010-12-08 Thread Charlietuna
Hi All,

I'm a newbie. I would like to use the @login_required decorator, but I
don't want to redirect to the standard default accounts/login. I would
like to redirect to '/login/'

The book says add the following to the end of the settings.py file.:

import django.contrib.auth
django.contrib.auth.LOGIN_URL = '/login/'


The server says: GET /accounts/login/?login/=/save/ HTTP/1.1  404 2273
I assume that it is going the path:

/account/login/login

Any help would be appreciated!

Thanks,

Steve

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



Re: django-extensions - "Error: no module named django_extensions"

2010-12-08 Thread Victor Hooi
heya,


Thanks for the reply. I'm fairly sure it is in the PYTHONPATH.


I'm using virtualenvs and pip to install, so it should be there in the
system-wide Python directory for that environment.


Also, as per my first post, I can import it fine from a Python shell,
it's just it seems to act up within Django...*confused*.


Cheers,
Victor

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



Re: FileField and location and storage

2010-12-08 Thread Sam Lai
Some more background -

If you look at lines 228 to 230 of django/db/models/fields/files.py,
you'll see that the generate_filename method is overwritten by your
upload_to method if you specify one.

228 self.upload_to = upload_to
229 if callable(upload_to):
230 self.generate_filename = upload_to

On 9 December 2010 15:43, Sam Lai  wrote:
> I have a custom file storage working with a specific subdir structure.
>
> Did you pass in a method specifying the path in the upload_to kwarg
> for FileField?
>
> Here's my model code, where EnhancedFileSystemStorage is my custom
> file storage class, and get_random_dir_name is just a helper method
> that does exactly as named.
>
>    file_storage = EnhancedFileSystemStorage(location=settings.DYNMEDIA_ROOT,
>                                             base_url=settings.DYNMEDIA_URL)
>
>    def file_upload_to(instance, filename):
>        return os.path.join(get_random_dir_name(instance.file_storage.location,
> filename), filename)
>
>    file = models.FileField(upload_to=file_upload_to, storage=file_storage)
>
> On 9 December 2010 05:24, dmitry b  wrote:
>> Hi,
>>
>> I've written a custom Storage that uses WebDAV as its underlying
>> engine.  When I save a file '/foo/bar/file.ext', I want it to be saved
>> under /foo/bar in the webdav filesystem.  However, it seems that
>> FileField overrides the directory structure:
>>
>>    def generate_filename(self, instance, filename):
>>        return os.path.join(self.get_directory_name(),
>> self.get_filename(filename))
>>
>> where get_directory_name() is defined as
>>
>>    def get_directory_name(self):
>>        return
>> os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to
>>
>> I'm not really sure why FileField finds it appropriate to impose its
>> own directory structure on the underlying storage engine.  But short
>> of creating a custom subclass of FileField and overriding
>> generate_filename and/or get_directory_name(), is there a different
>> way of preserving the original file location path?
>>
>>
>> Thanks
>> Dmitry
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django-extensions - "Error: no module named django_extensions"

2010-12-08 Thread Christophe Pettus

On Dec 8, 2010, at 6:48 PM, Victor Hooi wrote:
> Not sure what's going on here?

Is the django_extensions module on your PYTHONPATH?

--
-- Christophe Pettus
   x...@thebuild.com

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



Re: FileField and location and storage

2010-12-08 Thread Sam Lai
I have a custom file storage working with a specific subdir structure.

Did you pass in a method specifying the path in the upload_to kwarg
for FileField?

Here's my model code, where EnhancedFileSystemStorage is my custom
file storage class, and get_random_dir_name is just a helper method
that does exactly as named.

file_storage = EnhancedFileSystemStorage(location=settings.DYNMEDIA_ROOT,
 base_url=settings.DYNMEDIA_URL)

def file_upload_to(instance, filename):
return os.path.join(get_random_dir_name(instance.file_storage.location,
filename), filename)

file = models.FileField(upload_to=file_upload_to, storage=file_storage)

On 9 December 2010 05:24, dmitry b  wrote:
> Hi,
>
> I've written a custom Storage that uses WebDAV as its underlying
> engine.  When I save a file '/foo/bar/file.ext', I want it to be saved
> under /foo/bar in the webdav filesystem.  However, it seems that
> FileField overrides the directory structure:
>
>    def generate_filename(self, instance, filename):
>        return os.path.join(self.get_directory_name(),
> self.get_filename(filename))
>
> where get_directory_name() is defined as
>
>    def get_directory_name(self):
>        return
> os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to
>
> I'm not really sure why FileField finds it appropriate to impose its
> own directory structure on the underlying storage engine.  But short
> of creating a custom subclass of FileField and overriding
> generate_filename and/or get_directory_name(), is there a different
> way of preserving the original file location path?
>
>
> Thanks
> Dmitry
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: percentage of models given field value?

2010-12-08 Thread Lachlan Musicman
On Thu, Dec 9, 2010 at 14:13, Lachlan Musicman  wrote:
> On Thu, Nov 25, 2010 at 16:00, Christophe Pettus  wrote:
>>
>> On Nov 24, 2010, at 8:13 PM, Lachlan Musicman wrote:
>>> Thanks Christopher. I've never done raw SQL in Django before. This may
>>> seem like a silly follow up question, but is it standard practice to
>>> put the relevant code, as described by the documentation
>>> (http://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly
>>> ) into views.py?
>>
>> Oh, and: Another very logical place to put this is in a custom Manager 
>> subclass for the relevant Model; there's documentation on that usage in the 
>> docs:
>>
>>        
>> http://docs.djangoproject.com/en/1.2/topics/db/managers/#adding-extra-manager-methods
>>
>
> I've successfully got the data I was after, and I've even got it into
> the template with success - thankyou!
>
> The problem I now have is that the data returned has the format:
>
> language,number,percent
>
> where language = short language code.
>
> In the template I'd like to represent language in it's long form, but
> am having all types of trouble getting it to do so. I have the longs
> in a dictionary in my models.py, in my views.py I've created a smaller
> dict of long_langs, but how do I then match them in the template?
>
> Here's some of my template attempts:
>
> these proved that the data is coming through to the template
> {{ target_stats }}
> {# {{ long_langs  }} #}
> {#  {{ lang_dict }}  #}
>
> These loops didn't work (for obvious reasons...)
>
>  {% for language, number, percent in target_stats %}
>        {{ long_lang.foorloop.counter }} {{ number }} {{ percent }} 
>  {% endfor %}
>
> and
>
>  {% for language, number, percent in target_stats %}
>        {{ lang_dict[language] }} {{ number }} {{ percent }} 
>  {% endfor %}
>
> there have been a few other attempts - mostly riffs on those
> themes...I even tried a
> for(for(if))) but nothing came out.
>
> I'm confused about how to get this right


Ignore - I got this within 5 minutes of posting. God.damn.it.



-- 
"... imagine a puddle waking up one morning and thinking, 'This is an
interesting world I find myself in - an interesting hole I find myself
in - fits me rather neatly, doesn't it? In fact it fits me
staggeringly well, must have been made to have me in it!' This is such
a powerful idea that as the sun rises in the sky and the air heats up
and as, gradually, the puddle gets smaller and smaller, it's still
frantically hanging on to the notion that everything's going to be
alright, because this world was meant to have him in it, was built to
have him in it; so the moment he disappears catches him rather by
surprise."
Douglas Adams

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



Re: percentage of models given field value?

2010-12-08 Thread Lachlan Musicman
On Thu, Nov 25, 2010 at 16:00, Christophe Pettus  wrote:
>
> On Nov 24, 2010, at 8:13 PM, Lachlan Musicman wrote:
>> Thanks Christopher. I've never done raw SQL in Django before. This may
>> seem like a silly follow up question, but is it standard practice to
>> put the relevant code, as described by the documentation
>> (http://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly
>> ) into views.py?
>
> Oh, and: Another very logical place to put this is in a custom Manager 
> subclass for the relevant Model; there's documentation on that usage in the 
> docs:
>
>        
> http://docs.djangoproject.com/en/1.2/topics/db/managers/#adding-extra-manager-methods
>

I've successfully got the data I was after, and I've even got it into
the template with success - thankyou!

The problem I now have is that the data returned has the format:

language,number,percent

where language = short language code.

In the template I'd like to represent language in it's long form, but
am having all types of trouble getting it to do so. I have the longs
in a dictionary in my models.py, in my views.py I've created a smaller
dict of long_langs, but how do I then match them in the template?

Here's some of my template attempts:

these proved that the data is coming through to the template
{{ target_stats }}
{# {{ long_langs  }} #}
{#  {{ lang_dict }}  #}

These loops didn't work (for obvious reasons...)

  {% for language, number, percent in target_stats %}
{{ long_lang.foorloop.counter }} {{ number }} {{ percent }} 
  {% endfor %}

and

  {% for language, number, percent in target_stats %}
{{ lang_dict[language] }} {{ number }} {{ percent }} 
  {% endfor %}

there have been a few other attempts - mostly riffs on those
themes...I even tried a
for(for(if))) but nothing came out.

I'm confused about how to get this right

cheers
L.

-- 
"... imagine a puddle waking up one morning and thinking, 'This is an
interesting world I find myself in - an interesting hole I find myself
in - fits me rather neatly, doesn't it? In fact it fits me
staggeringly well, must have been made to have me in it!' This is such
a powerful idea that as the sun rises in the sky and the air heats up
and as, gradually, the puddle gets smaller and smaller, it's still
frantically hanging on to the notion that everything's going to be
alright, because this world was meant to have him in it, was built to
have him in it; so the moment he disappears catches him rather by
surprise."
Douglas Adams

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



Re: running app in backend

2010-12-08 Thread Rendy Anthony
I recommend you to check on celery if you need to run background process. It
has a good django support and can allows you to run periodic tasks.
On Dec 9, 2010 8:44 AM, "commonzenpython"  wrote:
> hey guys, im trying to run a script in the backend of my django
> project, i have used django signals to call my script and run it when
> foo class is saved, and in the foo class theres a variable that can be
> true or false, if its true it calls an infinte loop that runs a
> function every x seconds, but since this is an infinite loop, its
> keeping the django HTTPRequest active, so the page never finishes
> loading, is there a way to bipass this behavior ?
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django-extensions - "Error: no module named django_extensions"

2010-12-08 Thread Victor Hooi
heya,


I original thought to post this in the django-extensions group, however
that seems like a fairly low-traffic group, so I thought I'd post here
in the hopes somebody here might be able to figure it out.


Basically, I've installed django-extensions via Pip
pip install django-extensions
Whenever I try to run any manage.py commands in my project, I get an
error:
Error: No module named django_extensions
In my settings.py, I have:
INSTALLED_APPS = (

'django_extensions',
In the Python shell,I can do a "import django_extensions" and it
imports fine with no error messages.


Not sure what's going on here?


I also tried with django-extensions from Github, same error.


Cheers,
Victor

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



django session InvalidOperation

2010-12-08 Thread kinder
I'm fairly new to Django, and I'm trying to move an existing Django
application to a new server. The old server is running Django 1.0.2
and Python 2.5.4. The closest I could come on my new server (to start)
is Django 1.0.4 and Python 2.5.5.

Anyway, I get an admin login screen, but when I try to log in, I get
an error:

Exception Type: InvalidOperation
Exception Value:Invalid literal for Decimal: '2010-12-22 17:36:30'
Exception Location: build/bdist.linux-i686/egg/MySQLdb/connections.py
in defaulterrorhandler, line 35

If I'm reading the error page right, it looks like it's happening in
db/models/query.py, somewhere around here:

 316. clone = self.filter(*args, **kwargs)
 317. num = len(clone) ...

Any advice on how to get past this?

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



running app in backend

2010-12-08 Thread commonzenpython
hey guys, im trying to run a script in the backend of my django
project, i have used django signals to call my script and run it when
foo class is saved, and in the foo class theres a variable that can be
true or false, if its true it calls an infinte loop that runs a
function every x seconds, but since this is an infinite loop, its
keeping the django HTTPRequest active, so the page never finishes
loading, is there a way to bipass this behavior ?

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



Re: __init__.py file executed twice ?

2010-12-08 Thread Mike Dewhirst

On 9/12/2010 5:10am, martvefun wrote:



On 08-12-10 18:39, Tom Evans wrote:

On Wed, Dec 8, 2010 at 4:52 PM, martvefun  wrote:

Hello,

I'd like to start some threads when the server launch to listen to
events (I'm doing message passing).

To do so, I guess I should be using the __init__.py file at the root of
my project (by the way, what's the used of the other __init__.py files
in the apps)

I've tried with a simple test by only having 'print "starting server"'
into the file and the result is :

$ python manage.py runserver
starting server
starting server
Validating models...
0 errors found

Django version 1.2.3, using settings 'website.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Why the file is executed twice ? I don't want to have twice the same
threads.

Thank you

mart



__init__.py files aren't executed at the start of programs, the
presence of them denotes that a directory is a python module, and the
__init__.py is executed when that module is first imported under a
particular name.

Do you have a structure like this:

project
├── __init__.py
├── app1
│   └── __init__.py
└── app2
 ├── __init__.py
 └── models.py

and import from project.app2.models and from app2.models? That would
cause app2's __init__.py to be executed twice.

Cheers

Tom



Yes the structure of my project is more or less like that but I've not
two but 6 apps all with 'from django.db import models' in models.py
In several model (more than two), I'm using foreign keys to different
models.
For now the site doesn't do much, I'm using the database created with
the models in other files in the project folder.

So if the __init__.py is not a good place to start operations at server
startup, where should I put it ?


It seems like a good place to put it. Maybe you can test to see if the 
threads have been started already?


Here is a singleton which could live in your __init__.py and might help 
to record the state of your threading ... or anything else for that matter.


class singleton(object):
""" designed by Oren Tirosh and Jeff Pitman """
def __new__(self, *args, **kwargs):
if not '_singleton' in self.__dict__:
slate = object.__new__(self)
slate.state = {
'threads':True,
# add other state things as required
}
self._singleton = slate
return self._singleton

hth

Mike







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



CSRF missing token

2010-12-08 Thread martvefun
Hello,

I've a login form which give me an CSRF error.
In the documentation, I read that I needed to have in my code :

# views.py
...
csrf_token = {}
csrf_token.update(csrf(request))
return render_to_response('index.html', locals())

# index.html
...

 {% csrf_token %}

But I've an error that the two tokens are different
I guess the problem is in the generation of the token :


}' />


It should use value="{'csrf_ instead of value='{'csrf._..

Any idea how to fix ?

Thanks

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



Re: Query about GenericTabularInline

2010-12-08 Thread nathan
Sorry. Item 1 is my fault.
But I still haven't resolved item 2.

On Dec 7, 1:35 pm, Nathan Geffen  wrote:
> Hi
>
> I have set up a Generic inline (using generic.GenericTabularInline). It
> behaves differently (and from my application's point of view, wrongly) from
> the standard admin.TabularInline in two ways:
>
> 1. It doesn't have the plus icon next to foreign key fields that allows
> users to add new foreign objects directly from this view.
>
> 2. In settings.py I set TEMPLATE_STRING_IF_INVALID = 'PROGRAMMING ERROR!
> INVALID TEMPLATE STRING.'
> Unfortunately, this string then appears on the left of each entry in my
> GenericTabularInline.
>
> Have other people experienced this? If so, should I log this as a bug or am
> I doing something wrong or making a wrong assumption about how it should
> work?
>
> Thanks.
>
> Regards
> Nathan

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



WebHelpers in Django

2010-12-08 Thread Lukasz Szymanski
Hi guys.
Is it possible to add and use Webhelpers module ( http://webhelpers.groovie.org/
) in Django ?
or does anyone know something similar to this?

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



Re: can't add via admin, get django template error

2010-12-08 Thread Wayne Smith
On Wed, Dec 8, 2010 at 10:49 AM, JeffH  wrote:

> So I'm working along, everything's humming fine. Then I try to add a
> record via the admin, and get the following:
>
> TemplateSyntaxError at /admin/expert/expertresponse/add/
> Caught AttributeError while rendering: 'unicode' object has no
> attribute 'date'
>
> [snip]
>
> Template error
>
> In template c:\python26\lib\site-packages\django\contrib\admin
> \templates\admin\includes\fieldset.html, error at line 12
> Caught AttributeError while rendering: 'unicode' object has no
> attribute 'date'
> 2   {% if fieldset.name %}{{ fieldset.name }}{% endif %}
> 3   {% if fieldset.description %} class="description">{{ fieldset.description|safe }}{% endif %}
> 4   {% for line in fieldset %}
> 5   
> 6   {{ line.errors }}
> 7   {% for field in line %}
> 8    endif %}>
> 9   {% if field.is_checkbox %}
> 10  {{ field.field }}{{ field.label_tag }}
> 11  {% else %}
> 12  {{ field.label_tag }}{{ field.field }}
>
> I can add records via a ModelForm without problem, it just doesn't
> work in the admin.
>
> As you probably surmised from the error, the admin is expecting a field
attribute of type date on your  model object (line?).  Anyway, what is
getting passed is an Unicode object, which obviously does not have the
attribute (field) it is looking for.

I would guess that the problem lies somewhere in your admin file
(admin.py).  What are the contents of it?

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



Re: Django template tags.

2010-12-08 Thread Nuño Iglesias
El Wed, 8 Dec 2010 20:00:42 +0100
Łukasz Rekucki  escribió:
> 2010/12/8 Nuño Iglesias :
> >
> > What i'm trying to do is this:
> >   {{ mystring | upper }}
> > to convert "mystring" into upper-case.
> 
> AFAIR, there should be no spaces before or after "|":
> {{ variable|upper }}
> 
> 
Ups :-s


Thanks a lot, I have been 40 minutes reading about the marvellous
template system...getting crazy
Now I fell stupid...but very happy :)
Thanks a lot Łukasz



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



Re: How to use django-command-extentions dumpscript?

2010-12-08 Thread fei
Have you successfully installed django-extensions into python?

Here are the detailed instructions

http://code.google.com/p/django-command-extensions/wiki/InstallationInstructions

Fei

On Dec 8, 6:30 am, mongoose  wrote:
> Hi all,
>
> I'm trying out django-command-extensions I want to use the dumpscript
> command but I don't understand what I'm supposed to do to set it up.
>
> How to use django-command-extentions dumpscript?
>
> Thanks

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



Re: handling generated files

2010-12-08 Thread Mark (Nosrednakram)
On Dec 7, 7:55 pm, dmitry b  wrote:
> Hi,
>
> How do I use Django's FileField with autogenerated files?  That is,
> these files aren't uploaded by a user, but rather are created on the
> fly.  I've looked at ContentFile, but this class doesn't seem to have
> a way to attach a file name (the name is also computed at run-time
> based on some criteria).  Do I need to write my own implementation of
> File for this or am I missing an existing class?
>
> Thanks
> Dmitry

Hello,

I'm not sure I understand the question so am making the following
assumptions.  Sorry if this isn't what you are looking for.

   1. You know how to access the generated content.
   2. You want to serve the content as a file with a specific name.

For this example let's say your file is a CSV file with content in
FILE_CONTENT.  You will need to set a few thing up in you http
response to serve up a proper csv file.

response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=%s' %
'MyRandomFileName'
response.write(FILE_CONTENT)
return response

You can set other header options like Expires, Content-Length, etc. in
this fashion.

Hope I helped.
Mark

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



Re: Django template tags.

2010-12-08 Thread Łukasz Rekucki
2010/12/8 Nuño Iglesias :
>
> What i'm trying to do is this:
>   {{ mystring | upper }}
> to convert "mystring" into upper-case.

AFAIR, there should be no spaces before or after "|": {{ variable|upper }}


-- 
Łukasz Rekucki

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



Django template tags.

2010-12-08 Thread Nuño Iglesias
Hi, i think it's the first time i write to this list, so 
 Hello to everybody...¡¡


Well, now my problem.
I'm trying to use "template filters" in one of my templates.

What i'm trying to do is this:
   {{ mystring | upper }}
to convert "mystring" into upper-case.

but Django is complaining:
TemplateSyntaxError at /
Could not parse the remainder:'| upper' from 'row.0 | upper'

I suppose I've forgotten to import something...but I cant find it. 

Any help ?

Thanks.

Nuño

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



Re: ORA-01425

2010-12-08 Thread Jirka Vejrazka
OK - here's my 2 cents:

Django 1.2.1, Oracle 9.2.0.7

  Cheers

Jirka

In [1]: from django.db import connections

In [2]: c = connections['oracle'].cursor()

In [3]: c.execute(r"SELECT 1 FROM DUAL WHERE 'A' LIKE TRANSLATE('A'
USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)")
---
   Traceback (most recent call last)

/data/ig/webapps/ig/ in ()

/usr/lib/python2.5/site-packages/django/db/backends/oracle/base.py in
execute(self, query, params)
505 self._guess_input_sizes([params])
506 try:
--> 507 return self.cursor.execute(query,
self._param_generator(params))
508 except Database.IntegrityError, e:
509 raise utils.IntegrityError,
utils.IntegrityError(*tuple(e)), sys.exc_info()[2]

: ORA-01425: escape character
must be character string of length 1


In [4]: c.execute("SELECT 1 FROM DUAL WHERE DUMMY LIKE TRANSLATE('X'
USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)")
---
   Traceback (most recent call last)

/data/ig/webapps/ig/ in ()

/usr/lib/python2.5/site-packages/django/db/backends/oracle/base.py in
execute(self, query, params)
505 self._guess_input_sizes([params])
506 try:
--> 507 return self.cursor.execute(query,
self._param_generator(params))
508 except Database.IntegrityError, e:
509 raise utils.IntegrityError,
utils.IntegrityError(*tuple(e)), sys.exc_info()[2]

: ORA-01425: escape character
must be character string of length 1

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



Re: IN clause in raw sql

2010-12-08 Thread David De La Harpe Golden
On 08/12/10 17:42, dgmyrs wrote:
> That's a simplified sql just as an example.  The actual one I need the
> in clause is a lot more complex and can't be handled in the ORM.
> 

[Are you _sure_? name__in=... is so much handier, django sorts it out
for you...]

Anyway, see also
http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/where.py#L177

Build up a parameterised query string dynamically (eurgh, I know):

l = ('Restaurants','Fast Food',)

pquery = "SELECT id FROM app_category WHERE name IN (%s)" % ',
'.join(["%s"]*len(l))

Category.objects.raw(pquery, l)[0]




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



FileField and location and storage

2010-12-08 Thread dmitry b
Hi,

I've written a custom Storage that uses WebDAV as its underlying
engine.  When I save a file '/foo/bar/file.ext', I want it to be saved
under /foo/bar in the webdav filesystem.  However, it seems that
FileField overrides the directory structure:

def generate_filename(self, instance, filename):
return os.path.join(self.get_directory_name(),
self.get_filename(filename))

where get_directory_name() is defined as

def get_directory_name(self):
return
os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to

I'm not really sure why FileField finds it appropriate to impose its
own directory structure on the underlying storage engine.  But short
of creating a custom subclass of FileField and overriding
generate_filename and/or get_directory_name(), is there a different
way of preserving the original file location path?


Thanks
Dmitry

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



Re: returning type and value

2010-12-08 Thread mongoose
Thanks Tom, worked like a charm.
So actually qs is a collection of results and I can iterate through
them. Good to know.


Cheers.

On Dec 7, 7:52 pm, Tom Evans  wrote:
> On Tue, Dec 7, 2010 at 5:29 PM, mongoose  wrote:
> > Hi all,
>
> > I have this in my model.py
> >        def recipe_cost(self):
>
> >                total = IngredientInfo.objects.filter(recipe =
> > self.id).aggregate(Sum('total')).values()
>
> >                return total
>
> > Then in my admin.py I call that to display the cost.
> >        class RecipeAdmin(admin.ModelAdmin):
> >                list_display = ('title','recipe_cost')
>
> > I can see the cost but it's being returned like this:
> >        [Decimal('500.00')]
>
> > But obviously I'd just want the value 500. What should I change?
>
> > Thanks
>
> What you are calling total isn't the total, its a ValuesQuerySet. You
> want to extract the value from there, and convert it into whatever
> format you want.
>
> Eg:
>
> def recipe_cost(self):
>     qs = IngredientInfo.objects.filter(
>         recipe=self.id).aggregate(Sum('total')).values()
>     return unicode(qs[0])
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: __init__.py file executed twice ?

2010-12-08 Thread martvefun


On 08-12-10 18:39, Tom Evans wrote:
> On Wed, Dec 8, 2010 at 4:52 PM, martvefun  wrote:
>> Hello,
>>
>> I'd like to start some threads when the server launch to listen to
>> events (I'm doing message passing).
>>
>> To do so, I guess I should be using the __init__.py file at the root of
>> my project (by the way, what's the used of the other __init__.py files
>> in the apps)
>>
>> I've tried with a simple test by only having 'print "starting server"'
>> into the file and the result is :
>>
>> $ python manage.py runserver
>> starting server
>> starting server
>> Validating models...
>> 0 errors found
>>
>> Django version 1.2.3, using settings 'website.settings'
>> Development server is running at http://127.0.0.1:8000/
>> Quit the server with CONTROL-C.
>>
>> Why the file is executed twice ? I don't want to have twice the same
>> threads.
>>
>> Thank you
>>
>> mart
>>
>
> __init__.py files aren't executed at the start of programs, the
> presence of them denotes that a directory is a python module, and the
> __init__.py is executed when that module is first imported under a
> particular name.
>
> Do you have a structure like this:
>
> project
> ├── __init__.py
> ├── app1
> │   └── __init__.py
> └── app2
> ├── __init__.py
> └── models.py
>
> and import from project.app2.models and from app2.models? That would
> cause app2's __init__.py to be executed twice.
>
> Cheers
>
> Tom
>

Yes the structure of my project is more or less like that but I've not
two but 6 apps all with 'from django.db import models' in models.py
In several model (more than two), I'm using foreign keys to different
models.
For now the site doesn't do much, I'm using the database created with
the models in other files in the project folder.

So if the __init__.py is not a good place to start operations at server
startup, where should I put it ?

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



Re: When to use Form API

2010-12-08 Thread ringemup
This.  Form processing is one of those tedious things 90% of which is
the same in every form: field definition, display, validation, and
error handling/presentation.

Django takes care of the repetitive parts, and if you need to
customize the validation or display, allows you to do so while still
abstracting away all the rest of the fiddly stuff.

If anything, manual form processing in Django would be overkill,
unless you have some special case that the form API simply can't
handle (e.g. nested formsets, although there are a few apps now that
enable that, IIRC)



On Dec 8, 12:14 pm, Wayne Smith  wrote:
> It is important to distinguish between display and functionality with
> forms.  What I mean is, using the forms does not mean you have to render
> (display) them the way Django has it set up by default.  I always use the
> Form API, and if I need custom validation on a field or the entire form, I
> override the appropriate clean method.  I pass the widget argument if I want
> a different widget.
>
> IMO, one of the best things about Django is the ease in which I can
> customize its parts but still leverage its functionality.
>
> On Wed, Dec 8, 2010 at 10:36 AM, christian.posta
> wrote:
>
> > Do django developers use the Form API any time form elements need to
> > be displayed to users? Or do you just code the form yourself in the
> > templates and manually process them for smaller forms?
>
> > In general, is it always better to use the Form API for any form you
> > display, regardless how simple, because of the built-in functionality
> > provided by django, or is it overkill?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: IN clause in raw sql

2010-12-08 Thread dgmyrs
That's a simplified sql just as an example.  The actual one I need the
in clause is a lot more complex and can't be handled in the ORM.


On Dec 8, 11:40 am, Tom Evans  wrote:
> On Wed, Dec 8, 2010 at 5:21 PM, dgmyrs  wrote:
> > Hi, I am trying to work with an in clause in my sql in a raw sql
> > statement.  A simplified example:
>
> > 
> Category.objects.raw('select * from app_category where name 
> in(\'Restaurants\',\'Fast Food\')')[0]
> > 
> > 
>
> > So that works fine with the in clause hard coded in there, and I could
> > simply build that sql string, but I am wondering if there is a way to
> > use the parameters argument of raw?  I tried using a list with the
> > strings, and just a string itself with the escaped quotes, but
> > couldn't get either to work.
>
> > Thanks
>
> Why use raw? Why not just use the ORM?
>
> Category.objects.filter(name__in=['Restaurants', 'Fast Food'])
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: IN clause in raw sql

2010-12-08 Thread Tom Evans
On Wed, Dec 8, 2010 at 5:21 PM, dgmyrs  wrote:
> Hi, I am trying to work with an in clause in my sql in a raw sql
> statement.  A simplified example:
>
> 
Category.objects.raw('select * from app_category where name 
in(\'Restaurants\',\'Fast Food\')')[0]
> 
> 
>
> So that works fine with the in clause hard coded in there, and I could
> simply build that sql string, but I am wondering if there is a way to
> use the parameters argument of raw?  I tried using a list with the
> strings, and just a string itself with the escaped quotes, but
> couldn't get either to work.
>
> Thanks
>

Why use raw? Why not just use the ORM?

Category.objects.filter(name__in=['Restaurants', 'Fast Food'])

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



Re: __init__.py file executed twice ?

2010-12-08 Thread Tom Evans
On Wed, Dec 8, 2010 at 4:52 PM, martvefun  wrote:
> Hello,
>
> I'd like to start some threads when the server launch to listen to
> events (I'm doing message passing).
>
> To do so, I guess I should be using the __init__.py file at the root of
> my project (by the way, what's the used of the other __init__.py files
> in the apps)
>
> I've tried with a simple test by only having 'print "starting server"'
> into the file and the result is :
>
> $ python manage.py runserver
> starting server
> starting server
> Validating models...
> 0 errors found
>
> Django version 1.2.3, using settings 'website.settings'
> Development server is running at http://127.0.0.1:8000/
> Quit the server with CONTROL-C.
>
> Why the file is executed twice ? I don't want to have twice the same
> threads.
>
> Thank you
>
> mart
>

__init__.py files aren't executed at the start of programs, the
presence of them denotes that a directory is a python module, and the
__init__.py is executed when that module is first imported under a
particular name.

Do you have a structure like this:

project
├── __init__.py
├── app1
│   └── __init__.py
└── app2
├── __init__.py
└── models.py

and import from project.app2.models and from app2.models? That would
cause app2's __init__.py to be executed twice.

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



__init__.py file executed twice ?

2010-12-08 Thread martvefun
Hello,

I'd like to start some threads when the server launch to listen to
events (I'm doing message passing).

To do so, I guess I should be using the __init__.py file at the root of
my project (by the way, what's the used of the other __init__.py files
in the apps)

I've tried with a simple test by only having 'print "starting server"'
into the file and the result is :

$ python manage.py runserver
starting server
starting server
Validating models...
0 errors found

Django version 1.2.3, using settings 'website.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Why the file is executed twice ? I don't want to have twice the same
threads.

Thank you

mart

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



IN clause in raw sql

2010-12-08 Thread dgmyrs
Hi, I am trying to work with an in clause in my sql in a raw sql
statement.  A simplified example:


>>>Category.objects.raw('select * from app_category where name 
>>>in(\'Restaurants\',\'Fast Food\')')[0]



So that works fine with the in clause hard coded in there, and I could
simply build that sql string, but I am wondering if there is a way to
use the parameters argument of raw?  I tried using a list with the
strings, and just a string itself with the escaped quotes, but
couldn't get either to work.

Thanks

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



Re: When to use Form API

2010-12-08 Thread Wayne Smith
It is important to distinguish between display and functionality with
forms.  What I mean is, using the forms does not mean you have to render
(display) them the way Django has it set up by default.  I always use the
Form API, and if I need custom validation on a field or the entire form, I
override the appropriate clean method.  I pass the widget argument if I want
a different widget.

IMO, one of the best things about Django is the ease in which I can
customize its parts but still leverage its functionality.

On Wed, Dec 8, 2010 at 10:36 AM, christian.posta
wrote:

> Do django developers use the Form API any time form elements need to
> be displayed to users? Or do you just code the form yourself in the
> templates and manually process them for smaller forms?
>
> In general, is it always better to use the Form API for any form you
> display, regardless how simple, because of the built-in functionality
> provided by django, or is it overkill?
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Alphabetic filtering of Django Admin drop down menu

2010-12-08 Thread vjimw
Should your relationship be Many-to-Many I found this to be very
helpful:

Autocomplete manytomany widget for admin panel
http://djangosnippets.org/snippets/1365/

On Dec 7, 1:29 pm, Heigler  wrote:
> If you can't use raw_id_fields i guess you should write that view and
> use javascript to search inside the view.
>
> Can you use a auto complete approach instead a drop down menu? If you
> can, my suggestion is to use a jquery plugin to do the hard 
> work:http://docs.jquery.com/Plugins/autocomplete

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



Re: Django based issue tracker

2010-12-08 Thread zodman
that use django-template* app .. can change it.

On Wed, Dec 8, 2010 at 12:30 AM, derek  wrote:
> The button on the first page of http://www.django-projector.org/ says
> "Sing up for the demo project".  Makes a refreshing change from the
> usual getting started red-tape ;)
>
> On Dec 7, 6:59 am, zodman  wrote:
>> django-projector
>>
>>
>>
>> On Wed, Nov 10, 2010 at 2:05 PM, Toby Champion  
>> wrote:
>> > I don't know of a Django-based issue tracker that's in active
>> > development, but I'd suggest you first try using a web-based, hosted
>> > tool. If your project is simple enough, something 
>> > likehttp://www.unfuddle.com/
>> > might meet your needs. Accounts are free for very small projects, and
>> > include a SVN or Git repository. Otherwise Trac, which is of course
>> > used for tracking issues in Dango itself athttp://code.djangoproject.com/,
>> > so at least you know there's knowledge in the community. It's written
>> > in Python, too, so if you enjoy working in Python even without Django,
>> > you're onto a winner.
>>
>> > On Nov 10, 12:12 am, Joakim Hove  wrote:
>> >> Hello,
>>
>> >> I am setting up a bug/issue tracker - the project is quite small and I
>> >> do not have complex needs. As I enjoy working with Django I was
>> >> looking for a Django based solution. Can someone reccomend a Django
>> >> based issue tracker?
>>
>> >> In case I fail finding something based on Django I think I will use
>> >> Trac which seems quite nice.
>>
>> >> Joakim
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> Andres Vargaswww.zodman.com.mx
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Andres Vargas
www.zodman.com.mx

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



can't add via admin, get django template error

2010-12-08 Thread JeffH
So I'm working along, everything's humming fine. Then I try to add a
record via the admin, and get the following:

TemplateSyntaxError at /admin/expert/expertresponse/add/
Caught AttributeError while rendering: 'unicode' object has no
attribute 'date'

[snip]

Template error

In template c:\python26\lib\site-packages\django\contrib\admin
\templates\admin\includes\fieldset.html, error at line 12
Caught AttributeError while rendering: 'unicode' object has no
attribute 'date'
2   {% if fieldset.name %}{{ fieldset.name }}{% endif %}
3   {% if fieldset.description %}{{ fieldset.description|safe }}{% endif %}
4   {% for line in fieldset %}
5   
6   {{ line.errors }}
7   {% for field in line %}
8   
9   {% if field.is_checkbox %}
10  {{ field.field }}{{ field.label_tag }}
11  {% else %}
12  {{ field.label_tag }}{{ field.field }}

I can add records via a ModelForm without problem, it just doesn't
work in the admin.

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



When to use Form API

2010-12-08 Thread christian.posta
Do django developers use the Form API any time form elements need to
be displayed to users? Or do you just code the form yourself in the
templates and manually process them for smaller forms?

In general, is it always better to use the Form API for any form you
display, regardless how simple, because of the built-in functionality
provided by django, or is it overkill?


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



Re: User not authenticated after login?

2010-12-08 Thread Daniel Roseman
On Dec 8, 3:20 pm, gunnar  wrote:
> Dear group,
>
> I run django 1.2 on windows on the development server.
>
> I set up a login site via the standard django login view. The user is
> then redirected to a site built from a base template. The view that
> calls the base template is only available to logged-in users (via the
> @login_required decorator) - otherwise, the user is redirected to the
> login site. This part works.
>
> However, when I try to access {{user.username}} from within the
> template, I find that it is empty. is_authenticated returns false.
>
> What am I doing wrong?
>
> Gunnar

You're probably simply not sending the user object to the template.
You need to either send it explicitly in the context, or ensure the
`auth` context processor is active and you're using RequestContext.
--
DR.

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



User not authenticated after login?

2010-12-08 Thread gunnar
Dear group,

I run django 1.2 on windows on the development server.

I set up a login site via the standard django login view. The user is
then redirected to a site built from a base template. The view that
calls the base template is only available to logged-in users (via the
@login_required decorator) - otherwise, the user is redirected to the
login site. This part works.

However, when I try to access {{user.username}} from within the
template, I find that it is empty. is_authenticated returns false.

What am I doing wrong?

Gunnar

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



Re: Help! I'm thick! First formset generating AttributeError

2010-12-08 Thread fgasperino
While I haven't worked with formsets, this line doesn't look correct:

formset = ClientFormSet(request.POST, request.FILES,
queryset=Client.objects.get(pk=client_id))

mainly due to a parameter named queryset being passed a model object,
instead of a queryset of model objects. It would seem that you want
queryset=Client.objects.filter(pk=client_id) to achieve the same
result.

Then again, I could be wildly off.

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



Re: Post URL characters problem

2010-12-08 Thread Keats
tanks !
the filter urlencode did the trick.

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



Help! I'm thick! First formset generating AttributeError

2010-12-08 Thread morgand
Either its age - the scotch - or some combination of both, but I am
having problems with a SIMPLE formset. (its my first).

On my formset I get an AttributeError - 'Client' object has no
attribute 'ordered'... .but I dont have an attribute of that
anywhere I tried changing from a "get" to a "raw" but still
get a (similar) message.

My code is :
(models.py)

class Client(models.Model):
title = models.CharField(max_length=3, choices=TITLE_CHOICES)
firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50)
mobilenumber = models.CharField(max_length=50)
phonenumber = models.CharField(max_length=50)
email = models.CharField(max_length=50)
street = models.CharField(max_length=50)
city = models.CharField(max_length=50)
state = models.CharField(max_length=10, choices=STATE_CHOICES)
class Meta:
ordering = ('lastname','firstname')
unique_together = ('firstname', 'lastname','mobilenumber')

def __unicode__(self):
return self.id


I have a forms.py containing

ClientFormSet = modelformset_factory(Client, extra=0, max_num=1)


In my view.py" I have the following... which is getting called and is
what generates the error

def c4(request, client_id=None):
if  client_id == None:
if request.method == 'POST':
formset = ClientFormSet(request.POST, request.FILES)
if formset.is_valid():
formset.save()
clients = Client.objects.all()
return SortableGrid(request,
clients).render_to_response("mylibrary/real.html")
else:
formset = ClientFormSet(request.POST, request.FILES)

else:
if request.method == 'POST':
formset = ClientFormSet(request.POST, request.FILES,
queryset=Client.objects.get(pk=client_id))
if formset.is_valid():
formset.save()
clients = Client.objects.all()
return SortableGrid(request,
clients).render_to_response("mylibrary/real.html")

else:
formset = ClientFormSet(request.POST, request.FILES,
queryset=Client.objects.get(pk=client_id))

return render_to_response("4.html", {
"formset": formset,
})


My "4.html" contains

{{ formset.management_form }}
{% for form in formset.forms %}
{{ form.id }}

{{ form.id }}
{{ form.firstname }}
{{ form.lastname }}

{% endfor %}




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



Re: Form attachment (FileField) upload not saving.

2010-12-08 Thread Sithembewena Lloyd Dube
100% fixed. I was calling save() on the form twice, once in form_capture and
once in form_errors.

:(



On Wed, Dec 8, 2010 at 12:34 PM, Sithembewena Lloyd Dube
wrote:

> 50% solved - I passed request.FILES into the form's constructor as
> indicated below:
>
> http://docs.djangoproject.com/en/1.2/topics/http/file-uploads/
>
> I then accessed the file as follows:
>
> attachment = request.FILES['attachment']
>
>
> Only problem left is to figure out why the form is posting twice. ideas
> please?
>
> Thanks.
>
>
> On Wed, Dec 8, 2010 at 12:02 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> Hi all,
>>
>> I have a contact form that is supposed to save a message as well as a file
>> upload. When I use the admin site, I can save a contact record with a file
>> upload of any type.
>>
>> However, saving from the 'front end' of my web application causes some
>> strange behaviour - the file is not uploaded, and the contact record is
>> saved twice as seen from the admin site.
>>
>>
>> My code is as follows:
>>
>> BEGIN
>> CODE---
>> *html template:*
>>
>> > enctype="multipart/form-data">{% csrf_token %}
>> > width="100%">
>> 
>> Message
>> {{ form.message }}
>> 
>> 
>> Upload
>> File:
>> {{ form.attachment }}
>> 
>>  
>> > value="Submit Request" />
>> 
>> 
>> 
>>
>> *view*:
>>
>> @csrf_protect
>> def contact_us(request):
>> form = form_capture(request)
>> return render_to_response('front_end/standard_pages/contactus.html',
>> {'form': form, }, context_instance=RequestContext(request))
>>
>> *the form_capture function (extra module named functions.py - keeps all
>> my custom functions)*:
>>
>> def form_capture(request):
>>  if request.method == 'POST':
>>   form = ContactForm(request.POST)
>>   if form.is_valid():
>>message = form.cleaned_data['message']
>>attachment = form.cleaned_data['attachment']
>>form.save()
>>  else:
>> form = ContactForm()
>>  return form
>>
>> *the form (forms.py):*
>>
>> class ContactForm(ModelForm):
>>  class Meta:
>>   model = Contact
>>  message = forms.CharField(widget=forms.Textarea(attrs={'cols': 60,
>> 'rows': 10, 'class': 'mceNoEditor'}))
>>  attachment = forms.FileField(required=False,
>> widget=forms.FileInput())
>>
>> *the Contact model (models.py):*
>>
>> class Contact(models.Model):
>>
>>  message = models.TextField(max_length=500)
>>  attachment = models.FileField(upload_to='attachments', blank=True)
>>
>>  def __unicode__(self):
>>   return self.message[:10] + '...'
>>
>>  class Meta:
>>   verbose_name_plural = "Contact Messages"
>>
>> END
>> CODE---
>>
>> Any ideas why saving a record from the contact form posts twice, and why
>> the file attachment is not uploaded?
>>
>> Thanks!
>> --
>> Regards,
>> Sithembewena Lloyd Dube
>>
>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
>



-- 
Regards,
Sithembewena Lloyd Dube

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



Re: Post URL characters problem

2010-12-08 Thread bruno desthuilliers
On 8 déc, 10:13, Keats  wrote:
> hi,
> How i can add it then ?
>
> i was thinking that the problem is "?" because :

It is. Please refer to the relevant RFC:  the question mark is a
reserved character used to specify the beginning of a querystring. If
you want it to be part of the url itself, you do have to properly
quote it (using django.utils.http.urlquote or the corresponding
template tag).

>  id="addReplyForm" name="addReplyForm">
> works perfectly any other characters in the topic_name part seems to
> work and since i'm only using : (.*) i didn't see how it could be an
> URL mismatch matter because for me (.*) means match everything ...

The url regexp is matched against the "path" part of the url - the
querystring is ignored at this point.



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



Re: Form attachment (FileField) upload not saving.

2010-12-08 Thread Sithembewena Lloyd Dube
50% solved - I passed request.FILES into the form's constructor as indicated
below:

http://docs.djangoproject.com/en/1.2/topics/http/file-uploads/

I then accessed the file as follows:

attachment = request.FILES['attachment']


Only problem left is to figure out why the form is posting twice. ideas
please?

Thanks.

On Wed, Dec 8, 2010 at 12:02 PM, Sithembewena Lloyd Dube
wrote:

> Hi all,
>
> I have a contact form that is supposed to save a message as well as a file
> upload. When I use the admin site, I can save a contact record with a file
> upload of any type.
>
> However, saving from the 'front end' of my web application causes some
> strange behaviour - the file is not uploaded, and the contact record is
> saved twice as seen from the admin site.
>
>
> My code is as follows:
>
> BEGIN
> CODE---
> *html template:*
>
>  enctype="multipart/form-data">{% csrf_token %}
>  width="100%">
> 
> Message
> {{ form.message }}
> 
> 
> Upload File:
> {{ form.attachment }}
> 
>  
>  value="Submit Request" />
> 
> 
> 
>
> *view*:
>
> @csrf_protect
> def contact_us(request):
> form = form_capture(request)
> return render_to_response('front_end/standard_pages/contactus.html',
> {'form': form, }, context_instance=RequestContext(request))
>
> *the form_capture function (extra module named functions.py - keeps all my
> custom functions)*:
>
> def form_capture(request):
>  if request.method == 'POST':
>   form = ContactForm(request.POST)
>   if form.is_valid():
>message = form.cleaned_data['message']
>attachment = form.cleaned_data['attachment']
>form.save()
>  else:
> form = ContactForm()
>  return form
>
> *the form (forms.py):*
>
> class ContactForm(ModelForm):
>  class Meta:
>   model = Contact
>  message = forms.CharField(widget=forms.Textarea(attrs={'cols': 60,
> 'rows': 10, 'class': 'mceNoEditor'}))
>  attachment = forms.FileField(required=False, widget=forms.FileInput())
>
> *the Contact model (models.py):*
>
> class Contact(models.Model):
>
>  message = models.TextField(max_length=500)
>  attachment = models.FileField(upload_to='attachments', blank=True)
>
>  def __unicode__(self):
>   return self.message[:10] + '...'
>
>  class Meta:
>   verbose_name_plural = "Contact Messages"
>
> END
> CODE---
>
> Any ideas why saving a record from the contact form posts twice, and why
> the file attachment is not uploaded?
>
> Thanks!
> --
> Regards,
> Sithembewena Lloyd Dube
>



-- 
Regards,
Sithembewena Lloyd Dube

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



Form attachment (FileField) upload not saving.

2010-12-08 Thread Sithembewena Lloyd Dube
Hi all,

I have a contact form that is supposed to save a message as well as a file
upload. When I use the admin site, I can save a contact record with a file
upload of any type.

However, saving from the 'front end' of my web application causes some
strange behaviour - the file is not uploaded, and the contact record is
saved twice as seen from the admin site.


My code is as follows:

BEGIN
CODE---
*html template:*

{%
csrf_token %}


Message
{{ form.message }}


Upload File:
{{ form.attachment }}

 





*view*:

@csrf_protect
def contact_us(request):
form = form_capture(request)
return render_to_response('front_end/standard_pages/contactus.html',
{'form': form, }, context_instance=RequestContext(request))

*the form_capture function (extra module named functions.py - keeps all my
custom functions)*:

def form_capture(request):
 if request.method == 'POST':
  form = ContactForm(request.POST)
  if form.is_valid():
   message = form.cleaned_data['message']
   attachment = form.cleaned_data['attachment']
   form.save()
 else:
form = ContactForm()
 return form

*the form (forms.py):*

class ContactForm(ModelForm):
 class Meta:
  model = Contact
 message = forms.CharField(widget=forms.Textarea(attrs={'cols': 60,
'rows': 10, 'class': 'mceNoEditor'}))
 attachment = forms.FileField(required=False, widget=forms.FileInput())

*the Contact model (models.py):*

class Contact(models.Model):

 message = models.TextField(max_length=500)
 attachment = models.FileField(upload_to='attachments', blank=True)

 def __unicode__(self):
  return self.message[:10] + '...'

 class Meta:
  verbose_name_plural = "Contact Messages"

END
CODE---

Any ideas why saving a record from the contact form posts twice, and why the
file attachment is not uploaded?

Thanks!
-- 
Regards,
Sithembewena Lloyd Dube

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



Re: Post URL characters problem

2010-12-08 Thread Keats
hi,
How i can add it then ?

i was thinking that the problem is "?" because :

works perfectly any other characters in the topic_name part seems to
work and since i'm only using : (.*) i didn't see how it could be an
URL mismatch matter because for me (.*) means match everything ...

thanx.

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