question about involve "vncserver" command with django

2010-11-09 Thread Bill
Hi all,

I met a problem, I can use python to execute the the command
"vncserver " to start vncserver use subprocess,
like this:
process = subprocess.Popen('vncserver' , shell=True)

but when I write this code to views.py it didn't work as I hope.
The Xvnc process listened on the port which Django used.

For example,  django listen on tcp port 8000, and the Xvnc also listen
on tcp port 8000.
It's wired.

Is there any way to involve the vncserver?


Regards,
Bill

-- 
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: question about involve "vncserver" command with django

2010-11-09 Thread Bill
Hi Jirka,

Thank you for your quickly reply.

>   this is technically impossible, two programs cannot listen on the
> same TCP port (on one interface). It's very likely that it was Django
> webserver listening there.

You are right, sorry for that stupid question, and I check it again, I
find the Xvnc process used the 8000 port and killed the Django
webserver
=
[r...@sun]# lsof -P -i -n |grep Xvnc
Xvnc      3691   bill0u  IPv4  14835   TCP *:6001 (LISTEN)
Xvnc      3691   bill3u  IPv4  14371   TCP *:8000 (LISTEN)
Xvnc      3691   bill4u  IPv4  14745   TCP 10.1.1.1:8000-
>10.1.1.144:52607 (ESTABLISHED)
Xvnc  3691   bill6u  IPv4  14838   TCP *:5901 (LISTEN)
Xvnc  3691   bill7u  IPv4  14839   TCP *:5801 (LISTEN)

==
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Error: That port is already in use.

>
>   Overall, starting VNC from a web application seems like a bad idea
> in principle as the request-response cycle is not well suited for this
> (as well as other reasons). Can you describe what are you trying to
> achieve and why?

What am I doing is want to simplify using vnc.
I'm a Linux administrator. As you know, if users want to use vnc they
must login the server with ssh to start vnc server first.
Then get the port or id number, then use vncviewer or http link to
access the vncserver.
I just want them to access the http link let django start the
vncserver and use it. they don't need to install any ssh client.


Thanks in advance.

Bill

-- 
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: question about involve "vncserver" command with django

2010-11-09 Thread Bill
Hi Clifford,

Thank you, sounds like good,  I will try FreeNX later.
but you know, I already wrote the python code, it works except I use
it on Django.


BTW, we are very close, I'm at Eglinton subwaystation.
Best regards,
Bill

> I've found FreeNX with the NoMachine client to be a much better
> alternative. You can distribute ready-made profiles to your users and
> their setup will be next to nothing. It's faster and more secure than
> VNC, too.
> --
> Regards,
>
> Clifford Ilkay
> Dinamis
> 1419-3266 Yonge St.
> Toronto, ON
> Canada  M4N 3P6
>
> <http://dinamis.com>
> +1 416-410-3326

-- 
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: question about involve "vncserver" command with django

2010-11-10 Thread Bill

> Well, using a web server to start VNC still seems like a bad idea. How
> do you stop the VNC server once a user does not need it anymore?

User can close the vncserver use webserver, just like How they can
start it.

Any way, I know maybe there are many better ways to do this job. I
really appreciate you guys give me many ideas.
but I want to know why Django can't involve the "vncserver" use
subprocess.


Thanks,
Bill

-- 
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: question about involve "vncserver" command with django

2010-11-10 Thread Bill
Thank you Sam,
I've checked the manual and try to change any port include rfbport or
http port, it doesn't work.
But finally,  I find my way, I use pexpect to involve the command. It
works.

Thank you everyone!
Bill

On Nov 10, 4:23 pm, Sam Lai  wrote:
> Why can't you tell vncserver to listen on a different port?
>
> the vncserver script passes any unknown args to Xvnc, so you can use
> the argument for Xvnc to change the port (-rfbport port_number).
>
> man vncserver:http://www.realvnc.com/products/free/4.1/man/vncserver.html
> man Xvnc:http://www.realvnc.com/products/free/4.1/man/Xvnc.html
>
> On 10 November 2010 06:33, Bill  wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I met a problem, I can use python to execute the the command
> > "vncserver " to start vncserver use subprocess,
> > like this:
> > process = subprocess.Popen('vncserver' , shell=True)
>
> > but when I write this code to views.py it didn't work as I hope.
> > The Xvnc process listened on the port which Django used.
>
> > For example,  django listen on tcp port 8000, and the Xvnc also listen
> > on tcp port 8000.
> > It's wired.
>
> > Is there any way to involve the vncserver?
>
> > Regards,
> > Bill
>
> > --
> > 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: email in settings.py

2008-01-11 Thread Bill

It looks like those variables are documented in the SVN docs, but not
0.96:

http://www.djangoproject.com/documentation/email/

If your server doesn't use authentication for SMTP, try not setting
_USER and _PASSWORD.

As for why those vars weren't in your settings.py, I believe the
settings.py should be considered and override for the defaults
specified in django/conf/global_settings.py.  See:

http://www.djangoproject.com/documentation/settings/

for more info.

Running the command:

python manage.py diffsettings

Will show you what you've changed from the defaults.

Bill

Michael Allen wrote:
> Hiya,
>
> I'm a noob running official release .96, please be gentle.
> I'm trying to enable email functionality.
> Per this doc
> http://www.djangoproject.com/documentation/0.96/settings/#DEFAULT_CHARSET
>
> I should see a set of email settings in my settings.py file.
> I don't see any of the following:
> EMAIL_HOST
> EMAIL_HOST_PASSWORD
> EMAIL_HOST_USER
> EMAIL_PORT
> EMAIL_SUBJECT_PREFIX
>
> I added them all and set them to use my mail server and I THINK it's working
> correctly now.
> (note I'm using the send_mail function)
>
> Now it's kicking an error on send_mail:
> 'SMTP AUTH extension not supported by server'
>
> I think this means that I have to configure my server differently to allow
> for SMTP AUTHentication.
> Here's some doc I found on how to do that (looks like a pain in the arse
> doesn't it?)
>
> http://postfix.state-of-mind.de/patrick.koetter/smtpauth/requirements.html
>
> Ah yes, my questions...
> 1.  Why weren't the email settings included in settings.py when I ran '
> djangoadmin.py startproject'?
> 2.  If I'm hitting the smtp auth error (see above), does that mean I've
> configured django correctly and that it's just burping at the email server
> side?
>
> Thanks in advance,
> -pug
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Something like an "all in" for filter of related set

2007-10-04 Thread bill

Hi folks,
I've reviewed the db api documentation page, and I'm pretty sure it
didn't have an example that would help me with this request.  I'd like
something like the "IN" operator that can be used in a lookup on a
field in a related model, but more like something that I guess could
be called something like "ALL_IN".  Example:
Models:
Article (title, pub_date, etc...)
TaggedArticle (article_id, tag)

One article can of course have multiple tags.  What if I wanted to
find Articles that have _all_ the tags in a particular set.  Similar
to IN:

Article.objects.filter(taggedarticle__tag__in=['python', 'perl',
'java'])

That would give me articles that have tags for python OR perl OR
java.  But what if I want a quick way to find all articles that have
all three of those tags (they may have more tags, but they at least
have all of those three.)

I've learned about making my own Manager class, so that's definitely
possible, but does there happen to be a built-in way?

Thx much,
bill


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



MySQL Query

2012-02-08 Thread Bill
Hello

I am completing the Django tutorials, however I am having a problem
when syncing the DB to Django.  I am getting the following message.
Any help would be appreciated.

C:\Python27\Django-131\django\bin\mysite>manage.py syncdb
Traceback (most recent call last):
  File "C:\Python27\Django-131\django\bin\mysite\manage.py", line 14,
in 
execute_manager(settings)
  File "C:\Python27\lib\site-packages\django\core\management
\__init__.py", line
438, in execute_manager
utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management
\__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management
\__init__.py", line
261, in fetch_command
klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management
\__init__.py", line
67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name,
name))
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
35, in im
port_module
__import__(name)
  File "C:\Python27\lib\site-packages\django\core\management\commands
\syncdb.py"
, line 7, in 
from django.core.management.sql import custom_sql_for_model,
emit_post_sync_
signal
  File "C:\Python27\lib\site-packages\django\core\management\sql.py",
line 6, in
 
from django.db import models
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 78,
in 
connection = connections[DEFAULT_DB_ALIAS]
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 93, in
__getitem
__
backend = load_backend(db['ENGINE'])
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 33, in
load_back
end
return import_module('.base', backend_name)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
35, in im
port_module
__import__(name)
  File "C:\Python27\lib\site-packages\django\db\backends\mysql
\base.py", line 14
, in 
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: No mo
dule named MySQLdb

Many 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-users@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: MySQL Query

2012-02-08 Thread Bill
Many thanks it is now working!!

On Feb 8, 6:21 pm, Anoop Thomas Mathew  wrote:
> Hi,
> Make sure that you have installed MySQL-python package for python bindings
> to mysql.
>
> Thanks,
> Anoop Thomas Mathew
>
> ___
> Life is short, Live it hard.
>
> On 8 February 2012 23:45, Bill  wrote:
>
>
>
>
>
>
>
> > Hello
>
> > I am completing the Django tutorials, however I am having a problem
> > when syncing the DB to Django.  I am getting the following message.
> > Any help would be appreciated.
>
> > C:\Python27\Django-131\django\bin\mysite>manage.py syncdb
> > Traceback (most recent call last):
> >  File "C:\Python27\Django-131\django\bin\mysite\manage.py", line 14,
> > in 
> >    execute_manager(settings)
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 438, in execute_manager
> >    utility.execute()
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 379, in execute
> >    self.fetch_command(subcommand).run_from_argv(self.argv)
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 261, in fetch_command
> >    klass = load_command_class(app_name, subcommand)
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 67, in load_command_class
> >    module = import_module('%s.management.commands.%s' % (app_name,
> > name))
> >  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
> > 35, in im
> > port_module
> >    __import__(name)
> >  File "C:\Python27\lib\site-packages\django\core\management\commands
> > \syncdb.py"
> > , line 7, in 
> >    from django.core.management.sql import custom_sql_for_model,
> > emit_post_sync_
> > signal
> >  File "C:\Python27\lib\site-packages\django\core\management\sql.py",
> > line 6, in
> >  
> >    from django.db import models
> >  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 78,
> > in  > e>
> >    connection = connections[DEFAULT_DB_ALIAS]
> >  File "C:\Python27\lib\site-packages\django\db\utils.py", line 93, in
> > __getitem
> > __
> >    backend = load_backend(db['ENGINE'])
> >  File "C:\Python27\lib\site-packages\django\db\utils.py", line 33, in
> > load_back
> > end
> >    return import_module('.base', backend_name)
> >  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
> > 35, in im
> > port_module
> >    __import__(name)
> >  File "C:\Python27\lib\site-packages\django\db\backends\mysql
> > \base.py", line 14
> > , in 
> >    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > module: No mo
> > dule named MySQLdb
>
> > Many 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-users@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-users@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: MySQL Query

2012-02-08 Thread Bill
Many thanks it is now working!!

On Feb 8, 6:21 pm, Sandro Dutra  wrote:
> Probably you've to install python-mysqldb.
>
> 2012/2/8 Bill :
>
>
>
>
>
>
>
> > Hello
>
> > I am completing the Django tutorials, however I am having a problem
> > when syncing the DB to Django.  I am getting the following message.
> > Any help would be appreciated.
>
> > C:\Python27\Django-131\django\bin\mysite>manage.py syncdb
> > Traceback (most recent call last):
> >  File "C:\Python27\Django-131\django\bin\mysite\manage.py", line 14,
> > in 
> >    execute_manager(settings)
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 438, in execute_manager
> >    utility.execute()
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 379, in execute
> >    self.fetch_command(subcommand).run_from_argv(self.argv)
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 261, in fetch_command
> >    klass = load_command_class(app_name, subcommand)
> >  File "C:\Python27\lib\site-packages\django\core\management
> > \__init__.py", line
> > 67, in load_command_class
> >    module = import_module('%s.management.commands.%s' % (app_name,
> > name))
> >  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
> > 35, in im
> > port_module
> >    __import__(name)
> >  File "C:\Python27\lib\site-packages\django\core\management\commands
> > \syncdb.py"
> > , line 7, in 
> >    from django.core.management.sql import custom_sql_for_model,
> > emit_post_sync_
> > signal
> >  File "C:\Python27\lib\site-packages\django\core\management\sql.py",
> > line 6, in
> >  
> >    from django.db import models
> >  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 78,
> > in  > e>
> >    connection = connections[DEFAULT_DB_ALIAS]
> >  File "C:\Python27\lib\site-packages\django\db\utils.py", line 93, in
> > __getitem
> > __
> >    backend = load_backend(db['ENGINE'])
> >  File "C:\Python27\lib\site-packages\django\db\utils.py", line 33, in
> > load_back
> > end
> >    return import_module('.base', backend_name)
> >  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line
> > 35, in im
> > port_module
> >    __import__(name)
> >  File "C:\Python27\lib\site-packages\django\db\backends\mysql
> > \base.py", line 14
> > , in 
> >    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > module: No mo
> > dule named MySQLdb
>
> > Many 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-users@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-users@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.



Linux password authentication for django

2010-12-29 Thread Bill
Hi there,

I want to know is there any authentication module base on Linux passwd/
shadow file for django?

Many thanks,
Bill

-- 
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: Linux password authentication for django

2010-12-31 Thread Bill
Hi Marc,

Thank you so much! You really helped me!

Bill

On Dec 30, 10:24 am, Marc Aymerich  wrote:
> On Thu, Dec 30, 2010 at 6:35 AM, Bill  wrote:
> > Hi there,
>
> > I want to know is there any authentication module base on Linux passwd/
> > shadow file for django?
>
> http://atlee.ca/software/pam/module-index.html
>
> import pam
> from django.contrib.auth.models import User
>
> class PamBackend:
>
>     def authenticate(self, username=None, password=None):
>         # Check the username/password and return a User.
>         if pam.authenticate(username, password, service='login'):
>              try:
>                 return User.objects.get(username=username)
>             except User.DoesNotExist:
>                 pass
>         return None
>
> --
> Marc

-- 
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: Source changes: How can I resolve import error -- cannot import django.db.models.query.parse_lookup

2008-07-17 Thread Bill Totman

Well, I'm not sure of the nature of the patch, but I hope to find out
how to do so.

I'll be certain to pass on the HOWTO to you here - since you found out
the solution and all. I, too, and going through the book and would
like to make progress.

-Bill

On Jul 17, 4:03 pm, LRP <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Still working my way through James Bennett's Practical Django
> Projects. Now on p. 64.
>
> I get this import error when I try to syncdb the Coltrane models.
>
>     from tagging.models import Tag
>   File "/usr/lib/python2.5/site-packages/tagging/models.py", line 9,
> in     from tagging.managers import TagManager,
> TaggedItemManager
>   File "/usr/lib/python2.5/site-packages/tagging/managers.py", line 6,
> in 
>     from django.db.models.query import QuerySet, parse_lookup
> ImportError: cannot import name parse_lookup
>
> Googling around I find this note:
>
> While the public interface for the ORM-layer should stay the same, the
> internals have undergone massive change. So if you're relying on some
> private part of the API, you will have to check if it still works.
> Affected of this if for example the popular django-tagging app (guess
> what it does ;-)) which in its current state (r132) uses the no longer
> available django.db.models.query.parse_lookup function. A patch by
> Joes Watts is available here and seems to solve this issue. For more
> details check out this ticket on django-tagging's google code project
> page.
>
> I've never patched code before. Can some kind soul please walk me
> through the process step-by-step so I can continue on to page 65?
>
> Many thanks,
>
> Lloyd

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



Re: Source changes: How can I resolve import error -- cannot import django.db.models.query.parse_lookup

2008-07-17 Thread Bill Totman

Here's the solution (so far):

1) Obtain the SVN version of django-tagging.
2) Place it or link the 'tagging' directory step '1' provides you into
your $PYTHONPATH
3) python manage.py syncdb (in your 'cms' directory)

To give helpful info:
1) Obtain the SVN version of django-tagging:
run:
svn checkout http://django-tagging.googlecode.com/svn/trunk/ NEW-
OR-EXISTING-DIRECTORY-OF-YOUR-CHOICE
Look into your target directory, the one 'of-your-choice', and find
the 'tagging' directory. That's the directory you'll need for step
'2'.
2) Place it or link the 'tagging' directory step '1' provides you into
your $PYTHONPATH
I kind of have a crazy $PYTHONPATH. Django's main site should have
more info on it. But, I run Debian Lenny and when I include this path:
/usr/lib/python2.5/site-packages/
in my $PYTHONPATH 'syncdb' finds it. Either moving the 'tagging'
directory from the 'directory-of-your-choice' into the 'site-packages'
directory would do the trick. Or, you can link it... something like
this:
sudo ln -s /tagging /usr/lib/python2.5/
site-packages/


Once 'syncdb' finds the (svn version of the) 'tagging' directory in
the $PYTHONPATH it will do it's job.


I hope this helps. (I'm off to the book.)

-Bill


On Jul 17, 4:03 pm, LRP <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Still working my way through James Bennett's Practical Django
> Projects. Now on p. 64.
>
> I get this import error when I try to syncdb the Coltrane models.
>
>     from tagging.models import Tag
>   File "/usr/lib/python2.5/site-packages/tagging/models.py", line 9,
> in     from tagging.managers import TagManager,
> TaggedItemManager
>   File "/usr/lib/python2.5/site-packages/tagging/managers.py", line 6,
> in 
>     from django.db.models.query import QuerySet, parse_lookup
> ImportError: cannot import name parse_lookup
>
> Googling around I find this note:
>
> While the public interface for the ORM-layer should stay the same, the
> internals have undergone massive change. So if you're relying on some
> private part of the API, you will have to check if it still works.
> Affected of this if for example the popular django-tagging app (guess
> what it does ;-)) which in its current state (r132) uses the no longer
> available django.db.models.query.parse_lookup function. A patch by
> Joes Watts is available here and seems to solve this issue. For more
> details check out this ticket on django-tagging's google code project
> page.
>
> I've never patched code before. Can some kind soul please walk me
> through the process step-by-step so I can continue on to page 65?
>
> Many thanks,
>
> Lloyd
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OK to put app_directories before filesystem template loader?

2009-08-20 Thread Bill Freeman
Thanks for the response.

Yeah, I found that while it make my app work, it broke others.  I switched
to renaming the subdirectory of templates in which my views look for their
templates.

Bill

On Wed, Aug 19, 2009 at 3:53 AM, David Christiansen  wrote:

>
> Well, it doesn't seem to make much sense to me.  I use the default
> order so that I can place files in a site-level templates directory in
> order to override the default templates in the app directory without
> having to directly open it up and modify its template files.
>
> -David Christiansen
>
> On Aug 18, 5:43 pm, ke1g  wrote:
> > I find myself wanting to place the app_directories template loader
> > before the filesystem template loader in
> > settings.TEMPLATE_LOADERS, so that when I clone an app to, among other
> > things, modifiy its templates, I get mine instead of the default.
> >
> > I'm wondering if anyone knows of reasons not to change the order?
> >
> > [I'm actually using pinax, but this seems like a general Django
> > question.]
> >
> > Bill
> >
>

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



Re: automatic initialization of sample data

2009-08-20 Thread Bill Freeman
Perhaps I'm not understanding correctly, but how about, assuming you have a
function
run_data_inits() that calls your chain of init_sample_data() functions:


$ python manage.py shell
>>> import myproject.myapp.models as m
>>> m.run_data_inits()
>>> ^D

Bill

On Thu, Aug 20, 2009 at 9:25 AM, Jan Ostrochovsky <
jan.ostrochov...@gmail.com> wrote:

>
> Hello,
>
> we are in the initial phase of software project, and data model and
> names of attributes are changing very often, and very often we need to
> create new database and fill it with the same sample data for testing.
> We want to automate this creation of sample data.
>
> Our idea: add into each models.py method e.g. init_sample_data() to
> each model class, and put sample data there (with well handled
> dependencies - ForeignKey, etc.) and each time we change model, we
> will aslo change concerned init_samle_data(). We will run these
> chained init_sample_data() for each class in the script.
>
> The question is: is there some existing solution for this (in Django
> or its extensions), which we can use, and not reinvent it, or not? Any
> idea?
>
> (We are using Django Evolution, which is good help, but only when
> changes are not too dramatic.)
>
> Thanks in advance.
>
> Jan Ostrochovsky
> >
>

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



Re: Get project name

2009-08-21 Thread Bill Freeman
Alessandro,

