Re: ModelForm save() cleans data first?

2009-12-01 Thread Jani Tiainen
On Tue, 2009-12-01 at 20:54 -0800, Skylar Saveland wrote:
> Wait, this is a better question than I thought on first glance.  Not
> entirely sure, sorry for the terse first response.
> 
> Skylar Saveland wrote:
> > Former
> >
> > Continuation wrote:
> > > When a ModelForm object calls save(), does it first clean the form
> > > data using form.cleaned_data? Or do I need to call form.cleaned_data
> > > explicitly?

Saving checks form.errors which (as being property) in turn causes call
to form.full_clean() to generate internal error structure.

So answer is yes, it cleans data if it hasn't been cleaned before
calling save. 

-- 

Jani Tiainen


--

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




Re: django not finding modules on pythonpath

2009-12-01 Thread neridaj
I have a few novice user questions:

1. If I installed apache2 with prefork do I need to uninstall in order
to change to worker?
2. If I add the following lines to my vhost definition does this make
mod_wsgi run in daemon mode?

  WSGIDaemonProcess mysite.com processes=1 threads=5 display-name=%
{GROUP}
  WSGIProcessGroup mysite.com

3. What is the syntax for adding the value of PYTHONPATH to the python-
path= option?
4. What is the syntax for adding the python-path option to
apache2.conf?

Thanks for all your help so far,

J
On Dec 1, 5:22 pm, Graham Dumpleton 
wrote:
> On Dec 2, 12:02 pm, neridaj  wrote:
>
> > During development I had my project apps in the same directory that
> > django-admin.py startproject mysite created. I would now like to have
> > my apps in a global directory, django-apps, to be used in other
> > projects. I thought this was what the PYTHONPATH environment variable
> > was for, do I need to add every PYTHONPATH module directory
> > from .profile to mysite.wsgi?
>
> Any directories listed in PYTHONPATH environment variable of user when
> running django-admin.py, must be individually added to 'sys.path' in
> the WSGI script file.
>
> Alternatively, take what you have in PYTHONPATH and use that same
> value to define WSGIPythonPath directive if using mod_wsgi embedded
> mode, or the python-path option to WSGIDaemonProcess if using mod_wsgi
> daemon mode. For information about the latter two directives see:
>
>  http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPyt...
>  http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDae...
>
> Do note that by doing it in WSGI script file, only applies to that
> Django instance. If done in Apache configuration, applies to all
> Django instances running in embedded mode or that daemon mode process
> group, as appropriate for way configured.
>
> As such, setting these in WSGI script file is better if they relate
> only to a specific Django instance.
>
> Graham
>
> > On Dec 1, 3:03 pm, Graham Dumpleton 
> > wrote:
>
> > > Have a read of:
>
> > >http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> > > In particular where it says:
>
> > > """
> > > If you have been using the Django development server and have made use
> > > of the fact that it is possible when doing explicit imports, or when
> > > referencing modules in 'urls.py', to leave out the name of the site
> > > and use a relative module path, you will also need to add to sys.path
> > > the path to the site package directory itself.
>
> > > sys.path.append('/usr/local/django')
> > > sys.path.append('/usr/local/django/mysite')
>
> > > In other words, you would have the path to the directory containing
> > > the 'settings.py' file created by 'django-admin.py startproject', as
> > > well as the parent directory of that directory, as originally added
> > > above.
>
> > > Note that it is not recommended to be setting 'DJANGO_SETTINGS_MODULE'
> > > to be 'settings' and only listing the path to the directory containing
> > > the 'settings.py' file. This is because such a setup will not mirror
> > > properly how the Django development server works and everything may
> > > not work as expected.
> > > """
>
> > > You have only added the path to the parent directory and not the path
> > > of the directory containing the settings.py file. Your use of relative
> > > modules references within the site package may therefore be a problem.
>
> > > Graham
>
> > > On Dec 2, 9:43 am, neridaj  wrote:
>
> > > > I'm using the same setup I have for another django site running on the
> > > > same server. I haven't had to use the python-path arg to WDP before so
> > > > I'm not sure how to do that. I'm still pretty new to this so any help
> > > > would be much appreciated. I'm using the same wsgi script that works
> > > > for the other site so I don't see any problem but here it is if you
> > > > want to have a look:
>
> > > > import os, sys
>
> > > > path = '/home/username/public_html/mysite.com/'
> > > > if path not in sys.path:
> > > >     sys.path.append(path)
>
> > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> > > > import django.core.handlers.wsgi
>
> > > > _application = django.core.handlers.wsgi.WSGIHandler()
>
> > > > def application(environ, start_response):
> > > >     environ['wsgi.url_scheme'] = environ.get('HTTP_X_URL_SCHEME',
> > > > 'http')
> > > >     return _application(environ, start_response)
>
> > > > On Dec 1, 1:53 pm, Skylar Saveland  wrote:
>
> > > > > Are you using python-path arg to WDP?  Also, you might do some
> > > > > sys.path hacking in the .wsgi script.
>
> > > > > neridaj wrote:
> > > > > > Hello,
>
> > > > > > I'm trying to deploy my project to my server and I don't understand
> > > > > > why django isn't finding modules I've added to my pythonpath. When I
> > > > > > try to access my site I get 500 errors 

Is there any way to make USStateField() to not have a pre-selected value?

2009-12-01 Thread Continuation
I use USStateField() from localflavor in one of my  models:

class MyClass(models.Model):
   state  = USStateField(blank=True)

Then I made a form from that class:

class MyClassForm(forms.ModelForm):
class Meta:
model   = MyClass

When I display the form, the field "State" is a drop-down box with
"Alabama" pre-selected.

Is there any way to make the drop-down box to show no pre-selected
value at all?

--

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




Re: ModelForm save() cleans data first?

2009-12-01 Thread Skylar Saveland
Wait, this is a better question than I thought on first glance.  Not
entirely sure, sorry for the terse first response.

Skylar Saveland wrote:
> Former
>
> Continuation wrote:
> > When a ModelForm object calls save(), does it first clean the form
> > data using form.cleaned_data? Or do I need to call form.cleaned_data
> > explicitly?

--

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: ModelForm save() cleans data first?

2009-12-01 Thread Skylar Saveland
Former

Continuation wrote:
> When a ModelForm object calls save(), does it first clean the form
> data using form.cleaned_data? Or do I need to call form.cleaned_data
> explicitly?

--

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




Re: Help with installing MySQLdb package for Django on OS X Snow Leopard

2009-12-01 Thread James Dekker
Also, tried easy_install and this is what happens:

sudo easy_install MySQLdb
Password:
Searching for MySQLdb
Reading http://pypi.python.org/simple/MySQLdb/
Couldn't find index page for 'MySQLdb' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for MySQLdb
error: Could not find suitable distribution for Requirement.parse('MySQLdb')

On Dec 1, 2009, at 7:47 PM, James Dekker wrote:

> Gene,
> 
> That link / URL you sent me redirects to the Zope MySQL Adapter (same
> one I was using)...
> 
> Thanks for the e-mail,
> 
> James
> 
> On Tue, Dec 1, 2009 at 7:35 PM, Gene  wrote:
>> You may have the wrong package- ZMySQLDA is an adapter for zope.
>> 
>> I believe you want this
>> http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
>> 
>> If you run into problems installing it, you may need to grab the
>> current release from subversion.
>> 
>> Also, I would highly recommend MacPorts for python + mysql on OSX for
>> ease of use. You can even grab the PIL and other python libraries from
>> the package system.
>> 
>> If you're interested. This blog post details how to do it:
>> http://rob.cogit8.org/blog/2007/Nov/14/installing-django-leopard-mac-os-105/
>> The post is written for Leopard but it works on Snow Leopard- just get
>> the appropriate Snow Leopard MacPorts package, and replace python2.4
>> with python2.6 in the instructions.
>> 
>> Cheers
>> G
>> 
>> On Dec 1, 3:23 pm, James Dekker  wrote:
>>> Hello there,
>>> 
>>> I am using Python 2.6.2 on OS X 10.6 ( Snow Leopard ).
>>> 
>>> Downloaded Django 1.1.1 and installed it by issuing:
>>> 
>>> sudo python setup.py install
>>> 
>>> Which placed Django-1.1.1-py2.6.egg-info and django dir inside the 
>>> site-packages directory:
>>> 
>>> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packag 
>>> es
>>> 
>>> I went inside the django/bin directory and issued a chmod +x to 
>>> django-admin.py and also
>>> created a symbolic link for django-admin to my system path by doing this:
>>> 
>>> ln -ls 
>>> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packag 
>>> es/django/bin/django-admin.py /usr/local/bin
>>> 
>>> Now, I am able to run django-admin startproject my_project_name anywhere 
>>> from the BASH shell...
>>> 
>>> My problem, however, is that I can't seem to figure out how to install the 
>>> MySQLdb package for Python / Django?
>>> 
>>> Downloaded the tar.gz from:
>>> 
>>> http://sourceforge.net/projects/mysql-python/
>>> 
>>> Unextracted it and can't seem to find a setup.py anywhere?
>>> 
>>> Here's the full contents of the extracted zip file:
>>> 
>>> CHANGES.txt
>>> README.txt
>>> CREDITS.txt
>>> VERSION.txt
>>> help
>>> db.py
>>> DA.py
>>> __init__.py
>>> icons
>>> DABase.py
>>> browse.dtml
>>> joinTM.py
>>> DEPENDENCIES.txt
>>> connectionAdd.dtml
>>> table_info.dtml
>>> NEWS.txt
>>> connectionEdit.dtml
>>> 
>>> Would apprecitiate it if someone could point me in the right direction...
>>> 
>>> Really am excited to learn Django...
>>> 
>>> Do I need to change any other settings before installing this Python MySQL 
>>> driver?
>>> 
>>> Happy programming,
>>> 
>>> James
>> 
>> --
>> 
>> 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: Help with installing MySQLdb package for Django on OS X Snow Leopard

2009-12-01 Thread James Dekker
Gene,

That link / URL you sent me redirects to the Zope MySQL Adapter (same
one I was using)...

Thanks for the e-mail,

James

On Tue, Dec 1, 2009 at 7:35 PM, Gene  wrote:
> You may have the wrong package- ZMySQLDA is an adapter for zope.
>
> I believe you want this
> http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
>
> If you run into problems installing it, you may need to grab the
> current release from subversion.
>
> Also, I would highly recommend MacPorts for python + mysql on OSX for
> ease of use. You can even grab the PIL and other python libraries from
> the package system.
>
> If you're interested. This blog post details how to do it:
> http://rob.cogit8.org/blog/2007/Nov/14/installing-django-leopard-mac-os-105/
> The post is written for Leopard but it works on Snow Leopard- just get
> the appropriate Snow Leopard MacPorts package, and replace python2.4
> with python2.6 in the instructions.
>
> Cheers
> G
>
> On Dec 1, 3:23 pm, James Dekker  wrote:
>> Hello there,
>>
>> I am using Python 2.6.2 on OS X 10.6 ( Snow Leopard ).
>>
>> Downloaded Django 1.1.1 and installed it by issuing:
>>
>> sudo python setup.py install
>>
>> Which placed Django-1.1.1-py2.6.egg-info and django dir inside the 
>> site-packages directory:
>>
>> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packag 
>> es
>>
>> I went inside the django/bin directory and issued a chmod +x to 
>> django-admin.py and also
>> created a symbolic link for django-admin to my system path by doing this:
>>
>> ln -ls 
>> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packag 
>> es/django/bin/django-admin.py /usr/local/bin
>>
>> Now, I am able to run django-admin startproject my_project_name anywhere 
>> from the BASH shell...
>>
>> My problem, however, is that I can't seem to figure out how to install the 
>> MySQLdb package for Python / Django?
>>
>> Downloaded the tar.gz from:
>>
>> http://sourceforge.net/projects/mysql-python/
>>
>> Unextracted it and can't seem to find a setup.py anywhere?
>>
>> Here's the full contents of the extracted zip file:
>>
>> CHANGES.txt
>> README.txt
>> CREDITS.txt
>> VERSION.txt
>> help
>> db.py
>> DA.py
>> __init__.py
>> icons
>> DABase.py
>> browse.dtml
>> joinTM.py
>> DEPENDENCIES.txt
>> connectionAdd.dtml
>> table_info.dtml
>> NEWS.txt
>> connectionEdit.dtml
>>
>> Would apprecitiate it if someone could point me in the right direction...
>>
>> Really am excited to learn Django...
>>
>> Do I need to change any other settings before installing this Python MySQL 
>> driver?
>>
>> Happy programming,
>>
>> James
>
> --
>
> 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: Help with installing MySQLdb package for Django on OS X Snow Leopard

2009-12-01 Thread Gene
You may have the wrong package- ZMySQLDA is an adapter for zope.

I believe you want this
http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download

If you run into problems installing it, you may need to grab the
current release from subversion.

Also, I would highly recommend MacPorts for python + mysql on OSX for
ease of use. You can even grab the PIL and other python libraries from
the package system.

If you're interested. This blog post details how to do it:
http://rob.cogit8.org/blog/2007/Nov/14/installing-django-leopard-mac-os-105/
The post is written for Leopard but it works on Snow Leopard- just get
the appropriate Snow Leopard MacPorts package, and replace python2.4
with python2.6 in the instructions.

Cheers
G

