Re: WEB SERVICE IN DJANGO USING ZSI

2010-11-29 Thread sami nathan
To create server file i used this command but showing following error
D:\Python25\Scripts>python wsdl2py --complexType localhost 8080 d:/soap/zz/FlypS
ms.wsdl
Expecting a file/url as argument (WSDL).
Traceback (most recent call last):
  File "wsdl2py", line 9, in 
wsdl2py()
  File "D:\Python25\Lib\site-packages\ZSI\generate\commands.py", line 122, in ws
dl2py
sys.exit(os.EX_USAGE)
AttributeError: 'module' object has no attribute 'EX_USAGE'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: WEB SERVICE IN DJANGO USING ZSI

2010-11-29 Thread sami nathan
ANY one knows how to generate server.py flie from wsdl2py in ZSI

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



Slug for some terms not working

2010-11-29 Thread Detectedstealth
I am completely at a loss here and have no idea what the problem is:

A slug was created for the term escape. So website.com/projects/
escape/

url patterns:
url(r'^projects/(?P[-\w]+)/$', 'views.projectslug',
name='view_project_slug'),

view:
def projectslug(request, slug):
"""Displays the selected project"""
project = get_object_or_404(Project, slug=slug)

if request.user.is_authenticated() and
project.team.members.filter(user=request.user):
is_member = True
else:
is_member = False

return render_to_response('projects/project.html', {
'selecteduser': project.user,
'project': project,
'is_member': is_member,
'latest_blog': project.blogs.all().order_by('-id')[:1],
'latest_videos': project.videos.all().order_by('-id')[:6],
'latest_galleries': project.photos.all().order_by('-id')[:
6],
'active_members': project.team.members.all().order_by('-
user__last_login')[:6],
'forum': project.forum
},
context_instance=RequestContext(request))

Now for some reason when trying to use the slug escape I am taken to a
page does not exists page. This has happened with a few other terms.
When I change the slug to escape-something it works without a problem.

What am I missing?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Sithembewena Lloyd Dube
Hi all,

So, I am back once more. I am having headaches with a simple file upload in
the Django admin.

I have a simple model as follows (partial):

class PhotoTest(models.Model):
 test_name = models.CharField(max_length=50)
 photo = models.ImageField(upload_to='testphotos', blank=True)
 thumbnail = models.ImageField(upload_to='thumbnails', blank=True)

I wish to find out how to override the save() method of this model so that,
when a user selects a photo, I can read that image out of wherever it is in
memory. I would like to thumbnail it with PIL,
assign it to the thumbnail field of the PhotoTest instance and finally, save
it.

My problem is that I can not figure out where to read the original image
from. Trying to read it from self.photo.path in the model's save() method
does not work (object does not have path property).

Perhaps what I should be asking is, which attribute or method of the
ImageField property allows me to access the selected file as a PIL File
object?

Please help?

-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.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: Django admin photo upload

2010-11-29 Thread Venkatraman S
Have a look at django-photologue.

-V-

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Kenneth Gonsalves
On Mon, 2010-11-29 at 15:24 +0530, Venkatraman S wrote:
> Have a look at django-photologue.

is it still maintained?
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Kenneth Gonsalves
On Mon, 2010-11-29 at 11:52 +0200, Sithembewena Lloyd Dube wrote:
> class PhotoTest(models.Model):
>  test_name = models.CharField(max_length=50)
>  photo = models.ImageField(upload_to='testphotos', blank=True)
>  thumbnail = models.ImageField(upload_to='thumbnails', blank=True)
> 
> I wish to find out how to override the save() method of this model so
> that,
> when a user selects a photo, I can read that image out of wherever it
> is in
> memory. I would like to thumbnail it with PIL,
> assign it to the thumbnail field of the PhotoTest instance and
> finally, save
> it. 

why not use easy_thumbnail instead? it is an excellent library with no
dependencies and very simple installation.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Venkatraman S
On Mon, Nov 29, 2010 at 3:37 PM, Kenneth Gonsalves wrote:

> On Mon, 2010-11-29 at 15:24 +0530, Venkatraman S wrote:
> > Have a look at django-photologue.
>
> is it still maintained?
>

Not sure. But the code is a good one to start off for the OP and get some
ideas on
how images and thumbnails can be handled..

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: WEB SERVICE IN DJANGO USING ZSI

2010-11-29 Thread Tom Evans
On Mon, Nov 29, 2010 at 8:32 AM, sami nathan  wrote:
> ANY one knows how to generate server.py flie from wsdl2py in ZSI
>


Have you tried asking someone who knows what ZSI is?

Ok, so slightly facetious, it's some sort of Zope web services layer.
However, you may have noticed that this is the Django mailing list,
and not the Zope mailing list. One of the best things about Django is
that it is not Zope, lets keep it that way.

Also, anyone who may have known may have been put off by you posting
the same question over and over in a short space of time.


Here is your next step:

http://lmgtfy.com/?q=zope+mailing+list


HTH

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: If logged in show X, if not Y

2010-11-29 Thread robos85
I there any way to name a template? For example my subtempaltes/
loginform.html - I want to name it loginform.
In group work it'll be a very useful feature. I knto that {% include
%} tag allows passing name - but how?

On 29 Lis, 04:09, Venkatraman S  wrote:
> On Mon, Nov 29, 2010 at 7:44 AM, Andre Terra  wrote:
> > I think a more elegant approach would be to have a main template with {%
> > block some_name_for_the_part_that_changes %}, and have two different
> > template (logged_in.html and not_logged_in.html) that both extend said block
> > in 'main.html'.
>
> The conditional logic in View or Template depends on what you want to
> show/not-show in the template -- if its just a small section that you want
> to conditionally show, then prefer the auth check in the template, else move
> it to the view.
>
> -V-http://twitter.com/venkasub

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Issue uploading photos through the admin. PIL issue.

2010-11-29 Thread Sid
You need to install a couple of pre built packages to allow PIL to
compile correctly.

Install python dev
$>sudo apt-get install python2.6-dev -y

Install JPEG Support for PIL first
$>sudo apt-get install libjpeg62 libjpeg62-dev zlib1g-dev libfreetype6
libfreetype6-dev -y

$>workon venv
(venv)$> pip install PIL


-Sid
sidmitra.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: Caching middleware causes default page caching

2010-11-29 Thread Tom Evans
On Sat, Nov 27, 2010 at 4:30 AM, ydjango  wrote:
> I have added following to cache some common DB data and it seems it
> has started caching whole pages by default. Some pages appeared to be
> retrieved from cache without even hitting the view.
>
> and in my views,
>
> from django.core.cache import cache
>  and cache.set('add_key', 'Initial value')
 cache.add('add_key', 'New value')
 cache.get('add_key')
> 'Initial value'
>

It's unclear, but are you querying this behaviour? This is correct
behaviour, cache.add(key, value) will only update the cache if the key
is not already set.

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: Django admin photo upload

2010-11-29 Thread Sithembewena Lloyd Dube
@ Venkatraman, and @kenneth - thanks gentlemen. I am trying out
easy_thumbnail as it looks light enough for my needs. django-photologue
looks great too, although I suspect it is a much more full-fledged solution?
I will look at it if need be.

Regards,
Lloyd

On Mon, Nov 29, 2010 at 12:15 PM, Venkatraman S  wrote:

>
> On Mon, Nov 29, 2010 at 3:37 PM, Kenneth Gonsalves wrote:
>
>> On Mon, 2010-11-29 at 15:24 +0530, Venkatraman S wrote:
>> > Have a look at django-photologue.
>>
>> is it still maintained?
>>
>
> Not sure. But the code is a good one to start off for the OP and get some
> ideas on
> how images and thumbnails can be handled..
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, 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,
Sithembewena Lloyd Dube
http://www.lloyddube.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: Create an object before calling the save method

2010-11-29 Thread bnabilos
Hi,

Thank you for your answer.

I will explain what I want to do.

Let's say that we have Category and Article classes in our model, each
one has a title. To make this title reusable, I created another
application that will manage fields, I created the class Title and I
added it as foreignkey to Category and Article forms.

I switched the select box to an input field using raw_id_fields.

Now, when I create a category or an article, I have to select or write
a title, when this title exists, it works perfectly but when it
doesn't exist I want to create it before creating the category so it
can use it.

