Problems with "initial" parameter in form handling

2009-12-31 Thread Steven Arnold
Hi, my problem is that the "initial" parameter in forms.Form seems to
have no effect.  I set the "subject" value in this code:

form = ContactForm(
initial={'subject': 'I love your site!'}
)

...yet this initialization string never makes it to the HTML as the
default value for the "subject" input field.  My question is, why
not?  What am I doing wrong?

I am using Django 1.0.2-1 on Kubuntu, python 2.6.2.

The model definition is as follows:

from django import forms

t_char = forms.CharField
t_email = forms.EmailField

class ContactForm(forms.Form):
subject = t_char(max_length=100)
email = t_email(required=False)
message = t_char(widget=forms.Textarea)

The sample views file looks like the following:

from django.shortcuts import render_to_response
from mysite.contact.forms import ContactForm

def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
 [...]
else:
form = ContactForm(
initial={'subject': 'I love your site!'}
)
return render_to_response('contact_form.html', {'form': form})

The contact_form.html looks like this:



Contact Us


Contact Us

{% if errors %}

{% for error in errors %}
{{ error }}
{% endfor %}

{% endif %}

Subject: 
Your email (optional): 
Message: 





--

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.




Dreamhost support

2009-12-31 Thread Ramdas S
List,

Got a mail from Dreamhost on availability of Django properly supported.

here are the links for fellow dreamhosters to check thru. Please post your
experience


http://wiki.dreamhost.com/Django
http://wiki.dreamhost.com/Passenger_WSGI


Thanks

Ramdas


-- 
Ramdas S
+91 9342 583 065

--

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: new readonly_fields in modeladmin

2009-12-31 Thread Tim Miller
Alex_Gaynor wrote:
> I've actually gone ahead and filed it, and uploaded a patch:
> http://code.djangoproject.com/ticket/12477
>

Thanks Alex. Your post on writing django tests has been helpful as
well.

--

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: Switching from soc2009/multidb to trunk; cross db foreign keys

2009-12-31 Thread CB
> Hrm, it's clear that the current implementation is probably overly
> aggressive in changing the DB

I definitely agree here. It just seems like a useful working solution
for 'now', clearly somethign a bit more elegant would be needed to
make it into Django's core.

> That being said in
> your case it might make sense for using() to be a no-op, since by
> definition your manager is supposed to work with a specific DB.

Yes, and I think this is a somewhat common use case. If we could
convince the related managers not to call .using() on the returned
queryset (perhaps by means of a class attribute on the manager just
like use_for_related_fields), we can drop the override of the .using()
method on the queryset.

Do you think this flag addition is small enough for a bugfix / feature
in the 1.2 timeframe?

--

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: Switching from soc2009/multidb to trunk; cross db foreign keys

2009-12-31 Thread Alex_Gaynor


On Dec 31, 3:30 pm, CB  wrote:
> *Oops, sorry about the refrences to 'AdSalesModel' and setting
> using='adsales' - you can see where I'm using these ideas :)
>
> Change them to PartitionedModel and self.objects.forced_using
> respectively.

Hrm, it's clear that the current implementation is probably overly
aggressive in changing the DB, there are plenty of cases where a
related model would be on a different database.  That being said in
your case it might make sense for using() to be a no-op, since by
definition your manager is supposed to work with a specific DB.

Alex

--

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: new readonly_fields in modeladmin

2009-12-31 Thread Alex_Gaynor


On Dec 31, 3:06 pm, Alex_Gaynor  wrote:
> On Dec 31, 12:46 pm, Tim Miller  wrote:
>
> > I just want to confirm this isn't my own idiocy or intended behaviour
> > before I file a bug.
>
> > I've got the following line defined in my modeladmin entry...
>
> > readonly_fields = ('date_created', 'date_modified', 'date_published')
>
> > They get displayed in the admin as 'Date created', 'Date modified' and
> > 'Date published'. I've tried specifying different strings for those
> > fields with the first positional argument and with verbose_name. Neither
> > of those change how the text is displayed in the admin.
>
> > readonly_fields was introduced in #11965.
>
> This sounds like a bug.  Could you please file it on trac?
>
> Thanks,
> Alex

I've actually gone ahead and filed it, and uploaded a patch:
http://code.djangoproject.com/ticket/12477

Alex

--

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: Switching from soc2009/multidb to trunk; cross db foreign keys

2009-12-31 Thread CB
*Oops, sorry about the refrences to 'AdSalesModel' and setting
using='adsales' - you can see where I'm using these ideas :)

Change them to PartitionedModel and self.objects.forced_using
respectively.

--

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: Switching from soc2009/multidb to trunk; cross db foreign keys

2009-12-31 Thread CB
So I did some basic poking around with managers, etc.

I noticed what 'may be' a 3 part solution to keep a model on one and
only one db:

First, we should modify the initial queryset to use our preferred db.
We can do this by adding a custom manager, with an overridden
get_query_set():

class PartionedManager(models.Manager):
use_for_related_fields = True #Forces this manager to be used
during related lookups
def __init__(self, *args, **kwargs):
self.forced_using = kwargs.pop('using', 'default')
super(PartionedManager, self).__init__(*args, **kwargs)
def get_query_set(self):
return super(PartionedManager, self).get_query_set().using
(self.forced_using)

However, this doesn't solve the ability to .save() into another db, so
lets create an abstract model our real stuff can inherit from:

class PartitionedModel(models.Model):
objects = PartitionedManager(using='aux')
def save(self, *args, **kwargs):
kwargs['using'] = 'adsales' #Makes sure instances are saved in
the proper place
super(AdSalesModel, self).save(*args, **kwargs)
class Meta:
abstract = True

class ConcreteModel(PartitionedModel):
name = models.CharField(max_length=255)

class SomeModelOnTheMainDB(models.Model):
name = models.CharField(max_length=255)
concrete = models.ForeignKey(ConcreteModel)