On Dec 1, 3:23 pm, James Dekker  wrote:
> Hello there,
>
> I am using Python 2.6.2 on OS X 10.6 ( Snow Leopard ).
>
> Downloaded Django 1.1.1 and installed it by issuing:
>
> sudo python setup.py install
>
> Which placed Django-1.1.1-py2.6.egg-info and django dir inside the 
> site-packages directory:
>
> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packag es
>
> I went inside the django/bin directory and issued a chmod +x to 
> django-admin.py and also
> created a symbolic link for django-admin to my system path by doing this:
>
> ln -ls 
> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packag 
> es/django/bin/django-admin.py /usr/local/bin
>
> Now, I am able to run django-admin startproject my_project_name anywhere from 
> the BASH shell...
>
> My problem, however, is that I can't seem to figure out how to install the 
> MySQLdb package for Python / Django?
>
> Downloaded the tar.gz from:
>
> http://sourceforge.net/projects/mysql-python/
>
> Unextracted it and can't seem to find a setup.py anywhere?
>
> Here's the full contents of the extracted zip file:
>
> CHANGES.txt            
> README.txt              
> CREDITS.txt            
> VERSION.txt            
> help
> db.py
> DA.py                  
> __init__.py            
> icons
> DABase.py              
> browse.dtml            
> joinTM.py
> DEPENDENCIES.txt        
> connectionAdd.dtml      
> table_info.dtml
> NEWS.txt                
> connectionEdit.dtml
>
> Would apprecitiate it if someone could point me in the right direction...
>
> Really am excited to learn Django...
>
> Do I need to change any other settings before installing this Python MySQL 
> driver?
>
> Happy programming,
>
> James

--

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: Trouble with mysqld.sock error when running python manage.py syncdb

2009-12-01 Thread Dave
Okay, figured this one out, too. If anyone comes across the same
problem, read this: 
http://2tbsp.com/content/install_and_configure_mysql_5_macports

On Dec 1, 4:47 pm, Dave  wrote:
> Okay, I figured out this problem by editing my PYTHONPATH in
> my .bash_profile, but now I have another problem. When I try and run
> "python manage.py syncdb" I get this error: "Can't connect to local
> MySQL server through socket '/opt/local/var/run/mysql5/
> mysqld.sock' (2)"
>
> Mysql is running; I have the little tool in system preferences that
> says it's running. The file mysqld.sock doesn't exist, though. The /
> run/ directory doesn't even exist. Any MySQL gurus out there know how
> to fix this?
>
> On Nov 30, 10:02 pm, Dave  wrote:
>
>
>
> > Hi all,
>
> > I created a django project and when I try to start the server I get
> > this:
>
> > Traceback (most recent call last):
> >   File "manage.py", line 2, in 
> >     from django.core.management import execute_manager
> > ImportError: No module named django.core.management
>
> > I did some Googling and I think it's because I got an error when
> > trying to create a symlink in the installation instructions:
>
> > "Next, make sure that the Python interpreter can load Django's code.
> > There are various ways of accomplishing this. One of the most
> > convenient, on Linux, Mac OSX or other Unix-like systems, is to use a
> > symbolic link:
>
> > ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django"
>
> > I changed SITE-PACKAGES-DIR to my directory and got this error:
>
> > $ ln -s `pwd`/django-trunk/django /Library/Frameworks/Python.framework/
> > Versions/2.6/lib/python2.6/site-packages/django
> > ln: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
> > site-packages/django: File exists
>
> > I'm not sure what it means by "file exists". The other option was
> > changing the Pythonpath to include the Django directory, but I'm not
> > sure how to do that. Answers on Google didn't make sense to me or
> > didn't seem to apply. Any help would be greatly appreciated!

--

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.




Pass URL variable to formwizard like a normal form in views.py

2009-12-01 Thread geraldcor
No normally I can use something lie /foo/edit/35/ and I can edit the
record whose pk is 35. Now with this, I have a url pattern like
(r'^edit/(?P\d+)/$', 'edit'), which points to def edit
(request, ssf_id): in my views.py.

For my formwizard, by overriding various methods I have successfully
made it so that I can edit an instance by using a view to capture the
above url pattern and instead of passing it to 'edit' I pass it to
'edit_wizard' which looks like this:
@login_required
def edit_wizard(request, ssf_id):
instance = get_object_or_404(SSF, pk=ssf_id)
return EDIT_SSFWizard([SSF1, SSF2, SSF3])(request, instance=instance)

This works perfectly. However, there has been a request to have a
listing of the items that the user has already selected so they can
easily see what they have or maybe left off.

Normally I would use something like s=SSF.objects.filter(id=ssf_id)
using the variable from the url and then pass that as a context to the
template so I have my form instance as well as a context full of data.

So I keep putting ssf_id in various methods in my formwizard class to
only have error after error. Any ideas on how to pass this other
variable so I can use the variable to perform a query as below (line
3):

def render_template(self, request, form, previous_fields, step,
max_step, context=None):
context = context or {}
context=SSF.objects.filter(pk=ssf_id).values
()--Look at this Line please
return render_to_response(self.get_template(step), dict
(context=context,
next_step_field=self.next_step_field_name,
max_step_field=self.max_step_field_name,
max_step=max_step,
step_field=self.step_field_name,
step0=step,
step=step + 1,
step_count=self.num_steps(),
form=form,
previous_fields=previous_fields
), context_instance=RequestContext(request))

--

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.




ModelForm save() cleans data first?

2009-12-01 Thread Continuation
When a ModelForm object calls save(), does it first clean the form
data using form.cleaned_data? Or do I need to call form.cleaned_data
explicitly?

--

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




Re: django not finding modules on pythonpath

2009-12-01 Thread Graham Dumpleton


On Dec 2, 12:02 pm, neridaj  wrote:
> During development I had my project apps in the same directory that
> django-admin.py startproject mysite created. I would now like to have
> my apps in a global directory, django-apps, to be used in other
> projects. I thought this was what the PYTHONPATH environment variable
> was for, do I need to add every PYTHONPATH module directory
> from .profile to mysite.wsgi?

Any directories listed in PYTHONPATH environment variable of user when
running django-admin.py, must be individually added to 'sys.path' in
the WSGI script file.

Alternatively, take what you have in PYTHONPATH and use that same
value to define WSGIPythonPath directive if using mod_wsgi embedded
mode, or the python-path option to WSGIDaemonProcess if using mod_wsgi
daemon mode. For information about the latter two directives see:

  http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonPath
  
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess

Do note that by doing it in WSGI script file, only applies to that
Django instance. If done in Apache configuration, applies to all
Django instances running in embedded mode or that daemon mode process
group, as appropriate for way configured.

As such, setting these in WSGI script file is better if they relate
only to a specific Django instance.

Graham

> On Dec 1, 3:03 pm, Graham Dumpleton 
> wrote:
>
>
>
> > Have a read of:
>
> >http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> > In particular where it says:
>
> > """
> > If you have been using the Django development server and have made use
> > of the fact that it is possible when doing explicit imports, or when
> > referencing modules in 'urls.py', to leave out the name of the site
> > and use a relative module path, you will also need to add to sys.path
> > the path to the site package directory itself.
>
> > sys.path.append('/usr/local/django')
> > sys.path.append('/usr/local/django/mysite')
>
> > In other words, you would have the path to the directory containing
> > the 'settings.py' file created by 'django-admin.py startproject', as
> > well as the parent directory of that directory, as originally added
> > above.
>
> > Note that it is not recommended to be setting 'DJANGO_SETTINGS_MODULE'
> > to be 'settings' and only listing the path to the directory containing
> > the 'settings.py' file. This is because such a setup will not mirror
> > properly how the Django development server works and everything may
> > not work as expected.
> > """
>
> > You have only added the path to the parent directory and not the path
> > of the directory containing the settings.py file. Your use of relative
> > modules references within the site package may therefore be a problem.
>
> > Graham
>
> > On Dec 2, 9:43 am, neridaj  wrote:
>
> > > I'm using the same setup I have for another django site running on the
> > > same server. I haven't had to use the python-path arg to WDP before so
> > > I'm not sure how to do that. I'm still pretty new to this so any help
> > > would be much appreciated. I'm using the same wsgi script that works
> > > for the other site so I don't see any problem but here it is if you
> > > want to have a look:
>
> > > import os, sys
>
> > > path = '/home/username/public_html/mysite.com/'
> > > if path not in sys.path:
> > >     sys.path.append(path)
>
> > > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> > > import django.core.handlers.wsgi
>
> > > _application = django.core.handlers.wsgi.WSGIHandler()
>
> > > def application(environ, start_response):
> > >     environ['wsgi.url_scheme'] = environ.get('HTTP_X_URL_SCHEME',
> > > 'http')
> > >     return _application(environ, start_response)
>
> > > On Dec 1, 1:53 pm, Skylar Saveland  wrote:
>
> > > > Are you using python-path arg to WDP?  Also, you might do some
> > > > sys.path hacking in the .wsgi script.
>
> > > > neridaj wrote:
> > > > > Hello,
>
> > > > > I'm trying to deploy my project to my server and I don't understand
> > > > > why django isn't finding modules I've added to my pythonpath. When I
> > > > > try to access my site I get 500 errors and after looking at the server
> > > > > log I see a traceback with this:
>
> > > > > [error] [client 174.xxx.xxx.xxx] ImportError: No module named blog
>
> > > > > However, when I run python I am able to import the modules. I'm using
> > > > > nginx as a proxy to apache2/mod_wsgi on Ubuntu 9.04.
>
> > > > > Thanks,
>
> > > > > J

--

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-12-01 Thread Stodge
This is mhy laptop so I'm not bothered about where the code is stored.
If it goes live it'll be correctly located/secured etc.

Thanks

On Dec 1, 5:03 pm, Skylar Saveland  wrote:
> I thought that it was best practice to not put python code in /var/www
> and to own the code with an unprivileged user.  Doesn't seem like it
> is necessarily germane to the present topic but perhaps something to
> think about.
>
> Am I wrong? Are there exceptions?  I think I have seen some high
> profile websites running application code under /var/www
>
> Stodge wrote:
> > This:
>
> >            sys.path.append("/var/www/sites/indigo/")
> >            os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
> >            from django.core.management import setup_environ
> >            import settings
> >            project_directory = setup_environ(settings)
> >            from indigo.project.ticket.models import Ticket
>
> > Gives me "ImportError: No module named project.ticket.models". Hmmm.
> > So it can import the settings before calling setup_environ but the
> > environment isn't unusable afterwards.
>
> > On Dec 1, 12:51 pm, Stodge  wrote:
> > > Argh! Taking this a step further - I'm now trying to access my Django
> > > environment from within a Trac (http://trac.edgewall.org) plugin, but
> > > I'm getting a similar issue.
>
> > > This works:
>
> > >                 sys.path.append("/var/www/sites/indigo/")
> > >                 os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
> > >                 from django.core.management import setup_environ
> > >                 import settings
> > >                 project_directory = setup_environ(settings)
>
> > > But this:
>
> > >                 sys.path.append("/var/www/sites/indigo/")
> > >                 os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
> > >                 from django.core.management import setup_environ
> > >                 import settings
> > >                 project_directory = setup_environ(settings)
> > >                 from django.contrib.auth.models import User
>
> > > Gives "ImportError: Could not import settings 'indigo.settings' (Is it
> > > on sys.path? Does it have syntax errors?): No module named settings"
>
> > > It's the exact same code that works in my Mercurial plugin. 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: django error page: traceback too shallow?

2009-12-01 Thread Karen Tracey
On Tue, Dec 1, 2009 at 7:56 PM, notcourage  wrote:

> Is there a way to force django to show the full traceback? It only
> shows the following though the query is called from the view home(req)
> in my views.py:
>
> Traceback:
> File "C:\swe\Python25\lib\site-packages\django\core\handlers\base.py"
> in get_response
>  92. response = callback(request, *callback_args,
> **callback_kwargs)
> File "c:\swe\python25\lib\site-packages\django\db\models\fields
> \related.py" in __get__
>  191. rel_obj = self.related.model._base_manager.get
> (**params)
> File "c:\swe\python25\lib\site-packages\django\db\models\manager.py"
> in get
>  120. return self.get_query_set().get(*args, **kwargs)
> File "c:\swe\python25\lib\site-packages\django\db\models\query.py" in
> get
>  305. % self.model._meta.object_name)
>
> Exception Type: DoesNotExist at /
> Exception Value: Member matching query does not exist.
>

Django isn't doing anything to the traceback here that would cause missing
levels.  What is the URL pattern that triggers this traceback?  And the home
view code?

Karen

--

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




Re: django not finding modules on pythonpath

2009-12-01 Thread neridaj
During development I had my project apps in the same directory that
django-admin.py startproject mysite created. I would now like to have
my apps in a global directory, django-apps, to be used in other
projects. I thought this was what the PYTHONPATH environment variable
was for, do I need to add every PYTHONPATH module directory
from .profile to mysite.wsgi?