In settings.py:

import os.path
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
PROJECT_NAME = os.path.basename(PROJECT_ROOT)

Then, in modules where you need it:

from django.conf import settings

PROJECT_NAME = settings.PROJECT_NAME

Bill


On Fri, Aug 21, 2009 at 2:31 PM, Alessandro Ronchi <
alessandro.ron...@soasi.com> wrote:

>
> Is there any way to get the project name that's running in the code?
>
> Now I use a manual setting: PROJECT_NAME = "ambiente"
> but it should be useful to avoid that, because I'm working on an
> external app and every new unuseful configuration simplify my life a
> lot.
>
> --
> Alessandro Ronchi
>
> SOASI
> Sviluppo Software e Sistemi Open Source
> http://www.soasi.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-users@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: template tag response None. but why?

2009-08-27 Thread Bill Freeman
I don't know what else is wrong but:

On Wed, Aug 26, 2009 at 8:15 PM, MIL  wrote:

>bits = token.contents.split()


should probably be:

bits = token.split_contents()

and render must return a string whether or not there is an
ObjectDoesNotExist exception, so, maybe:

   def render(self, context):
   try:
   context[self.varname] =
Blog.objects.get(user=self.user)
   except ObjectDoesNotExist:
   context[self.varname] = None   # Or whatever you want
to get if the user doesn't exist
   # Or, if the variable was previously set to the no
such user value, use "pass".
   return ""


Another issue, if I understand another thread correctly, is that the
variable assignment will go away when you return (the dictionary stack will
be popped).  Or this might only apply from one file to another (extends,
include).  I'm not sure of that.  The tag that I wrote has a matching end
tag, so the stuff between gets rendered before my render returns, and the
variable that I set is available there.

Bill

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



Re: Model Theory 101 - Video Sharing App

2009-08-27 Thread Bill Freeman
Look at django-oembed.  A CharField will serve for every (supported)
provider.

On Wed, Aug 26, 2009 at 8:17 PM, thornomad  wrote:

>
> Hi - need some suggestions.
>
> I am trying to put together an app that allows users to submit links
> to videos at popular video sharing sites (e.g., youtube, vimeo, etc)
> -- the links get submitted, data about the video (title, description,
> play count, etc) is collected from the respective site and populates
> model fields, and the video entry is queued for review.
>
> Caveats: I would like to keep the original "synced" data in its own
> field and the "approved" data (as edited) in separate field.  I
> imagine that the data first gets brought into the "edit" field, admin
> may make changes and save, but the "originating" data will remain
> separate and continue to be updated (synced).
>
> This means I need at least
>
> I am stuck, though, on the most appropriate/logical approach to this
> app.  Some approaches I've considered.
>
> [1] My first thought is to create base model "Video" (with the main
> fields) and then create child models like YoutubeVideo and VimeoVideo
> and BlipVideo ... when the user submits a url, would do a regex on it
> in the view, and send it through the appropriate child class.  I could
> then grab the base Video model in my views (not having to distinguish
> the type of video) and use a "leaf" technique (eg,
> http://www.djangosnippets.org/snippets/1031/) to run the child's
> "sync" or "update" command.  CONS: seems tacky and not easy to build
> on.  The leaf technique isn't working when I override the save()
> function in leaf models.
>
> [2] Perhaps create only a single model and then create separate
> classes/functions to handle the the syncing of data based on the
> URLField data ... so, perhaps when Video.update() is called, it would
> run the logic then to see what kind of url it has, and how to update
> it.  CONS: I thought maybe I could just create a ForeignKey field to a
> non-model group of classes with common functions (update, sync,
> etc) ... but I am not sure how, or if, I can do that.
>
> [3] Outsourcing.
>
> Hope this makes sense and folks have some feedback about how they
> might approach this.  I would like this to be easily expandable -- for
> example, add YouTube and Vimeo support to start, and easily add other
> sites without having to "hack" it.
>
> I know this is a huge question, but am interested in your "Design
> Approach" thoughts ...
>
> Thanks,
> Damon
> >
>

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



Re: subprocess.Popen in django production - are file descriptors closed?

2009-08-31 Thread Bill Freeman
Are you saying that it works in the development server environment?  If so,
it could be permission
issues.  Have the ruby script append a time stamp to a world writable log
file to confirm that it gets
run.

Bill

On Fri, Aug 28, 2009 at 9:07 PM, aaron smith <
beingthexemplaryli...@gmail.com> wrote:

>
> Hey All, quick question.
>
> I have a small snippet of code that runs a ruby script, which I read
> the stdout when it's done. But, I'm not getting the stdout when it's
> in django production.
>
> Here's my python snippet:
>
> def generate_license(paymentForm,dsaPrivFile):
>name = paymentForm.cleaned_data['firstname'] + " " +
> paymentForm.cleaned_data['lastname']
>product = paymentForm.cleaned_data['product_code']
>command = "/usr/bin/ruby licensing/genlicense.rb " + "'" +
> dsaPrivFile + "'" + " " + product + " '"+name+"'"
>process =
> subprocess.Popen(command,stdout=subprocess.PIPE,shell=True)
>stdout_value = process.communicate()[0]
>print process.stdout.read()
>print stdout_value
>return stdout_value
>
> I have a couple prints in there just for testing in debug. My question
> is how to get this to behave normally in django production
> environment. I've tried a couple different things with opening tmp
> files and using that for stdout for subprocess. But no luck. Any help
> is much appreciated.
>
> 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-users@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: create a link from an object - template tag or?

2009-08-31 Thread Bill Freeman
WIth your original version here, I'm going to guess that you need to use
template.Variable()  (or learn a lot about doing what it does).  It is
mentioned
on the how to page for template tags.  IIRC, all arguments to a tag are
strings (after all, you get them with a split operation), so they must be
looked up.  So, instead of self.object = object in LinkNode, use
self.object = template.Variable(object)

Not that you need it for this tag, since simple_tag works, but you may want
to
write something fancier someday.

Bill

On Fri, Aug 28, 2009 at 10:34 PM, MIL  wrote:

>
> Hi :o)
>
> I am attempting to create a simpler way to create my links. and I
> developed this template tag:
>
>
> class LinkNode(Node):
>def __init__(self, object):
>self.object = object
>
>def render(self, context):
>model_name = self.object.get_model_name()
>linktext = self.object.get_linktext()
>url = self.object.get_absolute_url()
>if model_name and linktext and url:
>return '%s' % (url,
> model_name.lower(),
> linktext)
>return ''
>
> @register.tag
> def create_a_link(parser, token):
># {% create_a_link to object %}
>bits = token.contents.split()
>if len(bits) != 3:
>raise TemplateSyntaxError, "create_a_link tag takes exactly
> three
> arguments"
>if bits[1] != 'to':
>raise TemplateSyntaxError, "second argument to create_a_link
> tag
> must be 'to'"
>return LinkNode(bits[2],)
>
>
> But I get this error message:
> TemplateSyntaxError at /
> Caught an exception while rendering: 'unicode' object has no attribute
> 'get_model_name'
>
> What am I doing wrong
>
> Is there a simpler and better way to do this job?
>
> I would also like to develop something that can make it simpler to
> create tables and lists, but that later on.
>
> Thank you :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-users@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 make admin app use templates from app templates folder?

2009-09-01 Thread Bill Freeman
Add the filesystem template loader, put it before app directories loader,
and put the (absolute) path to your templates directory (e.g.;
/home/moho/myapp/templates) in TEMPLATES_DIR.

Bill

On Tue, Sep 1, 2009 at 11:52 AM, Aljosa Mohorovic <
aljosa.mohoro...@gmail.com> wrote:

>
> admin app uses templates/admin/base_site.html but when i move that
> file in myapp/templates/admin/base_site.html it is ignored.
> is there an additional step to ensure admin app uses templates from
> app templates folder?
> i do have
> 'django.template.loaders.app_directories.load_template_source' in
> TEMPLATE_LOADERS and it is the only entry in list.
> also, this works as expected for my apps, is there something different
> with admin app?
> is there some document that describes what can i expect when using
> admin app via manage.py runserver?
> any tips appreciated.
>
> Aljosa Mohorovic
>
> p.s.
> i'm running this with manage.py runserver
> >
>

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



Re: Is valid {% ifequal model.name "Mymodelname" %}??

2009-09-04 Thread Bill Freeman
I'm going to take a flier and guess that you want this to be conditional on
the name of the class of an instance passed in the context.  That is, you
have a model class Foo, maybe another named Bar that you have an instance of
the class, e.g.; x = Foo.objects.get(pk=1), and that you're passing it into
a template, e.g.; context(..., model=x,...).

In this case, try something like:

{% ifequal model.__class__.__name__ "Foo" %}
...

Remember, you can always temporarily add something like {{ model.name }} to
the text to see what you're comparing to that string.

Bill

On Wed, Sep 2, 2009 at 11:44 AM, Sandra Django wrote:

> Hi friends, Can I do a condition depending on my model name? For example, I
> did that:
> {% ifequal model.name "Mymodelname" %}
>  do something
> {% endifequal %}
>
> But don't work. Someone could 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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: automatic initialization of sample data

2009-09-08 Thread Bill Freeman
Jan,

Well, do you want this to happen every time that the module is imported?  Or
spend time
each server start determining that these items are already in the data base
and skipping
the initialization?  If not, then you're stuck telling the system when to do
this anyway (perhaps
a syncdb extension that does them if it has to create the database?).

You do realize that having initializers as default arguments, that they
consume virtual memory
forever, whether the database is already loaded or not.  That isn't
significant for loading 3 rows,
as in your example, but I presume that you're actually loading a much larger
set.

I typically have a CSV file, or a pickle of a list of dictionaries, and use
csv.DictReader or cpickle.load
in a loop that creates a model instance, populates such fields as have keys
in the source, and saves
the instance.  I think that it's less work than figuring out how to
configure some extension, and if you
let it be driven by the keys present, the code is pretty generic (at least
for the pickle; with the CSB
you typically want to convert some strings to ints, floats, and bools.  You
can also use XML, but I find
it more complicated, though attributes could control conversions.)

I've taken to putting that code in a separate load.py file, so that even the
code isn't loaded in the
server.  You could also just hand code a list of dictionaries in such a
file.  I still wind up running the
code from the manage shell, though you could certainly create, for example,
a view that imports the
load.py only if the view is referenced (by someone with enough privelege),
and runs the code.  Or
you could figure out how to attach it to syncdb.

But you should probably look at fixtures.  I haven't, as yet, but should.
They seem to be a supported
means of initializing a database.

Bill

On Mon, Sep 7, 2009 at 4:43 AM, Jan Ostrochovsky  wrote:

>
> Thanks Bill, yes, that is one possible solution, when implementing
> such feature from the scratch.
>
> I am only asking, if there is some existing framework for such need,
> which I see as common.
>
> For example some add-on to Django, which will do this for me. Let's
> imagine additional option for any field of Django model, e.g.:
>
> class Person(models.Model):
>  firstname = models.CharField(max_length=30, initial_values="John,
> Bill, Peter")
>  lastname = models.CharField(max_length=70, initial_values="Smith,
> Clinton, Parker")
>  ...
>
> Django with such add-on could be able to build initial database from
> these values, for example when running syncdb or other way.
>
> Am I more readable now?
>
> Jano
>
> On Aug 20, 10:09 pm, Bill Freeman  wrote:
> > Perhaps I'm not understanding correctly, but how about, assuming you have
> a
> > function
> > run_data_inits() that calls your chain of init_sample_data() functions:
> >
> > $ python manage.py shell
> >
> > >>> import myproject.myapp.models as m
> > >>> m.run_data_inits()
> > >>> ^D
> >
> > Bill
> >
> > On Thu, Aug 20, 2009 at 9:25 AM, Jan Ostrochovsky <
> >
> > jan.ostrochov...@gmail.com> wrote:
> >
> > > Hello,
> >
> > > we are in the initial phase of software project, and data model and
> > > names of attributes are changing very often, and very often we need to
> > > create new database and fill it with the same sample data for testing.
> > > We want to automate this creation of sample data.
> >
> > > Our idea: add into each models.py method e.g. init_sample_data() to
> > > each model class, and put sample data there (with well handled
> > > dependencies - ForeignKey, etc.) and each time we change model, we
> > > will aslo change concerned init_samle_data(). We will run these
> > > chained init_sample_data() for each class in the script.
> >
> > > The question is: is there some existing solution for this (in Django
> > > or its extensions), which we can use, and not reinvent it, or not? Any
> > > idea?
> >
> > > (We are using Django Evolution, which is good help, but only when
> > > changes are not too dramatic.)
> >
> > > Thanks in advance.
> >
> > > Jan Ostrochovsky
> >
>

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



Re: Django settings function object?

2009-09-08 Thread Bill Freeman
On Tue, Sep 8, 2009 at 8:00 AM, Maksymus007  wrote:

>
> I tried following code
>
> from django.conf import settings
>
> ...
>
>
> a = setting.MY_OWN_VARIABLE=2
>

If that's really what you have, try, instead:

a = settings.My_OWN_VARIABLE=2

(note the "s" on the end of "settings".)

Bill

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



Abstract Base Classes

2009-09-08 Thread Bill Freeman

I'm trying to use an Abstract Base Class as described at:

http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes

(Django 1.1, Python 2.6.2)

Things may be complicated by my desire to use a mixin:

class Mixin(object):
"""I will actually be creating some of these that aren't model instances"""
def _setFoo(self, v):
self._inner_foo = ...

def _getFoo(self):
...

foo = property(_getFoo, _setFoo)

# and other methods that process self that has _inner_foo

class AbsModel(models.Model, Mixin):
_inner_foo = models.FloatFiedl(...)

class Meta:
abstract = True

class Thing(AbsModel):
"""I want to use the property and methods from Mixin on these instances
and on instances of other subclasses of AbsModel without having to
define _inner_foo as a field in each lexical class definition (there are
actually a number of fields)."""
# Other fields
# Other methods

x = Thing()

So far, so good.  But, while x is an instance of models.Model, it is
not an instance of Mixin (according to isinstance, and also according
to the lack of a foo property).

I can make it seem to work by changing the Meta class declaration to:

class Meta(models.Model.__metaclass__):

The property is there, and isinstance reports that x is an instance of
both, but now Thing doesn't have a _meta_ attribute (so it doesn't
have fields).

Is this a bug in the Abstract Base Class mechanism, my efforts, or both?

Bill

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



Re: Abstract Base Classes

2009-09-08 Thread Bill Freeman

Actually, maybe it is working.  I should have been looking for _meta
rather than _meta_ .

But does anyone have an opinion about subclassing models.Model.__metaclass__ ?

Bill

On Tue, Sep 8, 2009 at 4:35 PM, Bill Freeman wrote:
> I'm trying to use an Abstract Base Class as described at:
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes
>
> (Django 1.1, Python 2.6.2)
>
> Things may be complicated by my desire to use a mixin:
>
> class Mixin(object):
>    """I will actually be creating some of these that aren't model instances"""
>    def _setFoo(self, v):
>        self._inner_foo = ...
>
>    def _getFoo(self):
>        ...
>
>    foo = property(_getFoo, _setFoo)
>
>    # and other methods that process self that has _inner_foo
>
> class AbsModel(models.Model, Mixin):
>    _inner_foo = models.FloatFiedl(...)
>
>    class Meta:
>        abstract = True
>
> class Thing(AbsModel):
>    """I want to use the property and methods from Mixin on these instances
>    and on instances of other subclasses of AbsModel without having to
>    define _inner_foo as a field in each lexical class definition (there are
>    actually a number of fields)."""
>    # Other fields
>    # Other methods
>
> x = Thing()
>
> So far, so good.  But, while x is an instance of models.Model, it is
> not an instance of Mixin (according to isinstance, and also according
> to the lack of a foo property).
>
> I can make it seem to work by changing the Meta class declaration to:
>
>    class Meta(models.Model.__metaclass__):
>
> The property is there, and isinstance reports that x is an instance of
> both, but now Thing doesn't have a _meta_ attribute (so it doesn't
> have fields).
>
> Is this a bug in the Abstract Base Class mechanism, my efforts, or both?
>
> Bill
>

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



Re: no such table ERROR

2009-09-14 Thread Bill Freeman

Make DATABASE_NAME an absolute path.

On Mon, Sep 14, 2009 at 12:11 AM, AIM  wrote:
>
> HI,
>
> When I browse to
> http://127.0.0.1:8000/mysite/Start/
>
> I get the following error:
>
> OperationalError at /mysite/Start/
>
> no such table: wiki_page
>
> Request Method:         GET
> Request URL:    http://127.0.0.1:8000/mysite/Start/
> Exception Type:         OperationalError
> Exception Value:
>
> no such table: wiki_page (ERROR HERE)
>
> My traceback is located at the following.
> http://dpaste.com/93287/
>
> I have ALREADY done the following in the EXACT order.
>
> --mysite/urls.py
> (r'^mysite/(?P)','mysite.wiki.views.view_page' ),
>
> --mysite/settings.py
>
> DATABASE_ENGINE = 'sqlite3'
> DATABASE_NAME = 'wiki.db'
>
> INSTALLED_APPS = (
>    #'django.contrib.auth', DELETED
>    'django.contrib.contenttypes',
>    'django.contrib.sessions',
>    'django.contrib.sites',
>    'django_extensions',
>    'mysite.wiki',
> )
>
>
> --created these three tables in wiki.db
> mysite>python manage.py syncdb
>
> Creating table django_content_type
> Creating table django_session
> Creating table django_site
>
> --creates a wiki folder containing models.py and views.py
> mysite>python manage.py startapp wiki
>
> --mysite/wiki/models.py created a model
> from django.db import models
>
> class Page(models.Model):
>        name = models.CharField(max_length="20",primary_key=True)
>        content = models.TextField(blank=True)
>
> mysite>python manage.py syncdb
> Creating table wiki_page
>
>
> --wiki/views.py
> from mysite.wiki.models import Page
> from django.shortcuts import render_to_response
>
> def view_page(request, page_name):
>  try:
>    page = Page.objects.get(pk=page_name)
>  except Page.DoesNotExist:
>    return render_to_response("create.html",{"page_name" : page_name})
>
> --mysite/create.html (NEVER MADE IT THIS FAR)
> 
>  
>     {{page_name}} - Create
>  
>  
>     {{page_name}} 
>  
> 
>
>
> Then, I reboot my wsgi web server.
>
> Last  I browse to
> http://127.0.0.1:8000/mysite/Start/
>
> And, again last I get the following error:
>
> OperationalError at /mysite/Start/
>
> no such table: wiki_page
>
> Request Method:         GET
> Request URL:    http://127.0.0.1:8000/mysite/Start/
> Exception Type:         OperationalError
> Exception Value:
>
> no such table: wiki_page
>
> My traceback is located at the following.
> http://dpaste.com/93287/
>
>
> Any ideas?
>
> Thanks.
> Andre
>
>
>
> >
>

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



Re: Removing line breaks in a template

2009-09-14 Thread Bill Freeman

1. Realize that no all line boundaries are "\r\n'.

2. You might try passing in "\r\n" in a template variable in case the
filter argument handling isn't processing the backslashes:
render...(...{...newline:"\r\n",...}) in the view, or in the extra
context in the urls.py if you're using generic views, and then {{
text|cut:newline }}

3. If 2 works on some but not all newlines (see 1) you could pass two
template variables, cr and lf, and do {{ text|cut:cr|cut:nl }}.

4. If you're not using generic views, you can always strip the line
boundaries in the view:  text=text.replace("\r\n","")

5. You can always write a custom filter.

6. You probably actually want to replace the line boundary with a
space, rather than cut it, since otherwise you may run words together.

Bill

On Thu, Sep 10, 2009 at 2:47 PM, EricR86  wrote:
>
> Hello,
>
> I was wondering if it was at all possible to remove line breaks from a
> text passed in from a template variable. Ideally I'd like to do
> something like: {{ text|cut:"\r\n" }} , but that doesn't seem to work.
> I've tried googling and searching on the mailing list with no results.
>
> Thanks for your time in advance,
>
> - Eric
> >
>

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



Re: Naming and scoping guidelines to make apps that are actually 'pluggable'?

2009-10-02 Thread Bill Freeman