So far so good. However, relations still throw an error that models
can't be found. The reason for this is:

http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L262

The related code instantiates the manager, and then immediately
changes it's db with a .using() clause to wherever the original model
came from (e.g., another db). Since we want to force this, we have two
options:

1) get a django patch that can find another class attribute on the
manager and optionally not apply that using(), or apply a forced using
(), or
2) hack it!:

class PartionedManager(models.Manager):
use_for_related_fields = True #Forces this manager to be used
during related lookups
def __init__(self, *args, **kwargs):
self.forced_using = kwargs.pop('using', 'default')
super(PartionedManager, self).__init__(*args, **kwargs)
def get_query_set(self):
qs = super(PartionedManager, self).get_query_set().using
(self.forced_using)
qs._real_using = qs.using
qs.using = lambda new_using: qs._real_using(qs._db) #Disable
changing db with .using() - required because related manager tries to
set .using after we return the qs
return qs

class PartitionedModel(models.Model):
objects = PartitionedManager(using='aux')
def save(self, *args, **kwargs):
kwargs['using'] = 'adsales' #Makes sure instances are saved in
the proper place
super(AdSalesModel, self).save(*args, **kwargs)
class Meta:
abstract = True

class ConcreteModel(PartitionedModel):
name = models.CharField(max_length=255)

ConcreteModel here is now tied to a db. I'm testing this code in
production, and was wondering what everyone thought?

--

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.




multidb workaround

2009-12-31 Thread Continuation
>From reading several posts here, it looks like it's not a good idea to
try to have ForeignKey pointing from 1 DB to another DB.

The problem for me is that pretty much every single model of mine has
a link to User. And I suspect that's a very common case for most
people.

If I put in FK to User in my models, I wouldn't be able to have
multidb.

One workaround I can think of is to have an IntegerField pointing to
User.id instead of a FK to User.

Is that a good alternative? Or is it going to cause more problems that
it's worth?

--

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: new readonly_fields in modeladmin

2009-12-31 Thread Alex_Gaynor


On Dec 31, 12:46 pm, Tim Miller  wrote:
> I just want to confirm this isn't my own idiocy or intended behaviour
> before I file a bug.
>
> I've got the following line defined in my modeladmin entry...
>
> readonly_fields = ('date_created', 'date_modified', 'date_published')
>
> They get displayed in the admin as 'Date created', 'Date modified' and
> 'Date published'. I've tried specifying different strings for those
> fields with the first positional argument and with verbose_name. Neither
> of those change how the text is displayed in the admin.
>
> readonly_fields was introduced in #11965.

This sounds like a bug.  Could you please file it on trac?

Thanks,
Alex

--

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: Seemingly Random Admin Errors

2009-12-31 Thread Karen Tracey
On Thu, Dec 31, 2009 at 1:22 PM, DizzyDoo  wrote:

> Bill,
>
> It's my own fault for capitalising the file names in the first post,
> but I'll be sure to watch out for that.
>
> Also, I hadn't realised it, but it did seem I was running mod_python
> accidentally, when all I wanted was my django.wsgi. So a quick
> uninstall and a few minutes of testing seems to give the appearence
> everything is just fine.
>
>
Everything may seem to be fine now, when you have DEBUG set to True, but
placing your admin registrations in your models.py file is likely to cause
problems under a production server when  DEBUG is set to False.  There is no
guarantee your models.py file will have been loaded (thus triggering the
admin registration for your model) when a request for an admin URL is
processed.  Thus your admin will not necessarily know about your model.  You
should put admin definitions in a file named admin.py in your app, and
include a call to admin.autodiscover() in your main urls.py file.  That way
the admin registrations will be sure to be run before any view is called.

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.




new readonly_fields in modeladmin

2009-12-31 Thread Tim Miller
I just want to confirm this isn't my own idiocy or intended behaviour 
before I file a bug.

I've got the following line defined in my modeladmin entry...

readonly_fields = ('date_created', 'date_modified', 'date_published')

They get displayed in the admin as 'Date created', 'Date modified' and 
'Date published'. I've tried specifying different strings for those 
fields with the first positional argument and with verbose_name. Neither 
of those change how the text is displayed in the admin.

readonly_fields was introduced in #11965.

--

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: Seemingly Random Admin Errors

2009-12-31 Thread DizzyDoo
Bill,

It's my own fault for capitalising the file names in the first post,
but I'll be sure to watch out for that.

Also, I hadn't realised it, but it did seem I was running mod_python
accidentally, when all I wanted was my django.wsgi. So a quick
uninstall and a few minutes of testing seems to give the appearence
everything is just fine.

So thank you Bill, that's wonderful, have a happy new year yourself,
Matt

--

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: Tutorial help

2009-12-31 Thread Bill Freeman
Your code doesn't belong in any directory being served by webserver at
all.  If your
hosting arrangement requires that, then it's the wrong hosting
environment.  In order of
preference django should be running:

  under mod_wsgi
  under mod_python
  as the development server with the front end acting as proxy server

None of these require the code to live in a web accessible directory.
Your static files,
however, like css, js, static html, images, etc. probably should be
served by the front
end without django's help.

On Thu, Dec 31, 2009 at 12:03 PM, Tim Goddard
 wrote:
> After more testing:
>
> Can I restrict access to the code by using an .htaccess file or is
> that not safe enough?
>
> --
>
> 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: questions from a noob - win7 using django

2009-12-31 Thread Bill Freeman
On Thu, Dec 31, 2009 at 5:31 AM, shofty  wrote:
> ive been using django for a couple of weeks, i can see massive
> potential for actually finishing a couple of projects that i've had on
> the go for a good while. thing is its my first attempt at using a
> framework and ive found the tutorial followable, but lacking. it tells
> you what to do, but doesnt explain the why very well imo? so i've come
> to a point where i need a little assistance to take this further. i've
> got a couple of understanding points that once i get past im sure the
> frustration will die. I've actually written an app already, got quite
> far in it but in trying not to reinvent the wheel I've decided to use
> avatar and come up against a brick wall.