On Dec 1, 3:03 pm, Graham Dumpleton 
wrote:
> Have a read of:
>
> http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> In particular where it says:
>
> """
> If you have been using the Django development server and have made use
> of the fact that it is possible when doing explicit imports, or when
> referencing modules in 'urls.py', to leave out the name of the site
> and use a relative module path, you will also need to add to sys.path
> the path to the site package directory itself.
>
> sys.path.append('/usr/local/django')
> sys.path.append('/usr/local/django/mysite')
>
> In other words, you would have the path to the directory containing
> the 'settings.py' file created by 'django-admin.py startproject', as
> well as the parent directory of that directory, as originally added
> above.
>
> Note that it is not recommended to be setting 'DJANGO_SETTINGS_MODULE'
> to be 'settings' and only listing the path to the directory containing
> the 'settings.py' file. This is because such a setup will not mirror
> properly how the Django development server works and everything may
> not work as expected.
> """
>
> You have only added the path to the parent directory and not the path
> of the directory containing the settings.py file. Your use of relative
> modules references within the site package may therefore be a problem.
>
> Graham
>
> On Dec 2, 9:43 am, neridaj  wrote:
>
> > I'm using the same setup I have for another django site running on the
> > same server. I haven't had to use the python-path arg to WDP before so
> > I'm not sure how to do that. I'm still pretty new to this so any help
> > would be much appreciated. I'm using the same wsgi script that works
> > for the other site so I don't see any problem but here it is if you
> > want to have a look:
>
> > import os, sys
>
> > path = '/home/username/public_html/mysite.com/'
> > if path not in sys.path:
> >     sys.path.append(path)
>
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> > import django.core.handlers.wsgi
>
> > _application = django.core.handlers.wsgi.WSGIHandler()
>
> > def application(environ, start_response):
> >     environ['wsgi.url_scheme'] = environ.get('HTTP_X_URL_SCHEME',
> > 'http')
> >     return _application(environ, start_response)
>
> > On Dec 1, 1:53 pm, Skylar Saveland  wrote:
>
> > > Are you using python-path arg to WDP?  Also, you might do some
> > > sys.path hacking in the .wsgi script.
>
> > > neridaj wrote:
> > > > Hello,
>
> > > > I'm trying to deploy my project to my server and I don't understand
> > > > why django isn't finding modules I've added to my pythonpath. When I
> > > > try to access my site I get 500 errors and after looking at the server
> > > > log I see a traceback with this:
>
> > > > [error] [client 174.xxx.xxx.xxx] ImportError: No module named blog
>
> > > > However, when I run python I am able to import the modules. I'm using
> > > > nginx as a proxy to apache2/mod_wsgi on Ubuntu 9.04.
>
> > > > Thanks,
>
> > > > J

--

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




django error page: traceback too shallow?

2009-12-01 Thread notcourage
Is there a way to force django to show the full traceback? It only
shows the following though the query is called from the view home(req)
in my views.py:

Traceback:
File "C:\swe\Python25\lib\site-packages\django\core\handlers\base.py"
in get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "c:\swe\python25\lib\site-packages\django\db\models\fields
\related.py" in __get__
  191. rel_obj = self.related.model._base_manager.get
(**params)
File "c:\swe\python25\lib\site-packages\django\db\models\manager.py"
in get
  120. return self.get_query_set().get(*args, **kwargs)
File "c:\swe\python25\lib\site-packages\django\db\models\query.py" in
get
  305. % self.model._meta.object_name)

Exception Type: DoesNotExist at /
Exception Value: Member matching query does not exist.

--

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.




Trouble with mysqld.sock error when running python manage.py syncdb

2009-12-01 Thread Dave
Okay, I figured out this problem by editing my PYTHONPATH in
my .bash_profile, but now I have another problem. When I try and run
"python manage.py syncdb" I get this error: "Can't connect to local
MySQL server through socket '/opt/local/var/run/mysql5/
mysqld.sock' (2)"

Mysql is running; I have the little tool in system preferences that
says it's running. The file mysqld.sock doesn't exist, though. The /
run/ directory doesn't even exist. Any MySQL gurus out there know how
to fix this?

On Nov 30, 10:02 pm, Dave  wrote:
> Hi all,
>
> I created a django project and when I try to start the server I get
> this:
>
> Traceback (most recent call last):
>   File "manage.py", line 2, in 
>     from django.core.management import execute_manager
> ImportError: No module named django.core.management
>
> I did some Googling and I think it's because I got an error when
> trying to create a symlink in the installation instructions:
>
> "Next, make sure that the Python interpreter can load Django's code.
> There are various ways of accomplishing this. One of the most
> convenient, on Linux, Mac OSX or other Unix-like systems, is to use a
> symbolic link:
>
> ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django"
>
> I changed SITE-PACKAGES-DIR to my directory and got this error:
>
> $ ln -s `pwd`/django-trunk/django /Library/Frameworks/Python.framework/
> Versions/2.6/lib/python2.6/site-packages/django
> ln: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
> site-packages/django: File exists
>
> I'm not sure what it means by "file exists". The other option was
> changing the Pythonpath to include the Django directory, but I'm not
> sure how to do that. Answers on Google didn't make sense to me or
> didn't seem to apply. Any help would be greatly appreciated!

--

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




Help with installing MySQLdb package for Django on OS X Snow Leopard

2009-12-01 Thread James Dekker
Hello there,

I am using Python 2.6.2 on OS X 10.6 ( Snow Leopard ).

Downloaded Django 1.1.1 and installed it by issuing:

sudo python setup.py install 

Which placed Django-1.1.1-py2.6.egg-info and django dir inside the 
site-packages directory:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

I went inside the django/bin directory and issued a chmod +x to django-admin.py 
and also
created a symbolic link for django-admin to my system path by doing this:

ln -ls 
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/bin/django-admin.py
 /usr/local/bin

Now, I am able to run django-admin startproject my_project_name anywhere from 
the BASH shell...

My problem, however, is that I can't seem to figure out how to install the 
MySQLdb package for Python / Django?

Downloaded the tar.gz from:

http://sourceforge.net/projects/mysql-python/

Unextracted it and can't seem to find a setup.py anywhere? 

Here's the full contents of the extracted zip file:

CHANGES.txt 
README.txt  
CREDITS.txt 
VERSION.txt 
help
db.py
DA.py   
__init__.py 
icons
DABase.py   
browse.dtml 
joinTM.py
DEPENDENCIES.txt
connectionAdd.dtml  
table_info.dtml
NEWS.txt
connectionEdit.dtml

Would apprecitiate it if someone could point me in the right direction... 

Really am excited to learn Django...

Do I need to change any other settings before installing this Python MySQL 
driver?

Happy programming,

James

--

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




Re: Can multiple fields be updated with F() & without all at once?

2009-12-01 Thread Karen Tracey
On Tue, Dec 1, 2009 at 5:09 PM, Continuation wrote:

> In the doc, F() is used to update a single field atomically in one go.
> Can I use it to update multiple fields and mixed it with non-F() field
> updates?
>
> Using the example from doc (http://docs.djangoproject.com/en/dev/ref/
> models/instances/#updating-attributes-based-on-existing-fields
> )
>
> Can I do something like this -
>
> >>> from django.db.models import F
> >>> product = Product.objects.get(name='Venezuelan Beaver Cheese')
> >>> product.number_sold = F('number_sold') + 1
> >>> product.total_sales = F('total_sales') + 199.99
> >>> product.name = 'Cheddar Cheese
> >>> product.save()
>
> When product.save() is executed in the above example, will both
> number_sold & total_sales be updated atomically & name updated to
> 'Cheddar Cheese'?
>

Assuming DEBUG is True in your settings file,

>>> from django.db import connection
>>> connection.queries[-1]

issued right after your product.save() above will answer your question.

Karen

--

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: mod_wsgi configure problem

2009-12-01 Thread Graham Dumpleton
Read Apache documentation on virtual hosts.

http://httpd.apache.org/docs/2.2/vhosts/

Graham