On Sun, Sep 20, 2009 at 6:46 PM, Hostile Fork  wrote:
>
> Hello all,
>
> Page one of the tutorial features a large picture of a lightbulb, next
> to a statement of Philosophy:
>
>     "Django apps are 'pluggable': You can use an app in multiple
> projects, and you can distribute apps, because they don't have to be
> tied to a given Django installation."
>
> The tutorial proceeds to import "mysite.polls.models" from various
> files inside the /polls directory:
>
>   
> http://docs.djangoproject.com/en/dev/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin
>   
> http://docs.djangoproject.com/en/dev/intro/tutorial03/#write-views-that-actually-do-something
>
> I think I'm stating the obvious: if your project is called "mysite"
> and your app is called "polls", there should be no appearances of the
> string "mysite" inside your /mysite/polls directory.  That won't let
> polls plug very well into "yoursite".  I know changing your PythonPath
> can get you to the point where you can say "import polls.models", but
> this seems too foundational for the tutorial to gloss over.
>
> From my point of view, it's a further problem that "polls" appears
> inside the app... over and over.  Namespaces seem to have been
> introduced to work around the inevitable problem of wanting to
> instantiate an app twice.  But I'd like to have differently-versioned
> enlistments of the same app (in different directories) running at the
> same time.  Can namespaces help me, in a way that I don't have to
> "import polls_alpha.models" in /polls_alpha and "import
> polls_beta.models" in /polls_beta??
>
> (I don't know much Python, but I wish there'd been some way to apply
> the DRY principle to my app's name through "sys.modules[globals()
> ['__name__']]"...or some other magic).
>
> What I'd really like to find are best-practices of how to scope
> references at every level in the proejct.  Right now I find myself in
> constant puzzlement.  Like, if your PythonPath is going to get you
> access to polls.models from inside the mysite directory... why would
> your mysite's settings.py refer to it as "mysite.polls.models" and not
> just "polls.models"?
>
> Thanks,
> Brian

I've been using os.path based manipulations of __file__ in settings.py
to calculate "PROJECT_NAME", which can then be obtained from
django.conf.settings and used to customize various strings, even
passed in template context.

That's less help with bare imports, though you can call the underlying
mechanisms to pass the module name as a string (django does this a
lot).  An alternative, if you are willing to tie yourself to reasonably recent
pythons is to use the new explicit relative import syntax.  I'm not sure
when it changes to the default, probably 2.7?, but you will probably
need to use:

  from __future__ import absolute_inport

Then you can say things like:

  from . import models

or

  from .models import MyModel

or, from your templatetags directory

  from ..models import MyModel



Note that this makes it possible to have an app specific settings module,
in the same directory as models.py, which can calculate APP_NAME, or the
like, and be relatively imported (django.conf doesn't help you here).  You
can almost do it without absolute_import, since a bare:

  import settings

will get the app specific one from your models.py, views.py, etc., and it will
work, but not from subpackages like templatetags.  Of course, each module
could perform it's own os.path manipulations to figure out the app name.

These os.path manipulations probably mean that you can't run from a
zipped egg.

Bill

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



Re: How to pass values between views/templates

2009-10-05 Thread Bill Freeman

On Fri, Oct 2, 2009 at 9:16 PM, adelaide_mike
 wrote:
>
> Hi
> In my app the user needs to drill down through a series of templates
> and their views to identify a house.  We start with the city, then the
> street and finally the house, in each case chosen from a rendering of
> the possible values selected from the relevant database table.
>
> I have all this working nicely using request.session['insert value
> here'] as the tool for storing the choices as they are made.
>
> My question is: is there a better or more proper way?
>
> Mike

Mike,

The primary disadvantage of storing navigation state in the session,
or, for that mater,
in variables sent in a POST, is that, for example, a user emailing the
url to their spouse
("Hey, honey, look at this one!") isn't going to work.  If you are
concerned about long
urls, you could always compress them and then uuencode the value and
use that in the
url.  Better probably would be just use a database primary key for the url part.

Bill

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



Re: "manage.py syncdb" fails when called via SCons

2009-10-05 Thread Bill Freeman

Before you start python (assuming *nix, including os/x), type:

   $ which python

Then, in the subshell, before starting python,  type the same thing.  Compare.

Bill

On Mon, Oct 5, 2009 at 12:02 PM, Ralph Heinkel  wrote:
>
> Hi,
>
> I just checked the environment for PYTHONPATH, it is neither set in
> the parent nor in the subshell.
>
> Actually, I can reduce the problem to this:
>
> 1. In my unix shell I start the python interpreter
> 2. in Python:   import os; os.system('/bin/bash')
> 3. In the just opened subshell:   python manage.py syncdb
>
> Again, it doesn't create my own model tables, just the system tables.
>
> Ralph
>
> >
>

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



media url naming, philosophies and reasons?

2009-10-06 Thread Bill Freeman

Media seems to come in several flavors (admin, non-admin read only,
uploadable to, maybe more).  We have MEDIA_URL and
ADMIN_MEDIA_PREFIX available in settings.py for configuring where our
projects will look for their media.

I've seen '/media/' and MEDIA_URL+'admin/', but I've also seen '/site_media/'
and '/media/' where the "admin media" is not within the 'media root'.  I've also
seen some apps hardwired to use '/site_media/' (though that might be Pinax
specific).

Of course there are several apps/extensions which seem to use
ADMIN_MEDIA_PREFIX as a guide.

1. Ignoring, for the moment, OSes that don't implement symbolic links, is there
a good reason not to put all usages under the same hierarchy?

2. Is the Django world converging on a single strategy?

3. Do any of you have a strong feeling about "The Right Way (TM)" to do
it?

Bill

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



Re: compilemessages invalid multibyte sequence error

2009-10-13 Thread Bill Freeman

This may be a matter of using the correct encoding in the file.
Be sure that the editor that you are using is treating the file as UTF-8.
(I presume from the headers that the compile step is treating the
file as UTF-8, but the editor may not look at that header, and may,
for example, be using latin-1.)

Bill

On Tue, Oct 13, 2009 at 12:40 AM, celopes  wrote:
>
> I have a django.po file containing:
>
> # SOME DESCRIPTIVE TITLE.
> # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
> # This file is distributed under the same license as the PACKAGE
> package.
> # FIRST AUTHOR , YEAR.
> #
> #, fuzzy
> msgid ""
> msgstr ""
> "Project-Id-Version: PACKAGE VERSION\n"
> "Report-Msgid-Bugs-To: \n"
> "POT-Creation-Date: 2009-10-12 22:28-0400\n"
> "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
> "Last-Translator: FULL NAME \n"
> "Language-Team: LANGUAGE \n"
> "MIME-Version: 1.0\n"
> "Content-Type: text/plain; charset=UTF-8\n"
> "Content-Transfer-Encoding: 8bit\n"
>
> #: core/templates/index.html:7
> msgid "Currently selected language is"
> msgstr "A linguagem atualmente selecionada é"
>
> #: core/templates/index.html:8
> msgid "Howdy!"
> msgstr "E aí?!"
>
> When I try to compile messages, I get an error like:
>
> processing file django.po in .../locale/pt_br/LC_MESSAGES
> .../locale/pt_br/LC_MESSAGES/django.po:25:44: invalid multibyte
> sequence
> .../locale/pt_br/LC_MESSAGES/django.po:29:12: invalid multibyte
> sequence
> msgfmt: found 2 fatal errors
>
> The problem is obviously related to any accented characters (in the
> excerpt above é and í). If I replace those by their non-accented
> counterparts or by é and í the compilation works fine
> and translation operates normally.
>
> I'm running mac os x 10.6.1 and the accented characters are the result
> of me typing using the US International - PC keyboard layout (so, I
> press single-quote-e to obtain é; for example).
>
> What am I doing wrong, please?
>
> Thanks,
>
> CE
>
> >
>

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



Truth values for current database type for custom queries.

2009-10-26 Thread Bill Freeman

I have a query that is complex enough that, even if it can be done
with filter, exclude, and Qs, I find more maintainable as custom SQL.
That all works fine.

But I want to add the test of a boolean field in my WHERE clause, and
different databases represent true and false differently.
Specifically, during development, and probably for later bug fix
testing, I find it convenient to use sqlite, where true and false are
1 and 0, but we will likely deploy on PostgreSQL, where they (at least
as returned
by the command line tool) be t and f, and the documentation implies
that true and false will also work.

I can clearly check settings from django.conf to see which DB I'm
using, and adjust my queries, but it occurs to me that the ORM already
knows how to represent true and false for the current DB.

Is there a reasonable and unlikely to change way of programatically
asking the ORM for the representations?

Thanks, Bill

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



Re: static models methods

2009-10-26 Thread Bill Freeman

I have to wonder whether "get_default" is a name that already means
something to Django.

On Mon, Oct 26, 2009 at 12:22 PM, Alessandro Ronchi
 wrote:
>
> I need to create a static method for a model class like this. The line
> Settore.objects.all()[0].id gives error  (
> psycopg2.InternalError: current transaction is aborted) when creating
> the tables at first syncdb. What's the correct way to do that?
>
> ~
> class Settore(models.Model):
>    nome = models.CharField(max_length=200, blank=False, null=False)
>    email = models.EmailField()
>
>    class Meta:
>
>        verbose_name_plural = 'settori'
>        ordering = ('nome',)
>        get_latest_by = "nome"
>
>    def __unicode__(self):
>        return self.nome
>
>   �...@staticmethod
>    def get_default():
>        try:
>            return Settore.objects.all()[0].id
>        except:
>            return None
> ~
> --
> Alessandro Ronchi
>
> SOASI
> Sviluppo Software e Sistemi Open Source
> http://www.soasi.com
> http://www.linkedin.com/in/ronchialessandro
>
> >
>

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



Re: Specifying Django Project/Application Templates

2009-10-29 Thread Bill Freeman

If I understand your problem correctly, you can already override such
templates.  If there is a template in your project's template directory
with the same name and sub-path as that used by django base code
or a system wide installed application, it will be used instead.

Perhaps an example.  Suppose that you're using the foo application,
and it loads a template 'foo/bar.html', which is in the application's
'templates/foo' directory.  This is found via the app template loader.
If you create a directory 'foo' as a subdirectory of your project's
'templates' directory, and put a file in it named 'bar.html', that will
be used instead of the one provided by the app.

The necessary (and common) pre-conditions for this to work are,
all in settings.py:

The full path to your templates directory is listed (probably first)
in the TEMPLATE_DIRS tuple.  (I use os.path.join(PROJECT_ROOT,
"templates") which requires that I have earlier said something like
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__)) .)

'django.template.loaders.filesystem.load_template_source' must
be listed in the TEMPLATE_LOADERS tuple, and come before
'django.template.loaders.app_directories.load_template_source'.
(These are usually the only two, and they are in that order by
default.)

Now, if you want to change what template the app's view tries to load,
so that you can still access the original to extend it, without copying
and renaming it, that's a more interesting problem.

Bill

On Thu, Oct 29, 2009 at 8:44 AM, Johan  wrote:
>
> Hi. Is there a way to specify custom project (or what I call sites)
> and application templates. At present the python-admin.py startproject/
> startapp uses the default templates that ships with django. I end up
> either having to create these myself or heavily modify them for my dev
> structure. It seems to me that it would be quite simple to change the
> code in django.core.management.base and
> django.core.management.commands.startproject/startapp to allow the
> user to specify custom project and application templates. The idea
> would be that i can run the following type of command: djang-admin.py
> startproject template.config. Does anybody see the need for this type
> of functionality or not?
> >
>

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



Re: pdb doesn't break in django

2009-10-30 Thread Bill Freeman

It works for me.

Maybe you're not getting to those statements?  Another module of the same name
on the path being imported instead?  When I stick it in a view
function and it doesn't
hit it's usually because I've botched urls.py.

Try putting them at top level in the module, in which case it should
stop during import.
Follow it with a print statement so that if it doesn't stop you know
whether the code
got run.

You are doing this from the command line, such as shell or runserver,
right?  set_trace()
isn't useful, so far as I know, in WSGI or mod_python modes.

[What bothers me is that if I use
pdb.run('some_module.some_function()') in manage
shell, it doens't seem to be able to figure out what filesystem .py
file goes with the module,
so it can't print source lines and you're single stepping blind.
Works fine from a set_trace()
but sometimes I'd rather not edit the source code, especially on a
shared server, and it's
a pain to create a dummy module with a set_trace() and the call to the
target function.]

Bill

On Fri, Oct 30, 2009 at 1:11 PM, skunkwerk  wrote:
>
> Hi,
>   i've been trying to use pdb inside my django code, but it never
> breaks the program flow.  I insert this into my code:
>
> import pdb
> pdb.set_trace()
>
> but it just continues execution - is there something i need to be
> doing?
>
> 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-users@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: Display Certain Fields of the Model Formset As Text

2009-10-30 Thread Bill Freeman

Yet another option is to write a widget that subclasses the existing
one, and adds
disabled='disabled' to the dictionary that will be used to populate
the attributes
(usually the 'attrs' argument, I think, and you will have to handle
the possibility
that you will be passed None instead of a dict).

Bill

On Fri, Oct 30, 2009 at 1:47 AM, Anthony Simonelli
 wrote:
>
> Hello,
>
> I am using a Model Formset because there are two foreign keys in my Model and 
> it makes it easy to create forms with them preselected from data in my model:
>
> class ForecastActualSum(models.Model):
>    sales_rep = models.ForeignKey(SalesrepGrpname)
>    customer = models.ForeignKey(Customer)
>    item = models.CharField(max_length=200)
>    actual = models.FloatField(null=True, blank=True)
>    forecast = models.FloatField(null=True, blank=True)
>    plan = models.FloatField(null=True, blank=True)
>
> When using a model formset, all the fields are displayed and are editable, 
> but I just want the 'forecast' field to be editable and the rest of the 
> fields to be displayed.  Is there any way to display the fields as text 
> rather than as input fields?  I've also tried sending the corresponding 
> ForecastActualSum objects along with the formset to the template to be 
> displayed along side formset, but I can't iterate both at the same time to 
> make them line up like a table.  Anyone have any ideas?  Maybe model formset 
> is not the way to go?
>
> Anthony
>
> >
>

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



Re: Display Certain Fields of the Model Formset As Text

2009-10-30 Thread Bill Freeman

On Fri, Oct 30, 2009 at 4:36 PM, Preston Holmes  wrote:
>
>
>
> On Oct 30, 12:00 pm, Bill Freeman  wrote:
>> Yet another option is to write a widget that subclasses the existing
>> one, and adds
>> disabled='disabled' to the dictionary that will be used to populate
>> the attributes
>> (usually the 'attrs' argument, I think, and you will have to handle
>> the possibility
>> that you will be passed None instead of a dict).
>
> When using widget.attr how does one specify a attr that is name only,
> not key/value.
>
> T

he disabled key is not a k/v attr:
>
> 
>
> -Preston
>

True.  But it seems to work, and I don't know whether you can use the
attr dict hack of widget.render() to set it without a value.

Do you know of browsers in which the following will fail?"

  

Or, if just overriding render when subclassing a widget, and mostly
calling the superclass render with modified arguemtns, is there
something else to add to attrs to get it to produce it without the
"='something'"?

Bill

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



Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-02 Thread Bill Freeman

I've been developing a Django 1.0 project (using Pinax, actaully) on a
machine that has PostgreSQL 8.1.11 (Linux), where things work just
fine.  Now I've deployed to a (still development) customer visible
server that has an 8.4 PostgreSQL (also on Linux), which throws errors
complaining that equals doesn't know how to compare a character
varying with an integer.

Not much analysis reveals that that folks are accustomed to treating
the FriendInvitation.status field, a models.CharField with
max_length=1 and a set of choices whose DB side representation is a
string composed of a single decimal digit, with literal ints (e.g.;
self.status = 5 in the FriendInvitation.accept()).  This is
django_friends version 0.1.2.  I'm hitting the problem on a queryset
with exclude(status=8).

Some testing with psql shows that of:

  select * from friends_friendshipinvitation where status = '8' ;

and

  select * from friends_friendshipinvitation where status = 8 ;

work fine on pg8.1.11, but only the first works on pg8.4 (the column
is character varying(1) in both databases).

My presumption is that the older PostgreSQL, expecting to have to
decide whether unquoted things are strings (e.g.; "status" in the
query samples above), used to look at the context and decided that we
had meant the 8 as a string.  That probably led to difficult to
diagnose errors, and they have tightend up in 8.4.  I can still get
away with not quoting the table and field names (so long as they don't
have funny characters), but things that look like numbers now are
numbers unless quoted.

I can make myself a copy of django_friends that won't get updated when
Pinax does, and patch it to work, but since I found my failure in a
profiles app that uses friends, I wonder how many other places I'll
have to patch.

It occurs to me that the ORM could fix this.  It knows that status is
a CharField.  For anything but None (which it should try to store as
null) it should be reasonable to apply str() (or unicode()) to the
field value before storing it.  str(8) -> '8' (and unicode(8) ->
u'8'), while str() applied to a string (or unicode() applied to a
unicode string) leaves it unchanged (doesn't even copy in, in a few
quick tests in python 2.6.2).  Then the backend will know to quote it.

Thoughts?  Workaround suggestions?

Bill

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



Re: Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-03 Thread Bill Freeman

On Tue, Nov 3, 2009 at 7:05 AM, Russell Keith-Magee
 wrote:
>
> On Tue, Nov 3, 2009 at 12:19 PM, Christophe Pettus  wrote:
>>
>>
>> On Nov 2, 2009, at 2:14 PM, Bill Freeman wrote:
>>> My presumption is that the older PostgreSQL, expecting to have to
>>> decide whether unquoted things are strings (e.g.; "status" in the
>>> query samples above), used to look at the context and decided that we
>>> had meant the 8 as a string.
>>
>> In particular, as of PostgreSQL 8.3 (and thus 8.4), non-text types are
>> not automatically cast to text.  You can find the details in the 8.3
>> release notes:
>>
>>        http://www.postgresql.org/docs/8.3/static/release-8-3.html
>>
>> The relevant section is E.9.2.1.
>>
>>> Thoughts?  Workaround suggestions?
>>
>> I'm not completely sure why the ORM is generating SQL that compares a
>> number with a character string in the first place; that sounds like a
>> bug in either the ORM or the client code, to me.
>
> I concur. This looks like it might be a Django bug.
>
> If I understand the original problem correctly, it is this:
>
> class MyObj(models.Model):
>    CHOICES = (
>        ('1', 'first choice')
>        ('2', 'second choice')
>    )
>    choice = models.CharField(max_length=1, choices=CHOICES)
>
> Now run two queries. First, query using an integer:
>
> MyObj.objects.filter(choice=1)
>
> This yields the SQL:
>
> ('SELECT `myapp_myobj`.`id`, `myapp_myobj`.`choice` FROM `myapp_myobj`
> WHERE `myapp_myobj`.`choice` = %s ', (1,))
>
> Now, query with an actual string:
>
> MyObj.objects.filter(choice='1')
>
> which yields the SQL:
>
> ('SELECT `myapp_myobj`.`id`, `myapp_myobj`.`choice` FROM `myapp_myobj`
> WHERE `myapp_myobj`.`choice` = %s ', ('1',))

Might that have to be:

'SELECT ... `choice` = `%s`', ('1',))

because %s renders both 1 and '1' as the single character 1.

But then, if I understand correctly, by the time this gets to the DB
it's actually something like:
   SELECT ... = ? '

and I don't know how the quoting works there.  Still that's the
province of the adaptor, and all django can do is decide what is
passed to psycopg2.  I guess I'm going to learn more about the DB
adaptor.
>
> The fact that the first example (the integer lookup) passes at all is
> due to the good grace of the databases themselves - logically, I think
> Postgres 8.4 is correct in declaring this an error. "1" != 1.
>
> I think the fix is pretty simple. CharField doesn't currently have a
> get_db_prep_value() method, and it should.
>
> Compare and contrast with IntegerField or BooleanField - both these
> fields have get_db_prep_value() methods that cast the provided value
> to int() and bool(). CharField (and TextField for that matter) should
> do the same, but with unicode(). This would force the filter value of
> 1 into '1', which will be passed to the backend as a string, as it
> should be.
>
> I've just opened ticket #12137 to track this. I've put it on the 1.2
> milestone, so we will endeavour to fix it before we hit v1.2. Any
> assistance in turning the example and suggested fix into a trunk-ready
> patch will be gratefully accepted.

Since this is impacting me right now, I'll spend some quality time
with pdb to try and come up with a patch.

News at it happens.
>
> Yours,
> Russ Magee %-)

Bill

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



Re: Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-03 Thread Bill Freeman