It's fine to ask for help.  It's not necessary (and is probably inadvisable)
to justify your request by maligning documentation that many of us would
find tedious if it were any more detailed.  I don't, for example, believe that
the django tutorial should be responsible for teaching one python.  There
are fine tutorials for that at python.org and elsewhere on the net.


>
> so i've been through the tutorials. im struggling understanding how
> best to code for this on windows. im trying to make life as easy as
> possible for myself. ive seen pretty much no clues on how best to work
> in windows.

By installing the free VMWare stuff and a Linux distribution under it.  You
did ask "how best", which is a request for an opinion, and that is my opinion.

But, actually, python and django work pretty well on windows. though I
can't say I've tried it on windows 7.

> i've got python installed at c:\python26 . im creating mysites at c:
> \django-sites
> - would experienced coders advise against this? would it be better to
> drop the django projects/apps inside the python path?

You can do either.  When I've developed on windows I've put my
projects in home directory or even in (subdirectories of) the desktop.
It is probably wise to run the manage.py commands from a cmd.exe
session cd'ed to the directory containing manage.py and settings.py,
and I think that you can specify the current directory to use in a shortcut.
But you can actually put your projects in any directory you can access,
so \django-sites is fine.  I wouldn't add that to the global python paht
environment variable, however.

>
> - im really struggling with apps. i've downloaded a few and tried to
> get them working by dropping them inside my project folder and linking
> them in. so for example i've tried to get brookie working by dropping
> it into c:\django-sites\projectname\django-brookie. all sorts of
> errors ensued.
> where would experienced coders put their apps? and then how do you
> link them into your project? i tried project.app inside the installed
> apps section, but it fails to pick up the urls file.
> is it best practice to use the setup.py file and then refer to it as
> django.contrib.brookie?

Where to put an app depends on what you're going to do with it.  If I
expect to use the same unmodified version of the same app in many
projects, I definitely install it in the main python site-packages (often
by using easy_install).  But if I want different versions in different
projects, say to track what's actually deployed on various production
servers, I may put it in the project directory (though I'm starting to use
virtualenv more and more, and you should check whether it works on
windows and use it if so).  If I'm going to modify an app, I definately
put it under my project.

Note, however, that some apps expect to be installed globally, and the
way that they refer to parts of themselves can become invalid when
installed another way, requiring modification.  For example:

   import foo.views

might have to become:

   import myproject.foo.views

or:

   import myproject.apps.foo.views

For simply structured apps

   import views

would have worked in all cases, but sometimes apps refer to one another,
and that never works, or some people want to put their views or modes in
a subfolder, meaning that they either need to restrict themselves to new
enough pythons that they can say:

   from __future__ import absolute_imports

(or however it is spelled) or the app needs to be edited if plugged into an
unexpected spot in the module hierarchy.


Also, note that django NEVER picks up the urls.py of an app on it's own.
Your root urls.py must import it by whatever name necessary (probably
as the argument to an "include" in a urlpattern).  django finds the models
module of the things in INSTALLED_APPS, but not urls.  How would it know
where you want it plugged into your url scheme?

>
> any help is appreciated, i can tell django is something that i need to
> be using, but i just need to get past these first few hurdles. im
> going to invest in the books to see if a bit of light reading helps,
> but im impatient and frustrated!

You can't write python without writing python.  If you haven't already done
so, find the tutorial on pyt

Re: Tutorial help

2009-12-31 Thread Tim Goddard
After more testing:

Can I restrict access to the code by using an .htaccess file or is
that not safe enough?

--

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: Seemingly Random Admin Errors