On Dec 2, 3:29 am, knight  wrote:
> Hi,
>
> I need my django app to listen to port 80 and port .
>
> I have 2 servers. One is listening to both ports and one is not
> listening to .
> The first one's apache conf is:
>
> Listen 
> WSGIRestrictStdout Off
> WSGIPassAuthorization On
> LoadModule wsgi_module modules/mod-wsgi.so
> WSGIScriptAlias /peergw /home/user/mx30/django.wsgi
>
> 
>         Order deny,allow
>         allow from all
> 
>
> Alias /media/ "/var/www/media/"
> Alias /peergw/site_media/ "/var/www/site_media/"
>
> 
>         Order deny,allow
>         Allow from all
> 
>
> WSGIScriptAlias /peergw_test /home/user/test/mx30/django.wsgi
> Alias /peergw_test/site_media/ "/var/www/site_media_test/"
>
> The second one is (The one that doesn't listen to ):
>
> Listen 
> WSGIRestrictStdout Off
> WSGIPassAuthorization On
> LoadModule wsgi_module modules/mod-wsgi.so
> WSGIScriptAlias /peergw /home/reeptv/mx30/django.wsgi
>
> 
>         Order deny,allow
>         allow from all
> 
>
> Alias /media/ "/var/www/media/"
> Alias /peergw/site_media/ "/var/www/site_media/"
>
> 
>         Order deny,allow
>         Allow from all
> 
>
> The main difference are the last 2 lines. Does anybody has an idea how
> can I make the last one listen to  and 80?
>
> Regards,
> Arshavski Alexander.

--

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




Re: django not finding modules on pythonpath

2009-12-01 Thread Graham Dumpleton
Have a read of:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

In particular where it says:

"""
If you have been using the Django development server and have made use
of the fact that it is possible when doing explicit imports, or when
referencing modules in 'urls.py', to leave out the name of the site
and use a relative module path, you will also need to add to sys.path
the path to the site package directory itself.

sys.path.append('/usr/local/django')
sys.path.append('/usr/local/django/mysite')

In other words, you would have the path to the directory containing
the 'settings.py' file created by 'django-admin.py startproject', as
well as the parent directory of that directory, as originally added
above.

Note that it is not recommended to be setting 'DJANGO_SETTINGS_MODULE'
to be 'settings' and only listing the path to the directory containing
the 'settings.py' file. This is because such a setup will not mirror
properly how the Django development server works and everything may
not work as expected.
"""

You have only added the path to the parent directory and not the path
of the directory containing the settings.py file. Your use of relative
modules references within the site package may therefore be a problem.

Graham

On Dec 2, 9:43 am, neridaj  wrote:
> I'm using the same setup I have for another django site running on the
> same server. I haven't had to use the python-path arg to WDP before so
> I'm not sure how to do that. I'm still pretty new to this so any help
> would be much appreciated. I'm using the same wsgi script that works
> for the other site so I don't see any problem but here it is if you
> want to have a look:
>
> import os, sys
>
> path = '/home/username/public_html/mysite.com/'
> if path not in sys.path:
>     sys.path.append(path)
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> import django.core.handlers.wsgi
>
> _application = django.core.handlers.wsgi.WSGIHandler()
>
> def application(environ, start_response):
>     environ['wsgi.url_scheme'] = environ.get('HTTP_X_URL_SCHEME',
> 'http')
>     return _application(environ, start_response)
>
> On Dec 1, 1:53 pm, Skylar Saveland  wrote:
>
>
>
> > Are you using python-path arg to WDP?  Also, you might do some
> > sys.path hacking in the .wsgi script.
>
> > neridaj wrote:
> > > Hello,
>
> > > I'm trying to deploy my project to my server and I don't understand
> > > why django isn't finding modules I've added to my pythonpath. When I
> > > try to access my site I get 500 errors and after looking at the server
> > > log I see a traceback with this:
>
> > > [error] [client 174.xxx.xxx.xxx] ImportError: No module named blog
>
> > > However, when I run python I am able to import the modules. I'm using
> > > nginx as a proxy to apache2/mod_wsgi on Ubuntu 9.04.
>
> > > Thanks,
>
> > > J

--

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




Re: django not finding modules on pythonpath

2009-12-01 Thread neridaj
I'm using the same setup I have for another django site running on the
same server. I haven't had to use the python-path arg to WDP before so
I'm not sure how to do that. I'm still pretty new to this so any help
would be much appreciated. I'm using the same wsgi script that works
for the other site so I don't see any problem but here it is if you
want to have a look:

import os, sys

path = '/home/username/public_html/mysite.com/'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

_application = django.core.handlers.wsgi.WSGIHandler()

def application(environ, start_response):
environ['wsgi.url_scheme'] = environ.get('HTTP_X_URL_SCHEME',
'http')
return _application(environ, start_response)

On Dec 1, 1:53 pm, Skylar Saveland  wrote:
> Are you using python-path arg to WDP?  Also, you might do some
> sys.path hacking in the .wsgi script.
>
> neridaj wrote:
> > Hello,
>
> > I'm trying to deploy my project to my server and I don't understand
> > why django isn't finding modules I've added to my pythonpath. When I
> > try to access my site I get 500 errors and after looking at the server
> > log I see a traceback with this:
>
> > [error] [client 174.xxx.xxx.xxx] ImportError: No module named blog
>
> > However, when I run python I am able to import the modules. I'm using
> > nginx as a proxy to apache2/mod_wsgi on Ubuntu 9.04.
>
> > Thanks,
>
> > J

--

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 Margie Roginski
Ah, right.  I had actually forgotten that the action attribute was
what was setting my url!  What you said makes perfect sense, thanks!

Margie

On Dec 1, 12:50 pm, Bill Freeman  wrote:
> 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:
>
>    
> On Tue, Dec 1, 2009 at 3:38 PM, Margie Roginski
>
>  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 
> > 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.




Can multiple fields be updated with F() & without all at once?

2009-12-01 Thread Continuation
In the doc, F() is used to update a single field atomically in one go.
Can I use it to update multiple fields and mixed it with non-F() field
updates?

Using the example from doc (http://docs.djangoproject.com/en/dev/ref/
models/instances/#updating-attributes-based-on-existing-fields)

Can I do something like this -

>>> from django.db.models import F
>>> product = Product.objects.get(name='Venezuelan Beaver Cheese')
>>> product.number_sold = F('number_sold') + 1
>>> product.total_sales = F('total_sales') + 199.99
>>> product.name = 'Cheddar Cheese
>>> product.save()

When product.save() is executed in the above example, will both
number_sold & total_sales be updated atomically & name updated to
'Cheddar Cheese'?

--

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-12-01 Thread Skylar Saveland
I thought that it was best practice to not put python code in /var/www
and to own the code with an unprivileged user.  Doesn't seem like it
is necessarily germane to the present topic but perhaps something to
think about.

Am I wrong? Are there exceptions?  I think I have seen some high
profile websites running application code under /var/www



Stodge wrote:
> This:
>
>   sys.path.append("/var/www/sites/indigo/")
>   os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
>   from django.core.management import setup_environ
>   import settings
>   project_directory = setup_environ(settings)
>   from indigo.project.ticket.models import Ticket
>
> Gives me "ImportError: No module named project.ticket.models". Hmmm.
> So it can import the settings before calling setup_environ but the
> environment isn't unusable afterwards.
>
>
> On Dec 1, 12:51 pm, Stodge  wrote:
> > Argh! Taking this a step further - I'm now trying to access my Django
> > environment from within a Trac (http://trac.edgewall.org) plugin, but
> > I'm getting a similar issue.
> >
> > This works:
> >
> >                 sys.path.append("/var/www/sites/indigo/")
> >                 os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
> >                 from django.core.management import setup_environ
> >                 import settings
> >                 project_directory = setup_environ(settings)
> >
> > But this:
> >
> >                 sys.path.append("/var/www/sites/indigo/")
> >                 os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
> >                 from django.core.management import setup_environ
> >                 import settings
> >                 project_directory = setup_environ(settings)
> >                 from django.contrib.auth.models import User
> >
> > Gives "ImportError: Could not import settings 'indigo.settings' (Is it
> > on sys.path? Does it have syntax errors?): No module named settings"
> >
> > It's the exact same code that works in my Mercurial plugin. 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: django not finding modules on pythonpath

2009-12-01 Thread Skylar Saveland
Are you using python-path arg to WDP?  Also, you might do some
sys.path hacking in the .wsgi script.

neridaj wrote:
> Hello,
>
> I'm trying to deploy my project to my server and I don't understand
> why django isn't finding modules I've added to my pythonpath. When I
> try to access my site I get 500 errors and after looking at the server
> log I see a traceback with this:
>
> [error] [client 174.xxx.xxx.xxx] ImportError: No module named blog
>
> However, when I run python I am able to import the modules. I'm using
> nginx as a proxy to apache2/mod_wsgi on Ubuntu 9.04.
>
> Thanks,
>
> J

--

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




django not finding modules on pythonpath

2009-12-01 Thread neridaj
Hello,

I'm trying to deploy my project to my server and I don't understand
why django isn't finding modules I've added to my pythonpath. When I
try to access my site I get 500 errors and after looking at the server
log I see a traceback with this:

[error] [client 174.xxx.xxx.xxx] ImportError: No module named blog

However, when I run python I am able to import the modules. I'm using
nginx as a proxy to apache2/mod_wsgi on Ubuntu 9.04.

Thanks,

J

--

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




How to get rid of anchor in url when rendering via render_to_response()

2009-12-01 Thread Margie Roginski
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.




Re: Help with Custom Manager and UNION query?

2009-12-01 Thread Info Cascade
John,

Thanks for the response.
I don't think Q objects will work, since I need to do the fullsearch,
and I'm pretty sure that has to go in .extra().
Also, I think Django would create a query with the joins, which are much
slower than the UNION query.
Somebody must have encountered this situation before!

Liam


John M wrote:
> I'm not sure a Manager is what you want, what about Q(http://
> docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-
> q-objects) objects?  I've used them before and I think it's about what
> you'd need.  As for performance, not sure how they stack up
>
> On Nov 30, 2:45 pm, Info Cascade  wrote:
>   
>> Hi --
>>
>> I've been programming with Django about a year, and really like it, but
>> I've run into something that I can't quite solve on my own.
>> I think someone else may be able to offer the answer, or at least a hint
>> to send me in the right direction.
>>
>> I have two tables I want to search in simultaneously, Article and Tag.
>> They have a many-to-many relationship.
>> I want to get a QuerySet of Articles that match a query term on
>> article.title, as well as those that match on tag.name.
>> I can get what I want using SQL, but how do I do it in Django (with
>> acceptable performance)?
>> Ideally, I want to be able to add .filter() and .exclude() to the
>> QuerySet.  These SQL examples below are the basic idea, but in some
>> cases I'm adding .filter and .exclude.
>> Currently, the code looks something like this (I simplified it a bit,
>> but this should give an idea):
>>
>> 
>>> art_list = Article.objects.filter(status__status='PUBLISHED')
>>> art_list = art_list.extra(
>>> where=["title_tsv @@ plainto_tsquery(%s)"],
>>> params=[term])
>>>  if channel:
>>> art_list = art_list.filter(channel=channel)
>>>  art_list = art_list.distinct()
>>>  art_list = art_list.order_by(*order_by)
>>>   
>> Somehow, I want to include the fulltext search on the tag.name field,
>> where=['name_tsv @@ plainto_tsquery(%s)'],
>> params=[term])
>>
>> The two SQL example queries below both give the correct results.
>> However, the first one with joins takes over 20 seconds.
>> The second one with UNION is quite fast.
>>
>> I think what I need to do might be to create a custom manager for
>> Article that would execute the UNION query and return a QuerySet with
>> all the matching Articles.  I'm not sure quite how to do that,
>> especially if I expect it to work with the .filter() and .exclude()
>> methods.
>>
>> -- full-text search on article.title and tag.name
>> SELECT DISTINCT article.title  
>> FROM article JOIN article_tags ON article.id = article_tags.article_id
>> JOIN tag ON article_tags.tag_id = tag.id
>> JOIN article_status ON article_status.id = article.status_id
>> WHERE article_status.status = 'PUBLISHED'
>> AND (tag.name @@ plainto_tsquery('french restaurants')
>> OR title_tsv @@ plainto_tsquery('french restaurants'))
>> ORDER BY article.title;
>>
>> -- alternative full-text search on article.title and tag.name with UNION
>> --  with ranking
>> SELECT DISTINCT article.title, ts_rank_cd(title_tsv, q1) AS rank
>> FROM plainto_tsquery ('french restaurants') AS q1, article
>> JOIN article_status ON article.status_id = article_status.id
>> WHERE article_status.status = 'PUBLISHED' AND
>> title_tsv @@ q1
>> UNION
>> SELECT DISTINCT article.title, ts_rank_cd(name_tsv, q2) AS rank
>> FROM plainto_tsquery('french restaurants') AS q2, article
>> JOIN article_tags ON article.id = article_tags.article_id
>> JOIN article_status ON article.status_id = article_status.id
>> JOIN tag ON article_tags.tag_id = tag.id
>> WHERE article_status.status = 'PUBLISHED' AND
>> tag.name @@ q2
>> ORDER BY rank DESC, title;
>>
>> So -- if anyone can offer any advice on this, I would very much
>> appreciate it!!!
>>
>> Best,
>> Liam
>> 
>
> --
>
> 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.




Finding a form field's widget type from the template

2009-12-01 Thread Jon
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.




Re: loaddata encoding problem

2009-12-01 Thread Ian
On Dec 1, 9:29 am, Johan  wrote:
> Hi,
>
> I have two oracle schemas created with the same characterset
> (NLS_CHARACTERSET = WE8ISO8859P1).
>
> I get a  "DatabaseError: ORA-12704: character set mismatch" when doing
> this:
> 1) dumpdata to export data from a module named log in the first schema
> and then
> 2) loaddata to import the result into the second schema.
>
> Stacktrace:
>
> Problem installing fixture '../../data/fixtures/dev/r1797_20091201/
> log.xml': Traceback (most recent call last):
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> core/management/commands/loaddata.py", line 153, in handle
>     obj.save()
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> core/serializers/base.py", line 163, in save
>     models.Model.save_base(self.object, raw=True)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/models/base.py", line 495, in save_base
>     result = manager._insert(values, return_id=update_pk)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/models/manager.py", line 177, in _insert
>     return insert_query(self.model, values, **kwargs)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/models/query.py", line 1087, in insert_query
>     return query.execute_sql(return_id)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/models/sql/subqueries.py", line 320, in execute_sql
>     cursor = super(InsertQuery, self).execute_sql(None)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/models/sql/query.py", line 2369, in execute_sql
>     cursor.execute(sql, params)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/backends/util.py", line 19, in execute
>     return self.cursor.execute(sql, params)
>   File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
> db/backends/oracle/base.py", line 434, in execute
>     raise e
> DatabaseError: ORA-12704: character set mismatch
>
> Why do I get this "character set mismatch" when I have the same
> character sets in the two schemas?
>
> Thanks,
> Johan

Hi Johan,

Do you only have VARCHAR2 / CLOB columns in the tables, or are there
any NVARCHAR2 / NCLOB columns (which Django creates by default)?  If
the latter, then what is the NLS_NCHAR_CHARACTERSET of each database?

Also, the dumpdata output should be in utf-8.  Can you verify that it
can be re-encoded as iso-8859-1 by running the code `file
('dumpdata.json').read().decode('utf-8').encode('iso-8859-1')`?

Thanks,
Ian

--

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: Can't run Django from the command line using just "manage.py runserver", following attempt to install Python2.6 on windows 7.

2009-12-01 Thread Rodrigo Cea
Hi Ken, thanks for your response,

I get the exact same results as you,
.py=Python.File and Python.File="C:\Python25\python.exe" "%1" %*

Thanks,

Rodrigo

On Dec 1, 11:49 am, Ken MacDonald  wrote:
> Hi,
> Check this out - on my XP system anyway (understand it hasn't changed much
> for W7) use the 'assoc' and 'ftype' commands to find out what ".py" is doing
> on your system. It should look something like this, except for file paths
> appropriate for your system. If your ftype is messed up (missing the "%*"
> maybe), you wouldn't see the args.
> Ken
>
> C:\>*assoc .py*
> .py=Python.File
>
> C:\>*ftype Python.File*
> Python.File="C:\Python25\python.exe" "%1" %*
>
> On Tue, Dec 1, 2009 at 7:18 AM, Rodrigo Cea  wrote:
> > Thanks for the response.
>
> > Doing some more tests python programs do work, they just seem to not
> > recieve sys.argv. The results of calling "manage.py runserver" is the
> > same as calling just "manage.py". Other simple scripts bear this out.
>
> > Thanks,
>
> > Rodrigo
>
> > On Dec 1, 6:32 am, John M  wrote:
> > > Sounds like the .py extension isn't seen as using python, should be an
> > > easy fix.  Check your file associations (where they are in Win7) I'll
> > > have to find at work tomorrow, but that should fix your issue.
>
> > > Or, it could be some new security scheme that MS has come up with to
> > > not allow associations at the CMD level?  sounds like that would break
> > > too much stuff though, I'll try it at work tomorrow and if it's not an
> > > association thing, I'll check back on this thread.
>
> > > J
>
> > > On Nov 30, 8:36 am, Rodrigo Cea  wrote:
>
> > > > Following an abortive attempt to install Python2.6 on Windows 7, I
> > > > can't run the Django dev server without prepending "python" before
> > > > "manage.py runserver".
>
> > > > I tried recently to install Python2.6 on a windows 7 system that
> > > > already has python 2.5 installed. I had problems running some Django
> > > > applications I'm working on, so I uninstalled it.
>
> > > > Now I can't run the dev server the way I used to: "manage.py
> > > > runserver", I get:
>
> > > > "Type 'manage.py help' for usage."
>
> > > > If I run it like so: "python manage.py runserver" it works.
>
> > > > I have checked for other python installs on the system, and there was
> > > > just one in Cygwin which I have deleted.
> > > > I have checked running programs with and without "python" and the
> > > > executable is the same: "C:\python2.5\python.exe".
>
> > > > This also affects other programs, e.g.: easy_setup, which I can't just
> > > > run as "easy_setup package_name" anymore, but rather "python /path/to/
> > > > easy_setup package_name".
>
> > > > This is more annoying than anything else, but any help is greatly
> > > > appreciated.
>
> > --
>
> > 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-12-01 Thread Stodge
This:

sys.path.append("/var/www/sites/indigo/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
from django.core.management import setup_environ
import settings
project_directory = setup_environ(settings)
from indigo.project.ticket.models import Ticket

Gives me "ImportError: No module named project.ticket.models". Hmmm.
So it can import the settings before calling setup_environ but the
environment isn't unusable afterwards.


On Dec 1, 12:51 pm, Stodge  wrote:
> Argh! Taking this a step further - I'm now trying to access my Django
> environment from within a Trac (http://trac.edgewall.org) plugin, but
> I'm getting a similar issue.
>
> This works:
>
>                 sys.path.append("/var/www/sites/indigo/")
>                 os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
>                 from django.core.management import setup_environ
>                 import settings
>                 project_directory = setup_environ(settings)
>
> But this:
>
>                 sys.path.append("/var/www/sites/indigo/")
>                 os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
>                 from django.core.management import setup_environ
>                 import settings
>                 project_directory = setup_environ(settings)
>                 from django.contrib.auth.models import User
>
> Gives "ImportError: Could not import settings 'indigo.settings' (Is it
> on sys.path? Does it have syntax errors?): No module named settings"
>
> It's the exact same code that works in my Mercurial plugin. 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-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: redundant SQL's in Django tutorial

2009-12-01 Thread stargazer
And here is the Postgresql log file for the same "polls" screens.
Same select as in debug_toolbar

It seems, such thing like a connection pool does not exists by default
(every time connection is initialized)
Is it just a setting in Django or in the psycopg2 ?

**
LOG:  statement: SET DATESTYLE TO 'ISO'
LOG:  statement: SHOW client_encoding
LOG:  statement: SHOW default_transaction_isolation
LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: SET TIME ZONE E'Europe/Berlin'
LOG:  statement: SELECT version()
LOG:  statement: SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date" FROM "polls_poll"
LOG:  statement: ROLLBACK
LOG:  statement: SET DATESTYLE TO 'ISO'
LOG:  statement: SHOW client_encoding
LOG:  statement: SHOW default_transaction_isolation
LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: SET TIME ZONE E'Europe/Berlin'
LOG:  statement: SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date" FROM "polls_poll" WHERE "polls_poll"."id" = 2
LOG:  statement: SELECT "polls_choice"."id", "polls_choice"."poll_id",
"polls_choice"."choice", "polls_choice"."votes" FROM "polls_choice"
WHERE "polls_choice"."poll_id" = 2
LOG:  statement: ROLLBACK
LOG:  statement: SET DATESTYLE TO 'ISO'
LOG:  statement: SHOW client_encoding
LOG:  statement: SHOW default_transaction_isolation
LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: SET TIME ZONE E'Europe/Berlin'
LOG:  statement: SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date" FROM "polls_poll" WHERE "polls_poll"."id" = 2
LOG:  statement: SELECT "polls_choice"."id", "polls_choice"."poll_id",
"polls_choice"."choice", "polls_choice"."votes" FROM "polls_choice"
WHERE ("polls_choice"."poll_id" = 2  AND "polls_choice"."id" = 10 )
LOG:  statement: SELECT (1) AS "a" FROM "polls_choice" WHERE
"polls_choice"."id" = 10
LOG:  statement: UPDATE "polls_choice" SET "poll_id" = 2, "choice" =
E'choice2', "votes" = 31 WHERE "polls_choice"."id" = 10
LOG:  statement: COMMIT
LOG:  statement: SET DATESTYLE TO 'ISO'
LOG:  statement: SHOW client_encoding
LOG:  statement: SHOW default_transaction_isolation
LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: SET TIME ZONE E'Europe/Berlin'
LOG:  statement: SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date" FROM "polls_poll" WHERE "polls_poll"."id" = 2
LOG:  statement: SELECT "polls_choice"."id", "polls_choice"."poll_id",
"polls_choice"."choice", "polls_choice"."votes" FROM "polls_choice"
WHERE "polls_choice"."poll_id" = 2
LOG:  statement: 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.




Re: Adding a dashboard to admin

2009-12-01 Thread Brian Neal
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.

Best regards,
BN

--

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-12-01 Thread Stodge
Argh! Taking this a step further - I'm now trying to access my Django
environment from within a Trac (http://trac.edgewall.org) plugin, but
I'm getting a similar issue.

This works:

sys.path.append("/var/www/sites/indigo/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
from django.core.management import setup_environ
import settings
project_directory = setup_environ(settings)

But this:

sys.path.append("/var/www/sites/indigo/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'indigo.settings'
from django.core.management import setup_environ
import settings
project_directory = setup_environ(settings)
from django.contrib.auth.models import User

Gives "ImportError: Could not import settings 'indigo.settings' (Is it
on sys.path? Does it have syntax errors?): No module named settings"

It's the exact same code that works in my Mercurial plugin. 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-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 call this function

2009-12-01 Thread David
Thanks Daniel. I am working in the way just as you said.



On Dec 1, 10:21 am, Daniel Roseman  wrote:
> On Dec 1, 3:53 pm, David  wrote:
>
>
>
>
>
> > Hello John and Daniel, thanks for your replies. Let me tell what I
> > need in more details.
>
> > {% for value in data %}
> >              >                    {% ifequal all_domain 1 %}
> >                           class="odd" id="{{value.publisher}}"  
> > "showDomain('{{value.publisher}}', '{{value.country}}');"
> >                    {% else %}
> >                           class="odd" id="{{value.publisher}}"
> > onclick=
> > "showDomain('{{value.publisher}}', '{{value.country}}');"
>
> >                    {% endifequal %}
> >             >
>
> >       ...
> > {% endfor %}
>
> > Here "showDomain(...)" is ajax. There are many lines of records on the
> > webpage. If I click a line, then just below this line it shows domain
> > related information. This is realized with the "onclick=..." in the
> > script.
>
> > Now my question is: if I want to show all domain related information
> > for each line without clicking any lines, how can I do it?
>
> > Here is an example. On my webpage I have
> >  line 1 
> >  line 2 
> >  line 3 
>
> > If I click "line 2", then I get
> >  line 1 
> >  line 2 
> >  line 2 related domain =
> >  line 3 
>
> > Now I do not want to click any lines, however I want to show all
> > domain related information when a browser loads this data. It should
> > look like
>
> >  line 1 
> >  line 1 related domain =
> >  line 2 
> >  line 2 related domain =
> >  line 3 
> >  line 3 related domain =
>
> > Is this clear?
>
> > Any suggestions?
>
> > Thanks so much.
>
> This should be done in the template or the view. You know you want
> this at the outset, so why would you use ajax for it? That just means
> you would be making one extra HTTP request for *every single* line in
> your table. That makes no sense at all, and would massively slow down
> the loading of your page.
>
> Presumably your ajax function is accessing your Django site. So, for
> example, move that code into a templatetag, then you can call it via
> the Django template language without any javascript being necessary at
> all.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -

--

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 call this function

2009-12-01 Thread Daniel Roseman
On Dec 1, 3:53 pm, David  wrote:
> Hello John and Daniel, thanks for your replies. Let me tell what I
> need in more details.
>
> {% for value in data %}
>                                 {% ifequal all_domain 1 %}
>                           class="odd" id="{{value.publisher}}"  
> "showDomain('{{value.publisher}}', '{{value.country}}');"
>                    {% else %}
>                           class="odd" id="{{value.publisher}}"
> onclick=
> "showDomain('{{value.publisher}}', '{{value.country}}');"
>
>                    {% endifequal %}
>             >
>
>       ...
> {% endfor %}
>
> Here "showDomain(...)" is ajax. There are many lines of records on the
> webpage. If I click a line, then just below this line it shows domain
> related information. This is realized with the "onclick=..." in the
> script.
>
> Now my question is: if I want to show all domain related information
> for each line without clicking any lines, how can I do it?
>
> Here is an example. On my webpage I have
>  line 1 
>  line 2 
>  line 3 
>
> If I click "line 2", then I get
>  line 1 
>  line 2 
>  line 2 related domain =
>  line 3 
>
> Now I do not want to click any lines, however I want to show all
> domain related information when a browser loads this data. It should
> look like
>
>  line 1 
>  line 1 related domain =
>  line 2 
>  line 2 related domain =
>  line 3 
>  line 3 related domain =
>
> Is this clear?
>
> Any suggestions?
>
> Thanks so much.

This should be done in the template or the view. You know you want
this at the outset, so why would you use ajax for it? That just means
you would be making one extra HTTP request for *every single* line in
your table. That makes no sense at all, and would massively slow down
the loading of your page.

Presumably your ajax function is accessing your Django site. So, for
example, move that code into a templatetag, then you can call it via
the Django template language without any javascript being necessary at
all.
--
DR.

--

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




Re: Should empty formsets call their own clean method?

2009-12-01 Thread Tom Evans
On Tue, Dec 1, 2009 at 4:14 PM, Tom Evans  wrote:
> Hi all
>
> We encountered a strange issue today. When a user submits a formset
> that is empty, we call is_valid() on the formset, expecting the
> clean() method to be called. We then subsequently get errors later on,
> because the formset did not call self.clean(), and therefore it did
> not populate the fields we require on the formset.
> 

Raised as http://code.djangoproject.com/ticket/12295

Cheers

Tom

--

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




Re: 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: style guide/autoformatter/linter for Django templates?

2009-12-01 Thread Antoni Aloy
2009/12/1 Tom Evans :
> On Tue, Dec 1, 2009 at 4:13 PM, Steve Howell  wrote:
>>
>> On Dec 1, 3:33 am, Tom Evans  wrote:
>>> On Tue, Dec 1, 2009 at 7:33 AM, Steve Howell  wrote:
>>> > Just following up on this a few days later, in case it got lost in the
>>> > shuffle due to the weekend and U.S. holiday.
>>>
>>> > On Nov 27, 2:18 pm, Steve Howell  wrote:
>>> >> I am wondering if there is a style guide anywhere for writing Django
>>> >> templates.  Also, are there programs to automatically format your
>>> >> templates...to indent block tags, for example?  I

I have been playing with Ulipad editor,
http://code.google.com/p/ulipad/, it has Django template syntax
support as well as Django project support.

It's a nice and fast editor, and it has one of the best autocomplete
feature for Python and Django that I have seen so far.


-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.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.




loaddata encoding problem

2009-12-01 Thread Johan
Hi,

I have two oracle schemas created with the same characterset
(NLS_CHARACTERSET = WE8ISO8859P1).

I get a  "DatabaseError: ORA-12704: character set mismatch" when doing
this:
1) dumpdata to export data from a module named log in the first schema
and then
2) loaddata to import the result into the second schema.

Stacktrace:

Problem installing fixture '../../data/fixtures/dev/r1797_20091201/
log.xml': Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
core/management/commands/loaddata.py", line 153, in handle
obj.save()
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
core/serializers/base.py", line 163, in save
models.Model.save_base(self.object, raw=True)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/models/base.py", line 495, in save_base
result = manager._insert(values, return_id=update_pk)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/models/manager.py", line 177, in _insert
return insert_query(self.model, values, **kwargs)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/models/query.py", line 1087, in insert_query
return query.execute_sql(return_id)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/models/sql/subqueries.py", line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/backends/util.py", line 19, in execute
return self.cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/Django-1.1-py2.6.egg/django/
db/backends/oracle/base.py", line 434, in execute
raise e
DatabaseError: ORA-12704: character set mismatch

Why do I get this "character set mismatch" when I have the same
character sets in the two schemas?

Thanks,
Johan

--

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.




mod_wsgi configure problem

2009-12-01 Thread knight
Hi,

I need my django app to listen to port 80 and port .

I have 2 servers. One is listening to both ports and one is not
listening to .
The first one's apache conf is:

Listen 
WSGIRestrictStdout Off
WSGIPassAuthorization On
LoadModule wsgi_module modules/mod-wsgi.so
WSGIScriptAlias /peergw /home/user/mx30/django.wsgi


Order deny,allow
allow from all


Alias /media/ "/var/www/media/"
Alias /peergw/site_media/ "/var/www/site_media/"


Order deny,allow
Allow from all


WSGIScriptAlias /peergw_test /home/user/test/mx30/django.wsgi
Alias /peergw_test/site_media/ "/var/www/site_media_test/"



The second one is (The one that doesn't listen to ):

Listen 
WSGIRestrictStdout Off
WSGIPassAuthorization On
LoadModule wsgi_module modules/mod-wsgi.so
WSGIScriptAlias /peergw /home/reeptv/mx30/django.wsgi


Order deny,allow
allow from all


Alias /media/ "/var/www/media/"
Alias /peergw/site_media/ "/var/www/site_media/"


Order deny,allow
Allow from all



The main difference are the last 2 lines. Does anybody has an idea how
can I make the last one listen to  and 80?

Regards,
Arshavski Alexander.

--

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: style guide/autoformatter/linter for Django templates?

2009-12-01 Thread Tom Evans
On Tue, Dec 1, 2009 at 4:13 PM, Steve Howell  wrote:
>
> On Dec 1, 3:33 am, Tom Evans  wrote:
>> On Tue, Dec 1, 2009 at 7:33 AM, Steve Howell  wrote:
>> > Just following up on this a few days later, in case it got lost in the
>> > shuffle due to the weekend and U.S. holiday.
>>
>> > On Nov 27, 2:18 pm, Steve Howell  wrote:
>> >> I am wondering if there is a style guide anywhere for writing Django
>> >> templates.  Also, are there programs to automatically format your
>> >> templates...to indent block tags, for example?  I know there are
>> >> autoformatters for HTML, but I am not aware of any tools that handle
>> >> Django tags.  Also, it would be nice to have a command line tool that
>> >> detected unbalanced tags before rendering occurs, knowing, of course,
>> >> that that task is a little complicated due to conditionals.
>>
>> >> [...]
>>
>> vim 7.2 comes with two syntax, highlighting and indentation modes for django.
>>
>> "set ft=django" for just django template syntax highlighting/indentation
>> "set ft=htmldjango" for mixed HTML/django template syntax highlighting
>>
>
> That's a start, but is there anything that runs from the command
> line?  Am I correct that vim does not indent blocks for django tags,
> only HTML tags?
>

Vim runs from the command line, and could be probably be coerced to
behave like indent. It'd be more than a bit hacky though!

For djangohtml, it uses HTML's indentation rules. There are benefits
to this, your HTML comes out all nicely formed.

Cheers

Tom

--

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




Should empty formsets call their own clean method?

2009-12-01 Thread Tom Evans
Hi all

We encountered a strange issue today. When a user submits a formset
that is empty, we call is_valid() on the formset, expecting the
clean() method to be called. We then subsequently get errors later on,
because the formset did not call self.clean(), and therefore it did
not populate the fields we require on the formset.

This is probably easier to explain with an example:

from django import forms
from django.forms.formsets import BaseFormSet, formset_factory

class EmptyFsetWontValidate(BaseFormSet):
  def clean(self):
raise forms.ValidationError, "Clean method called"

class SimpleForm(forms.Form):
  name = forms.CharField()

EmptyFsetWontValidateFormset = formset_factory(SimpleForm, extra=0,
formset=EmptyFsetWontValidate)
formset = EmptyFsetWontValidateFormset({'form-INITIAL_FORMS':'0',
'form-TOTAL_FORMS':'0'})
formset2 = EmptyFsetWontValidateFormset({'form-INITIAL_FORMS':'0',
'form-TOTAL_FORMS':'1', 'form-0-name':'bah' })

>>> formset.is_valid()
True
>>> formset2.is_valid()
False

I would have expected both to be invalid.

The reason it doesn't mark both as invalid is clear enough.
BaseFormSet::is_valid() and BaseFormSet::errors looks like so:

def _get_errors(self):
"""
Returns a list of form.errors for every form in self.forms.
"""
if self._errors is None:
self.full_clean()
return self._errors
errors = property(_get_errors)

def is_valid(self):
"""
Returns True if form.errors is empty for every form in self.forms.
"""
if not self.is_bound:
return False
# We loop over every form.errors here rather than short
circuiting on the
# first failure to make sure validation gets triggered for every form.
forms_valid = True
for i in range(0, self.total_form_count()):
form = self.forms[i]
if self.can_delete:
# The way we lookup the value of the deletion field here takes
# more code than we'd like, but the form's cleaned_data will
# not exist if the form is invalid.
field = form.fields[DELETION_FIELD_NAME]
raw_value = form._raw_value(DELETION_FIELD_NAME)
should_delete = field.clean(raw_value)
if should_delete:
# This form is going to be deleted so any of its errors
# should not cause the entire formset to be invalid.
continue
if bool(self.errors[i]):
forms_valid = False
return forms_valid and not bool(self.non_form_errors())

It loops over each form in the list, and sets forms_valid to False if
any one of them has errors in self.errors[i]. self.errors is a
property, which runs self.full_clean() if unpopulated. The problem is
that if there are no forms in the fieldset, then self.errors is never
examined, and hence self.full_clean() is never called.

I think this is a bug, especially as the return value of
formset.is_valid() can depend on whether formset.errors has been
populated. Eg:

>>> formset3 = EmptyFsetWontValidateFormset({'form-INITIAL_FORMS':'0', 
>>> 'form-TOTAL_FORMS':'0'})
>>> formset3.is_valid()
True
>>> formset3.errors
[]
>>> formset3.is_valid()
False


Cheers

Tom

--

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




Re: style guide/autoformatter/linter for Django templates?

2009-12-01 Thread Steve Howell

On Dec 1, 3:33 am, Tom Evans  wrote:
> On Tue, Dec 1, 2009 at 7:33 AM, Steve Howell  wrote:
> > Just following up on this a few days later, in case it got lost in the
> > shuffle due to the weekend and U.S. holiday.
>
> > On Nov 27, 2:18 pm, Steve Howell  wrote:
> >> I am wondering if there is a style guide anywhere for writing Django
> >> templates.  Also, are there programs to automatically format your
> >> templates...to indent block tags, for example?  I know there are
> >> autoformatters for HTML, but I am not aware of any tools that handle
> >> Django tags.  Also, it would be nice to have a command line tool that
> >> detected unbalanced tags before rendering occurs, knowing, of course,
> >> that that task is a little complicated due to conditionals.
>
> >> [...]
>
> vim 7.2 comes with two syntax, highlighting and indentation modes for django.
>
> "set ft=django" for just django template syntax highlighting/indentation
> "set ft=htmldjango" for mixed HTML/django template syntax highlighting
>

That's a start, but is there anything that runs from the command
line?  Am I correct that vim does not indent blocks for django tags,
only HTML tags?

--

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: Best way to customize create form in admin

2009-12-01 Thread fxvazquez
A not so dirty trick:

{% with inline_admin_formsets.0 as inline_admin_formset %}
{% include inline_admin_formset.opts.template %}
{% endwith %}


> To insert inlines between two form fields I made this dirty trick:
>
> 
>         {% for inline_admin_formset in inline_admin_formsets %}
>                 {# DIY method to show only the wanted inline. #}
>                 {% ifequal inline_admin_formsets.0  inline_admin_formset %}
>                         {% include inline_admin_formset.opts.template %}
>                 {% endifequal %}
>         {% endfor %}
> 
>

--

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




Re: WebFaction warning

2009-12-01 Thread digicase
On Nov 30, 10:38 am, David Zhou  wrote:
> On Sun, Nov 29, 2009 at 9:18 PM, digicase  
> wrote:
> > I received a good email From Remi at WF which told me all I needed to
> > know. The outage was unacceptable but hopefully lessons have been
> > learned.
>
> Do you mind sharing what he said? I'd be curious to know if any new
> controls have been put into place to prevent this sort of sustained
> outage from happening again.  And if new protocols on communication
> during extended outages are being considered.

Nothing specific really, mainly assurances that this will never happen
again. I'm sure if you contact Remi D at WebFaction he would be able
to answer your questions and be open to ideas on how communication can
be improved during outages. He seems like a nice, helpful fellow.

--

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.




I want to save django debug information page when setttings.DEBUG = False

2009-12-01 Thread hoamon
Hi all:

I wrote the sources below:

from django.views.debug import ExceptionReporter
def recordErrorPage(R, **kw):
if kw.has_key('exc_info'):
reporter = ExceptionReporter(R, *kw['exc_info'])
bug_html = reporter.get_traceback_html()
   # bug_html is the content of default Django debug info
page.
else:
bug_html = 'no exc_info'
bp = BugPage(html=bug_html)
bp.save()

t = get_template('customize_500.html')
# this customize_500.html has few information for client.
html = t.render(RequestContext(R, {'bug_page': bp}))
return HttpResponseServerError(html, mimetype='text/html')

handler500 = 'recordErrorPage'

But this method must add a line("param_dict['exc_info'] = exc_info")
in the Django framework library(django/core/handlers/base.py near 166
line)
to let recordErrorPage gets the "exc_info" variable.  This is so
dirty.

Perhaps i should use the middleware framework to implement this
feature.
but i read the Django document, the "process_exception" function can
not get the "exc_info" variable, so i can not render a debug info page
like django default page.

Any suggestion?

Thank you so much.

--

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: ModelMultipleChoiceField with checkboxes: How to generate the HTML "checked" option?

2009-12-01 Thread Gloria

After much digging, I discovered that I cannot iterate over a
forms.ModelMultipleChoiceField.
This explains the template iteration issue.
It seems like I need a FormSet to be able to set these values, and
iterate over them.
This is overly complicated, just for a set of checkboxes, but it looks
like it will work.
~G~

--

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 call this function

2009-12-01 Thread David
Hello John and Daniel, thanks for your replies. Let me tell what I
need in more details.

{% for value in data %}


  ...
{% endfor %}


Here "showDomain(...)" is ajax. There are many lines of records on the
webpage. If I click a line, then just below this line it shows domain
related information. This is realized with the "onclick=..." in the
script.

Now my question is: if I want to show all domain related information
for each line without clicking any lines, how can I do it?

Here is an example. On my webpage I have
 line 1 
 line 2 
 line 3 

If I click "line 2", then I get
 line 1 
 line 2 
 line 2 related domain =
 line 3 


Now I do not want to click any lines, however I want to show all
domain related information when a browser loads this data. It should
look like

 line 1 
 line 1 related domain =
 line 2 
 line 2 related domain =
 line 3 
 line 3 related domain =


Is this clear?

Any suggestions?

Thanks so much.














--

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: redundant SQL's in Django tutorial

2009-12-01 Thread stargazer
> Caching isn't the issue here, it's a matter of writing the queries
> properly. Yes, select_related will help.
Well, I tried select_related but without success.
It would be good to see an example...

--

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: Got error when update object

2009-12-01 Thread 邓超
Hi DR,
  Thank you very much! It works now. I will check the doc about the
difference of the queryset and instance. Anyway, thanks a lot!

2009/12/1 Daniel Roseman 

> On Dec 1, 3:24 pm, 邓超  wrote:
> > Hi all,
> >   I'm writing a small app, and get an error when trying to update the
> > object, the error message is
> >
> > 'QuerySet' object has no attribute '_meta'. and It shows that I made
> > some mistake on this line:
> > form = ProjectForm(instance = projectInstance). But I don't know where
> > am I wrong. The below is my code in views.py.
> >
> > @login_required
> > def edit_project(request, project_id = None):
> > if project_id == None:
> > projectInstance = Project()
> > else:
> > projectInstance = Project.objects.filter(id =
> > project_id).filter(Q(creater = request.user) | Q(administrator =
> > request.user))
>
> Here's your problem. filter() returns a queryset, not an instance.
> Either use get() (if you're sure you're never going to have more than
> one matching object), or slice the result with [0] to get a single
> instance.
> --
> DR.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>


-- 
Deng Chao

--

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: redundant SQL's in Django tutorial

2009-12-01 Thread Daniel Roseman
On Dec 1, 1:57 pm, stargazer  wrote:
> Hi all,
>
> I'm trying the famous Django 
> tutorial:http://docs.djangoproject.com/en/1.1/intro/
>
> Playing with "polls" and "choices" I see lot of SQL queries this
> application creates. Actually, I just selected a list of polls
> than selected the poll with ID=2, than voted for a choice.
> Here are details (SQL's recorded using "debug_toolbar", may be a
> database log will show something else):

> It seems, same records are selected several time.
> With some sort of caching this could be greatly improved.
>
> May be some built-in Django tools (like select_related()? )  can help
> here?
>
> I now, number of cache implementations exists
> (like thishttp://github.com/mmalone/django-caching/ and 
> thishttp://github.com/dcramer/django-orm-cache)
> but I would like to use built-in Django instruments first.


Caching isn't the issue here, it's a matter of writing the queries
properly. Yes, select_related will help.

But you can't expect the tutorial to explain these concepts - it's
supposed to be a very basic introduction to using Django, and doesn't
go into detail. The full explanation of how to make queries is in the
actual documentation.
--
DR.

--

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




Re: Got error when update object

2009-12-01 Thread Daniel Roseman
On Dec 1, 3:24 pm, 邓超  wrote:
> Hi all,
>   I'm writing a small app, and get an error when trying to update the
> object, the error message is
>
> 'QuerySet' object has no attribute '_meta'. and It shows that I made
> some mistake on this line:
> form = ProjectForm(instance = projectInstance). But I don't know where
> am I wrong. The below is my code in views.py.
>
> @login_required
> def edit_project(request, project_id = None):
>     if project_id == None:
>         projectInstance = Project()
>     else:
>         projectInstance = Project.objects.filter(id =
> project_id).filter(Q(creater = request.user) | Q(administrator =
> request.user))

Here's your problem. filter() returns a queryset, not an instance.
Either use get() (if you're sure you're never going to have more than
one matching object), or slice the result with [0] to get a single
instance.
--
DR.

--

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




Got error when update object

2009-12-01 Thread 邓超
Hi all,
  I'm writing a small app, and get an error when trying to update the
object, the error message is

'QuerySet' object has no attribute '_meta'. and It shows that I made
some mistake on this line:
form = ProjectForm(instance = projectInstance). But I don't know where
am I wrong. The below is my code in views.py.


@login_required
def edit_project(request, project_id = None):
if project_id == None:
projectInstance = Project()
else:
projectInstance = Project.objects.filter(id =
project_id).filter(Q(creater = request.user) | Q(administrator =
request.user))

if projectInstance.count() == 0:
return HttpResponseRedirect('/edit/fail/')

if request.method == 'POST':
form = ProjectForm(request.POST, instance = projectInstance)

if form.is_valid():
project = form.save(commit = False)

if project.creater is None:
project.creater = request.user
else:
project.creater = project.creater

project.save()
form.save_m2m()

return HttpResponseRedirect('/')
else:
form = ProjectForm(instance = projectInstance)

variables = RequestContext(request, {'form': form})

return render_to_response('add_project.html', variables)

My environment is: UBUNTU910, Django 1.1.1. Anyone can help me? Thank you
very much!
-- 
Deng Chao

--

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




Re: HELP PyAMF - Django + FLEX

2009-12-01 Thread esatterwh...@wi.rr.com
http://pyamf.org/wiki/DjangoHowto

On Nov 30, 10:55 am, Rafael Vieira  wrote:
> Good afternoon people,
>
> I am starting with pyAmf framework, and I have questions about how to
> integrate models of Django with RemoteObjects of FLEX;

--

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




Re: Can't run Django from the command line using just "manage.py runserver", following attempt to install Python2.6 on windows 7.

2009-12-01 Thread Ken MacDonald
Hi,
Check this out - on my XP system anyway (understand it hasn't changed much
for W7) use the 'assoc' and 'ftype' commands to find out what ".py" is doing
on your system. It should look something like this, except for file paths
appropriate for your system. If your ftype is messed up (missing the "%*"
maybe), you wouldn't see the args.
Ken

C:\>*assoc .py*
.py=Python.File

C:\>*ftype Python.File*
Python.File="C:\Python25\python.exe" "%1" %*


On Tue, Dec 1, 2009 at 7:18 AM, Rodrigo Cea  wrote:

> Thanks for the response.
>
> Doing some more tests python programs do work, they just seem to not
> recieve sys.argv. The results of calling "manage.py runserver" is the
> same as calling just "manage.py". Other simple scripts bear this out.
>
> Thanks,
>
> Rodrigo
>
> On Dec 1, 6:32 am, John M  wrote:
> > Sounds like the .py extension isn't seen as using python, should be an
> > easy fix.  Check your file associations (where they are in Win7) I'll
> > have to find at work tomorrow, but that should fix your issue.
> >
> > Or, it could be some new security scheme that MS has come up with to
> > not allow associations at the CMD level?  sounds like that would break
> > too much stuff though, I'll try it at work tomorrow and if it's not an
> > association thing, I'll check back on this thread.
> >
> > J
> >
> > On Nov 30, 8:36 am, Rodrigo Cea  wrote:
> >
> > > Following an abortive attempt to install Python2.6 on Windows 7, I
> > > can't run the Django dev server without prepending "python" before
> > > "manage.py runserver".
> >
> > > I tried recently to install Python2.6 on a windows 7 system that
> > > already has python 2.5 installed. I had problems running some Django
> > > applications I'm working on, so I uninstalled it.
> >
> > > Now I can't run the dev server the way I used to: "manage.py
> > > runserver", I get:
> >
> > > "Type 'manage.py help' for usage."
> >
> > > If I run it like so: "python manage.py runserver" it works.
> >
> > > I have checked for other python installs on the system, and there was
> > > just one in Cygwin which I have deleted.
> > > I have checked running programs with and without "python" and the
> > > executable is the same: "C:\python2.5\python.exe".
> >
> > > This also affects other programs, e.g.: easy_setup, which I can't just
> > > run as "easy_setup package_name" anymore, but rather "python /path/to/
> > > easy_setup package_name".
> >
> > > This is more annoying than anything else, but any help is greatly
> > > appreciated.
> >
> >
>
> --
>
> 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.




redundant SQL's in Django tutorial

2009-12-01 Thread stargazer
Hi all,

I'm trying the famous Django tutorial:
http://docs.djangoproject.com/en/1.1/intro/

Playing with "polls" and "choices" I see lot of SQL queries this
application creates. Actually, I just selected a list of polls
than selected the poll with ID=2, than voted for a choice.
Here are details (SQL's recorded using "debug_toolbar", may be a
database log will show something else):
***
polls/
One select:
SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date" FROM "polls_poll"

polls/2/
Two selects:
SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date"
FROM "polls_poll" WHERE "polls_poll"."id" = 2
SELECT "polls_choice"."id", "polls_choice"."poll_id",
"polls_choice"."choice", "polls_choice"."votes"
FROM "polls_choice" WHERE "polls_choice"."poll_id" = 2

polls/2/vote/
Three selects, one update
SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date"
FROM "polls_poll" WHERE "polls_poll"."id" = 2
SELECT "polls_choice"."id", "polls_choice"."poll_id",
"polls_choice"."choice", "polls_choice"."votes"
FROM "polls_choice" WHERE ("polls_choice"."poll_id" = 2 AND
"polls_choice"."id" = 10 )
SELECT (1) AS "a"
FROM "polls_choice" WHERE "polls_choice"."id" = 10
UPDATE "polls_choice" SET "poll_id" = 2, "choice" = E'choice2',
"votes" = 29 WHERE "polls_choice"."id" = 10

polls/2/results/
Again, two selects
SELECT "polls_poll"."id", "polls_poll"."question",
"polls_poll"."pub_date"
FROM "polls_poll" WHERE "polls_poll"."id" = 2
SELECT "polls_choice"."id", "polls_choice"."poll_id",
"polls_choice"."choice", "polls_choice"."votes"
FROM "polls_choice" WHERE "polls_choice"."poll_id" = 2
***
It seems, same records are selected several time.
With some sort of caching this could be greatly improved.

May be some built-in Django tools (like select_related()? )  can help
here?

I now, number of cache implementations exists
(like this http://github.com/mmalone/django-caching/  and this
http://github.com/dcramer/django-orm-cache )
but I would like to use built-in Django instruments first.

--

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: Dynamicly preset forms in the admin interface

2009-12-01 Thread Kai Timmer
2009/12/1 rebus_ :

> I hope this casts some light on what i am trying to say.
> Anyway, the best way is to read docs and look in django code. Sorry i
> can't help more.

You helped a lot. Thank you.

Greets,
-- 
Kai Timmer | http://kaitimmer.de
Email : em...@kaitimmer.de
Jabber (Google Talk): k...@kait.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.




Re: Dynamicly preset forms in the admin interface

2009-12-01 Thread rebus_
models.py
=
from django.db import models

class Country(models.Model):
name  = CharField(max_length=70)

def __unicode__(self):
return '%s' % (self.name)


admin.py
=
from django.contrib import admin
from your_app.models import Country

site.register(Country)


When you runserver and visit add view for this model you should get
simple *empty* form to add new country in your database.

http://127.0.0.1:8000/admin/invest_core/country/add/


Ok, now we want to preset the name of the country. To test this you
can go to this URL:

http://127.0.0.1:8000/admin/invest_core/country/add/?name=Croatia

The field name should now contain "Croatia". I think this explains all
my muttering about GET and model attributes.

=

Now we want to do this but through admin not through URL. For this we
change admin.py like this:

admin.py
=
from django.contrib import admin
from your_app.models import Country

class CountryAdmin(admin.ModelAdmin):
def add_view(self, request, form_url='', extra_context=None): #
Override built in add_view
request.GET = request.GET.copy() # GET is immutable
QueryDict so we need to get a copy() as explaind in docs
request.GET.update({'name':'Croatia'}) # This sets value
for field "name"
return super(CountryAdmin, self).add_view(request,
form_url=form_url, extra_context=extra_context) #This calls original
add_view method
site.register(Country, CountryAdmin)


Now when you open up add_view again the name should also be set to "Croatia"

http://127.0.0.1:8000/admin/invest_core/country/add/


Background:

Class ModelAdmin is located in django/contrib/admin/options.py and has
add_view method which gets called when you open add view in your
Django admin.
URL pattern for this view is located in get_url method on the same class.

This means when you subclass admin.ModelAdmin to create admin pages
for you model you can override all the methods that ModelAdmin has by
default or add your own methods (for custom views or whatever). So to
change behaviour of add_view method you simply override it in your
CountryAdmin. It still needs to return same thing (HttpResponse with
some Context) as the built in add_view.

I hope this casts some light on what i am trying to say.
Anyway, the best way is to read docs and look in django code. Sorry i
can't help more.

Davor

--

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: multilingual flatpages

2009-12-01 Thread Jani Tiainen
On Mon, 2009-11-30 at 16:36 -0800, Nev wrote:
> Hey,
> 
> Today I did a bunch of searching and reading to find what is the best
> way to have flatpages presented in multiple languages. Flatpages
> apparently don't support internationalization and I went down several
> avenues looking for the recommended way, and finding various things
> that appeared way over the top for my simple requirement - present the
> translated version of my flat page according to the current
> 'django_language'.

There also exists django-multilingual pluggable app that has (among
other features), multilingual flatpages application.

-- 

Jani Tiainen


--

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: Dynamicly preset forms in the admin interface

2009-12-01 Thread rebus_
2009/11/30 Kai Timmer :
> 2009/11/29 rebus_ :
>> I  imagine some of core devs or django gurus would maybe have better
>> ideas on how to do this (or can even tell you if this is documented
>> somewhere).
> What i wonder is: Isn't this a fairly common thing? I could think of
> so many situations where you would preset fields with values from the
> database. So I am pretty suprised that it seems like there is no
> "default" way of doing this. This maybe because i never used a
> framework like django before and I'm missing a general design
> principle. If so, please tell me ;)
>
Well default would be to set "default" on your models.

class SomeModel(models.Model):
   level = IntegerField(default=22)

When you open add view in admin this field would have number 22 already set.
But it would always have 22 set, and you would have to work some magic
to change it in runtime.

Usually, i don't care if people can set preset fields, so i override
save_model method and populate fields i want with the values i want.
For example if i want to set author of the article i just set it
before it gets written to database to value of
request.user.get_full_name()

request.user.get_full_name() would return the full name of the user
that is currently logged in (in other words owns a request)

Still i am not sure about read-only fields. But i guess you could use
custom templates in admin to achieve this, or override form widgets.

>> As far as readonly fields go i found snippet [3] but i haven't look at
>> it closely to tell you is it any good or not.
>> But if you set your fields read only how would you make them editable
>> if necessary? With JavaScript?
> It is more like the fields should be either preset and editable XOR
> preset and not editable. Nothing to change there once the page is
> rendered
>
>> Hope i helped this time :)
> Too much Information :) I'm just getting started with django ;)

Example i gave in previous email can be used to set different values
for different cases in different requests and wrapping add_view method
seems fairly easy.
Of course, to do this you have to be familiar with Django at least a
bit. All you need to do is create your AdminModel (which is described
in Django tutorial among other places) and inside of that class create
method add_view (for which i gave example in previous mail).

Also using GET methods to retrieve data is common in HTTP protocol and
it is not something specific to Django.

If your URL looks like http://127.0.0.1/?variable=value in PHP you
would use $_GET["variable"]; to get the value while in Django you
would use request.GET["variable"].

If any of variables in request.GET have the same name as some
attribute on your model, fields for that attribute is set to value of
request.GET["that_var"].

I can give you full code example if it would make it easier to understand.
I believe this can sound overwhelming but as people tend to say, it's
just python :)

And as i have said, there might be easier ways to do this, but i can't
think of any, and if there are i would like to see them myself too.

Also, i would suggest further reading:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/
http://docs.djangoproject.com/en/dev/topics/forms/
http://docs.djangoproject.com/en/dev/ref/request-response/

Davor

--

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




Re: Can't run Django from the command line using just "manage.py runserver", following attempt to install Python2.6 on windows 7.

2009-12-01 Thread Rodrigo Cea
Thanks for the response.

Doing some more tests python programs do work, they just seem to not
recieve sys.argv. The results of calling "manage.py runserver" is the
same as calling just "manage.py". Other simple scripts bear this out.

Thanks,

Rodrigo

On Dec 1, 6:32 am, John M  wrote:
> Sounds like the .py extension isn't seen as using python, should be an
> easy fix.  Check your file associations (where they are in Win7) I'll
> have to find at work tomorrow, but that should fix your issue.
>
> Or, it could be some new security scheme that MS has come up with to
> not allow associations at the CMD level?  sounds like that would break
> too much stuff though, I'll try it at work tomorrow and if it's not an
> association thing, I'll check back on this thread.
>
> J
>
> On Nov 30, 8:36 am, Rodrigo Cea  wrote:
>
> > Following an abortive attempt to install Python2.6 on Windows 7, I
> > can't run the Django dev server without prepending "python" before
> > "manage.py runserver".
>
> > I tried recently to install Python2.6 on a windows 7 system that
> > already has python 2.5 installed. I had problems running some Django
> > applications I'm working on, so I uninstalled it.
>
> > Now I can't run the dev server the way I used to: "manage.py
> > runserver", I get:
>
> > "Type 'manage.py help' for usage."
>
> > If I run it like so: "python manage.py runserver" it works.
>
> > I have checked for other python installs on the system, and there was
> > just one in Cygwin which I have deleted.
> > I have checked running programs with and without "python" and the
> > executable is the same: "C:\python2.5\python.exe".
>
> > This also affects other programs, e.g.: easy_setup, which I can't just
> > run as "easy_setup package_name" anymore, but rather "python /path/to/
> > easy_setup package_name".
>
> > This is more annoying than anything else, but any help is greatly
> > appreciated.
>
>

--

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: style guide/autoformatter/linter for Django templates?

2009-12-01 Thread Tom Evans
On Tue, Dec 1, 2009 at 7:33 AM, Steve Howell  wrote:
> Just following up on this a few days later, in case it got lost in the
> shuffle due to the weekend and U.S. holiday.
>
> On Nov 27, 2:18 pm, Steve Howell  wrote:
>> I am wondering if there is a style guide anywhere for writing Django
>> templates.  Also, are there programs to automatically format your
>> templates...to indent block tags, for example?  I know there are
>> autoformatters for HTML, but I am not aware of any tools that handle
>> Django tags.  Also, it would be nice to have a command line tool that
>> detected unbalanced tags before rendering occurs, knowing, of course,
>> that that task is a little complicated due to conditionals.
>>
>> [...]
>

vim 7.2 comes with two syntax, highlighting and indentation modes for django.

"set ft=django" for just django template syntax highlighting/indentation
"set ft=htmldjango" for mixed HTML/django template syntax highlighting

Cheers

Tom

--

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




Re: Creating a Django project alike stackoverflow.com

2009-12-01 Thread ~km
Thanks for the many, great answers!

First off I'm not surprised that I'm not the first with the idea, but
I'm surprised that there are so many projects running, trying to clone
SO.

Does anyone have experience with SOclone and Co.? I'll be trying it/
them tonight, and see what they're like...

Cheers,
Kenny

--

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 patrickk
having a different admin site instance won´t help you much with this
issue. I´d say ... go with what you have. if someday you need to
customize the admin-site, create your own admin site or even subclass
djangos AdminSite.

regards,
patrick


On 1 Dez., 03:52, Brian Neal  wrote:
> On my site, users submit content that needs to be approved before
> getting published. Thus I wanted a simple "dashboard" on the admin
> page to show me how many pending items from each model are waiting for
> approval. I created a template tag for the dashboard. I then mulled my
> options for getting this template tag on the admin index page. Here is
> what I came up with and I'd like some feedback.
>
> Reading the Django docs, it says that if you want to change the index
> page, "you are better off creating your own AdminSite instance [...],
> and changing the AdminSite.index_template". [1]
>
> I started research that option, but I didn't need any custom behavior
> from my admin site, and I already have about a dozen applications that
> have admin.py files and are they are registering with the default
> admin site.
>
> So in my main urls.py file, right before the admin.autodiscover()
> call, I just did this:
>
> admin.site.index_template = 'admin/custom_index.html'
> admin.autodiscover()
>
> 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.
>
> It works great but I can't help but be haunted by that "you are better
> off creating your own AdminSite instance" bit. Am I missing something
> by not doing that?
>
> Thanks!
>
> [1]http://docs.djangoproject.com/en/dev/ref/contrib/admin/#root-and-logi...

--

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: A Design Question

2009-12-01 Thread John M
Even though it is outside the scope, I'd say start simple and build
slowly with related tables, those are easy to add to a system.  I'd
probably find the attributes you'd like to capture in the 'extra
details' and start putting them in a table.  Determine what the
purpose of these attributes are, searching, reporting, calculations,
etc and that should help you determine if you need more than one
'extra' table.

HTH

John

On Nov 29, 10:36 am, Ramdas S  wrote:
> This is probably outside Django. But I am checking out since I am building
> it with Django.
>
> I am building a specialized closed group social networking web site for
> special set of medical practitioners. Idea for my client is to be a mini-
> LinkedIn of sorts for this small community.
>
> We want to capture as many details as possible from some clinical practices,
> to education, work experience, papers submitted etc. However at registration
> time we want to limit it to just the basic details like name, email and may
> be some license number.
>
> However over a period of time we would like the user to add details.
>
> Do I build one large UserProfile Table, with ForeignKey to colleges,
> specializations etc or do I break it up into number of smaller profiles, and
> link each profile to a User. What's the best practice?
>
> --
> Ramdas S

--

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 call this function

2009-12-01 Thread Daniel Roseman
On Dec 1, 5:42 am, David  wrote:
> Hello,
>
> In my template file I have
>
>   {% for value in data %}
>                                 {% ifequal all_domain 1 %}
>                           class="odd" id="{{value.publisher}}"  
> "showDomain('{{value.publisher}}', '{{value.country}}');"
>                    {% else %}
>                       ...
>                    {% endifequal %}
>             >
>
> {% endfor %}
>
> "showDomain(...)" is a JavaScript function. I would like this function
> to be called in each iteration of the for-loop when all_domain == 1.
> Anybody knows how to call this function? There are no events (click,
> drag, mouseover, etc) here.
>
> Thanks so much.

This is waving a massive red flag for me. The template loop is
evaluated when it is output, so if you really want to call the
javascript function on each iteration of the loop, what you're
effectively doing would be calling it immediately the page reaches the
browser. Why would you want to do that? It sounds like you're putting
some of the responsibility for building some of the page into
Javascript, which is a very bad idea (what about those people with JS
turned off, or on mobile phones without JS support, or using
screenreaders?)

Much better would be to do whatever logic is required within the view
or the template itself, and leave Javascript for adding extra
functionality.
--
DR.

--

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




Re: Can't run Django from the command line using just "manage.py runserver", following attempt to install Python2.6 on windows 7.

2009-12-01 Thread John M
Sounds like the .py extension isn't seen as using python, should be an
easy fix.  Check your file associations (where they are in Win7) I'll
have to find at work tomorrow, but that should fix your issue.

Or, it could be some new security scheme that MS has come up with to
not allow associations at the CMD level?  sounds like that would break
too much stuff though, I'll try it at work tomorrow and if it's not an
association thing, I'll check back on this thread.

J

On Nov 30, 8:36 am, Rodrigo Cea  wrote:
> Following an abortive attempt to install Python2.6 on Windows 7, I
> can't run the Django dev server without prepending "python" before
> "manage.py runserver".
>
> I tried recently to install Python2.6 on a windows 7 system that
> already has python 2.5 installed. I had problems running some Django
> applications I'm working on, so I uninstalled it.
>
> Now I can't run the dev server the way I used to: "manage.py
> runserver", I get:
>
> "Type 'manage.py help' for usage."
>
> If I run it like so: "python manage.py runserver" it works.
>
> I have checked for other python installs on the system, and there was
> just one in Cygwin which I have deleted.
> I have checked running programs with and without "python" and the
> executable is the same: "C:\python2.5\python.exe".
>
> This also affects other programs, e.g.: easy_setup, which I can't just
> run as "easy_setup package_name" anymore, but rather "python /path/to/
> easy_setup package_name".
>
> This is more annoying than anything else, but any help is greatly
> appreciated.

--

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 call this function

2009-12-01 Thread John M
I think you're confusing Templates and HTML in this one, the for loop
is just a construct while the template is constructing the final HTML
code, not executing the HTML alongside the template?  Does that
help?

I think you'll need to look at custom filters
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters
for a solution to what you want, but if you could tell us what
ShowDomain does, that would help alot.



On Nov 30, 9:42 pm, David  wrote:
> Hello,
>
> In my template file I have
>
>   {% for value in data %}
>                                 {% ifequal all_domain 1 %}
>                           class="odd" id="{{value.publisher}}"  
> "showDomain('{{value.publisher}}', '{{value.country}}');"
>                    {% else %}
>                       ...
>                    {% endifequal %}
>             >
>
> {% endfor %}
>
> "showDomain(...)" is a JavaScript function. I would like this function
> to be called in each iteration of the for-loop when all_domain == 1.
> Anybody knows how to call this function? There are no events (click,
> drag, mouseover, etc) here.
>
> Thanks so much.

--

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




Re: Help with Custom Manager and UNION query?

2009-12-01 Thread John M
I'm not sure a Manager is what you want, what about Q(http://
docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-
q-objects) objects?  I've used them before and I think it's about what
you'd need.  As for performance, not sure how they stack up