I tried to do that in the save method, in the pre_save signal and in
the clean method but I always get the error "Select a valid choice.
That choice is not one of the available choices."

I'm using a hard coded solution to create the title now, I want just
to see if it will work, these are the lines that I inserted in the
different methods to create the title before creating the category :

t = Title(title = "MyTitle")
t.save()

I tried to create a Category with MyTitle as title but I get the same
error, when I try to create another one using an existing title, it
works and the title "MyTitle" is created. That's mean that the
creation of the object happens after the form verification. What I
want is just doing this before. The title object should be created
before the verification.

Thank you very much for your help

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



Installing on Ubuntu Python 2.6- Install failure

2010-11-29 Thread Tim Bowden
When installing django from an official release tarball onto Ubuntu
10.04 python 2.6, (python setup.py install) it installs to
/usr/local/lib/python2.6/dist-packages/ rather than
/usr/lib/python2.6/dist-packages (as reported by python -c "from
distutils.sysconfig import get_python_lib; print get_python_lib()").

Is this expected behaviour?  If so, the install instructions and
tutorial will need to be updated.  How should django best be imported
into a running python interpreter in this case?  import django
returns:
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named django

I solved the problem by doing python setup.py build then manually
copying build/django into /usr/local/lib/python2.6/dist-packages, but
that is not a very user friendly procedure.

Is this an Ubuntu/python 2.6 specific issue?  Should the install
instructions be updated or is this a bug in the packaging?

Regards,
Tim Bowden

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



manytomany display field

2010-11-29 Thread Anderson Goulart
Hi,

How do I choose which field should appears on the admin interface when I use 
manytomany field?

eg: 

class Service(models.Model):
name = models.CharField(..)
acronym  = models.CharField(..)

class Test(models.Model):
services = models.ManyToManyField()


When I add a new Test object on admin interface, the services field displays 
the "name" field on the multiple select box. I want to display the acronym 
field on this box. How can I do this?



thanks, anderson

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Sithembewena Lloyd Dube
@Kenneth, thanks again. easy_thumbnail cuts it just fine.

Regards,
Lloyd

On Mon, Nov 29, 2010 at 1:01 PM, Sithembewena Lloyd Dube
wrote:

> @ Venkatraman, and @kenneth - thanks gentlemen. I am trying out
> easy_thumbnail as it looks light enough for my needs. django-photologue
> looks great too, although I suspect it is a much more full-fledged solution?
> I will look at it if need be.
>
> Regards,
> Lloyd
>
>
> On Mon, Nov 29, 2010 at 12:15 PM, Venkatraman S wrote:
>
>>
>> On Mon, Nov 29, 2010 at 3:37 PM, Kenneth Gonsalves wrote:
>>
>>> On Mon, 2010-11-29 at 15:24 +0530, Venkatraman S wrote:
>>> > Have a look at django-photologue.
>>>
>>> is it still maintained?
>>>
>>
>> Not sure. But the code is a good one to start off for the OP and get some
>> ideas on
>> how images and thumbnails can be handled..
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, 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,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.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: Installing on Ubuntu Python 2.6- Install failure

2010-11-29 Thread Karen Tracey
On Mon, Nov 29, 2010 at 6:56 AM, Tim Bowden  wrote:

> When installing django from an official release tarball onto Ubuntu
> 10.04 python 2.6, (python setup.py install) it installs to
> /usr/local/lib/python2.6/dist-packages/ rather than
> /usr/lib/python2.6/dist-packages (as reported by python -c "from
> distutils.sysconfig import get_python_lib; print get_python_lib()").
>
> Is this expected behaviour?  If so, the install instructions and
> tutorial will need to be updated.  How should django best be imported
> into a running python interpreter in this case?  import django
> returns:
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named django
>
> I solved the problem by doing python setup.py build then manually
> copying build/django into /usr/local/lib/python2.6/dist-packages, but
> that is not a very user friendly procedure.
>
> Is this an Ubuntu/python 2.6 specific issue?  Should the install
> instructions be updated or is this a bug in the packaging?
>
>
On that system, I believe it is expected behavior that Django gets installed
in /usr/local/lib/python2.6/dist-packages when installed via setup.py. Per
the Debian packaging doc (
http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html),
this is "[a] special directory [that] is dedicated to public Python modules
installed by the local administrator, /usr/local/lib/pythonX.Y/dist-packages
for python2.6 and later". What is unexpected in your case is that this
directory is not in the system default sys.path. It is in sys.path on my
Ubuntu 10.04 box (as is the other directory, which is called "the system
Python modules directory" in that packaging doc):

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.6/dist-packages/pip-0.8.1-py2.6.egg',
'/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0',
'/usr/local/lib/python2.6/dist-packages']
>>> '/usr/local/lib/python2.6/dist-packages' in sys.path
True
>>> '/usr/lib/python2.6/dist-packages' in sys.path
True
>>>

Karen
-- 
http://tracey.org/kmt/

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



umlaut

2010-11-29 Thread Thomas Rega
Hi,

is there a recommended way to deal with German 'umlauts' (like ü.ö.etc.)

I was lookingfor some kind of template filter but without success :(

The data is stored as utf-8 format. What I am looking for is an
automatic transformation into 'ü, ö etc.

Is such a template filter the right approach?

Is there a recommended way to do that?

many thanks in advance

TR

-- 
--- http://thoreg.org/ ---

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: umlaut

2010-11-29 Thread Brian Bouterse
Yes I think a template filter is the right approach.  You could always
define a custom template
tag.
 I've had to do this before to display currency information multinationally
before.

Brian

On Mon, Nov 29, 2010 at 8:20 AM, Thomas Rega  wrote:

> Hi,
>
> is there a recommended way to deal with German 'umlauts' (like ü.ö.etc.)
>
> I was lookingfor some kind of template filter but without success :(
>
> The data is stored as utf-8 format. What I am looking for is an
> automatic transformation into 'ü, ö etc.
>
> Is such a template filter the right approach?
>
> Is there a recommended way to do that?
>
> many thanks in advance
>
> TR
>
> --
> --- http://thoreg.org/ ---
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Brian Bouterse
ITng Services

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 book

2010-11-29 Thread octopusgrabbus
There are many books on Django. You can look on www.softpro.com,
Amazon, or your favorite book store.
I've gotten a lot out of two books. The Definitive Guide to Django and
Visual Quick Pro Django.

On Nov 28, 11:24 am, Matthias Runge  wrote:
> Djangobook is available as printed edition from apress, as well as "practical 
> django projects". The latter, I think, aims to more advanced django 
> programmers. "The definitive guide to django" was a good starting point for 
> me.
> I hope, this helps for you,
> Matthias
>
> "Reeti Pal"  schrieb:>i gues there are no printed 
> books available.
> >www.djangobook.com
>
> >http://docs.djangoproject.com/en/1.2/contents/
>
> >are two sites from where you can learn
>
> >reeti
>
> >--
> >You received this message because you are subscribed to the Google
> >Groups "Django users" group.
> >To post to this group, send email to django-us...@googlegroups.com.
> >To unsubscribe from this group, 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: umlaut

2010-11-29 Thread Javier Guerra Giraldez
On Mon, Nov 29, 2010 at 8:24 AM, Brian Bouterse  wrote:
> Yes I think a template filter is the right approach.

I'd say that generating UTF-8 HTML is 'more right'

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

2010-11-29 Thread David De La Harpe Golden
On 29/11/10 13:20, Thomas Rega wrote:
> Hi,
> 
> is there a recommended way to deal with German 'umlauts' (like ü.ö.etc.)
> I was lookingfor some kind of template filter but without success :(
> The data is stored as utf-8 format. What I am looking for is an
> automatic transformation into 'ü, ö etc.
> Is such a template filter the right approach?
>

Well, I suppose you could, but just in case do bear in mind most stuff
these days is after all utf-8 capable.  I just wouldn't bother mapping
to html entities unless you know you need something else, really.
Django in fact defaults to utf-8 [1]

[1] http://docs.djangoproject.com/en/dev/ref/settings/#default-charset

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Installing on Ubuntu Python 2.6- Install failure

2010-11-29 Thread Tim Bowden
On 29 November 2010 21:15, Karen Tracey  wrote:
> On Mon, Nov 29, 2010 at 6:56 AM, Tim Bowden  wrote:
>>
>> When installing django from an official release tarball onto Ubuntu
>> 10.04 python 2.6, (python setup.py install) it installs to
>> /usr/local/lib/python2.6/dist-packages/ rather than
>> /usr/lib/python2.6/dist-packages (as reported by python -c "from
>> distutils.sysconfig import get_python_lib; print get_python_lib()").
>>
>> Is this expected behaviour?  If so, the install instructions and
>> tutorial will need to be updated.  How should django best be imported
>> into a running python interpreter in this case?  import django
>> returns:
>> Traceback (most recent call last):
>>  File "", line 1, in 
>> ImportError: No module named django
>>
>> I solved the problem by doing python setup.py build then manually
>> copying build/django into /usr/local/lib/python2.6/dist-packages, but
>> that is not a very user friendly procedure.
>>
>> Is this an Ubuntu/python 2.6 specific issue?  Should the install
>> instructions be updated or is this a bug in the packaging?
>>
>
> On that system, I believe it is expected behavior that Django gets installed
> in /usr/local/lib/python2.6/dist-packages when installed via setup.py. Per
> the Debian packaging doc
> (http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html),
> this is "[a] special directory [that] is dedicated to public Python modules
> installed by the local administrator, /usr/local/lib/pythonX.Y/dist-packages
> for python2.6 and later". What is unexpected in your case is that this
> directory is not in the system default sys.path. It is in sys.path on my
> Ubuntu 10.04 box (as is the other directory, which is called "the system
> Python modules directory" in that packaging doc):
>
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import sys
 sys.path
> ['', '/usr/local/lib/python2.6/dist-packages/pip-0.8.1-py2.6.egg',
> '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
> '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old',
> '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages',
> '/usr/lib/python2.6/dist-packages/PIL',
> '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6',
> '/usr/lib/python2.6/dist-packages/gtk-2.0',
> '/usr/lib/pymodules/python2.6/gtk-2.0',
> '/usr/local/lib/python2.6/dist-packages']
 '/usr/local/lib/python2.6/dist-packages' in sys.path
> True
 '/usr/lib/python2.6/dist-packages' in sys.path
> True

>
> Karen

Problem solved.  Permissions issue.  The version of ubuntu I'm using
is a minimalist bastardised version pre-installed on a VPS.  I'm
installing as root and it isn't giving appropriate permissions on the
django directory.

Sorry for the noise.

Tim Bowden

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



Sqlite :memory: database for production?

2010-11-29 Thread Subsume
Hey there,

I've got an app on my site that's a game where people make picks from
Pack objects. These objects only exist during the life of the game
(about 20 minutes) and then are gone. I'm hoping to reduce some Disk I/
O on my server by allowing this app to use a database that is purely
in sqlite memory.

I see all kinds of efforts for people to use such an in-memory sqlite
database during tests but how would this work live? I'd need all my
web-server processes to share this database.

Right now I've got the name :memory: but the table always seems to be
empty, despite objects being created.

Is my approach off? Maybe I should I try some other way to create my
sqlite file in debian's mounted ram space?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Sqlite :memory: database for production?

2010-11-29 Thread Javier Guerra Giraldez
On Mon, Nov 29, 2010 at 10:10 AM, Subsume  wrote:
> Right now I've got the name :memory: but the table always seems to be
> empty, despite objects being created.

from the docs (http://www.sqlite.org/inmemorydb.html):

> Every :memory: database is distinct from every other. So, opening two 
> database connections each with the filename ":memory:" will create two 
> independent in-memory databases.

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

2010-11-29 Thread Thomas Rega
Thanks a lot for your replies.

The following code does the job for me ...



>From 8a110f8358f545fae0a9d0c8d69b496fd0e35cdf Mon Sep 17 00:00:00 2001
From: Thomas Rega 
Date: Mon, 29 Nov 2010 16:51:01 +0100
Subject: [PATCH] custom template filter to convert umlauts

This simple custom template filter converts German umlauts from unicode to
ascii. 99,99 percent of this code are stolen from:
http://djangosnippets.org/snippets/588/
---
 plain_site/templatetags/unicode_to_ascii.py |   75 +++
 1 files changed, 75 insertions(+), 0 deletions(-)
 create mode 100644 plain_site/templatetags/unicode_to_ascii.py

diff --git a/plain_site/templatetags/unicode_to_ascii.py
b/plain_site/templatetags/unicode_to_ascii.py
new file mode 100644
index 000..730ab52
--- /dev/null
+++ b/plain_site/templatetags/unicode_to_ascii.py
@@ -0,0 +1,75 @@
+
+import unicodedata, sys
+
+from django import template
+from django.template.defaultfilters import stringfilter
+
+register = template.Library()
+
+# Translation dictionary.  Translation entries are added to this
+# dictionary as needed.
+
+CHAR_REPLACEMENT = {
+
+0xc4: u"Ä",
+0xd6: u"Ö",
+0xdc: u"Ö",
+
+0xdf: u"ß",
+
+0xe4: u"ä",
+0xf6: u"ö",
+0xfc: u"ü",
+
+0x2018: u"'", # LEFT SINGLE QUOTATION MARK
+0x2019: u"'", # RIGHT SINGLE QUOTATION MARK
+0x201c: u'"', # LEFT DOUBLE QUOTATION MARK
+0x201d: u'"', # RIGHT DOUBLE QUOTATION MARK
+}
+
+
+class unaccented_map(dict):
+"""
+Maps a unicode character code (the key) to a replacement code
+(either a character code or a unicode string).
+"""
+
+def mapchar(self, key):
+ch = self.get(key)
+if ch is not None:
+return ch
+
+de = unicodedata.decomposition(unichr(key))
+if key not in CHAR_REPLACEMENT and de:
+try:
+ch = int(de.split(None, 1)[0], 16)
+except (IndexError, ValueError):
+ch = key
+else:
+ch = CHAR_REPLACEMENT.get(key, key)
+self[key] = ch
+return ch
+
+if sys.version >= "2.5":
+# use __missing__ where available
+__missing__ = mapchar
+else:
+# otherwise, use standard __getitem__ hook (this is slower,
+# since it's called for each character)
+__getitem__ = mapchar
+
+...@register.filter(name='unicode_to_ascii')
+...@stringfilter
+def unicode_to_ascii(unicodestring):
+"""
+Convert a unicode string into an ASCII representation, converting non-ascii
+characters into close approximations where possible.
+
+Special thanks to http://effbot.org/zone/unicode-convert.htm
+
+@param Unicode String unicodestring  The string to translate
+@result String
+"""
+charmap = unaccented_map()
+return unicodestring.translate(charmap).encode("ascii", "ignore")
+
-- 
1.5.6.5



2010/11/29 David De La Harpe Golden :
> On 29/11/10 13:20, Thomas Rega wrote:
>> Hi,
>>
>> is there a recommended way to deal with German 'umlauts' (like ü.ö.etc.)
>> I was lookingfor some kind of template filter but without success :(
>> The data is stored as utf-8 format. What I am looking for is an
>> automatic transformation into 'ü, ö etc.
>> Is such a template filter the right approach?
>>
>
> Well, I suppose you could, but just in case do bear in mind most stuff
> these days is after all utf-8 capable.  I just wouldn't bother mapping
> to html entities unless you know you need something else, really.
> Django in fact defaults to utf-8 [1]
>
> [1] http://docs.djangoproject.com/en/dev/ref/settings/#default-charset
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
--- http://thoreg.org/ ---

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: absolute url in template and url name

2010-11-29 Thread Jumpfroggy
As a followup, I had to do something similar and ended up using this:

# Gets the http://domain.com without the trailing /
base_url = request.build_absolute_uri('/')[:-1]

And in the template I can do this:

...

The benefits:
-You only have to create the base_url in the view, the rest you can do
in the template itself.
-The URLs are absolute & contain the domain (ie. http://www.domain.com/page/1,
https://www.domain.com:8008/view2, etc).
-Includes http & https.
-Simple.

This the method I'm using from now on.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Sqlite :memory: database for production?

2010-11-29 Thread Subsume
Yeah I gathered that but I found some django code that seemed to deal
with that:

http://code.djangoproject.com/ticket/2658

I wasn't sure what the implications of this would be in a live
situation.

On Nov 29, 11:05 am, Javier Guerra Giraldez 
wrote:
> On Mon, Nov 29, 2010 at 10:10 AM, Subsume  wrote:
> > Right now I've got the name :memory: but the table always seems to be
> > empty, despite objects being created.
>
> from the docs (http://www.sqlite.org/inmemorydb.html):
>
> > Every :memory: database is distinct from every other. So, opening two 
> > database connections each with the filename ":memory:" will create two 
> > independent in-memory databases.
>
> --
> 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: Sqlite :memory: database for production?

2010-11-29 Thread Cal Leeming [Simplicity Media Ltd]
Hi,

To be honest, if you're that worried about performance and concurrent user
handling, then you wouldn't be using SQLite anyway. Please can you explain
some details about what you are trying to achieve, and lets see if we can
give you a better solution :)

Cal

On Mon, Nov 29, 2010 at 3:10 PM, Subsume  wrote:

> Hey there,
>
> I've got an app on my site that's a game where people make picks from
> Pack objects. These objects only exist during the life of the game
> (about 20 minutes) and then are gone. I'm hoping to reduce some Disk I/
> O on my server by allowing this app to use a database that is purely
> in sqlite memory.
>
> I see all kinds of efforts for people to use such an in-memory sqlite
> database during tests but how would this work live? I'd need all my
> web-server processes to share this database.
>
> Right now I've got the name :memory: but the table always seems to be
> empty, despite objects being created.
>
> Is my approach off? Maybe I should I try some other way to create my
> sqlite file in debian's mounted ram space?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 

Cal Leeming

Operational Security & Support Team

*Out of Hours: *+44 (07534) 971120 | *Support Tickets: *
supp...@simplicitymedialtd.co.uk
*Fax: *+44 (02476) 578987 | *Email: *cal.leem...@simplicitymedialtd.co.uk
*IM: *AIM / ICQ / MSN / Skype (available upon request)
Simplicity Media Ltd. All rights reserved.
Registered company number 7143564

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 timestamp to Javascript timestamp

2010-11-29 Thread Matt Thompson
Hello guys and girls,

I'm looking to use Flot to graph some data I have in my Django app.
I'd like to graph a time based query and need to get the time is
Javascript format (milliseconds since 01/01/1970).

I can get it into seconds\unix format, this is seconds since
01/01/1970, but not milliseconds.

Can anyone help?

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.



generic views template problem

2010-11-29 Thread Carlos Aboim
Guys,
Someone can tell me what is happening with my generic
views?

I have the templates in my application folder 'templates' in the root
my project.
This folder is referenced in settings such as:
TEMPLATE_DIRS = (
os.path.join (PROJECT_ROOT_PATH, 'templates')
)

and I am calling a generic view thus:
(r'index / $ ',' django.views.generic.list_detail.object_list '
info_dict, dict (name = "obras_index" template_object_name = 'obra',
template_name = 'templates/obra_list.html "))

It turns out that the server is not finding my folder
templates and an error:
Exception Type: TemplateDoesNotExist
Exception Value: obra/obra_list.html

how can I resolve the situation?
Thanks
Aboim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Andre Terra
For anyone else who's interested, I've heard great things about
sorl-thumbnail too, haven't used it myself.

I hope all is fine with easy_thumbnail.


Regards,
Andre Terra

On Mon, Nov 29, 2010 at 10:39, Sithembewena Lloyd Dube wrote:

> @Kenneth, thanks again. easy_thumbnail cuts it just fine.
>
> Regards,
> Lloyd
>
>
> On Mon, Nov 29, 2010 at 1:01 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> @ Venkatraman, and @kenneth - thanks gentlemen. I am trying out
>> easy_thumbnail as it looks light enough for my needs. django-photologue
>> looks great too, although I suspect it is a much more full-fledged solution?
>> I will look at it if need be.
>>
>> Regards,
>> Lloyd
>>
>>
>> On Mon, Nov 29, 2010 at 12:15 PM, Venkatraman S wrote:
>>
>>>
>>> On Mon, Nov 29, 2010 at 3:37 PM, Kenneth Gonsalves wrote:
>>>
 On Mon, 2010-11-29 at 15:24 +0530, Venkatraman S wrote:
 > Have a look at django-photologue.

 is it still maintained?

>>>
>>> Not sure. But the code is a good one to start off for the OP and get some
>>> ideas on
>>> how images and thumbnails can be handled..
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, 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,
>> Sithembewena Lloyd Dube
>> http://www.lloyddube.com
>>
>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: generic views template problem

2010-11-29 Thread Daniel Roseman
On Nov 29, 7:08 pm, Carlos Aboim  wrote:
> Guys,
> Someone can tell me what is happening with my generic
> views?
>
> I have the templates in my application folder 'templates' in the root
> my project.
> This folder is referenced in settings such as:
> TEMPLATE_DIRS = (
>     os.path.join (PROJECT_ROOT_PATH, 'templates')
> )
>
> and I am calling a generic view thus:
> (r'index / $ ',' django.views.generic.list_detail.object_list '
> info_dict, dict (name = "obras_index" template_object_name = 'obra',
> template_name = 'templates/obra_list.html "))
>
> It turns out that the server is not finding my folder
> templates and an error:
> Exception Type: TemplateDoesNotExist
> Exception Value: obra/obra_list.html
>
> how can I resolve the situation?
> Thanks
> Aboim

You don't need the extra 'templates/' in the template_name in your
url.
--
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.



Javascript and template rendering problem

2010-11-29 Thread Anderson Goulart
Hi,

How can I render to a javascript code a variable set in a view? I tried {{ 
variable }} but it returns nothing in the html source code. When I put this {{ 
variable }} outside 

Error in ajax request

2010-11-29 Thread James Matthews
Hi,

When I use this rate limiter
http://www.levigross.com/post/1721427025/django-rate-limiting and preform an
ajax request I get this error

django/middleware/common.py", line 84, in process_response
if response.status_code == 404:
AttributeError: 'function' object has no attribute 'status_code'

[CODE]
@ratelimit
@never_cache
def ajaxrequester(request):
if request.is_ajax():
stuff = submitform(request.POST)
return HttpResponse("{'ok':200}",content_type="text/xml")
else:
return HttpResponseForbidden("You don't belong here")
[/CODE]

Any thoughts?



-- 
http://www.goldwatches.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: Sqlite :memory: database for production?

2010-11-29 Thread Subsume
I'm not really worried about concurrent user handling. I'm more
worried about things happening quickly.

Basically take 3 objects: Pack, Card, Pick. A user is handed a Pack
with many Cards, they make a Pick and hand the Pack to the next user.
Eventually the Pack depopulates of Cards and deletes itself.

Right now making sure the transaction happens smoothly takes a lot of
little queries. Just trying to speed this process up.

-Steve

On Nov 29, 1:31 pm, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> Hi,
>
> To be honest, if you're that worried about performance and concurrent user
> handling, then you wouldn't be using SQLite anyway. Please can you explain
> some details about what you are trying to achieve, and lets see if we can
> give you a better solution :)
>
> Cal
>
>
>
>
>
>
>
>
>
> On Mon, Nov 29, 2010 at 3:10 PM, Subsume  wrote:
> > Hey there,
>
> > I've got an app on my site that's a game where people make picks from
> > Pack objects. These objects only exist during the life of the game
> > (about 20 minutes) and then are gone. I'm hoping to reduce some Disk I/
> > O on my server by allowing this app to use a database that is purely
> > in sqlite memory.
>
> > I see all kinds of efforts for people to use such an in-memory sqlite
> > database during tests but how would this work live? I'd need all my
> > web-server processes to share this database.
>
> > Right now I've got the name :memory: but the table always seems to be
> > empty, despite objects being created.
>
> > Is my approach off? Maybe I should I try some other way to create my
> > sqlite file in debian's mounted ram space?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
>
> Cal Leeming
>
> Operational Security & Support Team
>
> *Out of Hours: *+44 (07534) 971120 | *Support Tickets: *
> supp...@simplicitymedialtd.co.uk
> *Fax: *+44 (02476) 578987 | *Email: *cal.leem...@simplicitymedialtd.co.uk
> *IM: *AIM / ICQ / MSN / Skype (available upon request)
> Simplicity Media Ltd. All rights reserved.
> Registered company number 7143564

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Javascript and template rendering problem

2010-11-29 Thread Sam Lai
On 30 November 2010 07:03, Anderson Goulart  wrote:
> Hi,
>
> How can I render to a javascript code a variable set in a view? I tried {{ 
> variable }} but it returns nothing in the html source code. When I put this 
> {{ variable }} outside 

Re: Error in ajax request

2010-11-29 Thread Daniel Roseman
On Nov 29, 8:28 pm, James Matthews  wrote:
> Hi,
>
> When I use this rate 
> limiterhttp://www.levigross.com/post/1721427025/django-rate-limitingand 
> preform an
> ajax request I get this error
>
> django/middleware/common.py", line 84, in process_response
>     if response.status_code == 404:
> AttributeError: 'function' object has no attribute 'status_code'
>
> [CODE]
> @ratelimit
> @never_cache
> def ajaxrequester(request):
>     if request.is_ajax():
>         stuff = submitform(request.POST)
>         return HttpResponse("{'ok':200}",content_type="text/xml")
>     else:
>         return HttpResponseForbidden("You don't belong here")
> [/CODE]
>
> Any thoughts?

It looks like that is a callable decorator - it is intended to be
called immediately, with arguments:

@ratelimit(limit=5)
   ...etc...

You can tell it's meant to be used like this because of the extra
level of nested functions: normal decorators just return a function
(which calls the decorated function), but callable decorators return a
function (the actual decorator) which itself returns a function.

(Actually I'm not sure that 'callable decorator' is the right term
here, but I can't think of a better one. Is there a canonical name for
this sort of thing?)
--
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.



MySQLdb InterfaceError

2010-11-29 Thread David Smithson
I'm so frustrated with this problem I am about to lose it.  I've tried
multiple versions of python, mysql, mysql-python, django, etc.  I've
resorted to a clean installation of CentOS 5, fully up to date, with
all packages installed by the book.  Currently I'm using DJango 1.2.3
and MySQL-python 1.2.3, both built on this system from clean source.
I've tried both mod_wsgi and mod_python methods.  Currently I'm using
mod_python.  Ignore the Request URL, please.  This is a new system and
not the live site.  I'm using internal host entries.  Why am I getting
this InterfaceError?  The only reference that I can find is a problem
in MySQL 5.0, but this isn't relevant to our situation:
http://bugs.mysql.com/bug.php?id=21543.  I'm pulling my hair out.  Any
help or guidance would be appreciated.

Request Method: GET
Request URL: 
http://nydn.findingdulcinea.com/nydailynews/news/on-this-day/November/Harvey-Milk-Murdered
Django Version: 1.2.3
Exception Type: InterfaceError
Exception Value: (0, '')
Exception Location: build/bdist.linux-x86_64/egg/MySQLdb/
connections.py in set_character_set, line 294
Python Executable: /usr/bin/python
Python Version: 2.4.3
Python Path: ['/app/django_fD', '/app/', '/usr/lib64/python2.4/site-
packages/MySQL_python-1.2.3-py2.4-linux-x86_64.egg', '/usr/lib64/
python24.zip', '/usr/lib64/python2.4', '/usr/lib64/python2.4/plat-
linux2', '/usr/lib64/python2.4/lib-tk', '/usr/lib64/python2.4/lib-
dynload', '/usr/lib64/python2.4/site-packages', '/usr/lib64/python2.4/
site-packages/gtk-2.0', '/usr/lib/python2.4/site-packages']
Server time: Mon, 29 Nov 2010 13:37:44 -0500

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/django/core/handlers/
base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)

  File "/usr/lib/python2.4/site-packages/django/utils/decorators.py",
line 76, in _wrapped_view
response = view_func(request, *args, **kwargs)

  File "/app/django_fD/../django_fD/nydailynews/views.py", line 28, in
get_HB1
return render_today_article1()

  File "/app/django_fD/../django_fD/nydailynews/views.py", line 296,
in render_today_article1
article = get_today_article(type)

  File "/app/django_fD/../django_fD/nydailynews/views.py", line 267,
in get_today_article
row = __get_otd_article_row(cnt, type)

  File "/app/django_fD/../django_fD/nydailynews/views.py", line 302,
in __get_otd_article_row
cursor = connection.cursor()

  File "/usr/lib/python2.4/site-packages/django/db/backends/
__init__.py", line 75, in cursor
cursor = self._cursor()

  File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/
base.py", line 297, in _cursor
self.connection = Database.connect(**kwargs)

  File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 81, in
Connect

  File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line
215, in __init__

  File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line
294, in set_character_set

InterfaceError: (0, '')


,
POST:,
COOKIES:{'__utma':
'81870849.504635047.1291000318.1291000318.1291000318.1',
 '__utmb': '81870849.1.10.1291000318',
 '__utmc': '81870849',
 '__utmz': '81870849.1291000318.1.1.utmcsr=bing|utmccn=(organic)|
utmcmd=organic|utmctr=human%20anatomy%20for%20kids'},
META:{'AUTH_TYPE': None,
 'CONTENT_LENGTH': 0,
 'CONTENT_TYPE': None,
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT': 'application/x-ms-application, image/jpeg, application/
xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/
vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
application/x-shockwave-flash, */*',
 'HTTP_ACCEPT_LANGUAGE': 'en-US',
 'HTTP_CONNECTION': 'Close',
 'HTTP_COOKIE':
'__utma=81870849.504635047.1291000318.1291000318.1291000318.1;
__utmb=81870849.1.10.1291000318; __utmc=81870849;
__utmz=81870849.1291000318.1.1.utmcsr=bing|utmccn=(organic)|
utmcmd=organic|utmctr=human%20anatomy%20for%20kids',
 'HTTP_HOST': 'nydn.findingdulcinea.com',
 'HTTP_REFERER': 'http://www.findingdulcinea.com/guides/Science/Human-
Anatomy.pg_00.html',
 'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT
6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR
3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0;
HPNTDF; .NET4.0C)',
 'HTTP_X_FORWARDED_FOR': '67.143.191.85',
 'PATH_INFO': u'/nydailynews/happybirthday1/',
 'PATH_TRANSLATED': None,
 'QUERY_STRING': None,
 'REMOTE_ADDR': '67.142.171.22',
 'REMOTE_HOST': None,
 'REMOTE_IDENT': None,
 'REMOTE_USER': None,
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': '',
 'SERVER_NAME': 'nydn.findingdulcinea.com',
 'SERVER_PORT': 80,
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SOFTWARE': 'mod_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:/

Django - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Victor Hooi
Hi,

I'm wondering what the community's stance on using NULL in Django is?

Say for example you have:

class Person(models.Model):
street_address = models.CharField(max_length=50, blank=True)
suburb = models.CharField(max_length=30)
postcode = models.IntegerField()
state = models.CharField(max_length=3)
email = models.EmailField()
mobile_phone_number = models.IntegerField(max_length=12)
home_phone_number = models.IntegerField(max_length=10,
null=True, blank=True)
work_phone_number = models.IntegerField(max_length=8,
null=True, blank=True)

   spouse = models.ForeignKey('self', null=True, blank=True)
   children = models.ManyToManyField('self', null=True,
blank=True)

For string fields like street_address, I can make these "blank=True",
and Django will store an empty string if the user leaves it blank.

However, for integer fields like home_phone_number and
work_phone_number, I've had to make these "null=True" for the case
where somebody doesn't supply them (i.e. they're meant to be optional,
mobile is required).

However, is there a better way of handling this case? (assuming I want
to keep these fields as integers).

What about in the case of optional foreign keys (spouse and children)
- is there a better way of handling these, without using NULLs?

Cheers,
Victor

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



Re: Django timestamp to Javascript timestamp

2010-11-29 Thread Bill Freeman
Unix (and python) timestamps are also from the beginning of Jan 1, 1970, but are
in seconds, so you might think that multiplying by 1000 would be enough.  But
unix timestamps (and, presumably, their emulation on Windows) are in GMT, while
JavaScript, if memory serves, uses the browser's local machine's timezone.  JS
data/time manipulations have enough stuff to fix this, but you have to
work a bit,
including considering whether you are in daylight savings time, etc..

Bill

On Mon, Nov 29, 2010 at 1:16 PM, Matt  Thompson  wrote:
> Hello guys and girls,
>
> I'm looking to use Flot to graph some data I have in my Django app.
> I'd like to graph a time based query and need to get the time is
> Javascript format (milliseconds since 01/01/1970).
>
> I can get it into seconds\unix format, this is seconds since
> 01/01/1970, but not milliseconds.
>
> Can anyone help?
>
> 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.



DEBUG=False and emailing pretty html

2010-11-29 Thread Sells, Fred
Is there an easy way to get django to email error tracebacks in the
pretty html format that it uses when Debug=True?

I've got it emailing plain text, but that requires I "reconstruct" the
url from the query string while the html version had it nicely presented
-- not the end of the world, but would be nice.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 timestamp to Javascript timestamp

2010-11-29 Thread Brett Thomas
I found it easiest to use the javascript date constructor with a date
string. Just have Django output the date in whatever time zone you want it
displayed to the user:

var d=new Date("November 29, 2010 9:22:00");

Unfortunately Django's default Date display, the ISO standard, prints a
string that cannot be read by javascript, so:

var d=new Date("{{ mymodel.date }}");

will not work out of the box.

If you change the DATETIME_FORMAT setting to "r", some other standard, the
above will work.

Also...you are using a DateTimeField, not a DateField, right?




On Mon, Nov 29, 2010 at 8:47 PM, Bill Freeman  wrote:

> Unix (and python) timestamps are also from the beginning of Jan 1, 1970,
> but are
> in seconds, so you might think that multiplying by 1000 would be enough.
>  But
> unix timestamps (and, presumably, their emulation on Windows) are in GMT,
> while
> JavaScript, if memory serves, uses the browser's local machine's timezone.
>  JS
> data/time manipulations have enough stuff to fix this, but you have to
> work a bit,
> including considering whether you are in daylight savings time, etc..
>
> Bill
>
> On Mon, Nov 29, 2010 at 1:16 PM, Matt  Thompson 
> wrote:
> > Hello guys and girls,
> >
> > I'm looking to use Flot to graph some data I have in my Django app.
> > I'd like to graph a time based query and need to get the time is
> > Javascript format (milliseconds since 01/01/1970).
> >
> > I can get it into seconds\unix format, this is seconds since
> > 01/01/1970, but not milliseconds.
> >
> > Can anyone help?
> >
> > 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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Adam V.
A "phone number" is actually a character string, not an integer; so
use CharField for these as well.
For optional foreign keys, the standard (only?) database way to handle
these is indeed with a NULL value.

On Nov 29, 5:28 pm, Victor Hooi  wrote:
> Hi,
>
> I'm wondering what the community's stance on using NULL in Django is?
>
> Say for example you have:
>
>     class Person(models.Model):
>         street_address = models.CharField(max_length=50, blank=True)
>         suburb = models.CharField(max_length=30)
>         postcode = models.IntegerField()
>         state = models.CharField(max_length=3)
>         email = models.EmailField()
>         mobile_phone_number = models.IntegerField(max_length=12)
>         home_phone_number = models.IntegerField(max_length=10,
> null=True, blank=True)
>         work_phone_number = models.IntegerField(max_length=8,
> null=True, blank=True)
>
>        spouse = models.ForeignKey('self', null=True, blank=True)
>        children = models.ManyToManyField('self', null=True,
> blank=True)
>
> For string fields like street_address, I can make these "blank=True",
> and Django will store an empty string if the user leaves it blank.
>
> However, for integer fields like home_phone_number and
> work_phone_number, I've had to make these "null=True" for the case
> where somebody doesn't supply them (i.e. they're meant to be optional,
> mobile is required).
>
> However, is there a better way of handling this case? (assuming I want
> to keep these fields as integers).
>
> What about in the case of optional foreign keys (spouse and children)
> - is there a better way of handling these, without using NULLs?
>
> Cheers,
> Victor

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



Re: Django - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Lachlan Musicman
On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:
> Hi,
>
> I'm wondering what the community's stance on using NULL in Django is?
>
> Say for example you have:
>
>    class Person(models.Model):
>        street_address = models.CharField(max_length=50, blank=True)
>        suburb = models.CharField(max_length=30)
>        postcode = models.IntegerField()
>        state = models.CharField(max_length=3)
>        email = models.EmailField()
>        mobile_phone_number = models.IntegerField(max_length=12)
>        home_phone_number = models.IntegerField(max_length=10,
> null=True, blank=True)
>        work_phone_number = models.IntegerField(max_length=8,
> null=True, blank=True)
>
>       spouse = models.ForeignKey('self', null=True, blank=True)
>       children = models.ManyToManyField('self', null=True,
> blank=True)
>
> For string fields like street_address, I can make these "blank=True",
> and Django will store an empty string if the user leaves it blank.
>
> However, for integer fields like home_phone_number and
> work_phone_number, I've had to make these "null=True" for the case
> where somebody doesn't supply them (i.e. they're meant to be optional,
> mobile is required).
>
> However, is there a better way of handling this case? (assuming I want
> to keep these fields as integers).


Is it possible to know why you would want to keep them as integers?
Given that there are no mathematical functions that you would want to
apply to them


> What about in the case of optional foreign keys (spouse and children)
> - is there a better way of handling these, without using NULLs?

As I understand it, foreign keys are kept in the db as follows:

1. table_Person
2. table_Person_children
3. table_Person_spouse

table 2 has three columns: id, Person, Children
table 3 has three columns: id, Person, Spouse

or something to that effect.

Therefore, if there is no Spouse or Child, there is no entry for
Person in tables 2 or 3.



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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 admin photo upload

2010-11-29 Thread Kenneth Gonsalves
On Mon, 2010-11-29 at 17:17 -0200, Andre Terra wrote:
> For anyone else who's interested, I've heard great things about
> sorl-thumbnail too, haven't used it myself.
> 
> I hope all is fine with easy_thumbnail. 

easy_thumbnail is one of the forks from sorl-thumbnail which is retired
after doing yeoman service for several years.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Victor Hooi
heya,

Phone Number - Yup, you're both right, I'll be using CharField now,
and model validation to make sure they're digits.

Spouse/Children:

With children, a M2M field, there's a link table, and if you don't
have a spouse, then there won't be any lines in that table. So no need
for NULLs there. I've just tested it with just blank=True, and no
null=True - seems to do what I want (optional children).

With ForeignKeyField though, I thought this was simply an FK field,
with the ID number of the object we're relating/pointing stored in
that field? Isn't that how it works in a normal DB? Why is there a
separate Person_spouse table?

Is there any way to make this optional without using NULLs, or should
I make it a m2m field? (I suppose in theory you can have multiple
spouses...well, not under my jurisdiction, I guess...lol).

Cheers,
Victor

On Nov 30, 3:11 pm, Lachlan Musicman  wrote:
> On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:
> > Hi,
>
> > I'm wondering what the community's stance on using NULL in Django is?
>
> > Say for example you have:
>
> >    class Person(models.Model):
> >        street_address = models.CharField(max_length=50, blank=True)
> >        suburb = models.CharField(max_length=30)
> >        postcode = models.IntegerField()
> >        state = models.CharField(max_length=3)
> >        email = models.EmailField()
> >        mobile_phone_number = models.IntegerField(max_length=12)
> >        home_phone_number = models.IntegerField(max_length=10,
> > null=True, blank=True)
> >        work_phone_number = models.IntegerField(max_length=8,
> > null=True, blank=True)
>
> >       spouse = models.ForeignKey('self', null=True, blank=True)
> >       children = models.ManyToManyField('self', null=True,
> > blank=True)
>
> > For string fields like street_address, I can make these "blank=True",
> > and Django will store an empty string if the user leaves it blank.
>
> > However, for integer fields like home_phone_number and
> > work_phone_number, I've had to make these "null=True" for the case
> > where somebody doesn't supply them (i.e. they're meant to be optional,
> > mobile is required).
>
> > However, is there a better way of handling this case? (assuming I want
> > to keep these fields as integers).
>
> Is it possible to know why you would want to keep them as integers?
> Given that there are no mathematical functions that you would want to
> apply to them
>
> > What about in the case of optional foreign keys (spouse and children)
> > - is there a better way of handling these, without using NULLs?
>
> As I understand it, foreign keys are kept in the db as follows:
>
> 1. table_Person
> 2. table_Person_children
> 3. table_Person_spouse
>
> table 2 has three columns: id, Person, Children
> table 3 has three columns: id, Person, Spouse
>
> or something to that effect.
>
> Therefore, if there is no Spouse or Child, there is no entry for
> Person in tables 2 or 3.
>
>
>
>
>
>
>
> > Cheers,
> > Victor
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > 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: Current Django 1.3 Alpha 2 Documentation as PDF

2010-11-29 Thread derek
Hmm.  So you're not planning to upgrade the doc when the final release
is made...?!

On Nov 25, 4:22 pm, "ckar...@googlemail.com" 
wrote:
> Okay, please remind me ;-)
>
> On 25 Nov., 09:38, derek  wrote:
>
>
>
>
>
>
>
> > Please post a link to the PDF when the final release is available.
>
> > On Nov 21, 7:38 pm, "ckar...@googlemail.com" 
> > wrote:
>
> > > Sry for dublepost.
>
> > > For those who don't want to install all the *tex* libraries. Here is
> > > the link:http://ubuntuone.com/p/QFl/
>
> > > Have fun with printing and reading ;-)
>
> > > On 21 Nov., 18:00, "ckar...@googlemail.com" 
> > > wrote:
>
> > > > Are you interested in the current Django 1.3 Alpha 2 documentation as
> > > > PDF?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Mike Dewhirst

On 30/11/2010 4:26pm, Victor Hooi wrote:

heya,

Phone Number - Yup, you're both right, I'll be using CharField now,
and model validation to make sure they're digits.

Spouse/Children:


Victor

I'm coming in late on this and don't have the context for your design 
but I think there might be a better (perhaps more flexible) way to 
handle spouses and children without worrying about NULLs.


I really like a single table for everyone. After all spouses and 
children are persons too. You can use a separate table to hold named 
many-to-many relationships between the person table and itself.


If the relationship is "Spouse" then that relationship speaks for 
itself. Children can simultaneously have relationships with "Father", 
"Mother", "Step-mother" etc. Other persons can have "Ex-spouse" 
relationships when divorced etc.


If you can find any person then you can navigate through all the 
relationships to find all connected persons.


Finally, if someone has multiple spouses then they probably need 
counselling but at least you can represent it with multiple relationship 
records :)


Mike



With children, a M2M field, there's a link table, and if you don't
have a spouse, then there won't be any lines in that table. So no need
for NULLs there. I've just tested it with just blank=True, and no
null=True - seems to do what I want (optional children).

With ForeignKeyField though, I thought this was simply an FK field,
with the ID number of the object we're relating/pointing stored in
that field? Isn't that how it works in a normal DB? Why is there a
separate Person_spouse table?

Is there any way to make this optional without using NULLs, or should
I make it a m2m field? (I suppose in theory you can have multiple
spouses...well, not under my jurisdiction, I guess...lol).

Cheers,
Victor

On Nov 30, 3:11 pm, Lachlan Musicman  wrote:

On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:

Hi,



I'm wondering what the community's stance on using NULL in Django is?



Say for example you have:



class Person(models.Model):
street_address = models.CharField(max_length=50, blank=True)
suburb = models.CharField(max_length=30)
postcode = models.IntegerField()
state = models.CharField(max_length=3)
email = models.EmailField()
mobile_phone_number = models.IntegerField(max_length=12)
home_phone_number = models.IntegerField(max_length=10,
null=True, blank=True)
work_phone_number = models.IntegerField(max_length=8,
null=True, blank=True)



   spouse = models.ForeignKey('self', null=True, blank=True)
   children = models.ManyToManyField('self', null=True,
blank=True)



For string fields like street_address, I can make these "blank=True",
and Django will store an empty string if the user leaves it blank.



However, for integer fields like home_phone_number and
work_phone_number, I've had to make these "null=True" for the case
where somebody doesn't supply them (i.e. they're meant to be optional,
mobile is required).



However, is there a better way of handling this case? (assuming I want
to keep these fields as integers).


Is it possible to know why you would want to keep them as integers?
Given that there are no mathematical functions that you would want to
apply to them


What about in the case of optional foreign keys (spouse and children)
- is there a better way of handling these, without using NULLs?


As I understand it, foreign keys are kept in the db as follows:

1. table_Person
2. table_Person_children
3. table_Person_spouse

table 2 has three columns: id, Person, Children
table 3 has three columns: id, Person, Spouse

or something to that effect.

Therefore, if there is no Spouse or Child, there is no entry for
Person in tables 2 or 3.








Cheers,
Victor



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group 
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.



Issues importing models in between apps

2010-11-29 Thread Victor Hooi
Hi,

I had an application with a fairly large models.py file, which I split
up into separate apps to make it easier to manage.

Two of the apps are called "conferences" and "people", each with their
own models.py.

These two are fairly tightly entwined, they each refer to each other.

At the top of project_name/conferences/models.py, I have:

from django.db import models
from nextgen.people.models import Person

At the top of project_name/people/models.py, I have:

from django.db import models
from project_name.conferences.models import Conference

However, when I try to run ./manage.py validate, it gives me an error:

  File "/sites/.virtualenvs/project_name/src/django/django/utils/
importlib.py", line 35, in import_module
__import__(name)
  File "/home/victorhooi/djangoProjects/project_name/../
project_name/conferences/models.py", line 2, in 
from project_name.people.models import Person
  File "/home/victorhooi/djangoProjects/project_name/../
project_name/people/models.py", line 3, in 
from project_name.conferences.models import Conference
ImportError: cannot import name Conference

I'm not sure why this is happening - from the looks of it, it's
opening up conferences/models.py, then importing people.models.Person
from there, which inside of that tries to import Conference - is it
somehow clashing?

Or is there a better way of creating multiple apps that all share
models? The main reason I split it up was for logically separating all
the different models, they still all need to import/relate to each
other.

Cheers,
Victor

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



Re: auth_user first_name and last_name editing

2010-11-29 Thread derek
Have you looked at:
http://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth.forms

Failing that, http://docs.djangoproject.com/en/dev/ref/generic-views/
may help get you going quickly.

On Nov 25, 8:08 pm, BozoJoe  wrote:
> So no builtin views and urls in any modules?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Victor Hooi
Mike,

Hmm, I'm currently using a recursive ('self') Many2Many and ForeignKey
for Children and Spouse, respectively (see source in the first post).

Is that what you meant?

Or perhaps I'm not quite getting what you mean - any chance you could
paste a models.py example so I can make sure I'm on the same page?

Cheers,
Victor

On Nov 30, 5:02 pm, Mike Dewhirst  wrote:
> On 30/11/2010 4:26pm, Victor Hooi wrote:
>
> > heya,
>
> > Phone Number - Yup, you're both right, I'll be using CharField now,
> > and model validation to make sure they're digits.
>
> > Spouse/Children:
>
> Victor
>
> I'm coming in late on this and don't have the context for your design
> but I think there might be a better (perhaps more flexible) way to
> handle spouses and children without worrying about NULLs.
>
> I really like a single table for everyone. After all spouses and
> children are persons too. You can use a separate table to hold named
> many-to-many relationships between the person table and itself.
>
> If the relationship is "Spouse" then that relationship speaks for
> itself. Children can simultaneously have relationships with "Father",
> "Mother", "Step-mother" etc. Other persons can have "Ex-spouse"
> relationships when divorced etc.
>
> If you can find any person then you can navigate through all the
> relationships to find all connected persons.
>
> Finally, if someone has multiple spouses then they probably need
> counselling but at least you can represent it with multiple relationship
> records :)
>
> Mike
>
>
>
>
>
>
>
>
>
> > With children, a M2M field, there's a link table, and if you don't
> > have a spouse, then there won't be any lines in that table. So no need
> > for NULLs there. I've just tested it with just blank=True, and no
> > null=True - seems to do what I want (optional children).
>
> > With ForeignKeyField though, I thought this was simply an FK field,
> > with the ID number of the object we're relating/pointing stored in
> > that field? Isn't that how it works in a normal DB? Why is there a
> > separate Person_spouse table?
>
> > Is there any way to make this optional without using NULLs, or should
> > I make it a m2m field? (I suppose in theory you can have multiple
> > spouses...well, not under my jurisdiction, I guess...lol).
>
> > Cheers,
> > Victor
>
> > On Nov 30, 3:11 pm, Lachlan Musicman  wrote:
> >> On Tue, Nov 30, 2010 at 12:28, Victor Hooi  wrote:
> >>> Hi,
>
> >>> I'm wondering what the community's stance on using NULL in Django is?
>
> >>> Say for example you have:
>
> >>>     class Person(models.Model):
> >>>         street_address = models.CharField(max_length=50, blank=True)
> >>>         suburb = models.CharField(max_length=30)
> >>>         postcode = models.IntegerField()
> >>>         state = models.CharField(max_length=3)
> >>>         email = models.EmailField()
> >>>         mobile_phone_number = models.IntegerField(max_length=12)
> >>>         home_phone_number = models.IntegerField(max_length=10,
> >>> null=True, blank=True)
> >>>         work_phone_number = models.IntegerField(max_length=8,
> >>> null=True, blank=True)
>
> >>>        spouse = models.ForeignKey('self', null=True, blank=True)
> >>>        children = models.ManyToManyField('self', null=True,
> >>> blank=True)
>
> >>> For string fields like street_address, I can make these "blank=True",
> >>> and Django will store an empty string if the user leaves it blank.
>
> >>> However, for integer fields like home_phone_number and
> >>> work_phone_number, I've had to make these "null=True" for the case
> >>> where somebody doesn't supply them (i.e. they're meant to be optional,
> >>> mobile is required).
>
> >>> However, is there a better way of handling this case? (assuming I want
> >>> to keep these fields as integers).
>
> >> Is it possible to know why you would want to keep them as integers?
> >> Given that there are no mathematical functions that you would want to
> >> apply to them
>
> >>> What about in the case of optional foreign keys (spouse and children)
> >>> - is there a better way of handling these, without using NULLs?
>
> >> As I understand it, foreign keys are kept in the db as follows:
>
> >> 1. table_Person
> >> 2. table_Person_children
> >> 3. table_Person_spouse
>
> >> table 2 has three columns: id, Person, Children
> >> table 3 has three columns: id, Person, Spouse
>
> >> or something to that effect.
>
> >> Therefore, if there is no Spouse or Child, there is no entry for
> >> Person in tables 2 or 3.
>
> >>> Cheers,
> >>> Victor
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups 
> >>> "Django users" group.
> >>> To post to this group, send email to django-us...@googlegroups.com.
> >>> To unsubscribe from this group, send email to 
> >>> django-users+unsubscr...@googlegroups.com.
> >>> For more options, visit this group 
> >>> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"

Re: Django - Alternative to using NULLs? (for integer and FK fields).

2010-11-29 Thread Mike Dewhirst

On 30/11/2010 5:10pm, Victor Hooi wrote:

Mike,

Hmm, I'm currently using a recursive ('self') Many2Many and ForeignKey
for Children and Spouse, respectively (see source in the first post).

Is that what you meant?

Or perhaps I'm not quite getting what you mean - any chance you could
paste a models.py example so I can make sure I'm on the same page?


Victor

I'm keeping track of companies, divisions and people with their 
relationships. For example, divisions can be traded between companies 
and people consult to companies or own trading entities. I can also keep 
track of pretty much any relationship of interest.


Hope this helps ...

class Entity(models.Model):
"""
Entities can be corporations or humans. entity_type indicates
which.
"""
entity_type = models.CharField(max_length=MEDIUM, blank=False,
choices=ENTITY_TYPES,
default=ENTITY_TYPES[0][0])
entity_name = models.CharField(max_length=LARGE, blank=False)
entity_title = models.CharField(max_length=SMALL, blank=True)
other_name = models.CharField(max_length=LARGE, blank=True)

slug = models.SlugField(max_length=VLARGE)

updated_by = models.ForeignKey(User, blank=True, null=True)
updated_date = models.DateTimeField(blank=True)
address = models.ForeignKey(Address, blank=True, null=True)

created = models.DateTimeField(auto_now_add=True)
saved = models.DateTimeField(auto_now=True)
saved_by = models.ForeignKey(User, blank=True, null=True,
related_name='entity_saved_by')
class Meta:
verbose_name_plural = 'entities'

def __unicode__(self):
ename = u' '.join(self.entity_title,
  self.other_name,
  self.entity_name)
return u'%s: %s (%s)' % (self.pk,
  ename.strip(),
  self.entity_type)


class Relationship(models.Model):
entity = models.ForeignKey(Entity, null=False,
related_name='rel_entity')
xref = models.ForeignKey(Entity, null=False,
related_name='xref_entity')
relationship = models.CharField(max_length=MEDIUM, blank=False,
choices=RELATIONSHIPS,
default=RELATIONSHIPS[0][0])
comment = models.CharField(max_length=HUGE, blank=True)
start_date = models.DateTimeField(blank=True, null=True)
end_date = models.DateTimeField(blank=True, null=True)

created = models.DateTimeField(auto_now_add=True)
saved = models.DateTimeField(auto_now=True)
saved_by = models.ForeignKey(User, blank=True, null=True,
related_name='relationship_saved_by')

def __unicode__(self):
return u'%s: %s ' % (self.relationship, self.xref)


Mike



Cheers,
Victor

On Nov 30, 5:02 pm, Mike Dewhirst  wrote:

On 30/11/2010 4:26pm, Victor Hooi wrote:


heya,



Phone Number - Yup, you're both right, I'll be using CharField now,
and model validation to make sure they're digits.



Spouse/Children:


Victor

I'm coming in late on this and don't have the context for your design
but I think there might be a better (perhaps more flexible) way to
handle spouses and children without worrying about NULLs.

I really like a single table for everyone. After all spouses and
children are persons too. You can use a separate table to hold named
many-to-many relationships between the person table and itself.

If the relationship is "Spouse" then that relationship speaks for
itself. Children can simultaneously have relationships with "Father",
"Mother", "Step-mother" etc. Other persons can have "Ex-spouse"
relationships when divorced etc.

If you can find any person then you can navigate through all the
relationships to find all connected persons.

Finally, if someone has multiple spouses then they probably need
counselling but at least you can represent it with multiple relationship
records :)

Mike










With children, a M2M field, there's a link table, and if you don't
have a spouse, then there won't be any lines in that table. So no need
for NULLs there. I've just tested it with just blank=True, and no
null=True - seems to do what I want (optional children).



With ForeignKeyField though, I thought this was simply an FK field,
with the ID number of the object we're relating/pointing stored in
that field? Isn't that how it works in a normal DB? Why is there a
separate Person_spouse table?



Is there any way to make this optional without using NULLs, or should
I make it a m2m field? (I suppose in theory you can have multiple
spouses...well, not under my jurisdiction, I guess...lol).



Cheers,
Victor



On Nov 30, 3:11 pm, Lachlan Musicmanwrote:

On Tue, Nov 30, 2010 at 12:28, Victor Hooiwrote:

Hi,



I'm wondering what the community's stance on using NULL in Django is?



Say for example you have:



 class Person(models.Model):
 street_address = models.CharFiel

Choices vs. ForeignKeys (was: Django - Alternative to using NULLs? (for integer and FK fields).)

2010-11-29 Thread Todd Wilson
Mike Dewhirst wrote, on 11/29/2010 10:33 PM:
> I'm keeping track of companies, divisions and people with their
> relationships. For example, divisions can be traded between companies
> and people consult to companies or own trading entities. I can also keep
> track of pretty much any relationship of interest.
> 
> Hope this helps ...
> 
> class Entity(models.Model):
> """
> Entities can be corporations or humans. entity_type indicates
> which.
> """
> entity_type = models.CharField(max_length=MEDIUM, blank=False,
> choices=ENTITY_TYPES,
> default=ENTITY_TYPES[0][0])

Although this is not directly related to the question that started this
thread, your example raises a question that I've had as I've read the
documentation.  Instead of hard-coding the entity types here, you are
using a constant, presumably because you may want to introduce more
entity types later.  But what are the trade-offs bewteen representing
types as CharFields with choices, as you are doing here, versus a
separate table of types to which this model has a foreign-key
relationship?  I'm facing this decision in a number of different places
in a Django application I'm working on.

Thanks,

--Todd

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