2009-12-31 Thread Bill Freeman
I don't see anything wrong with the code that you posted, other than perhaps
that the initial letter on your module names, Urls.py, Settings.py,
and Models.py,
appear to be in upper case.  That doesn't seem to be causing you a problem,
probably because you are running on a file system that is case preserving but
case insensitive (Windows, the default Mac OS filesystem), but it will cause you
problems in deployment to a *nix hosting provider, so you may as well fix that.
Django it self specially knows about the names settings.py (though you can
override this on the command line, I believe) and models.py (no override that I
know of) and possibly others these days (like admin.py, which may be known
about by django.contrib.admin, but you don't seem to be using that).  You can
specify the name of your root url conf, but you have specified (as is normal)
mysite.urls and not mysite.Urls .

But the problem you are having really feels as though you are somehow running
two python-django processes (maybe both a mod_python and a mod_wsgi --
you only need one) that are getting rotated among, and one of them hasn't
been restarted recently enough to know about the blog app.  Similar would be
if you somehow had two servers running (even on separate machines) behind
a DNS rotor.  Try accessing from the machine itself using "localhost"
in place of
"whatever.com" to check for this last possibility, or from wherever using the IP
address instead of the DNS name.

A bogusly configured cache is also a possibility if you're not using mod_python
or mod_wsgi, but are redirecting through a cache to the development server
running on another port.  In this case test by accessing the actual django
process port directly to see if the problem ever shows.

If you're doing the tutorial, I'd suggest using the django development server
until you have things running well, before throwing apache into the mix.  If
you don't have access to expose the additional port through the firewall of the
serving system, but you're sshing in, you can use ssh port forwarding to get
to it, though this can be a bit slow.  But python runs pretty much everywhere,
so I'd really suggest doing the development on the same computer where you
are running your browser, and then you certainly can access, for example, port
8000.

Good luck, and Happy New Year,
Bill

On Thu, Dec 31, 2009 at 9:12 AM, DizzyDoo  wrote:
> Hi,
>
> I'm following a tutorial, very simple, all I've done is got my
> database set up, wrote a small and simple blog app and activated the
> admin. I'm running Django 1.1.1 on Apache, on my deployment box.
>
> The problem is seemingly random. I have two blogpost objects
> successfully added to the MySQL database.  Sometimes I can access the
> admin panel, sometimes I cannot. When I cannot, for example,
> accessing /mysite/admin/blog/blogpost/, I get this error
> http://dpaste.com/hold/139625/
>
> If I wait 5 minutes, I can refresh the page, and use the admin panel
> for another five minutes until, once more, these url errors pop up.
>
> Why is this happening? Is it some kind of server misconfiguration, or
> something wrong with some kind of caching? I've tried uninstalling,
> apache and django, and redoing it, but no luck.
>
> Just in case you wanted to take a look at my urls.py, settings.py and
> models.py, here they are:
>
> Urls.py :  http://dpaste.com/hold/139628/
> Settings.py :  http://dpaste.com/hold/139626/
> Models.py :  http://dpaste.com/hold/139627/
>
> Any help is so very welcome, I've wasted too many hours trying to fix
> this.
>
> Thanks,
> Matt
>
> --
>
> 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: Tutorial help

2009-12-31 Thread Tim Goddard
Ok, so I need to do some testing of my server's capability Here is my
directory of my /home/www: name type backend folder
creativeapex.freehostia.com folder Inside backend there is a file name
test.html that has a simple heading of "This is a test file" or something
like that Inside the other folder is index.html that has a relative path to
backend: This is a link somewhere else It
appears that I cannot access that folder from the internet. See if you
agree. I've added some additional markup to check my linking skills.
http://creativeapex.freehostia.com/ Apparently heliohost has been successful
in offering django... I have a pending account request with them
http://www.heliohost.org/home/features-mainmenu-35/featuresscriptingmenu/python

--

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: Tutorial help

2009-12-31 Thread dartdog
as a general rule freehosts don't allow long running processes and
therefore can't run Django, YMMMV let us know if you do get it going
on a freehost, I doubt it..

On Dec 31, 9:39 am, CreativeApex  wrote:
> Ok, I've been following the tutorial.. I'm currently in the midst of
> part 3.  I have the development server running on my laptop and
> everything is working.  How Django works is 'clicking' with the
> exception of how it will work on a real server.
>
> I will be using free hosting.  I currently have freehostia, but
> considering using heliohost.org.
>
> In step 1: the tutorial states:
>
> "If your background is in PHP, you’re probably used to putting code
> under the Web server’s document root (in a place such as /var/www).
> With Django, you don’t do that. It’s not a good idea to put any of
> this Python code within your Web server’s document root, because it
> risks the possibility that people may be able to view your code over
> the Web. That’s not good for security.
>
> Put your code in some directory outside of the document root, such as /
> home/mycode."
>
> On freehostia, the root directory is /home and I have a /www folder
> containing a folder which contains my website.  I am not able to
> create a new folder in /home, but I can create one in my /www folder.
> My files are in /www/derelict.website.name.com/index.html so I could
> put my code in /www/backend/something.py.  Is this acceptable and what
> file permissions should I place on this folder?
>
> Second:
>
> In the settings.py it says I should use absolute paths what are
> absolute paths on a server? would it simply be /home/www/backend/
> something.py  or is there a unix file system nuance I need to know.
>
> Thirdly:
>
> Freehostia gives only this as a 'help' regarding python:
>
> The path to Python is:
>
> #!/usr/bin/python
>
> To execute a Python script you must ensure that the correct path is
> set in the beginning of the script.
> Once the path is set you must either:
>
> 1) create an .htaccess file and place the following code inside:
> AddHandler cgi-script .py
>
> 2) or rename the Python script by replacing .py with .cgi
> (no .htaccess is required in this case)
>
> Could someone dumb this down for me?
>
> 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: questions from a noob - win7 using django

2009-12-31 Thread dartdog
Look at a project like Django-mingus (on github)  to see good layout
and integration ideas..as well as proper use of the setup.py file
which you need to be using. Your issues have nothing to do with
windows at this time,, btw you should get familiar with Virtual-env
and use it again Mingus is good example.

On Dec 31, 4:31 am, shofty  wrote:
> ive been using django for a couple of weeks, i can see massive
> potential for actually finishing a couple of projects that i've had on
> the go for a good while. thing is its my first attempt at using a
> framework and ive found the tutorial followable, but lacking. it tells
> you what to do, but doesnt explain the why very well imo? so i've come
> to a point where i need a little assistance to take this further. i've
> got a couple of understanding points that once i get past im sure the
> frustration will die. I've actually written an app already, got quite
> far in it but in trying not to reinvent the wheel I've decided to use
> avatar and come up against a brick wall.
>
> so i've been through the tutorials. im struggling understanding how
> best to code for this on windows. im trying to make life as easy as
> possible for myself. ive seen pretty much no clues on how best to work
> in windows.
> i've got python installed at c:\python26 . im creating mysites at c:
> \django-sites
> - would experienced coders advise against this? would it be better to
> drop the django projects/apps inside the python path?
>
> - im really struggling with apps. i've downloaded a few and tried to
> get them working by dropping them inside my project folder and linking
> them in. so for example i've tried to get brookie working by dropping
> it into c:\django-sites\projectname\django-brookie. all sorts of
> errors ensued.
> where would experienced coders put their apps? and then how do you
> link them into your project? i tried project.app inside the installed
> apps section, but it fails to pick up the urls file.
> is it best practice to use the setup.py file and then refer to it as
> django.contrib.brookie?
>
> any help is appreciated, i can tell django is something that i need to
> be using, but i just need to get past these first few hurdles. im
> going to invest in the books to see if a bit of light reading helps,
> but im impatient and frustrated!

--

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: Tutorial help