On Nov 30, 2:45 pm, Info Cascade  wrote:
> Hi --
>
> I've been programming with Django about a year, and really like it, but
> I've run into something that I can't quite solve on my own.
> I think someone else may be able to offer the answer, or at least a hint
> to send me in the right direction.
>
> I have two tables I want to search in simultaneously, Article and Tag.
> They have a many-to-many relationship.
> I want to get a QuerySet of Articles that match a query term on
> article.title, as well as those that match on tag.name.
> I can get what I want using SQL, but how do I do it in Django (with
> acceptable performance)?
> Ideally, I want to be able to add .filter() and .exclude() to the
> QuerySet.  These SQL examples below are the basic idea, but in some
> cases I'm adding .filter and .exclude.
> Currently, the code looks something like this (I simplified it a bit,
> but this should give an idea):
>
> >             art_list = Article.objects.filter(status__status='PUBLISHED')
> >             art_list = art_list.extra(
> >                         where=["title_tsv @@ plainto_tsquery(%s)"],
> >                         params=[term])
> >              if channel:
> >                     art_list = art_list.filter(channel=channel)
> >              art_list = art_list.distinct()
> >              art_list = art_list.order_by(*order_by)
>
> Somehow, I want to include the fulltext search on the tag.name field,
>                         where=['name_tsv @@ plainto_tsquery(%s)'],
>                         params=[term])
>
> The two SQL example queries below both give the correct results.
> However, the first one with joins takes over 20 seconds.
> The second one with UNION is quite fast.
>
> I think what I need to do might be to create a custom manager for
> Article that would execute the UNION query and return a QuerySet with
> all the matching Articles.  I'm not sure quite how to do that,
> especially if I expect it to work with the .filter() and .exclude()
> methods.
>
> -- full-text search on article.title and tag.name
> SELECT DISTINCT article.title      
> FROM article JOIN article_tags ON article.id = article_tags.article_id
> JOIN tag ON article_tags.tag_id = tag.id
> JOIN article_status ON article_status.id = article.status_id
> WHERE article_status.status = 'PUBLISHED'
>     AND (tag.name @@ plainto_tsquery('french restaurants')
>         OR title_tsv @@ plainto_tsquery('french restaurants'))
> ORDER BY article.title;
>
> -- alternative full-text search on article.title and tag.name with UNION
> --  with ranking
> SELECT DISTINCT article.title, ts_rank_cd(title_tsv, q1) AS rank
> FROM plainto_tsquery ('french restaurants') AS q1, article
> JOIN article_status ON article.status_id = article_status.id
> WHERE article_status.status = 'PUBLISHED' AND
> title_tsv @@ q1
> UNION
> SELECT DISTINCT article.title, ts_rank_cd(name_tsv, q2) AS rank
> FROM plainto_tsquery('french restaurants') AS q2, article
> JOIN article_tags ON article.id = article_tags.article_id
> JOIN article_status ON article.status_id = article_status.id
> JOIN tag ON article_tags.tag_id = tag.id
> WHERE article_status.status = 'PUBLISHED' AND
> tag.name @@ q2
> ORDER BY rank DESC, title;
>
> So -- if anyone can offer any advice on this, I would very much
> appreciate it!!!
>
> Best,
> Liam