On Tue, Nov 3, 2009 at 9:14 AM, Bill Freeman  wrote:
> On Tue, Nov 3, 2009 at 7:05 AM, Russell Keith-Magee
>  wrote:
>>
>> On Tue, Nov 3, 2009 at 12:19 PM, Christophe Pettus  wrote:
>>>
>>>
>>> On Nov 2, 2009, at 2:14 PM, Bill Freeman wrote:
>>>> My presumption is that the older PostgreSQL, expecting to have to
>>>> decide whether unquoted things are strings (e.g.; "status" in the
>>>> query samples above), used to look at the context and decided that we
>>>> had meant the 8 as a string.
>>>
>>> In particular, as of PostgreSQL 8.3 (and thus 8.4), non-text types are
>>> not automatically cast to text.  You can find the details in the 8.3
>>> release notes:
>>>
>>>        http://www.postgresql.org/docs/8.3/static/release-8-3.html
>>>
>>> The relevant section is E.9.2.1.
>>>
>>>> Thoughts?  Workaround suggestions?
>>>
>>> I'm not completely sure why the ORM is generating SQL that compares a
>>> number with a character string in the first place; that sounds like a
>>> bug in either the ORM or the client code, to me.
>>
>> I concur. This looks like it might be a Django bug.
>>
>> If I understand the original problem correctly, it is this:
>>
>> class MyObj(models.Model):
>>    CHOICES = (
>>        ('1', 'first choice')
>>        ('2', 'second choice')
>>    )
>>    choice = models.CharField(max_length=1, choices=CHOICES)
>>
>> Now run two queries. First, query using an integer:
>>
>> MyObj.objects.filter(choice=1)
>>
>> This yields the SQL:
>>
>> ('SELECT `myapp_myobj`.`id`, `myapp_myobj`.`choice` FROM `myapp_myobj`
>> WHERE `myapp_myobj`.`choice` = %s ', (1,))
>>
>> Now, query with an actual string:
>>
>> MyObj.objects.filter(choice='1')
>>
>> which yields the SQL:
>>
>> ('SELECT `myapp_myobj`.`id`, `myapp_myobj`.`choice` FROM `myapp_myobj`
>> WHERE `myapp_myobj`.`choice` = %s ', ('1',))
>
> Might that have to be:
>
>    'SELECT ... `choice` = `%s`', ('1',))
>
> because %s renders both 1 and '1' as the single character 1.
>
> But then, if I understand correctly, by the time this gets to the DB
> it's actually something like:
>   SELECT ... = ? '
>
> and I don't know how the quoting works there.  Still that's the
> province of the adaptor, and all django can do is decide what is
> passed to psycopg2.  I guess I'm going to learn more about the DB
> adaptor.
>>
>> The fact that the first example (the integer lookup) passes at all is
>> due to the good grace of the databases themselves - logically, I think
>> Postgres 8.4 is correct in declaring this an error. "1" != 1.
>>
>> I think the fix is pretty simple. CharField doesn't currently have a
>> get_db_prep_value() method, and it should.
>>
>> Compare and contrast with IntegerField or BooleanField - both these
>> fields have get_db_prep_value() methods that cast the provided value
>> to int() and bool(). CharField (and TextField for that matter) should
>> do the same, but with unicode(). This would force the filter value of
>> 1 into '1', which will be passed to the backend as a string, as it
>> should be.
>>
>> I've just opened ticket #12137 to track this. I've put it on the 1.2
>> milestone, so we will endeavour to fix it before we hit v1.2. Any
>> assistance in turning the example and suggested fix into a trunk-ready
>> patch will be gratefully accepted.
>
> Since this is impacting me right now, I'll spend some quality time
> with pdb to try and come up with a patch.
>
> News at it happens.
>>
>> Yours,
>> Russ Magee %-)
>
> Bill
>

Well, adding the obvious get_db_prep_value()  (thanks Russ) to both
CharField and TextField in django/db/models/fields/__init__.py makes
my app work on ps8.4 without any ill effects on pg8.1.11.  I've tested
most of the page types that I have in both circumstances without
noticing any anomalies.

Of course that doesn't prove that there's nobody who depends on the
old behavior.

I basically copied the version from BooleanField, and changed the
"return bool(value)" to "return unicode(value)" (though everything
else inside the queryset's query object seems to be string rather than
unicode, so I'm not positive that "return str(value)" isn't more self
consistent).

I'll try to provide something more formal as a response to the ticket.

Bill

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



Re: Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-03 Thread Bill Freeman

On Tue, Nov 3, 2009 at 6:46 PM, Russell Keith-Magee
 wrote:
>
> On Wed, Nov 4, 2009 at 3:05 AM, Bill Freeman  wrote:
>>
>> On Tue, Nov 3, 2009 at 9:14 AM, Bill Freeman  wrote:
>>> On Tue, Nov 3, 2009 at 7:05 AM, Russell Keith-Magee
>>>  wrote:
>>>>
>>>> On Tue, Nov 3, 2009 at 12:19 PM, Christophe Pettus  
>>>> wrote:
>>>>>
>>>>>
>>>>> On Nov 2, 2009, at 2:14 PM, Bill Freeman wrote:
>>>>>> My presumption is that the older PostgreSQL, expecting to have to
>>>>>> decide whether unquoted things are strings (e.g.; "status" in the
>>>>>> query samples above), used to look at the context and decided that we
>>>>>> had meant the 8 as a string.
>>>>>
>>>>> In particular, as of PostgreSQL 8.3 (and thus 8.4), non-text types are
>>>>> not automatically cast to text.  You can find the details in the 8.3
>>>>> release notes:
>>>>>
>>>>>        http://www.postgresql.org/docs/8.3/static/release-8-3.html
>>>>>
>>>>> The relevant section is E.9.2.1.
>>>>>
>>>>>> Thoughts?  Workaround suggestions?
>>>>>
>>>>> I'm not completely sure why the ORM is generating SQL that compares a
>>>>> number with a character string in the first place; that sounds like a
>>>>> bug in either the ORM or the client code, to me.
>>>>
>>>> I concur. This looks like it might be a Django bug.
>>>>
>>>> If I understand the original problem correctly, it is this:
>>>>
>>>> class MyObj(models.Model):
>>>>    CHOICES = (
>>>>        ('1', 'first choice')
>>>>        ('2', 'second choice')
>>>>    )
>>>>    choice = models.CharField(max_length=1, choices=CHOICES)
>>>>
>>>> Now run two queries. First, query using an integer:
>>>>
>>>> MyObj.objects.filter(choice=1)
>>>>
>>>> This yields the SQL:
>>>>
>>>> ('SELECT `myapp_myobj`.`id`, `myapp_myobj`.`choice` FROM `myapp_myobj`
>>>> WHERE `myapp_myobj`.`choice` = %s ', (1,))
>>>>
>>>> Now, query with an actual string:
>>>>
>>>> MyObj.objects.filter(choice='1')
>>>>
>>>> which yields the SQL:
>>>>
>>>> ('SELECT `myapp_myobj`.`id`, `myapp_myobj`.`choice` FROM `myapp_myobj`
>>>> WHERE `myapp_myobj`.`choice` = %s ', ('1',))
>>>
>>> Might that have to be:
>>>
>>>    'SELECT ... `choice` = `%s`', ('1',))
>>>
>>> because %s renders both 1 and '1' as the single character 1.
>>>
>>> But then, if I understand correctly, by the time this gets to the DB
>>> it's actually something like:
>>>   SELECT ... = ? '
>>>
>>> and I don't know how the quoting works there.  Still that's the
>>> province of the adaptor, and all django can do is decide what is
>>> passed to psycopg2.  I guess I'm going to learn more about the DB
>>> adaptor.
>>>>
>>>> The fact that the first example (the integer lookup) passes at all is
>>>> due to the good grace of the databases themselves - logically, I think
>>>> Postgres 8.4 is correct in declaring this an error. "1" != 1.
>>>>
>>>> I think the fix is pretty simple. CharField doesn't currently have a
>>>> get_db_prep_value() method, and it should.
>>>>
>>>> Compare and contrast with IntegerField or BooleanField - both these
>>>> fields have get_db_prep_value() methods that cast the provided value
>>>> to int() and bool(). CharField (and TextField for that matter) should
>>>> do the same, but with unicode(). This would force the filter value of
>>>> 1 into '1', which will be passed to the backend as a string, as it
>>>> should be.
>>>>
>>>> I've just opened ticket #12137 to track this. I've put it on the 1.2
>>>> milestone, so we will endeavour to fix it before we hit v1.2. Any
>>>> assistance in turning the example and suggested fix into a trunk-ready
>>>> patch will be gratefully accepted.
>>>
>>> Since this is impacting me right now, I'll spend some quality time
>>> with pdb to try

Re: Dictionary pagination

2009-11-04 Thread Bill Freeman

On Wed, Nov 4, 2009 at 1:32 PM, David  wrote:
>
> Hello,
>
> I just wonder if anybody has handled this before. Here is a 2-D
> dictionary.
>
> dict[key_1] = {'a':'aa', 'b':'bb', 'c':'cc'}
> dict[key_2] = {'a':'dd', 'b':'ee', 'c':'ff'}
> dict[key_3] = {'a':'eef', 'b': 'ff', 'c':'ghh'}
> 
>
> Assume that this dict is so long that I need to paginate. Do I need to
> convert it to a list in order to use Paginator
> ?
>
> Is there a good way to paginate this dictionary?
>
> Thanks for your ideas.

You at least need to list the keys, say by using the keys() method.
The trouble with
thinking of paginating a dictionary is that it has no inherent order.
When you go back
for items n through 2n-1, for example, there is no guarantee that what
you get won't
share items with the first 0-n.  That the order may seem stable in
casual testing is an
implementation detail that you shouldn't depend on.

Probably you want to sort this somehow too, so that the presentation
order makes sense.
So something like:

ks = d.keys()
ks.sort()

Then for page p of n items:

for k in ks[n*(p-1):n*p]:
v = d[k]

Note that if pages are displayed across multiple requests, you need to
put ks somewhere that its value will be preserved until the next
request.  Or if you're sure that d won't change between requests, just
do the call to the keys method and the sort each time.

[Note, too, re your sample, that "dict" is a bad name for a dictionary
variable, because it is also the name of the type.  It will work, but
it will get confusing.]

Bill

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



Re: Imports, works from directory but not from file

2009-11-10 Thread Bill Freeman

Which all of these directories are on your python path, and which of
them have __init__.py files?

Bill

[Hint to answer first question:

from pprint import pprint as pp
import sys
pp(sys.path)

]

On Tue, Nov 10, 2009 at 5:12 PM, When ideas fail
 wrote:
>
> I have a folder called lib on my path and in there I have a folder
> called openid.
>
> If i want to import things from openid i have a problem.
>
> For example if I have these 2 import statements:
>
> from openid.yadis import xri
> from openid.association import Association as OIDAssociation
>
> yadis is a directory (in openid) and then there is xri.py inside. This
> works fine.
> association is a .py file not in a subdirectory, just in lib/openid
> this produces the following error:
>
> Traceback (most recent call last):
>  File "C:\TheAbeonaFile\Apache2.2\MyProject\test.py", line 18, in
> 
>    from openid.association import Association as OIDAssociation
> ImportError: No module named association
>
> I don't see why one would be a problem and not the other, does anyone
> have any ideas?
>
> 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-users@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: Imports, works from directory but not from file

2009-11-10 Thread Bill Freeman

Did you really mean "init.py", rather than the required "__init__.py".
 If so, that's wrong.

I presume that the names of the files and directories are all lower
case and contain no spaces or accented characters.

I presume that you've checked and rechecked the spelling of the file
name against the spelling in the import statement.

It is just possible that it's a permission problem.  Can you open the
files for reading?  In the manage.py shell try (and assuming FILE_ROOT
is the current directory):

open('lib/openid/association.py').readline()

If that doesn't give an exception, but just prints the first line of
the file, good.

If there's an association.pyc remove it and try again (write
permission problem to replace file
with compiled python for the version of the interpreter in use, though
I think it would work fine
anyway).

I'd expect a different exception, but maybe a problem in
association.py is preventing it from importing.  Try adding:

import pdb;pdb.set_trace()

to the top of association.py and see if it gets there and stops, then
step along ("n" command) to see that it all completes.

Check that the file doesn't have Apple line endings ('\r' only).  I
know that both DOS and *nix line endings work on Windows ('\r\n' and
'\n' respectively).

There could be problems if the file is in a unicode variant as opposed
to simple 7 bit ASCII, though I hope not.  That would probably be
clear from the open test above.

Check that the __init__.py files are either empty, or have valid
python contents.

Beyond that, I'm out of ideas.  Good luck.

Bill

On Tue, Nov 10, 2009 at 5:24 PM, When ideas fail
 wrote:
>
> I used this in my settings.py to add the open id folder on my path
> sys.path.append(os.path.join(FILE_ROOT, 'lib', 'openid'))
>
> and on my path it say:
> 'C:\\TheAbeonaFile\\Python26\\Lib\\idlelib\\lib\\openid'
>
> And both the yadis file and openid file have an init.py
>
> On 10 Nov, 22:18, Bill Freeman  wrote:
>> Which all of these directories are on your python path, and which of
>> them have __init__.py files?
>>
>> Bill
>>
>> [Hint to answer first question:
>>
>> from pprint import pprint as pp
>> import sys
>> pp(sys.path)
>>
>> ]
>>
>> On Tue, Nov 10, 2009 at 5:12 PM, When ideas fail
>>
>>  wrote:
>>
>> > I have a folder called lib on my path and in there I have a folder
>> > called openid.
>>
>> > If i want to import things from openid i have a problem.
>>
>> > For example if I have these 2 import statements:
>>
>> > from openid.yadis import xri
>> > from openid.association import Association as OIDAssociation
>>
>> > yadis is a directory (in openid) and then there is xri.py inside. This
>> > works fine.
>> > association is a .py file not in a subdirectory, just in lib/openid
>> > this produces the following error:
>>
>> > Traceback (most recent call last):
>> >  File "C:\TheAbeonaFile\Apache2.2\MyProject\test.py", line 18, in
>> > 
>> >    from openid.association import Association as OIDAssociation
>> > ImportError: No module named association
>>
>> > I don't see why one would be a problem and not the other, does anyone
>> > have any ideas?
>>
>> > 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-users@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: Imports, works from directory but not from file

2009-11-11 Thread Bill Freeman

I had another couple of thoughts.

In the manage.py shell, try:

from openid.yadis import xri
xri

The output will include from where it got xri.  Make sure that it's
coming from your lib directory, and not from some old system wide
installation of openid.


Instead of:

from openid.association import Association as OIDAssociation

try:

from association import Association as OIDAssociation


Also, expecially if the previous worked, in your settings.py, instead of:

sys.path.append(os.path.join(FILE_ROOT, 'lib', 'openid'))

try

sys.path.append(os.path.join(FILE_ROOT, 'lib'))

Bill

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



Re: Imports, works from directory but not from file

2009-11-11 Thread Bill Freeman

Does your project root (I'm assuming that's the directory containing
the sub directory "app") have an __init__.py file.  Does the app
directory?  I'm assuming that the one you mention below is in
app/models/ .  All three are required, if what you have on your
sys.path is just the project root.

Do make sure that your project root is on your sys.path.  You can do
that by temporarily adding:

import foo

to settings.py, and creating a file foo.py in the project root containing, say:

print "Foo!"

and then do:

python manage.py shell

As part of the startup printout you should get a line containing only:

Foo!

By the way, I'm pretty sure that lots of django internal machinery,
like syncdb, for example, depends on there being a file named exactly
"models.py" in each app.  So a better choice of directory structure
might be "app/myapp/models.py", with your myclass class in the
models.py file.  Pinax uses such a structure, though the upper
directory is called apps instead of app (there may be more than one)
and has been added to the path, so that you can mention it in
INSTALLED_APPS as just 'myapp', rather than 'apps/myapp'.  If you go
this route, you will want to insert the apps directory at or near the
beginning of sys.path, rather than appending it, so that when you
mention a possibly installed app, such as django_microblogging, but
which you have customized in a copy in your apps folder, you can say
'microblogging' in your INSTALLED_APPS and it will find yours rather
than the system version.  (TN.B.: emplate paths are a separate issue.)

Bill

On Wed, Nov 11, 2009 at 10:34 AM, andreas schmid  wrote:
>
> im experiencing the same problem.
> i started with a simple app and the modules.py was at the root of the
> app package, so everything was fine.
> now i extended the app and restructured the files in it by making a
> subfolder app/models and inside an __init__.py and the mymodel.py
>
> in the urls.py which i have an import like
> from app.models.mymodel import myclass
>
> and while the django shell is able to import it without any problem the
> django server isnt. im using buildout to build the whole django
> environment so the python interpreter im starting the shell and the one
> of the server is the same.
>
> i already tried to remove all .pyc and start everything again but i had
> no luck.
>
> this is weird and i cant figure out what the problem could be.
>
>
>
> Bill Freeman wrote:
>> I had another couple of thoughts.
>>
>> In the manage.py shell, try:
>>
>>     from openid.yadis import xri
>>     xri
>>
>> The output will include from where it got xri.  Make sure that it's
>> coming from your lib directory, and not from some old system wide
>> installation of openid.
>>
>>
>> Instead of:
>>
>>     from openid.association import Association as OIDAssociation
>>
>> try:
>>
>>     from association import Association as OIDAssociation
>>
>>
>> Also, expecially if the previous worked, in your settings.py, instead of:
>>
>>     sys.path.append(os.path.join(FILE_ROOT, 'lib', 'openid'))
>>
>> try
>>
>>     sys.path.append(os.path.join(FILE_ROOT, 'lib'))
>>
>> Bill
>>
>> >
>>
>>
>
>
> >
>

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



Re: Imports, works from directory but not from file

2009-11-12 Thread Bill Freeman
If that wasn't a typo, I suspect that you're going to have trouble
with having a directory
named "views.py".  I don't know how you import anything from it unless
it is directly on
your path.

When you say "my app is in the pythonpath of the environment":
   1. Which directory is in the python path?
   2. If you mean that you've added it to the PYTHONPATH environment