2009-12-31 Thread Shawn Milochik

You definitely need your Django code to be in a folder that is unavailable from 
the Internet. It shouldn't be accessed by your visitors or your server app 
(such as apache). When you run Django in a production environment, it listens 
on a specific port, and from there it serves the pages. Apache (or nginx, or 
whatever) must be configured to accept requests to a certain URL or IP address 
and hand them off to that port. Incidentally, the ability to do this without 
jumping through hoops depends on your host. Contact their support, and check 
out this page:
http://code.djangoproject.com/wiki/DjangoFriendlyWebHosts

Absolute paths are absolute paths. If you can type 'cd pathname' from any 
directory and have it always work, then that's what you need.

Regarding the path to Python on your host: The steps they provide are referring 
to CGI scripts, which are executed individually when they are called, very 
similar to PHP scripts. This has nothing to do with Django, which is a full 
service that will be running. The information about changing the file extension 
and the .htaccess file are not relevant to setting up Django.

Shawn


--

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




Tutorial help

2009-12-31 Thread CreativeApex
Ok, I've been following the tutorial.. I'm currently in the midst of
part 3.  I have the development server running on my laptop and
everything is working.  How Django works is 'clicking' with the
exception of how it will work on a real server.

I will be using free hosting.  I currently have freehostia, but
considering using heliohost.org.

In step 1: the tutorial states:

"If your background is in PHP, you’re probably used to putting code
under the Web server’s document root (in a place such as /var/www).
With Django, you don’t do that. It’s not a good idea to put any of
this Python code within your Web server’s document root, because it
risks the possibility that people may be able to view your code over
the Web. That’s not good for security.

Put your code in some directory outside of the document root, such as /
home/mycode."

On freehostia, the root directory is /home and I have a /www folder
containing a folder which contains my website.  I am not able to
create a new folder in /home, but I can create one in my /www folder.
My files are in /www/derelict.website.name.com/index.html so I could
put my code in /www/backend/something.py.  Is this acceptable and what
file permissions should I place on this folder?

Second:

In the settings.py it says I should use absolute paths what are
absolute paths on a server? would it simply be /home/www/backend/
something.py  or is there a unix file system nuance I need to know.

Thirdly:

Freehostia gives only this as a 'help' regarding python:

The path to Python is:

#!/usr/bin/python

To execute a Python script you must ensure that the correct path is
set in the beginning of the script.
Once the path is set you must either:

1) create an .htaccess file and place the following code inside:
AddHandler cgi-script .py

2) or rename the Python script by replacing .py with .cgi
(no .htaccess is required in this case)

Could someone dumb this down for me?

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.




Seemingly Random Admin Errors

2009-12-31 Thread DizzyDoo
Hi,

I'm following a tutorial, very simple, all I've done is got my
database set up, wrote a small and simple blog app and activated the
admin. I'm running Django 1.1.1 on Apache, on my deployment box.

The problem is seemingly random. I have two blogpost objects
successfully added to the MySQL database.  Sometimes I can access the
admin panel, sometimes I cannot. When I cannot, for example,
accessing /mysite/admin/blog/blogpost/, I get this error
http://dpaste.com/hold/139625/

If I wait 5 minutes, I can refresh the page, and use the admin panel
for another five minutes until, once more, these url errors pop up.

Why is this happening? Is it some kind of server misconfiguration, or
something wrong with some kind of caching? I've tried uninstalling,
apache and django, and redoing it, but no luck.

Just in case you wanted to take a look at my urls.py, settings.py and
models.py, here they are:

Urls.py :  http://dpaste.com/hold/139628/
Settings.py :  http://dpaste.com/hold/139626/
Models.py :  http://dpaste.com/hold/139627/

Any help is so very welcome, I've wasted too many hours trying to fix
this.

Thanks,
Matt

--

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.




obtaining sessionId(s) of logged in user by username

2009-12-31 Thread Subramanyam
Hi

what is the most efficient way to get the sessionId(s) of a user by
the username  (where in the same user can  log-in on mulitple
systems)  , btw the I am using sessionID as the key for my cached
objects

Is there any middleware that I can use

Thanks
Subramanyam

--

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: Foreign Key Across Database in Django multidb

2009-12-31 Thread Doug Blank
On Wed, Dec 30, 2009 at 11:54 PM, malik  wrote:

> I heard that that multi DB support is now available in Django.Can some
> one tell me whether it is possible to have foreign Key across
> Databases.
>
>
Please see this thread:

http://groups.google.com/group/django-users/browse_thread/thread/74bcd1afdeb2f0?hl=en

-Doug



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

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Javier Guerra
On Thu, Dec 31, 2009 at 7:13 AM, BobAalsma  wrote:
>  if request.get('q',False):

use:if request.GET.get('q',False):

-- 
Javier

--

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: IntegrityErrors after Postgres database restore attempt

2009-12-31 Thread Felipe Reyes
Hi

2009/12/31 Jason :

> The big problem now, as you can see from the above error, is that if I
> try to add a new app, it squawks presumably because it's trying to
> assign an already existing pkey to django_content_type.  The
> sequencereset command looked promising, but that applies to apps
> only-- resetting the django_content_type table is what I guess I need
> to do...?

You should check the current value for the sequences, and update them
to highest value used on your table
http://www.postgresql.org/docs/current/interactive/functions-sequence.html

Probably the next value in the sequence is X, but X is already being
used by some row, so that violates the primary key.

Regards,

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread BobAalsma
Thanks Jani,

I've tried to folow your suggestions (and thanks for explaining the r/
s difference) into the current version of the test:
def search(request):
if request.get('q',False):
q = request.GET['q']
klanten = Klant.objects.filter(naam__icontains=q)
return 
render_to_response('Beppe_klant/search_results_klanten.html',
{'klanten': klanten, 'query': q})
else:
message = 'Leeg, joh'
return HttpResponse(message)