--

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 query unique and ordered

2009-12-01 Thread John M
I would be easier to see it as a django table, but you'll need to
checkout the distinct() feature of the queryset

http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct

But yes, I'd say it's possible.

J

On Nov 30, 4:10 pm, Ali Rıza Keleş  wrote:
> Hi all,
>
> I need a little custom db query. My db table with sample data:  
>
>         id      content_id      author_id       order   is_public
>         1       68              1               1       1
>         3       189             2               2       1
>         4       154             2               3       1
>
> I want to catch unique authors public content ordered by order field.
>
> The result must be:
>
>         id      content_id      author_id       order   is_public
>         1       68              1               1       1
>         3       189             2               2       1
>
> How can I do it?
>
> Thanks..
>
> --
> Ali

--

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: Creating a Django project alike stackoverflow.com

2009-12-01 Thread Lakshman Prasad
> 1) Is it possible to realize my idea with Django, managing the traffic
load for 2.000+ user?

The precise question you asked is answered by the Django BDFL, right there
on Stackoverflow:
http://stackoverflow.com/questions/886221/does-django-scale/1739974#1739974

In summary, "Yes, it is possible to build a site like stackoverflow using
django, that caters to over 100k users per day." But as Russ rightly pointed
out, For that scalability, **You should** build it that way.