variable then
please check whether you can find it in sys.path when running in the manage.py
shell.  (If you don't know how to do that, please ask.)  I don't know
if your on Windows
or something else, but, especially on Windows, I don't take it for
granted that environment
settings will be properly respected/available.

Bill

On Thu, Nov 12, 2009 at 2:39 AM, andreas schmid  wrote:
> Bill Freeman wrote:
>> Does your project root (I'm assuming that's the directory containing
>> the sub directory "app") have an __init__.py file.  Does the app
>> directory?  I'm assuming that the one you mention below is in
>> app/models/ .  All three are required, if what you have on your
>> sys.path is just the project root.
>>
>>
> my app is in the pythonpath of the environment and every directory has
> an __init__.py
> everything worked fine till i changed the structure from:
>
> app/
>    __init__.py
>    models.py
>    views.py
>    urls.py
>
> to:
>
> app/
>    models/
>             __init__.py
>             models.py
>    views.py/
>             __init__.py
>             whatever.py
>             another.py
>    urls/
>             __init__.py
>             myurls.py
>             anotherurls.py
> __init__.py
>
> so it doesnt really make sense that i cant import something in the
> second case from my point of view.
>
>
>> Do make sure that your project root is on your sys.path.  You can do
>> that by temporarily adding:
>>
>>     import foo
>>
>> to settings.py, and creating a file foo.py in the project root containing, 
>> say:
>>
>>     print "Foo!"
>>
>> and then do:
>>
>>     python manage.py shell
>>
>> As part of the startup printout you should get a line containing only:
>>
>>     Foo!
>>
>> By the way, I'm pretty sure that lots of django internal machinery,
>> like syncdb, for example, depends on there being a file named exactly
>> "models.py" in each app.  So a better choice of directory structure
>> might be "app/myapp/models.py", with your myclass class in the
>> models.py file.  Pinax uses such a structure, though the upper
>> directory is called apps instead of app (there may be more than one)
>> and has been added to the path, so that you can mention it in
>> INSTALLED_APPS as just 'myapp', rather than 'apps/myapp'.  If you go
>> this route, you will want to insert the apps directory at or near the
>> beginning of sys.path, rather than appending it, so that when you
>> mention a possibly installed app, such as django_microblogging, but
>> which you have customized in a copy in your apps folder, you can say
>> 'microblogging' in your INSTALLED_APPS and it will find yours rather
>> than the system version.  (TN.B.: emplate paths are a separate issue.)
>>
>> Bill
>>
>> On Wed, Nov 11, 2009 at 10:34 AM, andreas schmid  
>> wrote:
>>
>>> im experiencing the same problem.
>>> i started with a simple app and the modules.py was at the root of the
>>> app package, so everything was fine.
>>> now i extended the app and restructured the files in it by making a
>>> subfolder app/models and inside an __init__.py and the mymodel.py
>>>
>>> in the urls.py which i have an import like
>>> from app.models.mymodel import myclass
>>>
>>> and while the django shell is able to import it without any problem the
>>> django server isnt. im using buildout to build the whole django
>>> environment so the python interpreter im starting the shell and the one
>>> of the server is the same.
>>>
>>> i already tried to remove all .pyc and start everything again but i had
>>> no luck.
>>>
>>> this is weird and i cant figure out what the problem could be.
>>>
>>>
>>>
>>> Bill Freeman wrote:
>>>
>>>> I had another couple of thoughts.
>>>>
>>>> In the manage.py shell, try:
>>>>
>>>>     from openid.yadis import xri
>>>>     xri
>>>>
>>>> The output will include from where it got xri

Re: Imports, works from directory but not from file

2009-11-12 Thread Bill Freeman
On Thu, Nov 12, 2009 at 10:33 AM, andreas schmid  wrote:
>>
> im on a unix system and i can import it on the django shell but it makes
> troubles when running the django server which doesnt make sense


It may be that it won't be recognized as an app because the app
directory doesn't
have a models.py file in it.  The app logic decides that an app listed
in settings.py
INSTALLED_APPS has a models.py.  I don't know off hand whether the test is made
by looking for that name in the directory, in which case your
configuration would fail,
by doing "import app.models" to see if it gets an exception, in which
case your code
passes, but your models wouldn't be available unless you put stuff in
app/models/__init__.py to import your other models files.

Bill

--

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=.




Re: Help a Rails refugee - how to do site specific layouts?

2009-11-12 Thread Bill Freeman
I haven't done rails, but my boilerplate is in a template that is
"extended" by the
page specific templates.  In fact, I have multiple levels: section
specific boilerplate
templates that extend a site wide template, with the section  specific templates
being extended by the page (type) specific templates.

Look at the "extends" and "block" tags in the template tags reference
and tutorial.

It's seems easy to misunderstand the documentation on these, so let me try a
phrase or two:  A template which will be extended provides one or more holes
which the extending templates can fill, by using the block tag.  The
extending template
fills it with the block tag.  block tags are named so that they can be
matched up.  If an
extending template does not fill a particular block in the extended
template, then that
block's content in the extended template is used.  If the extending
template uses that
block, then it's content is used instead.  Stuff in an extending
template that is not in a
block, or which is in a block that the extended template doesn't have
a block by that name,
is not sent to the browser (is not rendered).  See also the variable
block.super, which allows
you to add to rather than replace content from the extended template.

Also see the "include" tag, but if you use it very much, you probably
don't understand extends.

Bill

On Thu, Nov 12, 2009 at 1:35 PM, Todd Blanchard  wrote:
> I like the rails mechanism for specifying page layouts (boilerplate
> template that surrounds the currently rendered view).
>
> Its simple and obvious.
>
> I cannot, having read most of two books on django now along with the
> website stuff, figure out how to do the same thing in django.
>
> Also, I'm building a multiple-domain site and using the sites module
> so I want different layouts for different sites.
>
> Can someone point me an example or a module or something?
>
> Thx
>
> -Todd
>
> --
>
> 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=.
>
>
>

--

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=.




Re: django basic blog and inlines

2009-11-16 Thread Bill Freeman
Do you have among your installed apps a name identifying a directory on the
python path having both a models.py and a subdirectory named templatetags,
that subdirectory containing a file inlines.py ?  Or was that in the stuff you
excluded from basic.app?

Bill

On Sun, Nov 15, 2009 at 10:34 PM, Bobby Roberts  wrote:
> ok i have no idea what is going on here.  I have django basic blog
> loaded to my site.  I've also installed inlines as follows:
>
> INSTALLED_APPS = (
> ...
>    'inlines',
>    'blog',
> )
>
> (yeah i pulled out the blog dir from the basic dir because i'm not
> using all the other basic app stuff)
>
> You can verify the blog is in fact working by going here:
> http://www.thecigarcastle.com/blog/
>
> Now click on the title to one of the posts:
>
>
> The error i'm getting is:
>
> 'inlines' is not a valid tag library: Could not load template library
> from django.templatetags.inlines, No module named parser
>
>
> You can see the full traceback here:
> http://www.thecigarcastle.com/blog/2009/nov/15/asdfasd/
>
>
> any ideas why this isn't working?
>
> --
>
> 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=.
>
>
>

--

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=.




Re: django basic blog and inlines

2009-11-16 Thread Bill Freeman
So then the answer to my question is "no", you do not have a file
inlines.py in a directory named "templatetags" which is itself in an
app directrory recognizable by the presence of a models.py, the path
such that the models.py file is importable as appname.models, and the
app mentioned in INSTALLED_APPS.  Since those are the only places the
loader will look for the "inlines" tag library, it won't find one.

On Mon, Nov 16, 2009 at 12:20 PM, Bobby Roberts  wrote:
> the path to inlines.py is:
>
> /django_apps/live/inlines/inlines.py
>
>
> live is on my pythonpath (my main application)
>
> blogs and inlines were pulled out of the basic app and put into these
> directories
>
> /django_apps/live/blog/  (works)
> /django_apps/inlines/    (doesn't work)
>
> you can view the full traceback here:  
> http://www.thecigarcastle.com/blog/2009/nov/15/asdfasd/
>
> it's like it's trying to call inlines from
> django.templatetags.inlines   rather than from the inlines path noted
> above.
>
>
>
> On Nov 16, 10:49 am, Bill Freeman  wrote:
>> Do you have among your installed apps a name identifying a directory on the
>> python path having both a models.py and a subdirectory named templatetags,
>> that subdirectory containing a file inlines.py ?  Or was that in the stuff 
>> you
>> excluded from basic.app?

--

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=.




Re: Strange debugger behavior

2009-11-20 Thread Bill Freeman
I don't actually know, but I have a guess...

Ordinarily the blah.objects.exclude(...).filter(...) doesn't actually
perform the query.
It instead happens when you use it in, for example for obj in qset.
But your fancy
debugger may be trying to get variable values to display in a
variables value panel.
Single stepping in, rather than over, in the example above, will
normally step through
the exclude, then step through the filter, where at least self is
already a queryset
object, but which doesn't have the filter applied.  filter's job is to
make a new queryset
with updated sql.  But in trying to have something to show for self,
the debugger
probably effectively calls __str__(), which causes the queryset (the
original, without
filter applied) to be evaluated.

You might try stepping through this in pdb directly, and not looking
at the variables,
to see if it then works correctly.

Still, unless you're trying to teach yourself how django works, I'd try to avoid
stepping through the interior.

Bill

On Thu, Nov 19, 2009 at 5:28 PM, Nick Arnett  wrote:
> I'm not sure if this is a bug... couldn't find anything quite like it in the
> tracker.  I'm using Komodo as my IDE.  When I step through source, the
> filters in a Model.objects.filter method are ignored.  Instead of getting
> the handful of rows that I want from my database, Django (1.1) grabs the
> entire table -- there's no WHERE clause in the SQL it executes (this is with
> MySQL).  When I run it outside the debugger, or avoid stepping into the
> "magic" parts of the database stuff, it behaves properly - the WHERE clause
> is present.
>
> For an awful moment, I thought it was trying to cache the entire table...
>
> This makes debugging with Komodo somewhat challenging, since the table where
> I first encountered this has 50,000 rows that include the full text of web
> pages.  Lots of data and even with plenty of memory, my machine starts
> thrashing horribly when this happens.
>
> Anybody aware of this as a known issue?  Any fix?
>
> Since I can avoid it by not stepping through the "magic" parts of the
> database stuff, it isn't critical.
>
> Nick
>
>
> --
>
> 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=.
>

--

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=.




Re: querySet + select distinct

2009-11-20 Thread Bill Freeman
On Fri, Nov 20, 2009 at 2:47 AM, Andy McKay  wrote:
> On 09-11-19 3:36 PM, Benjamin Wolf wrote:
...
>
> Try using values in the filter eg:
>
> Disposal.objects.values("mydate").filter(mydate__year__gte=2008).distinct()
>
> The problem is the default django query selects all the fields, messing
> up the distinct part.
>

If you happen to be in PostgreSQL, might you be able to put "DISTINCT ON" in an
.extra() where?  Of course, you have to know what the ORM is calling
the columns.

Bill

--

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=.




Re: how to symlink to django-admin.py from some place on path?????.

2009-11-23 Thread Bill Freeman
Nice cheat sheet, but I'm not sure that it helps our Windows user.

I believe, that on windows, you can check the path by, at a command,
or more likely, cmd,
prompt, typing:

echo %PATH%

It's actually set, and you can check it in, the my computer properties
tool.  That is, right click
on my computer, choose properties.  (There's another way to get to
this, from the control
panel, I think, but I don't remember the details.)  On one of the tabs
there's a button labeled
something like "Advanced Settings", which opens a sub tool that lets
you set two lists from
which the path is made, one system wide, the other user specific.

I don't actually suggest adding the directory in which django-admin.py
exists on the path,
but you ought to have at least one directory on it with the philosophy
of the *nix /usr/local/bin,
that is, product installers don't know about it, and won't put stuff
there, or remove stuff there,
or replace stuff there.

Once you have such a directory, you could go to the effort of figuring
out how to make the
Windows equivalent of a symbolic link, but you can also just copy the
file (it's not very big).
One downside of this approach in general is that if you later upgrade
django, you have to
separately remember to re-copy this file, since the django installer
(or tarball or zip) doesn't
know about it.

But a bigger problem on Windows is that on windows .py files are not
an executable type.
They need to be run as an argument to the (appropriate version, should
you someday get
fancy and be developing different things using different versions of
python, or) python.exe
program.  Now, it does work when you double click on a .py file in the
GUI, because that
extension is registered with the GUI as being "opened" with
python.exe, but that registration
does not extend (unless things have changed) to where cmd.exe looks
for the programs that
you ask it to run.  And you need to run django-admin.py from the
command line so that you
can give it arguments, like "startproject" and "foo".

So what I would suggest is a batch file (the authorship of which is
beyond my current windows
chops), that you place in the above mentioned on the path directory, maybe named
'django-admin.bat', which, inside, invokes your choice, by using full
path, of python.exe, on,
again using full path, django-admin.py, and passing along (this is the
part that I don't know
how to do in a bat file) any arguments that were on the batch file's
command line as additional
arguments to python.exe, after the full path to django-admin.py .

Alternatively, starting a project is relatively rare, and it is the
only thing that I've needed
django-admin for.  Everything else can be done with manage.py, and you
should be cd'ed to
it's directory whenever using it anyway, so it's (relative) path
becomes trivial.  It still needs to
be an argument to python, though, rather than being the command itself.

(As an aside, the reason that this is all simpler on *nix is that any
file can be marked as an
executable, and if it is, the OS looks at the first two bytes in the
file, and if they are '#!', it treats
the first line of the file (which had better end with '\n', not '\r\n'
if your fond of editing stuff on
windows and running it on *nix) as a command to run instead, passing
the file itself to the
command being run.  Because most "interpreters", such a python, have
been arranged to
treat '#' as the beginning of a comment, this extra line does not confuse them.)

Bill

On Mon, Nov 23, 2009 at 7:40 AM, Tim Chase
 wrote:
>> I'm tryin to install django on my windows machine, but I got stuck in
>> the followin line "Consider symlinking to django-admin.py from some
>> place on your path, such as /usr/local/bin."  I'm not too techno-
>> savvy...can someone point me in the right direction as to what that
>> means and/or how I go about doing that???
>
> This assumes you're running a *nix-like OS instead of Windows
> (you can make links in Windows but it's a pain).
>
> Executive Cheat-code for the impatient:
> ===
>
>   bash$ ln -s /path/to/existing/django-admin.py
> /some/place/on/path/django-admin.py
>
>
>
> More detailed explanation:
> ==
> In most instances, the Django install doesn't drop its
> "django-admin.py" outside its own subdirectory.  This means that
> to run it, you have to specify its full path
>
>   bash$ /path/to/django-admin.py startproject foo
>
> If, however, it's on your path (the list of places your shell
> looks to find executables), you can get away with just typing
>
>   bash$ django-admin.py startproject foo
>
> The best geeks are lazy, so that 

Re: form fields slicing

2009-11-23 Thread Bill Freeman
Possibly the form class is not written to support slicing.  Supporting
itteration only
requires methods for __iter__() and next().  Slicing, like indexing
requires implementation
of __getitem__(), and for slicing to work, this method must check for
receiving a 'slice'
object as an index.  Since most folks probably can't think of a good
use for slicing here,
the maintainers probably just haven't implemented slicing.

Since a list of fields is just a list of references, and doesn't
involve actually copying
the fields, it's cheap enough to make such a list (preferably in your
view function),
pass that, and slice it.  (lists do, of course, implement slicing.)
Something at least
that complicated would need to be going on inside the code that would implement
slicing on the form anyway, so this shouldn't have a negative
performance impact.

Bill

On Mon, Nov 23, 2009 at 10:16 AM, gentlestone  wrote:
> the same result :(
>
> On 23. Nov, 13:47 h., Doug Blank  wrote:
>> On Mon, Nov 23, 2009 at 7:16 AM, gentlestone  wrote:
>> > why this piece of code doesn't work?
>>
>> > {% for field in form|slice:":2" %}
>>
>> > the result is iterating over all fields, not just the first two fields
>>
>> Perhaps break this up into two parts?
>>
>> {% with form|slice:":2" as formslice %}
>>     (% for field in formslice %}
>>
>> -Doug
>>
>> > --
>>
>> > 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=.
>
> --
>
> 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=.
>
>
>

--

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=.




Re: Big issue serving big files through a view

2009-11-23 Thread Bill Freeman
1. You could read (and thus write) in smaller chunks, by giving read() an
argument indicating the number of bytes to read:

   f = open(file)  # The mode 'r' is default
   for buf in read(1024*32):
  response.write(buf)
   f.close()

2. You could, instead, let Apache serve the files in encrypted form,
and sell the
user a decryption key.

On Mon, Nov 23, 2009 at 12:18 PM, Adrián Ribao  wrote:
> Hello,
>
> I have created a website where you can buy and download some files.
> For security reasons all the files are served through a view, where
> comprobations are made in order to assure that the user bought the
> product.
>
> The problem is that the files are at least 400Mb and some of them are
> nearly 1Gb. Using this view is inefficient since all the content is
> loaded into memory and it kills the server:
>
> type, encoding = mimetypes.guess_type(file)
> name = os.path.basename(file)
> response = HttpResponse(mimetype=type)
> response['Content-Disposition'] = 'attachment; filename=%s' %
> (smart_str(name),)
>
> f = open(file, 'r')
> response.write(f.read())
> f.close()
> return response
>
> How could I solve this problem?
>
> Regards,
>
> Adrian.
>
> --
>
> 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=.
>
>
>

--

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=.




Re: postgresql errors (works in sqlite)

2009-11-23 Thread Bill Freeman
counts[i] = Submission.objects.all().filter(status__exact=str(i)).count()

If you really intended status to be an integer, you might prefer to alter
your table to make the column the right type.  The alter table command
required is beyond my sql confidence.

Older postgresql and lots of other databases will automatically cast
things that look like integers to integers if needed for comparison,
but newer postgresql, and probably others, in time, require you to
say what you mean, and this is probably a (tm) good thing, in that
the automatic casting hides subtle bugs that are hard to find.

Or you could downgrade postgresql if you like.  But eventually you're
likely to want some new feature, so fixing your column seems to me
the right thing.

Bill

On Mon, Nov 23, 2009 at 1:17 PM, Some Guy  wrote:
> Hi,
> I was switching from sqlite3 to postgres, the data was imported ok.
> But now certain view queries are failing. i.e.
>
> counts[i] = Submission.objects.all().filter(status__exact=i).count()
>
> fails with ...
>
> File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py",
> line 2369, in execute_sql
> cursor.execute(sql, params)
>
> ProgrammingError: operator does not exist: character varying = integer
> LINE 1: ...ons_submission" WHERE "submissions_submission"."status" =
> 0
> ^
> HINT: No operator matches the given name and argument type(s). You
> might need to add explicit type casts.
>
> using postgres 8.3. any advise would help. including up/downgrading
> postgres (seems to be a lot of issues on the trac, is 8.3 even
> supported?)
>
> --
>
> 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=.
>
>
>

--

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=.




Re: string-based fields and null

2009-11-25 Thread Bill Freeman
The major problem that I see with NULL in strings is that there may be databases
out there that don't distinguish between NULL and "", that is that store them
the same way.

"" is just as good in most cases.  It behaves like False in python and
template tag
tests.  And it has the advantage that if you go ahead and apply a
string operation
to it without checking first, it won't raise an exception because the
operation isn't
applicable to the None object.  You can't test for it by using ISNULL
in SQL, but
unless NULL has a different meaning for you than "empty", who cares?

There are certainly cases where you might, for example, want to
distinguish between
"never been set" or "is unset", and "displays as no characters", and you could
encode the former states as NULL.  But you could also use a separate boolean.
Think about which code is going to be easier to maintain, especially
if by someone
else when they don't have you to talk to.  If this table will have
billions of rows, then
it might be worth thinking about the memory consumed for that boolean,
  But then
in an year and a half, hard drives will be twice as big.

Still, python (and lisp and C) programmers are used to thinking about
the possibility
of None (or nil or (void *)0), so experienced programmers may have an easy time
with maintenance or a NULL flag design.

So, it's not a hard and fast rule.  I still think that inconsistent
backend support is the
major factor.

Bill

On Tue, Nov 24, 2009 at 1:08 AM, chefsmart  wrote:
> The Django docs suggest "Avoid using null on string-based fields such
> as CharField and TextField unless you have an excellent reason."
>
> ImageField, EmailField, FileField, FilePathField, IPAddressField,
> SlugField, URLField, XMLField are also a string-based fields at the db
> level, so am I right in assuming that null=True is best avoided in
> these case also, "unless you have an excellent reason."?
>
> I am hoping Django has code to deal with the empty string value in
> these fields. For example, I am hoping that Django understands that an
> empty string in an ImageField means there is no corresponding image.
>
> --
>
> 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: How to resolve the view name from a url

2009-11-25 Thread Bill Freeman
Note that url pattern's aren't required to have names, so you can't capture
statistics on unnamed urls patterns in apps that you want to use unmodified.

If, on the other hand, you just want to collect statistics on url patters which
are "under your control", and thus can be required to have names, you can
add a copy of the name (or whatever token you like) to the extra context.
You could even make it less painful by providing your own implementation
of url that does it for you, either with a different name, which you apply to
the patterns of interest, or to the whole file by importing your version as
url.  You must be sure that all the views in question are prepared for the
extra context.

Bill

On Tue, Nov 24, 2009 at 5:48 AM, bcurtu  wrote:
> No, I don't.
>
> I want to know the name of the url for a given url pattern. So, when I
> get in my method the url someone is asking for (next='/people/'), I
> want to know the name of the url that identifies this pattern
> (people_name). It's not for a HttpRedirect, it's for statistical
> porpouses.
>
> It's something like resolve, but not reverse.
>
> Thanks
>
> On 24 nov, 11:15, rebus_  wrote:
>> 2009/11/24 bcurtu :
>>
>>
>>
>> > Hi,
>>
>> > I want to get the url name from a url. For example, having:
>>
>> >    url(
>> >        regex   = r'^people/$',
>> >        view    = 'people_view',
>> >        name    = 'people_name'
>> >        ),
>>
>> > and
>>
>> > @login_required
>> > def people_view(request)...
>> >     _some_code_here...
>>
>> > I'm looking for a function that accepts "people/" and returns
>> > "people_name". I have tried to use django.core.urlresolvers.resolve,
>> > however it returns a wrapper fuction for login_required.
>>
>> > Is it posible?
>>
>> > --
>>
>> > 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.
>>
>> Usually what you want to do is:
>>
>> from django.core.urlresolvers import reverse
>> reverse('people_name')
>>
>> http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
>>
>> I don't see why you need url name, i think the name is meant to be
>> used to resolve urls not other way around.
>
> --
>
> 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: Why are collapsed fieldsets expanded on submit in the admin?

2009-11-25 Thread Bill Freeman
You could attempt to conditionalize this on browser version.

On Wed, Nov 25, 2009 at 10:14 AM, Tom Evans  wrote:
> On Mon, Nov 23, 2009 at 3:57 PM, Benjamin Wohlwend 
> wrote:
>>
>> Hi,
>>
>> currently, when a form in the admin has collapsed fieldsets, those
>> fieldsets are expanded on submit. As I find this rather distracting
>> and couldn't find an explanation why this should be desired behavior,
>> I suspected that this is probably a hard to find bug somewhere in
>> between CSS, HTML and Django's JavaScript code.
>>
>> When I finally took a look at the code, I was quite surprised that
>> this isn't a bug, but a feature:
>>
>> >    if (collapsed_seen) {
>> >            // Expand all collapsed fieldsets when form is submitted.
>> >
>> >  addEvent(findForm(document.getElementsByTagName('fieldset')[0]), 'submit',
>> > function() { CollapsedFieldsets.uncollapse_all(); });
>> >    }
>>
>> This code is in the admin since revision 96 [1]. But why? From a
>> technical view, both the client and the server couldn't care less if
>> the form fields are visible or not, they process them all the same.
>> Was it UI-motivated?
>
> If that was true, then you would be right. However it isn't true. Some
> browsers will not submit non hidden form elements if they are not rendered.
> Admittedly, only crap old browsers[1].
>
> Cheers
>
> Tom
>
> [1]
> http://bytes.com/topic/javascript/answers/89759-problems-form-elements-hidden-div-style-display-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-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: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Bill Freeman
Does /var/www/sites/project/__init__.py exist?

Are the files and directories readable, and the directories searchable
(excutable)
by the user as which the webserver runs?

On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> If I break the code out and write a simple python script that only
> contains:
>
> import sys, os
> sys.path.append("/var/www/sites")
> from project import settings
> from django.core.management import setup_environ
> setup_environ(settings)
>
> Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> --
>
> 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: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Bill Freeman
Interesting.

I take it that hg and hg/hooks both have __init__.py files?  Otherwise
I'm not sure how django sees them.  Unless hg is also an app, listed
in installed apps and has a models.py file.  That is, I don't believe that
the name 'hg' has any special meaning to django.

You might try sticking "import pdb;pdb.set_trace()" in the beginning of
settings.py to see if it is at least trying to be imported.  If the breakpoint
is hit, you could "n" your way through the file to see if something is
getting an exception that prevents the import from succeeding, then
back up by moving the set_trace() to just before the failing item, restart,
and "s" your way into the failing item to see how it manages to depend
on the presence of an "hg" directory.

On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> project/hg/hooks. If I delete this directory it works. If I recreate
> the directory and the hook, it fails. Guess Django is getting confused
> by its existence.
>
> On Nov 25, 12:56 pm, Bill Freeman  wrote:
>> Does /var/www/sites/project/__init__.py exist?
>>
>> Are the files and directories readable, and the directories searchable
>> (excutable)
>> by the user as which the webserver runs?
>>
>> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
>> > If I break the code out and write a simple python script that only
>> > contains:
>>
>> > import sys, os
>> > sys.path.append("/var/www/sites")
>> > from project import settings
>> > from django.core.management import setup_environ
>> > setup_environ(settings)
>>
>> > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>>
>> > --
>>
>> > 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.
>
>
>

--

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: callback called twice for the same comment_will_be_posted signal

2009-11-30 Thread Bill Freeman
Might you have managed to register it twice?

(Just a stab in the dark.)

On Mon, Nov 30, 2009 at 3:19 PM, cirip  wrote:
> Hi,
>
> I am getting multiple signals (2) called for each comment that is
> submitted. The same for comment_will_be_posted.
>
> Code:
>
> def comment_wbp(sender, comment, request, **kwargs):
>    logging.debug("comment_will_be_posted called")
>
> from django.contrib.comments.signals import comment_will_be_posted
>
> comment_will_be_posted.connect(comment_wbp, sender=Comment)
>
> I have above listed code in models.py. I get the same behaviour for
> comment_was_posted.
>
> Thanks,
>
> Tomas
>
> --
>
> 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: Adding a dashboard to admin

2009-12-01 Thread Bill Freeman
>
> I then created my own template file in one of my TEMPLATE_DIRS called
> 'admin/custom_index.html" that extends 'admin/index.html'. I ended up
> copying the {% block content %} from the admin/index.html and
> inserting my template tag into it.

I, too, think you're going the right way.  One point is, if you really meant
"copying", consider whether you can use the block.super variable to
minimize the number of things you need to redo when you take an update
to 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.




Re: Adding a dashboard to admin

2009-12-01 Thread Bill Freeman
On Tue, Dec 1, 2009 at 12:53 PM, Brian Neal  wrote:
> On Dec 1, 10:56 am, Bill Freeman  wrote:
>> > I then created my own template file in one of my TEMPLATE_DIRS called
>> > 'admin/custom_index.html" that extends 'admin/index.html'. I ended up
>> > copying the {% block content %} from the admin/index.html and
>> > inserting my template tag into it.
>>
>> I, too, think you're going the right way.  One point is, if you really meant
>> "copying", consider whether you can use the block.super variable to
>> minimize the number of things you need to redo when you take an update
>> to admin.
>
> Thanks for the response. I did initially try using block.super, but
> because of the HTML my dashboard pushed the sidebar down. I really
> wanted to get my dashboard inside the main content div for aesthetic
> reasons, so I ended up copying the block contents. I really wish there
> was there was a empty {% block custom-dashboard %}{% endblock %} in
> there for just this purpose, but there wasn't. I suppose they can't
> anticipate everything and leave "holes" everywhere. But you're right,
> I'll have to diff my template with the admin template whenever I
> upgrade to see if I am missing a change.

You might be able to fiddle the positioning with CSS.  I've seen things that
border on magic.  Especially if you can limit the use of IE6 for 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.




Re: Finding a form field's widget type from the template

2009-12-01 Thread Bill Freeman
Maybe, but the template seems like a bad place to do that.  Why not
create a derived widget with your custom tweaks in it, and use it for
appropriate fields?

Or are you introspecting someone else's code that you don't want
to customize?

On Tue, Dec 1, 2009 at 2:14 PM, Jon  wrote:
> I'm trying to figure out how to determine a model form field's widget
> type from the template.
>
> I would like to loop through the fields as opposed to writing out each
> field explicitly in the template, but in order to loop through them, I
> need to know the widget type so I can do something special with
> certain types of form fields (checkboxes, for example). Is this
> possible?
>
> --
>
> 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: How to get rid of anchor in url when rendering via render_to_response()

2009-12-01 Thread Bill Freeman
Filter it off when you create the form action?  Or in more detail,
probably, in your view
function, create a copy of the url with such stuff removed, easy to do
with python
string manipulations, or maybe just use reverse on the view function
itself, and pass
that as, say, form_action, and in your template use:

wrote:
> I have a scenario where I have redirected the user to a particular
> url, something like:
>
> http://www.example.com/taskmanager/edit_task/5#comment_4
>
> In other words, they are viewing a particular comment associated with
> task 5.  This comment is say a page or two down (ie, scrolled down)
> from the top of the page where there are fields associated with task
> 5.
>
> Now the user scrolls up to the top of the page, which puts them as if
> they were viewing task 5 from its main url, ie
>
> http://www.example.com/taskamanger/edit_task/5
>
> They make some change to the task - say change the due date.  But they
> make an error which is caught on the server side.  When my server code
> runs, it calls render_to_response to re-render the page to display the
> error.  Howevever, because their original url was
>
> http://www.example.com/taskmanager/edit_task/5#comment_4
>
> they are now taken back to the page with comment_4 in their view,
> rather than to the top of the page where their error is.
>
> Is there a way for me to get rid of the #comment_4 anchor in the url,
> so that they are taken back to the top of the page when
> render_to_response() is called?
>
> Thanks,
>
> Margie
>
> --
>
> 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: Browsing Django modules from interactive python shell

2009-12-02 Thread Bill Freeman
import a

does not automatically import modules and sub packages of package a.  It takes
special action in a's __init__.py to make this happen as it does for
os.path when
you import os.

I assume that you're doing this directly in python, since in the manage.py shell
other stuff has already caused django.core to be imported, so it's available.
(And Frank was probably using the manage.py shell, thus finding that he
didn't have to separately import django.core .)

On Wed, Dec 2, 2009 at 11:14 AM, Kenny Meyer  wrote:
> Hi guys,
>
> I have some strange behaviour in my interactive python shell, when
> trying to browse Django modules...
>
> Example:
>
 import django
 dir(django.core)
> AttributeError: 'module' object has no attribute 'core'
>
 import django.core
 dir(django.core)
> ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
> '__path__']
>
> Can anyone, please, explain me this strange (to me) behaviour?
>
> Regards,
> Kenny
>
> 
>  .'  `.    knny [d0t] myer [at] gmail [d0t] com [42!]
>  |a_a  |   http://kenny.paraguayinfos.de | gpg key ID: 0x00F56BA1B2
>  \<_)__/   
>  /(   )\   Everything should be made as simple as possible, but not
>  |\`> < /\                        simpler.
>  \_|=='|_/                                        -- Albert Einstein
>

--

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: Importing users - salted sha1

2009-12-03 Thread Bill Freeman
Do you have access to the password checking code for the source system?
It's fine to say that you have an SHA1 hash, but even if that's true, there
are many choices for how to represent the digest, and how to apply the
salt.

If you have access to the code, you might insert print statements to see
what various intermediate values you see.  If it's just a case of representing
the hash (or salt) as an integer versus a hexadecimal string, for example,
then you have a prayer of converting.  But if one applies the salt to the
beginning of the message, and the other to the end, or to both, or embeds
it, or one squashes the password to radix 50 or some such and the other
doesn't, or a number of other possibilities, you are out of luck making it
work with the default auth framework.

You could implement an additional password type in Django, using the old
site's algorithm, and calling it something other than sha1 (the key before
the first '$').

On Wed, Dec 2, 2009 at 7:18 PM, Dave  wrote:
> I have a website with about 90 users that I'm trying to import into
> Django. Right now, the users have a password with a salt and a hash,
> so I tried (with a sample user) to format the password how Django
> likes them. I did sha1$salt$hash and I wasn't able to log into admin
> with that user (I made that user a superuser, staff, and active). I'm
> using Django's auth authentication system. Has anyone run into this
> before? Do I have to do something else to get this to work?
>
> Thanks in advance!
>
> --
>
> 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: Importing users - salted sha1

2009-12-03 Thread Bill Freeman
IANARP (I am not a ruby programmer), but:

If you look in django.contrib.auth.models.get_hexdigest() (about line 18),
you will see that django forms the digest on the sequence of the salt,
followed by the password the user types (raw_password).

Judging from  the apperance of  "self.encrypt(pass+salt)", below, ruby was
calculating the digest on the raw password followed by the salt.  These are
going to give different answers, even if the salt, raw password, and sha1
algorithms are the same.  (I expect the sha1s to be the same, returning 40
hexidecimal digits as a string, though the letters could be upper case in one
and lower case in the other.)

The easiest approach, if you can't demand that the users do a password
reset, would be to make yourself a custom version of that file where
get_hexdigest() accepts an additional encoding type, say 'rubysha1',
for which is combines the raw password and salt in the ruby order (and
possibly applies upper() or lower() to the result, if necessary).


On Thu, Dec 3, 2009 at 12:10 PM, Dave  wrote:
> Thanks, I didn't realize there was another wrinkle in this problem. I
> thought all SHA1 was the same.
>
> I'm not sure if I have access to the code -- the site was a Ruby on
> Rails site before. I followed a tutorial (http://www.aidanf.net/
> rails_user_authentication_tutorial) to create the authentication
> system. Here are some relevant (I think?) code snippets (from the user
> model):
>
> require 'digest/sha1'
>
> def password=(pass)
> �...@password=pass
>  self.salt = User.random_string(10) if !self.salt?
>  self.hashed_password = User.encrypt(@password, self.salt)
> end
>
> def self.encrypt(pass, salt)
>   Digest::SHA1.hexdigest(pass+salt)
>  end
>
> def self.authenticate(login, pass)
>  u=find(:first, :conditions=>["login = ?", login])
>  return nil if u.nil?
>  return u if User.encrypt(pass, u.salt)==u.hashed_password
>  nil
> end
>
> If I wanted to recreate that system in django to replace the sha1$
> part of the password field, would I basically need to port this code
> to django?
>
> Thanks again for your help!
>
>
>
> On Dec 3, 8:06 am, Bill Freeman  wrote:
>> Do you have access to the password checking code for the source system?
>> It's fine to say that you have an SHA1 hash, but even if that's true, there
>> are many choices for how to represent the digest, and how to apply the
>> salt.
>>
>> If you have access to the code, you might insert print statements to see
>> what various intermediate values you see.  If it's just a case of 
>> representing
>> the hash (or salt) as an integer versus a hexadecimal string, for example,
>> then you have a prayer of converting.  But if one applies the salt to the
>> beginning of the message, and the other to the end, or to both, or embeds
>> it, or one squashes the password to radix 50 or some such and the other
>> doesn't, or a number of other possibilities, you are out of luck making it
>> work with the default auth framework.
>>
>> You could implement an additional password type in Django, using the old
>> site's algorithm, and calling it something other than sha1 (the key before
>> the first '$').
>>
>>
>>
>> On Wed, Dec 2, 2009 at 7:18 PM, Dave  wrote:
>> > I have a website with about 90 users that I'm trying to import into
>> > Django. Right now, the users have a password with a salt and a hash,
>> > so I tried (with a sample user) to format the password how Django
>> > likes them. I did sha1$salt$hash and I wasn't able to log into admin
>> > with that user (I made that user a superuser, staff, and active). I'm
>> > using Django's auth authentication system. Has anyone run into this
>> > before? Do I have to do something else to get this to work?
>>
>> > Thanks in advance!
>>
>> > --
>>
>> > 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.
>
>
>

--

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: Forms - readonly representation?

2009-12-03 Thread Bill Freeman
1.  You can sub class the form widget of interest to override the
render method, and,
for example, do "attrs['disabled'] = 'disabled'" before calling the
superclass method.
This is nasty because some browsers are actually fussy about the fact that the
disabled attribute doesn't take a value, but most do the right thing.
You may want
to also set an additional selector on the 'class' attribute (you need
to check whether
there already is one and append or set as appropriate) so that you can
style this
differently.  Or you could just do the rendering here yourself, though
that's messy,
or massage the string returned by the superclass method.

2.  If you're going to whine about it taking longer than a couple of
hours to get an
answer you:
a. are in for a frustrating life, and
b. should probably think about PAYING someone for support.

On Thu, Dec 3, 2009 at 2:29 PM, Todd Blanchard  wrote:
> From the deafening silence, I'm going to take this as a "no".
>
> Seems like a pretty basic enhancement - sometimes you want to display data in 
> the same layout as a form, but not editable (checkboxes disabled, text fields 
> just styled text).
>
> And nobody thought of it?
>
> On Dec 3, 2009, at 9:05 AM, Todd Blanchard wrote:
>
>> Forms seem nifty, but sometimes I want to display the data in the same 
>> format but readonly.  Is there a to do this?  I can't seem to find it.
>>
>> -Todd Blanchard
>>
>> --
>>
>> 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.
>
>
>

--

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: DateTimeField arithmetic problem

2009-12-04 Thread Bill Freeman
On Fri, Dec 4, 2009 at 4:48 AM, Max Battcher  wrote:
> Continuation wrote:
>> if form.is_valid():
>>     object = form.save(commit=False)
>>     delta = datetime.timedelta(days=object.days_difference)
>>     object.end = object.start + delta
>>     object.save()
>>
>> But I got the error:
>> type object 'datetime.datetime' has no attribute 'timedelta'
>
> This sounds like a silly import error... It sounds like you've got
> something like:
>
> from datetime import datetime
>
> Where you really want just:
>
> import datetime

Or, to possibly reduce other code changes:

from datetime import datetime, timedelta

...

delta = timedelta(object.days_difference)  # Days is the first
positional argument, can also be float.


>
> (Because datetime.datetime.timedelta doesn't exist, but
> datetime.timedelta does.)
>
> --
> --Max Battcher--
> http://worldmaker.net
>
> --
>
> 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: How to create a form to edit an existing object without knowing the object's id?

2009-12-07 Thread Bill Freeman
Off the top of my head, you have three choices.

1. Create a hidden field to carry the id (yes, you do know it once you've done
that query - it's z.id or z.pk).

2. (My favorite) encode the id as part of the url or as a query parameter in the
action attribute of your form.  Then access it in the view via
urlpattern or the request
object, respectively.

In either case above you use the id to fetch the correct instance.

3. Redo your query based on fk and field, which must be carried in the form, and
not changed, so that you'll be able to get them from the request.

In any case, in the request method is post path, initialize your form
from both the
instance and the POST parameters, check for valid, and if so call the
save method.
This layout is nearly boilerplate, see the forms documentation of the
documentation
page for samples.

On Sun, Dec 6, 2009 at 7:22 PM, Continuation  wrote:
> I have:
>
> class MyModel(models.Model):
>    fk                    = models.ForeignKey(AnotherModel)
>    field               = models.PositiveIntegerField()
>
> class MyForm((forms.ModelForm):
>    class Meta:
>        model   = MyModel
>
> Now I want to create a form to edit an existing MyModel instance. But
> I don't know the pk of the instance. However I do now the value of fk
> & field, which together should be enough to uniquely identify an
> instance.
>
> So I do:
> z = MyModel.objects.get(fk=o, field=f)
> f = MyForm(instance=z)
>
> And the form f does have the correct data of z pre-populated.
>
> However when I submitted the form, a new MyModel object was created
> instead of just updating z.
>
> What do I need to do to create a form that would update z?
>
> --
>
> 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: model design problem

2009-12-07 Thread Bill Freeman
I'm not clear on what you need to store, so I'll assume that you have individual
data to store for each port of each type, and it is unrelated to data stored for
another instance of the same or a different product.

What comes to mind is that there is a "Product" model and a "Port" model (or if
red and green ports carry different fields, both a "RedPort" and a "GreenPort"
model).  Ports have a foreign key relationship on Products.  Now an assortment
of Port instances can be assigned to a Product instance.  Django will created
an accessor (or accessors) on the Product model for obtaining a query set of
the Port instances associated with a given Product instance.  (If you want
separate RedPort and GreenPort models, but they share a lot of behaviours
and/or fields, you may want to look at Django's abstract base class mechanism,
but it takes a bit to get right, in my experience.)


On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
> I am relatively new to django and relational databases, and need some
> Model advice.
>
> I have a family of network products each with a different combination
> of ports.. I will call them red ports and green ports.  For example,
> product A will have its own Model and could have 2 red ports and 1
> green port.  Product B is similar, but has only 3 green ports.
> My current approach is to use an abstract base Model, and then create
> Models for products A and B that contain all needed fields, for
> example:
>
> class A(basemodel):
>   Port1_redfield1 = ...
>   Port1_redfield2 = ...
>   ...
>   Port2_redfield1 = ...
>   Port2_redfield2 = ...
>   ...
>
>
> Yuck, not very DRY at all.  I also tried to create a red port Model
> and green port Model and use one to one fields to connect them to
> products.  The problem with this is that I could not figure out how to
> encapsulate the ports; I always had to worry about creating, linking
> and deleting port objects when dealing with products.  Not acceptable.
>
> I also thought about other tricks like generating my models.py file
> from a generator program, and dynamic insertion of attributes into
> existing classes.  I really would rather not go there.
>
> So, my question:  Is there a nice DRY way to get the kind of
> structured composition that I want?
>
> Side question: Is there another python ORM that could address my need
> better?
>
> Thanks,
> Dan.
>
> --
>
> 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: model design problem

2009-12-07 Thread Bill Freeman
Unless I'm very confused, django will happily delete your related
objects (since they
don't have anything to relate to anymore).  Many to many would be more
problematic.

As far as creating a set of ports, you were stuck with that anyway, if
I understand
your original approach correctly.  Even if your model had N red port slots and M
green port slots, with flags as to whether this product has that port,
(each product is
an instance of "A", no?), you have to fill in the flag and any
individual data (port address,
for example) when you create the instance for a product.  The only
difference with the
many to one is that you call the port constructor, passing the product
instance, and
after the fields are filled, you call the save method.  In turn, you
get enumeration of the
set of ports that you actually have in this product for free from the
framework, rather
than having to write code to skip the ports not present in this
product.  Probably not
useful in your case, but you can adjust the set of ports on a product
"later" with the
foreign key scheme.

If, on the other hand, you were going to make a model per product
type, forget all that
I said.

On Mon, Dec 7, 2009 at 11:56 AM, Daniel Goertzen
 wrote:
> Thanks for the reply Bill.  The problem I had with that approach is that
> after creating the product I have to worry about creating red and green
> ports.  Likewise, upon deletion, I have to mop up the ports.  Looking
> through the documentation, I did not find a way to bury this behavior in the
> Model.
> Hmm, abstract base class for the ports is an interesting idea.  Could be
> useful at template time.
> Dan.
>
> On Mon, Dec 7, 2009 at 10:07 AM, Bill Freeman  wrote:
>>
>> I'm not clear on what you need to store, so I'll assume that you have
>> individual
>> data to store for each port of each type, and it is unrelated to data
>> stored for
>> another instance of the same or a different product.
>>
>> What comes to mind is that there is a "Product" model and a "Port" model
>> (or if
>> red and green ports carry different fields, both a "RedPort" and a
>> "GreenPort"
>> model).  Ports have a foreign key relationship on Products.  Now an
>> assortment
>> of Port instances can be assigned to a Product instance.  Django will
>> created
>> an accessor (or accessors) on the Product model for obtaining a query set
>> of
>> the Port instances associated with a given Product instance.  (If you want
>> separate RedPort and GreenPort models, but they share a lot of behaviours
>> and/or fields, you may want to look at Django's abstract base class
>> mechanism,
>> but it takes a bit to get right, in my experience.)
>>
>>
>> On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
>> > I am relatively new to django and relational databases, and need some
>> > Model advice.
>> >
>> > I have a family of network products each with a different combination
>> > of ports.. I will call them red ports and green ports.  For example,
>> > product A will have its own Model and could have 2 red ports and 1
>> > green port.  Product B is similar, but has only 3 green ports.
>> > My current approach is to use an abstract base Model, and then create
>> > Models for products A and B that contain all needed fields, for
>> > example:
>> >
>> > class A(basemodel):
>> >   Port1_redfield1 = ...
>> >   Port1_redfield2 = ...
>> >   ...
>> >   Port2_redfield1 = ...
>> >   Port2_redfield2 = ...
>> >   ...
>> >
>> >
>> > Yuck, not very DRY at all.  I also tried to create a red port Model
>> > and green port Model and use one to one fields to connect them to
>> > products.  The problem with this is that I could not figure out how to
>> > encapsulate the ports; I always had to worry about creating, linking
>> > and deleting port objects when dealing with products.  Not acceptable.
>> >
>> > I also thought about other tricks like generating my models.py file
>> > from a generator program, and dynamic insertion of attributes into
>> > existing classes.  I really would rather not go there.
>> >
>> > So, my question:  Is there a nice DRY way to get the kind of
>> > structured composition that I want?
>> >
>> > Side question: Is there another python ORM that could address my need
>> > better?
>> >
>> > Thanks,
>> > Dan.
>> >
>> > --
>> >
>> > You received this message because you are subscribed to the Google
>> > Groups &quo

Re: model design problem

2009-12-07 Thread Bill Freeman
Hmmm.  Probably just as ugly, and untested, but:

class A(basemodel):
for o in range(MAXNUMREDPORTS):
 for i in (1,2):
 locals()["Port%d_redfield%d" % (o+1, i)] = models.FloatField()
...

On Mon, Dec 7, 2009 at 12:10 PM, Daniel Goertzen
 wrote:
> Okay, I explored model generation a bit and found an approach that wasn't
> too offensive.  For those that are trying to solve the same problem that I
> am, here is what I came up with:
>
> def red_port(prefix):
>    return """
> %(prefix)sredfield1 = models.FloatField()
> %(prefix)sredfield2 = models.FloatField()
> """ % {'prefix':prefix}
> class A(basemodel):
>   exec red_port("Port1_")
>   exec red_port("Port2_")
>   ...
>
> ...which yields sql something like...
> CREATE TABLE `A` (
>     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
>     ...
>     `Port1_redfield1` double precision,
>     `Port1_redfield2` double precision,
>     `Port2_redfield1` double precision,
>     `Port2_redfield2` double precision,
> );
>
>
> I feel DRY again, and only a little bit dirty. :)
> Dan.
>
> On Mon, Dec 7, 2009 at 9:12 AM, Dan  wrote:
>>
>> I am relatively new to django and relational databases, and need some
>> Model advice.
>>
>> I have a family of network products each with a different combination
>> of ports.. I will call them red ports and green ports.  For example,
>> product A will have its own Model and could have 2 red ports and 1
>> green port.  Product B is similar, but has only 3 green ports.
>> My current approach is to use an abstract base Model, and then create
>> Models for products A and B that contain all needed fields, for
>> example:
>>
>> class A(basemodel):
>>   Port1_redfield1 = ...
>>   Port1_redfield2 = ...
>>   ...
>>   Port2_redfield1 = ...
>>   Port2_redfield2 = ...
>>   ...
>>
>>
>> Yuck, not very DRY at all.  I also tried to create a red port Model
>> and green port Model and use one to one fields to connect them to
>> products.  The problem with this is that I could not figure out how to
>> encapsulate the ports; I always had to worry about creating, linking
>> and deleting port objects when dealing with products.  Not acceptable.
>>
>> I also thought about other tricks like generating my models.py file
>> from a generator program, and dynamic insertion of attributes into
>> existing classes.  I really would rather not go there.
>>
>> So, my question:  Is there a nice DRY way to get the kind of
>> structured composition that I want?
>>
>> Side question: Is there another python ORM that could address my need
>> better?
>>
>> Thanks,
>> Dan.
>
>
> --
> Daniel Goertzen
> -
> d...@networkintegritysystems.com (work)
> daniel.goert...@gmail.com (home)
> -
> 1 204 272 6149 (home/office)
> 1 204 470 8360 (mobile)
> -
>
>
>
> --
>
> 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: model design problem

2009-12-07 Thread Bill Freeman
Or there's overriding the metaclass...

On Mon, Dec 7, 2009 at 12:39 PM, Bill Freeman  wrote:
> Hmmm.  Probably just as ugly, and untested, but:
>
> class A(basemodel):
>    for o in range(MAXNUMREDPORTS):
>         for i in (1,2):
>             locals()["Port%d_redfield%d" % (o+1, i)] = models.FloatField()
> ...
>
> On Mon, Dec 7, 2009 at 12:10 PM, Daniel Goertzen
>  wrote:
>> Okay, I explored model generation a bit and found an approach that wasn't
>> too offensive.  For those that are trying to solve the same problem that I
>> am, here is what I came up with:
>>
>> def red_port(prefix):
>>    return """
>> %(prefix)sredfield1 = models.FloatField()
>> %(prefix)sredfield2 = models.FloatField()
>> """ % {'prefix':prefix}
>> class A(basemodel):
>>   exec red_port("Port1_")
>>   exec red_port("Port2_")
>>   ...
>>
>> ...which yields sql something like...
>> CREATE TABLE `A` (
>>     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
>>     ...
>>     `Port1_redfield1` double precision,
>>     `Port1_redfield2` double precision,
>>     `Port2_redfield1` double precision,
>>     `Port2_redfield2` double precision,
>> );
>>
>>
>> I feel DRY again, and only a little bit dirty. :)
>> Dan.
>>
>> On Mon, Dec 7, 2009 at 9:12 AM, Dan  wrote:
>>>
>>> I am relatively new to django and relational databases, and need some
>>> Model advice.
>>>
>>> I have a family of network products each with a different combination
>>> of ports.. I will call them red ports and green ports.  For example,
>>> product A will have its own Model and could have 2 red ports and 1
>>> green port.  Product B is similar, but has only 3 green ports.
>>> My current approach is to use an abstract base Model, and then create
>>> Models for products A and B that contain all needed fields, for
>>> example:
>>>
>>> class A(basemodel):
>>>   Port1_redfield1 = ...
>>>   Port1_redfield2 = ...
>>>   ...
>>>   Port2_redfield1 = ...
>>>   Port2_redfield2 = ...
>>>   ...
>>>
>>>
>>> Yuck, not very DRY at all.  I also tried to create a red port Model
>>> and green port Model and use one to one fields to connect them to
>>> products.  The problem with this is that I could not figure out how to
>>> encapsulate the ports; I always had to worry about creating, linking
>>> and deleting port objects when dealing with products.  Not acceptable.
>>>
>>> I also thought about other tricks like generating my models.py file
>>> from a generator program, and dynamic insertion of attributes into
>>> existing classes.  I really would rather not go there.
>>>
>>> So, my question:  Is there a nice DRY way to get the kind of
>>> structured composition that I want?
>>>
>>> Side question: Is there another python ORM that could address my need
>>> better?
>>>
>>> Thanks,
>>> Dan.
>>
>>
>> --
>> Daniel Goertzen
>> -
>> d...@networkintegritysystems.com (work)
>> daniel.goert...@gmail.com (home)
>> -
>> 1 204 272 6149 (home/office)
>> 1 204 470 8360 (mobile)
>> -
>>
>>
>>
>> --
>>
>> 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: How to use debugger from doctest

2009-12-15 Thread Bill Freeman
IIUC, the test jig redirects stdin and stdout so that it can drive
interpreter input from
the corresponding substrings of the doc test strings, and capture the output to
compare it to the corresponding substrings of the doc test strings.  So pdb is
waiting for input from the doctest string and it's output is captured
by the test
framework instead of printed.

One approach would be to, rather than simply calling set_trace(),
create a function
of your own to call instead, which rebinds stdin and stdout (and maybe
stderr) to
the terminal, and then calls set_trace() itself.

There are two variants on this approach:

  If you restore the test framework versions of I/O after set_trace(),
then you can
  print stuff, but single stepping and setting breakpoints is not
going to work.  You
  can, however, use the continue command to run further in the test.

  If you don't restore the test framework I/O, then pdb will work,
including breakpoints
  and single step, but all bets are off if you step or run to the
point that you have
  returned to the test framework.

Another approach is to hack pdb so that every time that it is entered
it saves the
existing I/O and sets things to the terming, and every time it
transfers back to the
program (s, n, r, c) it restores the I/O.  You can even step into the
test framework
with something like this.  A possible confusion could occur with
non-complete line
I/O, but maybe not.  (I wouldn't be surprised if there weren't
something like this
already in pdb, but to complex to mention in the simple user
documentation.  Or not.

A third possibility is a hacked pdb that can be told to interact over
a tcp socket, or,
on *nix, a pseudo tty.  Then you wire up telnet or an xterm, and drive
pdb from there,
without fiddling with stdin, stdout, and stderr at all.  (This would
definitely be a cool
addition to pdb, if it's not already there.)

And, of course, you can always sprinkle in code to append
informational lines to a file.
This is the equivalent of the print statement approach, except that
you must open a
file for append and print (or write) to that, and close it.  You might
also manage this
with the logging facility.

Bill

On Mon, Dec 14, 2009 at 5:21 AM, Phui Hock  wrote:
> Suppose I have the following in app 'app'.
> from django.db import models
> class Test(models.Model):
>    """
>    >>> v = "Hello, world!"
>    >>> import pdb; pdb.set_trace()
>    """
>
> Running manage.py test app will drop me to an interactive debugger
> mode but no output. How to execute the usual p, j, s etc?
>
> --
>
> 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: How to use debugger from doctest

2009-12-15 Thread Bill Freeman
Untested, but it looks like you can do:

   import pdb, sys; pdb.Pdb(stdin=sys.__stdin__,
stdout=sys.__stdout__).set_trace()

On Tue, Dec 15, 2009 at 11:07 AM, Bill Freeman  wrote:
> IIUC, the test jig redirects stdin and stdout so that it can drive
> interpreter input from
> the corresponding substrings of the doc test strings, and capture the output 
> to
> compare it to the corresponding substrings of the doc test strings.  So pdb is
> waiting for input from the doctest string and it's output is captured
> by the test
> framework instead of printed.
>
> One approach would be to, rather than simply calling set_trace(),
> create a function
> of your own to call instead, which rebinds stdin and stdout (and maybe
> stderr) to
> the terminal, and then calls set_trace() itself.
>
> There are two variants on this approach:
>
>  If you restore the test framework versions of I/O after set_trace(),
> then you can
>  print stuff, but single stepping and setting breakpoints is not
> going to work.  You
>  can, however, use the continue command to run further in the test.
>
>  If you don't restore the test framework I/O, then pdb will work,
> including breakpoints
>  and single step, but all bets are off if you step or run to the
> point that you have
>  returned to the test framework.
>
> Another approach is to hack pdb so that every time that it is entered
> it saves the
> existing I/O and sets things to the terming, and every time it
> transfers back to the
> program (s, n, r, c) it restores the I/O.  You can even step into the
> test framework
> with something like this.  A possible confusion could occur with
> non-complete line
> I/O, but maybe not.  (I wouldn't be surprised if there weren't
> something like this
> already in pdb, but to complex to mention in the simple user
> documentation.  Or not.
>
> A third possibility is a hacked pdb that can be told to interact over
> a tcp socket, or,
> on *nix, a pseudo tty.  Then you wire up telnet or an xterm, and drive
> pdb from there,
> without fiddling with stdin, stdout, and stderr at all.  (This would
> definitely be a cool
> addition to pdb, if it's not already there.)
>
> And, of course, you can always sprinkle in code to append
> informational lines to a file.
> This is the equivalent of the print statement approach, except that
> you must open a
> file for append and print (or write) to that, and close it.  You might
> also manage this
> with the logging facility.
>
> Bill
>
> On Mon, Dec 14, 2009 at 5:21 AM, Phui Hock  wrote:
>> Suppose I have the following in app 'app'.
>> from django.db import models
>> class Test(models.Model):
>>    """
>>    >>> v = "Hello, world!"
>>    >>> import pdb; pdb.set_trace()
>>    """
>>
>> Running manage.py test app will drop me to an interactive debugger
>> mode but no output. How to execute the usual p, j, s etc?
>>
>> --
>>
>> 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: How to use debugger from doctest

2009-12-15 Thread Bill Freeman
Or maybe:

  import pdb, sys; pdb.Pdb(stdin=sys.__stdin__,
stdout=sys.__stdout__).set_trace(sys._getframe().f_back)

On Tue, Dec 15, 2009 at 5:32 PM, Bill Freeman  wrote:
> Untested, but it looks like you can do:
>
>   import pdb, sys; pdb.Pdb(stdin=sys.__stdin__,
> stdout=sys.__stdout__).set_trace()
>
> On Tue, Dec 15, 2009 at 11:07 AM, Bill Freeman  wrote:
>> IIUC, the test jig redirects stdin and stdout so that it can drive
>> interpreter input from
>> the corresponding substrings of the doc test strings, and capture the output 
>> to
>> compare it to the corresponding substrings of the doc test strings.  So pdb 
>> is
>> waiting for input from the doctest string and it's output is captured
>> by the test
>> framework instead of printed.
>>
>> One approach would be to, rather than simply calling set_trace(),
>> create a function
>> of your own to call instead, which rebinds stdin and stdout (and maybe
>> stderr) to
>> the terminal, and then calls set_trace() itself.
>>
>> There are two variants on this approach:
>>
>>  If you restore the test framework versions of I/O after set_trace(),
>> then you can
>>  print stuff, but single stepping and setting breakpoints is not
>> going to work.  You
>>  can, however, use the continue command to run further in the test.
>>
>>  If you don't restore the test framework I/O, then pdb will work,
>> including breakpoints
>>  and single step, but all bets are off if you step or run to the
>> point that you have
>>  returned to the test framework.
>>
>> Another approach is to hack pdb so that every time that it is entered
>> it saves the
>> existing I/O and sets things to the terming, and every time it
>> transfers back to the
>> program (s, n, r, c) it restores the I/O.  You can even step into the
>> test framework
>> with something like this.  A possible confusion could occur with
>> non-complete line
>> I/O, but maybe not.  (I wouldn't be surprised if there weren't
>> something like this
>> already in pdb, but to complex to mention in the simple user
>> documentation.  Or not.
>>
>> A third possibility is a hacked pdb that can be told to interact over
>> a tcp socket, or,
>> on *nix, a pseudo tty.  Then you wire up telnet or an xterm, and drive
>> pdb from there,
>> without fiddling with stdin, stdout, and stderr at all.  (This would
>> definitely be a cool
>> addition to pdb, if it's not already there.)
>>
>> And, of course, you can always sprinkle in code to append
>> informational lines to a file.
>> This is the equivalent of the print statement approach, except that
>> you must open a
>> file for append and print (or write) to that, and close it.  You might
>> also manage this
>> with the logging facility.
>>
>> Bill
>>
>> On Mon, Dec 14, 2009 at 5:21 AM, Phui Hock  wrote:
>>> Suppose I have the following in app 'app'.
>>> from django.db import models
>>> class Test(models.Model):
>>>    """
>>>    >>> v = "Hello, world!"
>>>    >>> import pdb; pdb.set_trace()
>>>    """
>>>
>>> Running manage.py test app will drop me to an interactive debugger
>>> mode but no output. How to execute the usual p, j, s etc?
>>>
>>> --
>>>
>>> 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: How to use debugger from doctest

2009-12-16 Thread Bill Freeman
I use pdb with django often, and it works fine (caveats below), so I
don't think that
it is django per se.

When running doctest, however, at some level interpreter input must have been
arranged to come from that doc string, and that 2 that it prints has
to be captured
so that it can be compared to the 2 in the doctest string, so that
doctest can figure
out whether to tell you that the test succeeded or failed.

There may be other ways to do that, but I'd guess that it changes sys.stdin and
sys.stdout.  From your example below, I presume that it restores them when it
reaches the end of the string.  It is certainly possible that the django doctest
messes things up somehow.

Even so, it is worth trying the variant below.  The pdb.Pdb
constructor specifically
takes arguments named stdin and stdout, which (via the cmd.Cmd
subclass constructor)
get stored on the instance, and everything I had time to look at is
careful to use self.stdout
for printing, and in places where it gets input it saves the current
values of sys.stdin and
sys.stdout and sets them to the values saved on self, restoring the
saved values when
the debugger transfers control back to the debugee.  (I looked in the
python 2.6 pdb, but I
expect that it is the same in 2.5 and 2.4.)

sys.__stdin__ is the "original" value of sys.stdin, and sys.__stdout__
is the "original" value
of sys.stdout.  I'm guessing that, so long as you didn't start python
with shell redirection of
stdin and/or stdout, the double underscore version will refer to your terminal.

And the final piece is that pdb.set_trace is just a function that does:
   Pdb().set_trace(sys._getframe().f_back)

Looking deeper, it looks like your don't need to supply the argument
to the method, because
if it doesn't get one it does the same calculation, which is probably
the actual frame that
you want, rather than one level up. so try:

   import pdb, sys; pdb.Pdb(stdin=sys.__stdin__,
stdout=sys.__stdout__).set_trace()

The debugger, after all, is just python code with specific knowledge
of how the stack
frames and code objects are layed out.

Bill

On Tue, Dec 15, 2009 at 8:41 PM, Phui Hock  wrote:
> Thanks for the replies.
>
> The problem I described earlier exhibits only in Django doctest. If
> you write a doctest and run with plain python interpreter, such as
> this:
> test.py
> def print_i(i):
>    """
>    >>> i = 1 + 1
>    >>> i
>    2
>    >>> import pdb; pdb.set_trace()
>    """
>    print i
>
> $ python -m doctest test.py
> you will get the interactive debugger to do "p i", "w", "locals()"
> etc. So, I don't think it is a problem in pdb, or doctest in that
> matter.
>
> Unless I am missing the obvious, I believe Django replaces the stdout
> with it's own version of output (django/test/_doctest.py,1152) that
> simply won't print in debug mode. Having said that, is it not possible
> to activate debugger in Django doctest?

--

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 debugger from doctest

2009-12-16 Thread Bill Freeman
On Wed, Dec 16, 2009 at 9:09 AM, Bill Freeman  wrote:
> I use pdb with django often, and it works fine (caveats below), so I

And I forgot my caveat.  I can enter the debugger using set_trace() just fine,
but I have trouble using pdb.run('...') in that it seems confused
about where the
files are or otherwise has trouble displaying the appropriate source code line.
It still debugs, however, and can print variables, stack traces, etc.

Bill

--

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: Forms Delay

2009-12-16 Thread Bill Freeman
On Wed, Dec 16, 2009 at 10:09 AM, Limpy  wrote:
...
> class AllStatsForm(forms.Form):
>        game = forms.ChoiceField(choices=GetGameChoices())
>        birdies = forms.IntegerField(min_value=0, label="Number of Birdies")
...

I'm pretty sure that you can pass a callable as the value of choices, so try:

...
   game = forms.ChoiceField(choices=GetGameChoices)
...

That is, pass the function, not what it returns.  It will then be
called each time the form is rendered.

Bill

--

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: Directories inside app directory

2009-12-16 Thread Bill Freeman
1.  You must place a file __init__.py in each sub-directory (folder)
from which you will import, such as your models and views directories.

2.  The __init__.py in your models directory must import all modules
containing modules.  When you add an app to installed apps in
settings.py, django will import models in that app.  Normally this is
models.py and importing it causes the model classes to be defined, and
their __metaclass__ (do not confuse this with the Meta nested class)
registers the model.  This is how syncdb can know what models exist,
for example.  But in your case only models/__init__.py is imported,
unless that, in turn, imports the other modules.  I still can't
promise that this will work, since I don't know whether other parts of
django assume and test for the existance of an actual models.py file
in the app directory.

But. java practice notwithstanding, there is nothing wrong with having
several models in one models.py module, so why fight against the
design of django?  If your collection of models is truly so complex
that they should be separated into more than one module, then perhaps
your app is too complex, and should be refactored into multiple
applications.

On Wed, Dec 16, 2009 at 2:52 PM, Bruno Cordeiro  wrote:
> I want to create folder inside the app folder eg:
>
> application
>          __init__.py
>          models.py
>          views.py
> manager.py
> ...
>
> i want to separate in folder, like, one folder to models when i put
> models class inside like:
>
> application
>       __init__.py
>       models
>                 partner.py
>                 anothermodel.py
>      views
>                index.py
>                partner.py
>
> why i can do it, with the best manner? i know if i make the import
> inside the normal like models.py file like below this work, but have
> the best way to do it?
>
> from application.models.partner import __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 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: Python 2.6 Decompile --- I lost my views.py but have the views.pyc

2009-12-17 Thread Bill Freeman
I saw a demo of a byte code disassembler once.  It won't get you the
source code back, but you could conceivably construct equivalent from
it.  You can, for example, see what it's calling, and sketch out the
contiditionals and any loops.  You could google for it, or ask on the
python tutor mailing list.

On Thu, Dec 17, 2009 at 2:19 PM, Andrew  wrote:
> Hi guys,
> Ok...firstly me bad ... I didn't check into my source control which
> was stupid. So if I can close that book ;-)
>
> I am looking for a decompiler for my views.pyc ... Im using django
> 1.1.1 and python 2.6.2 ... I have tried UnPyc but fails.
>
> Has anyone successfully found a 2.6 decompiler ?
>
> Thanks
> Andrew
> ( desperate to get my ...eeek...days back )
>
> --
>
> 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: Python 2.6 Decompile --- I lost my views.py but have the views.pyc

2009-12-17 Thread Bill Freeman
The name of the byte code disassembler is dis, and it's part of the
standard python install in 2.4, 2.5, 2.6, and 3.0 (the ones I have
handy to test with) and will be documented in the default docs.  You
can confirm that you have it by trying "import dis".

On Thu, Dec 17, 2009 at 2:45 PM, Shawn Milochik  wrote:
> This won't help you unless there's something you forgot about, but it could 
> help you in the future. In addition to git, I also use JungleDisk. It backs 
> up my entire projects folder every hour. Perhaps you have Carbonite, 
> JungleDisk, Mozy, or one of those services and you might be able to recover 
> it there? Do you use a Mac with Time Machine? Is your computer a 
> company-owned machine which may be imaged or backed up automatically?
>
> Does your editor create an automatic hidden backup, like vim or emacs does?
>
> I hope you recover the work.
>
> Shawn
>
>
> --
>
> 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: Problem with Meta inner class accessing its parent

2009-12-18 Thread Bill Freeman
I can't promise that it will do what you want, but your problem is
that at the time
you try to set the value of Meta.ordering, class Substrate does not yet exist.
You can dig into the Substrate.objects._meta later to add ordering, probably.

Your design wouldn't have worked anyway, since getLanguage would only
have been called once, at import time, and even if that worked, it wouldn't
follow current language as it changes (I presume) from request to request.

Oh, and since you're not calling getLanguage on a class instance, it would
have to be declared a staticmethod or classmethod, and not get the self
argument or replace it with cls (for classmethod).  Static method would be
the choice here (and no self)

It's mildly possible that ordering is allowed to be a callable.  If
so, you could
assign it to a function (not a method of the not yet defined Substrate).  That's
the function itself, no parentheses.  The function would return the list.

If ordering can't be a callable, you could create a class that implements enough
of list behavior to satisfy the framework (a subject for research or
experimentation,
but iteration might be enough) and set ordering to an instance, whose apparent
content depends on the current language.

It still might not work, if the __metaclass__ processes Meta.ordering at clas
definition time.  You have the source code.

Bill


On Fri, Dec 18, 2009 at 6:07 AM, Kevin Renskers  wrote:
> Hi,
>
> I am having a bit of a problem. I have a model with 3 name fields,
> each for a different language. By creating an __unicode__ function
> like below, I always get the correct name for the current language.
> Works fine.
>
> But, I want to change the default ordering for this model, so that in
> each language, the correct order is used. Sadly, this doesn't work, as
> I get the error "NameError: name 'Substrate' is not defined". Also
> "self" and "super" don't seem to work. I just can't seem to be able to
> access the parent class from within the Meta class.
>
> I can't even repeat the getLanguage function into the Meta class,
> because then I get an the error "TypeError: 'class Meta' got invalid
> attribute(s): getLanguage".
>
> class Substrate(models.Model):
>    name_en = models.CharField(max_length=255)
>    name_de = models.CharField(max_length=255, blank=True)
>    name_nl = models.CharField(max_length=255, blank=True)
>
>    def getLanguage(self):
>        from django.utils import translation
>        current_language = translation.get_language()
>        if not current_language:
>            current_language = 'en'
>        return current_language
>
>    def getName(self):
>        current_language = self.getLanguage()
>        name = getattr(self, 'name_'+current_language, self.name_en)
>        if not name:
>            name = self.name_en
>
>        return name
>
>    def __unicode__(self):
>        return self.getName()
>
>    class Meta:
>        ordering = [('name_%s' % Substrate.getLanguage()), 'name_en']
>
>
>
> If anyone has an idea how on to do this, I would be very happy.
> Thanks!
>
> Cheers,
> Kevin
>
> --
>
> 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: Directories inside app directory

2009-12-18 Thread Bill Freeman
On Thu, Dec 17, 2009 at 5:02 AM, bruno desthuilliers
 wrote:
...
>
> [1] currently 970 LOCs, and I just have the basic models structures
> and only one custom manager defined yet, so I know there will be more
> to come. YMMV but I don't like modules growing much bigger than 1 to
> 1.5 KLOC.

In general I agree that many small files are nice.  And in the case of
view.py, forms.py, etc., django doesn't know about those names specially.
view files are referred to in your url.py, which itself is just
referred to in your
root url.py, which is referred to in your settings.py, so all their names can
change without any problem, other than making your code harder for
someone else to maintain.

But the name models is known specially by the framework.

All in all, I don't care much how many lines there are in a models.py file.
After all, I don't use notepad, with its 64kib limit,  to edit python code.
I *do* care how many lines there are in a class, since that is the unit
that I must understand.  Moving those classes into separate files doesn't
make them smaller.

I do, also, prefer small apps.  When I needed to rework the (pinax) profile
app, I was happy to only have to copy that to change, rather than having to
include django.contrib.auth, account, emailconfirmation, and who knows
what else has a close relationship with django.contrib.auth.  So I don't
care how many models are in a module, but I think that five is about as
many as I would want in an app.

--

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: Custom Django-Admin commands

2009-12-22 Thread Bill Freeman
If you are calling this from, for example, crontab note that each line
in crontab is executed in its own subshell, so you have the choice of
setting PYTHONPATH, or (my personal favorite because it works with so
many kinds of scripts) you can cd to the project directory and execute
the script as ./manage.py custom, by separating the cd and ./manage.py
with a semicolon.  Too, if you are doing this from a bash (or sh or,
probably, csh) script, commands run inside parentheses run in a sub
shell, so you can do the cd, semi, manage trick, and when the subshell
exits, the rest of your script is still running in its original
directory.  Finally, if this is a command line utility that you want
to run from wherever and just have on the path, create a sh (or bash)
script that cd's and runs it instead, and put that on the path.  This
last works on windows too, using bat files (or whatever the cmd.exe
equivalent is).

On Tue, Dec 22, 2009 at 5:59 AM, Justin Steward  wrote:
> I'm at a loss as to understand why, but I've worked out what I need to
> add to pythonpath.
>
> PYTHONPATH=/home/user
>
> i.e. The pythonpath needs to include NOT the project's root, but the
> directory one level ABOVE that for custom commands to work properly...
>
> Thanks for the help guys.
>
> ~Justin
>
> --
>
> 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: Does Django support sockets of type SOCK_STREAM for full-duplex communication with a client?

2009-12-22 Thread Bill Freeman
You can fun a separate process to do this.  It should probably be written
as a manage.py extension to make access to the DB via the ORM as
painless as possible.  This way the web server thread is not tied up
and can handle requests.  The saves to the database (that I presume
you're not showing) and activity of the web server accessing the database
are sorted out by the database transaction mechanism.

On Mon, Dec 21, 2009 at 7:49 PM, Chris  wrote:
> Hello,
>
> I have a client that needs to constantly send data to Django-based
> backend. The client code follows the pattern:
>
> ...
> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
> s.connect( ( '10.20.30.40',  8080 ) )
> while True :
>    data = s.recv( 2048 )
>    print data
>
>    s.send( r'something' )
> ...
>
> Could you advice on possible approaches to come up with a Django
> implementation of a backend that can work with such client, please?
>
> Thank you,
> Chris
>
> --
>
> 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: i18n: date translation in Python

2009-12-22 Thread Bill Freeman
My first guess is that you create a custom template tag that rebinds
the language
while rendering its content, then restores it when it returns.

On Tue, Dec 22, 2009 at 3:29 AM, Baurzhan Ismagulov  wrote:
> Hello Itay,
>
> On Tue, Dec 22, 2009 at 10:01:12AM +0200, Itay Donenhirsch wrote:
>> Maybe what I did can help you: in case you want to put the day name in
>> the template you can put a proper date for each day and just put into
>> the template for each day:
>> {{ day|date: "l" }}
>> day is a datetime.date object.
>> that should give the proper day name according to the locale you set
>> in settings.py.
>
> How can I get this to work for two languages on the same page?
>
> With kind regards,
> Baurzhan.
>
>
>> On Sun, Dec 20, 2009 at 7:53 PM, Baurzhan Ismagulov  wrote:
>> > Hello,
>> >
>> > I'd like to have translated week days in a bilingual (printed) form.
>> > Since templates support only one language, I want to do that in Python
>> > for now. I've looked at django.templates.defaultfilters.date and tried
>> > the following in my views.py:
>> >
>> >    from django.utils.dateformat import format
>> >    day = format(date, arg)
>> >
>> > This returns the name of the day, albeit in English. How can I set the
>> > target language? Is django.utils.dateformat a part of a published API
>> > (I couldn't find anything about it in 1.0 docs)? Or are there better
>> > ways to do that?
>> >
>> > Thanks in advance,
>> > --
>> > Baurzhan Ismagulov
>> > http://www.kz-easy.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.
>
>
>

--

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 help with namespaces in urls.py

2009-12-23 Thread Bill Freeman
Do you have an __init__.py file in zombie_django/battleships ?  It is allowed
to be empty, but it must be there for python to consider the folder to be
a "package" (folder of modules and sub-packages).

See the documentation and tutorials at python.org

On Wed, Dec 23, 2009 at 7:29 AM, Martyn  wrote:
> Hey,
>
> I'm new to django, so please excuse me for asking simple questions for
> a bit.
>
> I've installed django and have followed through a few of the simpler
> tutorials and have decided it's time to brave the world by
> myself...and have fallen at the first hurdle.
>
> I have a website with a urls.py and a views.py file in my django root,
> these work fine and I've added some stuff to both files and they work
> great:
>
> from django.conf.urls.defaults import *
> from zombie_django.views import hello, current_datetime, hours_ahead,
> mainpage
>
> urlpatterns = patterns('',
>    (r'^hello/$', hello),
>    (r'^time/$', current_datetime),
>    (r'^time/plus/(\d{1,2})/$', hours_ahead),
>    (r'^$', mainpage),
> )
>
> (imagine the views.py works fine - it's not relevant here)
>
> but, I want to make a new directory on the server and create a small
> application with all the file residing in that folder.
>
> so I created the folder
>
> zombie_django/battleships
>
> and put a new views.py inside with a method of main which just returns
> some text atm.
>
> My problem is that I'm not sure how to reference that views.py file
> from the urls.py.  I've tried adding these lines to the relevant
> places to no avail:
>
> from zombie_django.battleships.views import main
>
>    (r'^battleships$',main),
>
> and I've tried with
> (r'^battleships$', battleships.main),
>
> but still no luck.  I'm sure it's an easy one, but I'm stuck.
>
> Can you help?  Is there somewhere on the internet I can read up about
> this?  I've looked but can't find anything which looks right.
>
> Thanks for your help,
>
> Martyn
>
> --
>
> 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: Unicode name of field in form

2009-12-23 Thread Bill Freeman
I think that you need to pass the label as the "label" argument to
forms.CharField:

   field = forms.CharField(label="Ø")

or:

   field = forms.CharField(label=smart_unicode("Ø"))


On Wed, Dec 23, 2009 at 9:54 AM, Andrij Skalyuk  wrote:
> I am trying to create field in form with name "Ø" (special danish
> characters).
>
> My code is something like this:
>
> field = forms.CharField()
> form.fields[smart_unicode("Ø")] = field
>
> After that i got exception in django during validation:
> File "\django\forms\forms.py", line 233, in full_clean
>    if hasattr(self, 'clean_%s' % name):
>
> UnicodeEncodeError
> 'ascii' codec can't encode character u'\xd8' in position 6: ordinal
> not in range(128)
>
> I tried another way like:
> field = forms.CharField()
> form.fields[smart_str("Ø")] = field
>
> In this case i got exception in other place in code:
> File "\django\forms\forms.py", line 98, in __iter__
>    yield BoundField(self, field, name)
> File "\django\forms\forms.py", line 322, in __init__
>    self.html_initial_name = form.add_initial_prefix(name)
> File "\django\forms\forms.py", line 135, in add_initial_prefix
>    return u'initial-%s' % self.add_prefix(field_name)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 0: ordinal not in range(128)
>
> Thanks for any help with this problem. I tried this in 1.0.2 and 1.1.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.
>
>
>

--

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: super() argument 1 must be type, not None

2009-12-23 Thread Bill Freeman
Are you sure that Lid is defined in this context?  Try putting:

import pdb;pdb.set_trace()

before the super and check.

On Wed, Dec 23, 2009 at 10:41 AM, TiNo  wrote:
>> I am overriding a save function of a model with the following code:
>>
>>     def save(self, *args, **kwargs):
>>         if (not self.id) and self.email != '':
>>             self.create_user()
>>         if hasattr(self, 'user'):
>>             self.user.email = self.email
>>             self.user.first_name = self.voornaam
>>             self.user.last_name = " ".join((self.tussenvoegsel,
>> self.achternaam))
>>             self.user.save()
>>         super(Lid, self).save(*args, **kwargs)
>> where Lid is the name of the Model. However, for some reason it throws the
>> following error since a while (don't know since when, don't know what
>> changed, can't find anything suspicious in hg log...) "super() argument 1
>> must be type, not None". When I run with pdb.set_trace as the first line of
>> the save method in the dev server, I can see that Lid is indeed None. What
>> is surprising is that ALL my imports are None (User, datetime, models,
>> etc.). I vaguely remember encountering this error before, but I don't
>> remember what I did to fix it. What could have overridden all those things
>> with None?
>> Does anybody have any clues? I can post my whole models.py if necessary,
>> but it's rather large.
>
> Nobody any idea? It is quite frustrating as I have no way to further debug
> 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.
>

--

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: Unicode name of field in form

2009-12-23 Thread Bill Freeman
I haven't done any python programing with variable, function, class,
and attribute names
containing non-ASCII characters, so I don't know whether there is
support for them, or
how good it is.  If you can't say:

Ø = forms.CharField()

Then I think it's going to be down hill from there.  Templates are
going to want to say
things like:

{{ item.Ø }}

And that may not work either.  I'm also not sure whether all the
databases will work with
non-ASCII column names.

Note, too, if you are going to open source this, that not everyone's
text editor will make
it easy to edit these source files, though this should be getting
better.  I tend to use
the \u or \xNN escapes in unicode and string items containing
non-ASCII characters
just to keep the characters I type from being interpreted as something
else that is similar.

I might suggest the python tutor list for better infomration about
what constitutes a legal
identifier.

On Wed, Dec 23, 2009 at 10:54 AM, Andrij Skalyuk
 wrote:
> Thanks for reply.
>
> But what should i do with names of fields ?
> Replace unicode characters with some English ?
> I really want to keep unicode characters for names of fields, because
> it is easy to manage without any replacement.
>
> On Dec 23, 5:51 pm, Bill Freeman  wrote:
>> I think that you need to pass the label as the "label" argument to
>> forms.CharField:
>>
>>    field = forms.CharField(label="Ø")
>>
>> or:
>>
>>    field = forms.CharField(label=smart_unicode("Ø"))
>
> --
>
> 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: How do you rollback a transaction outside the context of a request?

2010-04-15 Thread Bill Freeman
Yes.  I saw that in the implementation of django.db.transaction.rollback().
I hesitate to use "private" methods, but since it's an odd requirement, I
may well go this way.

Thanks,
Bill

On Wed, Apr 14, 2010 at 7:25 PM, Joe  wrote:
> On Apr 14, 6:15 pm, Bill Freeman  wrote:
>> I'm running code from the manage.py shell to load stuff (from an XML export 
>> from
>> an excel read of a SQL Server dump, of all things), which gets a database 
>> error
>> (Postgersql correctly noticing that a value is too long for a field,
>> for instance) upon
>> calling the save method of a model.  I'd like to catch the exception, log 
>> about
>> what instance failed, and continue.
>>
>> But now the db connection is within a transaction, which I assume needs to be
>> rolled back, and the connection won't talk to me until I do so.
>>
>> The trouble is, I don't know how.  Just calling 
>> django.db.transaction.rollback()
>> doesn't work, and neither do several other guesses.
>>
>> I presume that the view decorators won't do it since this isn't a request
>> coming through the middleware to a view function.
>
> I found this ticket useful for an example of handling DatabaseErrors
> in the shell:
> http://code.djangoproject.com/ticket/10813
>
> Maybe try something like the following?
>
> from django.db import connection, DatabaseError
> try:
>    pass # your code that will throw the error
> except DatabaseError:
>    connection._rollback()
>
>
>
> --
> 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: How do you rollback a transaction outside the context of a request?

2010-04-15 Thread Bill Freeman
How does this apply when there is no request?  I'm not following you.

Bill

On Thu, Apr 15, 2010 at 4:20 AM, Thomas Guettler  wrote:
> Hi,
>
> here is the way I do it: I use the TransactionMiddleware. Every request gets
> commited or rollbacked (A of ACID (atomar)).
>
> Only methods that are called from the shell (scripts in bin/...) have the 
> commit_on_success decorator.
>
> If methods get used from the shell and from views, they do not use the 
> commit_on_success
> decorator. Only the calling script in bin/ uses this.
>
> I would not use django.db.transaction.rollback() or something. Use the
> available decorators. Maybe you need to restructure your code to
> put the statements which can fail into an new decorated method.
>
> HTH,
>  Thomas
>
> Bill Freeman wrote:
>> I'm running code from the manage.py shell to load stuff (from an XML export 
>> from
>> an excel read of a SQL Server dump, of all things), which gets a database 
>> error
>> (Postgersql correctly noticing that a value is too long for a field,
>> for instance) upon
>> calling the save method of a model.  I'd like to catch the exception, log 
>> about
>> what instance failed, and continue.
>>
>> But now the db connection is within a transaction, which I assume needs to be
>> rolled back, and the connection won't talk to me until I do so.
>>
>> The trouble is, I don't know how.  Just calling 
>> django.db.transaction.rollback()
>> doesn't work, and neither do several other guesses.
>>
>> I presume that the view decorators won't do it since this isn't a request
>> coming through the middleware to a view function.
>>
>> Can someone tell me the appropriate incantations?
>>
>> Bill
>>
>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>
> --
> 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.



  1   2   3   4   5   6   7   8   9   10   >