This leads to AttributeError at /search/
'WSGIRequest' object has no attribute 'get'

Typo?

On Dec 31, 12:31 pm, Jani Tiainen  wrote:
> On Thu, 2009-12-31 at 03:20 -0800, BobAalsma wrote:
> > Thanks Masklin, I've just tried your suggestion and there is no
> > change.
>
> > I'm somewhat mystified by the 'u' that gets added to all answer
> > messages - is this something to do with unicode? Could this be the
> > root of (some) evil?
>
> Again, your're using formatter %r which in python means "representation
> of object". In case of strings it prints either u'' for unicode strings,
> or just '' for non unicode ones.
>
> It's still a string and doesn't get "appended" magically.
>
> So instead of using %r use %s (which means "string") and you see that
> magical u to disappear.
>
> also if you send q (as in example), even it's empty it will get in GET
> query dictionary, just because it exists. And it has value - empty
> string.
>
> So what you need to test is:
>
> if 'q' in request.GET and request.GET['q']:
>
> Or to make things a bit more Pythonic:
>
> if request.get('q', False):
>
> > I've tried using [ ] instead of the suggested ( ), which leads to a
> > Django errorpage, stating that the contents of the variable 'q' is
> > u'd' - which seems to indicate to me that a "u" is added to all values
> > of q (also explaining why q is never empty).
>
> > On Dec 31, 11:27 am, Masklinn  wrote:
> > > On 31 Dec 2009, at 10:58 , BobAalsma wrote:
>
> > > > I'm following the Django book to learn Django. I'm getting unexpected
> > > > responses and can't find how to address this. It seems that submitting
> > > > an empty form is not handled as if it is empty ??
>
> > > > In views.py:
> > > > def search(request):
> > > >    if 'q' in request.GET:
> > > >            message = 'U zocht: %r' % request.GET['q']
> > > >    else:
> > > >            message = 'Leeg'
> > > >    return HttpResponse(message)
>
> > > > However, on submitting an empty form, the displayed message is:
> > > > U zocht: u''
>
> > > > On submitting a 'd', the answer is:
> > > > U zocht: u'd'
>
> > > > Consistent, that's the good news...
>
> > > > How to solve this?
>
> > > First of all, this has nothing to do with forms. "Forms" in a Django 
> > > context designates Django 
> > > Forms:http://docs.djangoproject.com/en/dev/topics/forms/. Here, you're 
> > > only playing with query parameters, forms are not involved.
>
> > > Second, this is a Python issue more than a Django one: even if the 
> > > parameter is empty (e.g. `yourpage.com/search?q=`) it is present, 
> > > therefore it will be put in the GET dictionary. `key in dict` only checks 
> > > that the key exists, not that it keys to a value (let alone a "falsy" 
> > > value such as an empty string). What you really want to check is that the 
> > > 'q' key exists *and is non-empty*.
>
> > > I suggest that you use the `dict.get` method for this: it returns the 
> > > value for the key if the key exists, None if it doesn't. Just replace 
> > > `'q' in request.GET` by `request.GET.get('q')` and you should have the 
> > > behavior you expect.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Masklinn
On 31 Dec 2009, at 12:31 , Jani Tiainen wrote:
> 
> Or to make things a bit more Pythonic:
> 
> if request.get('q', False):
The `False` is pretty pointless in this case: .get returns None by default, and 
None is falsy. Unless specifically testing with 'is False', the default 
behavior works correctly.

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread BobAalsma
Yes.

I've copied your text into the views.py and now I get the expected
answers - thanks!

I'll study the differences to see what went wrong.

Thanks again,
Bob

On Dec 31, 12:26 pm, Masklinn  wrote:
> On 31 Dec 2009, at 12:20 , BobAalsma wrote:
>
> > Thanks Masklin, I've just tried your suggestion and there is no
> > change.
>
> > I'm somewhat mystified by the 'u' that gets added to all answer
> > messages - is this something to do with unicode? Could this be the
> > root of (some) evil?
>
> It shouldn't be, it simply indicates that you're getting a unicode string 
> instead of a bytestring (sensible Django behavior).
>
> > I've tried using [ ] instead of the suggested ( ), which leads to a
> > Django errorpage, stating that the contents of the variable 'q' is
> > u'd' - which seems to indicate to me that a "u" is added to all values
> > of q (also explaining why q is never empty).
>
> No, you'll notice that the `u` prefixes the string, it's only here to say 
> that this is a unicode string (akin to the rawstring prefix, you can in fact 
> create a raw unicode string by writing `ru'foo'`). And an empty unicode 
> string is still considered 'falsy' so that should not be an issue:
>
> >>> bool(u'')
> False
> >>> if u'': print 'oops'
>
> ... else: print 'ok'
> ...
> ok
>
> If your code has been altered to
>
> def search(request):
>     if request.GET.get('q'):
>         message = 'U zocht: %r' % request.GET['q']
>     else:
>         message = 'Leeg'
>     return HttpResponse(message)
>
> then you should not see `U zocht: u''` in your output. Is the code for the 
> search function you provide here all of it?

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Masklinn
On 31 Dec 2009, at 12:20 , BobAalsma wrote:
> 
> Thanks Masklin, I've just tried your suggestion and there is no
> change.
> 
> I'm somewhat mystified by the 'u' that gets added to all answer
> messages - is this something to do with unicode? Could this be the
> root of (some) evil?
> 
> I've tried using [ ] instead of the suggested ( ), which leads to a
> Django errorpage, stating that the contents of the variable 'q' is
> u'd' - which seems to indicate to me that a "u" is added to all values
> of q (also explaining why q is never empty).

Well I just tested and it definitely works for me: with your original function

def search(request):
if 'q' in request.GET:
message = 'U zocht: %r' % request.GET['q']
else:
message = 'Leeg'
return HttpResponse(message)