>2) How long *may* it take to realize the following? I know that's a
very risky relative question, but assuming I'm a regular-skilled
programmer willing to spend +5h a day.

Some people think "It can be thrown together in a weekend"
http://news.ycombinator.com/item?id=678501 ;)

On Tue, Dec 1, 2009 at 7:23 AM, ~km  wrote:

> Hello,
>
> I'm a Python enthusiast and Django newbie. I'm trying to develop a
> website with an "Ask and Get an Answer"-Interface, with the goal to
> get a strong community; see http://stackoverflow.com to get an idea.
> For more information on stackoverflow.com see
> http://blog.stackoverflow.com/2008/09/what-was-stack-overflow-built-with/
>
> Following questions:
>
> 1) Is it possible to realize my idea with Django, managing the traffic
> load for 2.000+ user?
> 2) How long *may* it take to realize the following? I know that's a
> very risky relative question, but assuming I'm a regular-skilled
> programmer willing to spend +5h a day.
>
> I previously compared other Web frameworks, e.g. Zope, RoR, Gok,
> etc.. , with Django and came to the conclusion that Django /seems/ to
> be the most mature solution for developing such an idea from scratch.
> Do you think Django does the best job for my needs? (I know this is
> the wrong place to ask such a question, but comments are welcome.)
>
> Cheers,
> Kenny
>
> --
>
> 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.
>
>
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

--

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




Re: multilingual flatpages

2009-12-01 Thread andreas schmid
hi,

i didnt work on that yet but i will in the next weeks because ill need
the content translated on flatpages.
wouldnt it be easier to subclass the flatpages model or to get the
flatpages package and make the modifications there to get a
custom_flatpages app?

im thinkin that because im already using transmeta for all my other apps.

Nev wrote:
> Hey,
>
> Today I did a bunch of searching and reading to find what is the best
> way to have flatpages presented in multiple languages. Flatpages
> apparently don't support internationalization and I went down several
> avenues looking for the recommended way, and finding various things
> that appeared way over the top for my simple requirement - present the
> translated version of my flat page according to the current
> 'django_language'.
>
> So I thought I'd share it... (It's really only five lines added to
> your templates, and links to the pages updated).
>
> In my base template I have the usual forms for changing the languages,
> which are presented as clickable flags. The addition is the next_input
> block.
>
> 
>   {% for lang in languages %}
> 
>   
>   {% block next_input %}
>   {% endblock %}
> type="image"
>  src="/images/{{ lang.0 }}.png"
>  alt="{{ lang.1 }}"/>
> 
>   {% endfor %}
> 
>
> In my flatpage template which extends the base template I supply that
> block, which supplies a input tag which supplies the next value for
> the form.
>
> {% block next_input %}
>   
> {% endblock %}
>
> The key is that the urls of the flatpages are as such...
>
> /welcome/en/
> /welcome/es/
> /welcome/pt/
>
> The form therefore, after going to /i18n/setlang, returns to the same
> page, but in the new language by removing the trailing slash and
> language code and replacing it with the new currently selected
> language.
>
> Click on the flags for non-flatpages works as normal.
>
> And links to these flat pages within other templates are thus
> supplied... (where 'language' is supplied by the view as the value of
> 'django_language' or an appropriate default if it's not yet been
> selected, 'en' in my case).
>
> {% trans "Welcome" %}
>
> Hope this helps someone. It's extremely easy, does what I need, along
> with the django internationalization, without installing anything
> extra or getting complicated.
>
> Cheers,
>
> Nev
>
> --
>
> 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.