here are the results:
http://localhost:8000/search => Leeg
http://localhost:8000/search?q= => U zocht: u''
http://localhost:8000/search?q=foo => U zocht: u'foo'

while with the alteration I suggested

def search(request):
if request.GET.get('q'):
message = 'U zocht: %r' % request.GET['q']
else:
message = 'Leeg'
return HttpResponse(message)

the results are:
http://localhost:8000/search => Leeg
http://localhost:8000/search?q= => Leeg
http://localhost:8000/search?q=foo => U zocht: u'foo'

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Jani Tiainen
On Thu, 2009-12-31 at 03:20 -0800, BobAalsma wrote:
> Thanks Masklin, I've just tried your suggestion and there is no
> change.
> 
> I'm somewhat mystified by the 'u' that gets added to all answer
> messages - is this something to do with unicode? Could this be the
> root of (some) evil?

Again, your're using formatter %r which in python means "representation
of object". In case of strings it prints either u'' for unicode strings,
or just '' for non unicode ones.

It's still a string and doesn't get "appended" magically.

So instead of using %r use %s (which means "string") and you see that
magical u to disappear.

also if you send q (as in example), even it's empty it will get in GET
query dictionary, just because it exists. And it has value - empty
string.

So what you need to test is:

if 'q' in request.GET and request.GET['q']:

Or to make things a bit more Pythonic:

if request.get('q', False):

> I've tried using [ ] instead of the suggested ( ), which leads to a
> Django errorpage, stating that the contents of the variable 'q' is
> u'd' - which seems to indicate to me that a "u" is added to all values
> of q (also explaining why q is never empty).
> 
> 
> On Dec 31, 11:27 am, Masklinn  wrote:
> > On 31 Dec 2009, at 10:58 , BobAalsma wrote:
> >
> >
> >
> >
> >
> > > I'm following the Django book to learn Django. I'm getting unexpected
> > > responses and can't find how to address this. It seems that submitting
> > > an empty form is not handled as if it is empty ??
> >
> > > In views.py:
> > > def search(request):
> > >if 'q' in request.GET:
> > >message = 'U zocht: %r' % request.GET['q']
> > >else:
> > >message = 'Leeg'
> > >return HttpResponse(message)
> >
> > > However, on submitting an empty form, the displayed message is:
> > > U zocht: u''
> >
> > > On submitting a 'd', the answer is:
> > > U zocht: u'd'
> >
> > > Consistent, that's the good news...
> >
> > > How to solve this?
> >
> > First of all, this has nothing to do with forms. "Forms" in a Django 
> > context designates Django 
> > Forms:http://docs.djangoproject.com/en/dev/topics/forms/. Here, you're only 
> > playing with query parameters, forms are not involved.
> >
> > Second, this is a Python issue more than a Django one: even if the 
> > parameter is empty (e.g. `yourpage.com/search?q=`) it is present, therefore 
> > it will be put in the GET dictionary. `key in dict` only checks that the 
> > key exists, not that it keys to a value (let alone a "falsy" value such as 
> > an empty string). What you really want to check is that the 'q' key exists 
> > *and is non-empty*.
> >
> > I suggest that you use the `dict.get` method for this: it returns the value 
> > for the key if the key exists, None if it doesn't. Just replace `'q' in 
> > request.GET` by `request.GET.get('q')` and you should have the behavior you 
> > expect.
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 


--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Masklinn
On 31 Dec 2009, at 12:20 , BobAalsma wrote:
> 
> Thanks Masklin, I've just tried your suggestion and there is no
> change.
> 
> I'm somewhat mystified by the 'u' that gets added to all answer
> messages - is this something to do with unicode? Could this be the
> root of (some) evil?
It shouldn't be, it simply indicates that you're getting a unicode string 
instead of a bytestring (sensible Django behavior).

> I've tried using [ ] instead of the suggested ( ), which leads to a
> Django errorpage, stating that the contents of the variable 'q' is
> u'd' - which seems to indicate to me that a "u" is added to all values
> of q (also explaining why q is never empty).
> 
No, you'll notice that the `u` prefixes the string, it's only here to say that 
this is a unicode string (akin to the rawstring prefix, you can in fact create 
a raw unicode string by writing `ru'foo'`). And an empty unicode string is 
still considered 'falsy' so that should not be an issue:

>>> bool(u'')
False
>>> if u'': print 'oops'
... else: print 'ok'
... 
ok

If your code has been altered to

def search(request):
if request.GET.get('q'):
message = 'U zocht: %r' % request.GET['q']
else:
message = 'Leeg'
return HttpResponse(message)

then you should not see `U zocht: u''` in your output. Is the code for the 
search function you provide here all of it?


--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread BobAalsma
Thanks Masklin, I've just tried your suggestion and there is no
change.

I'm somewhat mystified by the 'u' that gets added to all answer
messages - is this something to do with unicode? Could this be the
root of (some) evil?

I've tried using [ ] instead of the suggested ( ), which leads to a
Django errorpage, stating that the contents of the variable 'q' is
u'd' - which seems to indicate to me that a "u" is added to all values
of q (also explaining why q is never empty).


On Dec 31, 11:27 am, Masklinn  wrote:
> On 31 Dec 2009, at 10:58 , BobAalsma wrote:
>
>
>
>
>
> > I'm following the Django book to learn Django. I'm getting unexpected
> > responses and can't find how to address this. It seems that submitting
> > an empty form is not handled as if it is empty ??
>
> > In views.py:
> > def search(request):
> >    if 'q' in request.GET:
> >            message = 'U zocht: %r' % request.GET['q']
> >    else:
> >            message = 'Leeg'
> >    return HttpResponse(message)
>
> > However, on submitting an empty form, the displayed message is:
> > U zocht: u''
>
> > On submitting a 'd', the answer is:
> > U zocht: u'd'
>
> > Consistent, that's the good news...
>
> > How to solve this?
>
> First of all, this has nothing to do with forms. "Forms" in a Django context 
> designates Django Forms:http://docs.djangoproject.com/en/dev/topics/forms/. 
> Here, you're only playing with query parameters, forms are not involved.
>
> Second, this is a Python issue more than a Django one: even if the parameter 
> is empty (e.g. `yourpage.com/search?q=`) it is present, therefore it will be 
> put in the GET dictionary. `key in dict` only checks that the key exists, not 
> that it keys to a value (let alone a "falsy" value such as an empty string). 
> What you really want to check is that the 'q' key exists *and is non-empty*.
>
> I suggest that you use the `dict.get` method for this: it returns the value 
> for the key if the key exists, None if it doesn't. Just replace `'q' in 
> request.GET` by `request.GET.get('q')` and you should have the behavior you 
> expect.

--

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.




questions from a noob - win7 using django

2009-12-31 Thread shofty
ive been using django for a couple of weeks, i can see massive
potential for actually finishing a couple of projects that i've had on
the go for a good while. thing is its my first attempt at using a
framework and ive found the tutorial followable, but lacking. it tells
you what to do, but doesnt explain the why very well imo? so i've come
to a point where i need a little assistance to take this further. i've
got a couple of understanding points that once i get past im sure the
frustration will die. I've actually written an app already, got quite
far in it but in trying not to reinvent the wheel I've decided to use
avatar and come up against a brick wall.

so i've been through the tutorials. im struggling understanding how
best to code for this on windows. im trying to make life as easy as
possible for myself. ive seen pretty much no clues on how best to work
in windows.
i've got python installed at c:\python26 . im creating mysites at c:
\django-sites
- would experienced coders advise against this? would it be better to
drop the django projects/apps inside the python path?

- im really struggling with apps. i've downloaded a few and tried to
get them working by dropping them inside my project folder and linking
them in. so for example i've tried to get brookie working by dropping
it into c:\django-sites\projectname\django-brookie. all sorts of
errors ensued.
where would experienced coders put their apps? and then how do you
link them into your project? i tried project.app inside the installed
apps section, but it fails to pick up the urls file.
is it best practice to use the setup.py file and then refer to it as
django.contrib.brookie?

any help is appreciated, i can tell django is something that i need to
be using, but i just need to get past these first few hurdles. im
going to invest in the books to see if a bit of light reading helps,
but im impatient and frustrated!

--

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.




Foreign Key Across Database in Django multidb

2009-12-31 Thread malik
I heard that that multi DB support is now available in Django.Can some
one tell me whether it is possible to have foreign Key across
Databases.

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Masklinn
On 31 Dec 2009, at 10:58 , BobAalsma wrote:
> 
> I'm following the Django book to learn Django. I'm getting unexpected
> responses and can't find how to address this. It seems that submitting
> an empty form is not handled as if it is empty ??
> 
> In views.py:
> def search(request):
>   if 'q' in request.GET:
>   message = 'U zocht: %r' % request.GET['q']
>   else:
>   message = 'Leeg'
>   return HttpResponse(message)
> 
> However, on submitting an empty form, the displayed message is:
> U zocht: u''
> 
> On submitting a 'd', the answer is:
> U zocht: u'd'
> 
> Consistent, that's the good news...
> 
> How to solve this?

First of all, this has nothing to do with forms. "Forms" in a Django context 
designates Django Forms: http://docs.djangoproject.com/en/dev/topics/forms/. 
Here, you're only playing with query parameters, forms are not involved.

Second, this is a Python issue more than a Django one: even if the parameter is 
empty (e.g. `yourpage.com/search?q=`) it is present, therefore it will be put 
in the GET dictionary. `key in dict` only checks that the key exists, not that 
it keys to a value (let alone a "falsy" value such as an empty string). What 
you really want to check is that the 'q' key exists *and is non-empty*.

I suggest that you use the `dict.get` method for this: it returns the value for 
the key if the key exists, None if it doesn't. Just replace `'q' in 
request.GET` by `request.GET.get('q')` and you should have the behavior you 
expect.

--

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




Re: Newbie question: empty is not empty?

2009-12-31 Thread Jani Tiainen
On Thu, 2009-12-31 at 01:58 -0800, BobAalsma wrote:
> I'm following the Django book to learn Django. I'm getting unexpected
> responses and can't find how to address this. It seems that submitting
> an empty form is not handled as if it is empty ??
> 
> In views.py:
> def search(request):
>   if 'q' in request.GET:
>   message = 'U zocht: %r' % request.GET['q']
>   else:
>   message = 'Leeg'
>   return HttpResponse(message)
> 
> However, on submitting an empty form, the displayed message is:
> U zocht: u''
> 
> On submitting a 'd', the answer is:
> U zocht: u'd'
> 
> Consistent, that's the good news...
> 
> How to solve this?

You don't tell do you have any elements on your HTML form.

But if you do - it will get submitted (exception being unselected
checkboxes) with empty value - and thus existing as empty string in
GET/POST parameters.

None of standard middlewares don't mangle POST/GET parameters. To make
something useful out of it, use Django forms to post process form to
distinguish between emtpy and non empty values.

-- 

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.




Newbie question: empty is not empty?

2009-12-31 Thread BobAalsma
I'm following the Django book to learn Django. I'm getting unexpected
responses and can't find how to address this. It seems that submitting
an empty form is not handled as if it is empty ??

In views.py:
def search(request):
if 'q' in request.GET:
message = 'U zocht: %r' % request.GET['q']
else:
message = 'Leeg'
return HttpResponse(message)

However, on submitting an empty form, the displayed message is:
U zocht: u''

On submitting a 'd', the answer is:
U zocht: u'd'

Consistent, that's the good news...

How to solve this?

--

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