Testing uploads and content types

2009-01-22 Thread Julien Phalip

Hi,

I have a view which processes a multi-part form and whose behaviour
varies depending on the content types of the uploaded files. I've
written some tests for that view as follows:

post_data = {
'name1': 'blah',
'file_field1': image_data,
}
response = self.client.post('/upload/', post_data)

But the problem is that (apparently by design) all files are
systematically encoded with the content type 'application/octet-
stream'.

I have found a way around that, but only by writing a very long piece
of code to create a customised request from scratch:

payload = []
payload.extend([
'--' + client.BOUNDARY,
'Content-Disposition: form-data; name="name1"',
'',
'blah'
])
payload.extend([
'--' + client.BOUNDARY,
'Content-Disposition: form-data; name="file_field1";
filename="image1.png"',
'Content-Type: image/png',
'',
image_data
])
payload.extend([
'--' + client.BOUNDARY + '--',
'',
])
payload = "\r\n".join(payload)

r = {
'CONTENT_LENGTH': len(payload),
'CONTENT_TYPE':   client.MULTIPART_CONTENT,
'PATH_INFO':  "/upload/",
'REQUEST_METHOD': 'POST',
'wsgi.input': client.FakePayload(payload),
}
response = self.client.request(**r)

Is there a more concise or more elegant way to do?

Thanks a lot for your help,

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



Re: The SQL "IN" operator

2009-01-22 Thread Mihai Călin Bazon
Looks like I missed that...  Thanks, it's great!

-M.

On Fri, Jan 23, 2009 at 12:05 AM, szunyog  wrote:
>
> > But how can I do the following?:
> >
> >   p = Page.objects.filter(tags in [ 'Tag1', 'Tag2' ])
> >
> > (of course it doesn't work, but it hopefully explains what I need..)
>
> check this: http://docs.djangoproject.com/en/dev/ref/models/querysets/#in
>
> Regards,
> Tibor
> >



--
Mihai Bazon,
http://mihai.bazon.net/blog

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



Re: The SQL "IN" operator

2009-01-22 Thread krylatij

There is a very good solution for tagging 
http://code.google.com/p/django-tagging/
try this, it will save you a waste of time
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Comparing values from multiple tables; *show new posts* forum feature

2009-01-22 Thread Piotr Husiatyński

On 18 Sty, 12:06, Malcolm Tredinnick  wrote:
> Wait a few days until ticket #7210 is resolved and you'll be able to use
> references to other fields as rhs values in filters. The work for that
> is nearly complete, so it's pretty close to being committed. I'm fairly
> sure that will help you there.

You mean #7210 http://code.djangoproject.com/ticket/7210 : "Added
expression support for QuerySet.update"
How that could solve my problem?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error: 'PersonForm' object is not callable

2009-01-22 Thread waltbrad



On Jan 23, 1:47 am, Alex Koshelev  wrote:
> You don't need to "call" form second time:
>
>         pForm = PersonForm(request.POST.copy(), instance=p)
>
> And pForm is the ready to use instance of form.
>
Thanks for that.  Would you know off hand where in the documentation I
could find that? I looked around but just couldn't find much on the
request.POST.copy function or it's use in modelforms.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OS X problem with an egg (maybe!)

2009-01-22 Thread Reza Muhammad

Hi Arbi,

I encountered a similar problem a while ago when I tried to install  
mod_python, MySQLdb on my OS X.  What seems to be the problem is that,  
by default mysqldb is only running on 32-bit, so you have to make sure  
that your MySQL, mod_python, MySQLdb and Apache running on 32-bit  
mode.  By default, Apache in OS X is running on 64-bit, so you have to  
change it to 32-bit mode. This link might help you: 
http://gidden.net/tom/2008/06/30/mysql-and-pdo-on-os-x-leopard-intel/ 
.  It's not exactly how to setup a MySQLdb, there is a part at the  
bottom on how to make Apache run on 32-bit mode.

Hope it helps,
Reza
On Jan 22, 2009, at 4:47 PM, arbi wrote:

>
> Hello every one,
>
> I am a new member in the Django community... But very beginner.
> I spent my whole day yesterday trying to run the "python manage.py
> syncdb" key but no success. I looked at many forums and this post
> seemed to be nice :
> http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/
>
> Now I have : Python 2.3 and 2.5 and mysql 32bits. Moreover I installed
> the "mysql-python 1.2.2" folder to tell Python where mysql is.
> I also did it : $ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/ 
> lib/
> mysql for compilation
> So I have everything!...
>
>
> ...But when I did "python manage.py syncdb" the terminal answers me :
>
> Traceback (most recent call last):
>  File "manage.py", line 11, in 
>execute_manager(settings)
>  File "/Library/Python/2.5/site-packages/django/core/management/
> __init__.py", line 340, in execute_manager
>utility.execute()
>  File "/Library/Python/2.5/site-packages/django/core/management/
> __init__.py", line 295, in execute
>self.fetch_command(subcommand).run_from_argv(self.argv)
>  File "/Library/Python/2.5/site-packages/django/core/management/
> base.py", line 192, in run_from_argv
>self.execute(*args, **options.__dict__)
>  File "/Library/Python/2.5/site-packages/django/core/management/
> base.py", line 218, in execute
>self.validate()
>  File "/Library/Python/2.5/site-packages/django/core/management/
> base.py", line 246, in validate
>num_errors = get_validation_errors(s, app)
>  File "/Library/Python/2.5/site-packages/django/core/management/
> validation.py", line 22, in get_validation_errors
>from django.db import models, connection
>  File "/Library/Python/2.5/site-packages/django/db/__init__.py", line
> 16, in 
>backend = __import__('%s%s.base' % (_import_path,
> settings.DATABASE_ENGINE), {}, {}, [''])
>  File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
> base.py", line 13, in 
>raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> module: dlopen(/Users/brouard/.python-eggs/MySQL_python-1.2.2-py2.5-
> macosx-10.5-i386.egg-tmp/_mysql.so, 2): Library not loaded: /usr/ 
> local/
> mysql/lib/libmysqlclient_r.16.dylib
>  Referenced from: /Users/brouard/.python-eggs/MySQL_python-1.2.2-
> py2.5-macosx-10.5-i386.egg-tmp/_mysql.so
>  Reason: image not found
>
> I did not find the solution and I lost my hairs!
> Thanks for helping me! :)
>
> Arbi
>
>
> >


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



Re: Error: 'PersonForm' object is not callable

2009-01-22 Thread Alex Koshelev
You don't need to "call" form second time:

pForm = PersonForm(request.POST.copy(), instance=p)

And pForm is the ready to use instance of form.


On Fri, Jan 23, 2009 at 8:29 AM, waltbrad  wrote:

>
> Hi folks. PersonForm is a modelform.  I'm trying to validate data by
> calling an instance of PersonForm.  (This is from Sam's 24 hour, and
> I've modified the example to accommodate the 1.0 changes.)  So,
>
> if request.method == 'POST':
> if request.POST['submit'] == 'update':
>  message = 'Update Request for %s.' % p.name
>  pForm = PersonForm(instance=p)
>  c=pForm(request.POST.copy())
>
> And I get the error alluded to in the Subject line.  The author has
> something similar:
>
> if request.method == 'POST':
> if request.POST['submit'] == 'update':
>  message = 'Update Request for %s.' % p.name
>  PersonForm = forms.form_for_instance(p)
>  f = PersonForm(request.POST.copy())
>
> >
>

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



Re: Error when Resending forgotten password

2009-01-22 Thread Alex Koshelev
Try to check your EMAIL_ settings.


On Fri, Jan 23, 2009 at 8:55 AM, Oleg Oltar  wrote:

> Hi! I am getting a strange error when trying to reset, forgotten password.
> I am using it this way
>
># Password resend group
>(r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$',
> 'django.contrib.auth.views.password_reset_confirm',
> {'template_name':'registration/password_reset_confirm.html'}),
>
>(r'^resend/$',
> 'django.contrib.auth.views.password_reset',
> {'template_name':'registration/password_reset_form.html',
> 'email_template_name':'registration/password_reset_email.html',
> 'post_reset_redirect':'/'}),
>)
>
>
> The error
>
> Environment:
>
> Request Method: POST
> Request URL: http://127.0.0.1:8000/resend/
> Django Version: 1.0.2 final
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'loginregister.loginreg']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py"
> in get_response
>   86. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/usr/local/lib/python2.5/site-packages/django/contrib/auth/views.py"
> in password_reset
>   92. form.save(**opts)
> File "/usr/local/lib/python2.5/site-packages/django/contrib/auth/forms.py"
> in save
>   135. t.render(Context(c)), None, [user.email])
> File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in
> send_mail
>   345. connection=connection).send()
> File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in send
>   271. return
> self.get_connection(fail_silently).send_messages([self])
> File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in
> send_messages
>   166. new_conn_created = self.open()
> File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in open
>   131.
>  local_hostname=DNS_NAME.get_fqdn())
> File "/usr/local/lib/python2.5/smtplib.py" in __init__
>   244. (code, msg) = self.connect(host, port)
> File "/usr/local/lib/python2.5/smtplib.py" in connect
>   310. raise socket.error, msg
>
> Exception Type: error at /resend/
> Exception Value: (49, "Can't assign requested address")
>
>
> Can you please help me to understand the problem?
>
> Thanks,
> Oleg
>
> >
>

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



Re: handling object hierarchies in templates

2009-01-22 Thread thedevilsprogram...@gmail.com

Oh, and my model

class Category(models.Model):

parent = models.ForeignKey('self', null=True)
slug = models.SlugField()
title = models.CharField(max_length=50)

def __unicode__(self):
return self.title

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



handling object hierarchies in templates

2009-01-22 Thread thedevilsprogram...@gmail.com

Lets say I have a bunch of categories which can optionally contain
subcategories... What would be the ideal way to go about a) preparing
this data for my templates, and b) displaying this data in m templates

Here is what I currently have.. it feels dirty

---
def article_browser(request, c):

categories = Category.objects.filter(parent__isnull=True).order_by
('title')

for category in categories:
category.children = 
category.category_set.all().order_by('title')


c = RequestContext(request,{
'categories': categories,
})




then in my template

-

{% for category in categories %}




{{ category.title }}



{% if category.children %}



{% for category in category.children %}


{{ category.title }}

{% endfor %}



{% endif %}

{% endfor %}
--

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



Flash ExternalInterface and GAE

2009-01-22 Thread BTang

I've been struggling with this for the past couple hours now and I
really don't know what could be wrong. I'm simply trying to get
Javascript to communicate text with Flash. I found this great example
with this source

http://blog.circlecube.com/wp-content/uploads/2008/02/ActionscriptJavascriptCommunication.zip

I ran the html file locally and it works just fine sending and
retrieving text from flash. Then I load that same exact sample into my
dev google app server and I can't send the text from javascript to
flash. Oddly enough though flash is able to send Javascript text. Can
anybody see if they can get this running with GAE? Thanks a million!

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



Error when Resending forgotten password

2009-01-22 Thread Oleg Oltar
Hi! I am getting a strange error when trying to reset, forgotten password.
I am using it this way

   # Password resend group
   (r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$',
'django.contrib.auth.views.password_reset_confirm',
{'template_name':'registration/password_reset_confirm.html'}),

   (r'^resend/$',
'django.contrib.auth.views.password_reset',
{'template_name':'registration/password_reset_form.html',
'email_template_name':'registration/password_reset_email.html',
'post_reset_redirect':'/'}),
   )


The error

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/resend/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'loginregister.loginreg']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/local/lib/python2.5/site-packages/django/contrib/auth/views.py"
in password_reset
  92. form.save(**opts)
File "/usr/local/lib/python2.5/site-packages/django/contrib/auth/forms.py"
in save
  135. t.render(Context(c)), None, [user.email])
File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in
send_mail
  345. connection=connection).send()
File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in send
  271. return
self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in
send_messages
  166. new_conn_created = self.open()
File "/usr/local/lib/python2.5/site-packages/django/core/mail.py" in open
  131.
 local_hostname=DNS_NAME.get_fqdn())
File "/usr/local/lib/python2.5/smtplib.py" in __init__
  244. (code, msg) = self.connect(host, port)
File "/usr/local/lib/python2.5/smtplib.py" in connect
  310. raise socket.error, msg

Exception Type: error at /resend/
Exception Value: (49, "Can't assign requested address")


Can you please help me to understand the problem?

Thanks,
Oleg

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



Error: 'PersonForm' object is not callable

2009-01-22 Thread waltbrad

Hi folks. PersonForm is a modelform.  I'm trying to validate data by
calling an instance of PersonForm.  (This is from Sam's 24 hour, and
I've modified the example to accommodate the 1.0 changes.)  So,

if request.method == 'POST':
 if request.POST['submit'] == 'update':
  message = 'Update Request for %s.' % p.name
  pForm = PersonForm(instance=p)
  c=pForm(request.POST.copy())

And I get the error alluded to in the Subject line.  The author has
something similar:

if request.method == 'POST':
 if request.POST['submit'] == 'update':
  message = 'Update Request for %s.' % p.name
  PersonForm = forms.form_for_instance(p)
  f = PersonForm(request.POST.copy())

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



Re: Anyway to see full UrlConf list of available imported urls?

2009-01-22 Thread Eric Abrahamsen

Here's one way. There's likely a cleaner option somewhere else:

from django.core.urlresolvers import get_resolver

r = get_resolver('mysite.urls')

for pattern in r._get_url_patterns(): print pattern

That works, at any rate.

Yours,
Eric


On Jan 23, 2009, at 3:55 AM, NoviceSortOf wrote:

>
>
> * Is there a way to see a full URLConf list of all the imported URLs,
> in
>  an application?
>
> This seems it would be a big debuging 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Disabling middleware for tests

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 15:17 -0800, davenaff wrote:
> What is the best way to disable a specific middleware when running
> django tests?
> 
> This ticket was designated wontfix, so I get test failures on the auth
> tests every time I run our test suite:
> http://code.djangoproject.com/ticket/9172#comment:12
> 
> I'd prefer not to have to edit settings.py every time I run our tests,
> and of course I don't like tests that fail...

Create a settings file for your testing purposes. It imports your
standard settings file and then modifies any settings that are specific
for the tests (e.g. altering the MIDDLEWARE_CLASSES tuple).

Regards,
Malcolm



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



Re: mod python child server won't start

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 12:01 -0800, May wrote:
> Hello,
> 
> I set up a windows XP(python 2.5, apache 2.2) startproject called
> myprograms and used this code in http.conf (this works and server
> starts):
> 
> SetHandler python-program
> PythonPath "['C:/django'] + sys.pat"

If this is a cut and paste, you've misspelled "path" in sys.path.
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE myprograms.settings
> PythonDebug On
> 
> I then set up an application under myprograms called cpssite and
> rewrote the http.conf code to this:
> 
> SetHandler python-program
> PythonPath "['C:/django'] + sys.pat"

Same typo here.

Regards,
Malcolm



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



Re: Convert iso-8859-1 queryset to utf-8

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 06:16 -0800, Polat Tuzla wrote:
> You may also want to make sure that you know whether your Flash/
> ActionScript components require UTF-8 with BOM (Byte-order Mark) or
> not.
> 
> Let me try to explain more clearly:
> In my case, I had i18n problems when a flash component rendered my
> utf-8 encoded templates.
> I had saved my templates as utf-8, had set the response headers as:
> 
> response = HttpResponse(mimetype='text/xml; charset=utf-8')
> 
> Nevertheless all of the characters that are out of ascii range were
> not displayed correctly.
> It turned out to be that my text editor (TextMate) was saving the file
> as UTF-8 without BOM for some good reasons.
> (http://blog.macromates.com/2005/handling-encodings-utf-8/)
> And the flash component required UTF-8 with BOM in order to display
> correctly.

Wow, that's pretty bad behaviour on the part of the flash component
(hope you reported the bug). BOMs are valid in UTF-8, but should never,
ever, be required, otherwise the tool cannot say that it handles UTF-8,
since BOMs are entirely optional.

It's annoying enough that some editors save UTF-8 with the BOM mark.
There's no option about the byte order in UTF-8! why are they wasting
space and processing time for everybody by specifying it? But for some
application to *require* it upon reading is just retarded.

Okay, rant over. I feel better now. But, that's just dumb. :-(

Malcolm


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



Re: why not load the index first?

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 19:46 +0530, Kenneth Gonsalves wrote:
> On Thursday 22 Jan 2009 7:31:07 pm Malcolm Tredinnick wrote:
> >  But please do understand that this isn't a
> > change that is necessarily universally better for everybody. It does
> > harm the content presentation, for example.
> 
> ok - I wont raise this again - but please check out the comments on the IRC 
> channel about the docs. End users are not happy.

Sure, some end users are not happy. That's always the case when
thousands of people are using something. Some are happy. Some are
delirious. Some don't care. Some, like me, think there are plenty of
improvements that could be made and are doing so, as time permits. It's
a big world out there; don't be swayed into thinking that one vocal
group is necessarily representative of the whole.

You'll notice that at no point in this thread am I saying that your
opinion is wrong for you, or that everybody likes the new structure.
It's simply not a black and white issue.

Malcolm


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



Re: Setting a field based on foreign key data

2009-01-22 Thread jason.t.stein

After a preliminary reading of your answer, the second solution seems
like what I am trying to do. Basically this is a simple Track and
Field competition manager, and one year a student will compete as a
midget and get a result for the 100m dash, and the next year compete
as a junior and get a result for the 100m dash.

Thank you for your time and effort.

On Jan 22, 5:15 pm, Russell Keith-Magee 
wrote:
> On Thu, Jan 22, 2009 at 10:57 PM, jason.t.stein  
> wrote:
>
> > Perhaps this is an sql question, and not a Django question so please
> > have patience. I am writing a student management app that keeps track
> > of student events. The relevant tables are:
>
> > class Student(models.Model):
> >  first_name = models.CharField(max_length=32)
> >  last_name = models.CharField(max_length=32)
> >  birth_date = models.DateField('Student Birth Date')
> >  gender = models.CharField(max_length=1, choices = GENDER_CHOICES)
> >  school = models.ForeignKey(School)
>
> > class Competitor(models.Model):
> >  student = models.ForeignKey(Student)
> >  track_meet = models.ForeignKey(TrackMeet)
> >  age_category = models.CharField(max_length=1, choices =
> > AGE_CATEGORY_CHOICES)
> >  event = models.CharField(max_length=16, choices = EVENT_CHOICES)
>
> > I want to set age_category, based on the age of a student on a certain
> > date. I can calculate the appropriate age, but am interested how to
> > set the age_category based on this calculation.
>
> > Any help is greatly appreciated. Thank you for your time.
>
> Hi Jason,
>
> There are several possible answers to your question, depending on how
> and when you want to set the age_category.
>
> Are you looking to do this as a bulk SQL operation (i.e., update every
> object at once)? In which case, the best way will be in raw SQL - you
> will need to investigate the CASE operator on your database of choice.
>
> Alternatively, if you are looking to set the initial age category when
> the competitor record is saved to the database, then all you need to
> do is override the save() method on your competitor. The following
> code is untested (and not particularly accurate as an age
> calculation), but should give you an idea of the approach:
>
>    def save(self, *args, **kwargs):
>       age = (date.today() - self.student.birth_date) / 365
>       if age > 10:
>           self.age_category = AGE_CATEGORY.SENIOR
>       else:
>           self.age_category = AGE_CATEGORY.JUNIOR
>       super(Competitor, self).save(*args, **kwargs)
>
> It's also worth asking whether the age category needs to be in the
> database at all. If it is purely derived from the age of the student,
> there may be an argument for not storing it in the database at all,
> and computing the age category whenever it is required.
>
> Hope this helps,
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Pickling a dictionary into a PostgreSQL database?

2009-01-22 Thread teth

Thank you for the tip. I was actually in the middle of debugging a
problem which I think may have been solved by this post. I used
urlsafe_b64encode() and urlsafe_b64decode because a URL cannot contain
any non-ASCII characters (can it?). I could also have used the normal
b64 functions, but I wanted to be sure.

On Jan 21, 10:07 am, Torsten Bronger 
wrote:
> Hallöchen!
>
> teth writes:
> > Using str(pickle.dumps()) and thepickle.loads(str()) works
> > perfectly.
>
> Unfortunately, I had to realise that it is not so simple due to
> .  Now it use the following
> functions:
>
> def ascii_pickle(python_object):
>     u"""Converts an arbitrary Python object to an ASCII-only string to be
>     written to thedatabase.  Unfortunately, even protocol 0 of Python's
>     ``pickle`` module may emit non-ASCII characters, see
>     .  However, this is dangerous since the
>    databaseexpects Unicode strings and can't decode such octet strings.
>     Therefore, this routine does another encoding step using base64.  This
>     makes debugging slightly more difficult, but there we go.
>
>     :Parameters:
>       - `python_object`: the object instance to be pickled
>
>     :type python_object: object
>
>     :Return:
>       the ASCII-only string representing the object instance
>
>     :rtype: str
>     """
>     # FixMe: Maybe instead of base64 another encoder should be used that keeps
>     # the string largely readable.
>     return base64.b64encode(pickle.dumps(python_object, protocol=2))
>
> def ascii_unpickle(string):
>     u"""This is the inverse function of `ascii_pickle`.
>
>     :Parameters:
>       - `string`: the ASCII-onlydatabasestring to be unpickled
>
>     :type string: str
>
>     :Return:
>       the original Python object instance that was represented by the string
>
>     :rtype: object
>     """
>     returnpickle.loads(base64.b64decode(string))
>
> Tschö,
> Torsten.
>
> --
> Torsten Bronger, aquisgrana, europa vetus
>                    Jabber ID: torsten.bron...@jabber.rwth-aachen.de
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Fixtures in production use - best practices

2009-01-22 Thread Russell Keith-Magee

On Fri, Jan 23, 2009 at 5:31 AM, Delta20  wrote:
>
> Fixtures are geared towards unit testing; I'm wondering if they are
> considered a good way to populate the database with some initial
> default values.
>
> For example, say we have a model TicketState, and the applications
> must be guaranteed to have two TicketStates representing the states
> "Open" and "Closed", and we want to make it so the user can add more
> TicketStates as needed.

This is exactly what the initial_data fixture is designed for. I have
used the initial_data fixture in this capacity on several deployed
sites.

> Is this something that would best be addressed by using fixtures? In
> particular, there doesn't seem to be a way to create fixtures
> programmaticly (rather than importing JSON or YAML data), which means
> that somewhere in the code you would need to have magic values to
> refer to the default models that were loaded (a magic value is some
> arbitrary string or number, rather than using constants or some other
> more controlled approach that is less likely to break later in
> mysterious ways). For example:
>
># if no state, assign the default state
>if not ticket.status:
># Below is bad practice, uses a magic value
>ticket.status = TicketStatus.objects.get(name='Open')

This is essentially the approach taken by the content_types contrib
app. The ContentTypes app uses a management hook (see management.py in
the contrib app), which listens for the post_sycndb signal and creates
the default content types when that signal is heard. This approach
works - although, as you have noted, it does mean you can't rely on
the primary key values for any given content type (which, in turn,
causes problems for fixtures). ContentTypes optimizes the process
slightly by introducing a cache for content type lookups.

> Would a different approach be better, such as a having a get_or_create
> method that creates the default instance if it doesn't exist already
> (rather than using fixtures)?

The 'Create on demand' approach would also work, but it might
complicate some logic - essentially, no code could ever assume that
the default states were available. However, providing you follow
through the consequences, it should work fine.

Yours,
Russ Magee %-)

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



Re: problems getting urls to import

2009-01-22 Thread davenaff

the urlpatterns += line looks right, but I don't really know what
you're doing with the # lines.  Could you post the full
mysite.myproject.urls file?

On Jan 22, 9:18 am, NoviceSortOf  wrote:
> Looking at mysite.myproject.urls I have...
>
> urlpatterns += patterns('', (r'^profiles/', include
> ('profiles.urls')), )
>
> But can't get the profiles.urls to import
>
> My URLconf list includes
>
> # ^accounts/ ^activate/(?P\w+)/$
> # ^accounts/ ^login/$
> # ^accounts/ ^logout/$
> # ^accounts/ ^register/$
> # ^accounts/ ^register/complete/$
> ...(and so on, but for profiles only shows
> # ^profiles/
>
> Please advise
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Disabling middleware for tests

2009-01-22 Thread davenaff

What is the best way to disable a specific middleware when running
django tests?

This ticket was designated wontfix, so I get test failures on the auth
tests every time I run our test suite:
http://code.djangoproject.com/ticket/9172#comment:12

I'd prefer not to have to edit settings.py every time I run our tests,
and of course I don't like tests that fail...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Setting a field based on foreign key data

2009-01-22 Thread Russell Keith-Magee

On Thu, Jan 22, 2009 at 10:57 PM, jason.t.stein  wrote:
>
> Perhaps this is an sql question, and not a Django question so please
> have patience. I am writing a student management app that keeps track
> of student events. The relevant tables are:
>
> class Student(models.Model):
>  first_name = models.CharField(max_length=32)
>  last_name = models.CharField(max_length=32)
>  birth_date = models.DateField('Student Birth Date')
>  gender = models.CharField(max_length=1, choices = GENDER_CHOICES)
>  school = models.ForeignKey(School)
>
> class Competitor(models.Model):
>  student = models.ForeignKey(Student)
>  track_meet = models.ForeignKey(TrackMeet)
>  age_category = models.CharField(max_length=1, choices =
> AGE_CATEGORY_CHOICES)
>  event = models.CharField(max_length=16, choices = EVENT_CHOICES)
>
> I want to set age_category, based on the age of a student on a certain
> date. I can calculate the appropriate age, but am interested how to
> set the age_category based on this calculation.
>
> Any help is greatly appreciated. Thank you for your time.

Hi Jason,

There are several possible answers to your question, depending on how
and when you want to set the age_category.

Are you looking to do this as a bulk SQL operation (i.e., update every
object at once)? In which case, the best way will be in raw SQL - you
will need to investigate the CASE operator on your database of choice.

Alternatively, if you are looking to set the initial age category when
the competitor record is saved to the database, then all you need to
do is override the save() method on your competitor. The following
code is untested (and not particularly accurate as an age
calculation), but should give you an idea of the approach:

   def save(self, *args, **kwargs):
  age = (date.today() - self.student.birth_date) / 365
  if age > 10:
  self.age_category = AGE_CATEGORY.SENIOR
  else:
  self.age_category = AGE_CATEGORY.JUNIOR
  super(Competitor, self).save(*args, **kwargs)

It's also worth asking whether the age category needs to be in the
database at all. If it is purely derived from the age of the student,
there may be an argument for not storing it in the database at all,
and computing the age category whenever it is required.

Hope this helps,

Yours,
Russ Magee %-)

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



Re: How do i display a count of items related to a model?

2009-01-22 Thread Russell Keith-Magee

On Thu, Jan 22, 2009 at 10:37 PM, Gath  wrote:
>
> In Django how can i return the total number of items (count) that a
> related to another model, e.g the way stackoverflow.com does a list of
> questions then on the side it shows the count on the answers related
> to that question.
>
> This is easy if i get the questionid, i can return all answers related
> to that question but when am displaying the entire list of question it
> becomes a bit tricky to display on the side the count showing the
> total answer count.
>
> I don't know if am clear but just think how www.stackoverflow.com
> displays its questions with answer,views count next to each question!

There are several ways you could do this:

1) Dropping to a raw SQL query is always an option. Get a database
cursor, and issue a query with the required GROUP BY to evaluate the
counts.

2) If you're using Django trunk (and soon in v1.1) you can use
annotate() to add an aggregate count to the question object:

for q in Question.objects.annotate(n_votes=Count('votes')):
print q.text, q.n_votes

See the documentation for more details on annotate()

3) Denormalize your relations, and store the answer/view/vote count on
the question table. On a very high traffic site, this could be a
useful optimization as it lets you get your answer  without requiring
a table join.

There are a few other options, but this covers the common ones.

Yours,
Russ Magee %-)

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



Re: install django on a shared host, with fastcgi

2009-01-22 Thread anode

I've managed to successfully install django running fcgi on my shared
host, but I've got to warn you, it's not usually an easy path. Took me
ages.

It's usually much, much easier to use a django-friendly host such as
webfaction, but anyway, here a couple of points from a non-expert.

1) Are you typing "http:///home/pri*/public_html/
django.fcgi/visual**/" or "http:///django.fcgi"
into your browser? Your error message seems to suggest you're using
the former instead of the latter. Should be the latter, but...

2) I don't think the latter would work anyway. The usual setup is to
have a .htaccess file in your public_html directory with a mod_rewrite
rule that takes all requests to your domain, and redirects them to
your django.fcgi file, which then spawns the fcgi process that django
runs within. Don't forget that the  django.fcgi file needs to have
permissions that allow it to be executed.

If you've got time to burn and want to learn the hard way (not always
a bad thing :)  ), then keep going down the fcgi route. If you want to
get up and running on a shared host quickly, find someone who runs a
more django friendly setup, which usually involves using mod_python.



On Jan 21, 11:41 pm, "codediscuss.com"  wrote:
> Hello,
>
> I'm new to python, apache and django. I'm trying to install django on
> my shared host (hostmonster). I searched for some tutorials and
> followed them but no luck.
>
> Here is the page I get when I try to visit my site:
>
> Not Found
>
> The requested URL /home/pri*/public_html/django.fcgi/visual**/
> was not found on this server.
>
> Additionally, a 404 Not Found error was encountered while trying to
> use an ErrorDocument to handle the request
>
> pri is my account name.
> django.fcgi is created by me following some tutorials
> Visual* is my web site name, which is a sub folder on the shared
> host.
>
> I need help to step into the world of django and 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: run function on session.flush()

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 11:55 -0800, Abe wrote:
> I would like to run a function (in my case, send an email summarizing
> recent activity) when a user logs out *or* when their session
> expires.  Is there an easy way to do it without making a new version
> of the Session class?

No.

Regards,
Malcolm



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



Re: The SQL "IN" operator

2009-01-22 Thread szunyog

> But how can I do the following?:
>
>   p = Page.objects.filter(tags in [ 'Tag1', 'Tag2' ])
>
> (of course it doesn't work, but it hopefully explains what I need..)

check this: http://docs.djangoproject.com/en/dev/ref/models/querysets/#in

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



Re: TypeError: Related Field has invalid lookup: icontains

2009-01-22 Thread Alessandro Ronchi

2009/1/22 Karen Tracey :

> Ah, you have in your search_fields for SchedaBilancioGenereOptions
> 'impresa', which is a ForeignKey.  You need to specify what field within the
> related model you want to search, so 'impresa__fieldname'.  (If there are
> multiple fields you need to list each explicitly, using the standard
> double-underscore syntax.)

You was right!

Thanks a lot!

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

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



Re: Recommendation on understanding CSS

2009-01-22 Thread rknobelspies

If learning-by-doing is your thing I would recommend having a look at
www.nettuts.com
and especially the css tutorials:

http://nettuts.com/tutorials/site-builds/from-psd-to-html-building-a-set-of-website-designs-step-by-step/
http://nettuts.com/tutorials/tools-and-tips/how-to-theme-any-cms-using-firebug-with-a-wiki-example/
http://nettuts.com/tutorials/html-css-techniques/solving-5-common-css-headaches/
http://nettuts.com/tutorials/html-css-techniques/5-time-saving-cssedit-tips/
http://nettuts.com/videos/screencasts/how-to-convert-a-psd-to-xhtml/
http://nettuts.com/articles/web-roundups/are-you-making-these-10-css-mistakes/
http://nettuts.com/videos/screencasts/converting-a-design-from-psd-to-html/

On 21 Jan., 09:52, Gath  wrote:
> Guys,
>
> Its seems the best way to do templates in Django is via plain html and
> css, but am having a problem in understanding css easily, can someone
> recommend some nice material/site on css i can read, i mean step by
> step till complex stuff.
>
> Paul

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



Re: Admin list exclusions

2009-01-22 Thread szunyog

Hi,

You should create an admin class and override its queryset method.
Something like this:

class EntryAdmin(admin.ModelAdmin):
...
def queryset(self, request):
qs =  qs = super(EntryAdmin, self).queryset(request)
qs = qs.filter(specify your filter criteria)
return qs

admin.site.register(Entry, EntryAdmin)

Regards,
Tibor

On jan. 21, 15:19, "django_fo...@codechimp.net" 
wrote:
> I have a class called Entry that has a one-to-many relationship with
> itself like:
>
> class Entry(models.Model):
>     title = models.CharField(max_length=255)
>     body = models.TextField()
>     author = models.ForeignKey(User)
>     date_published = models.DateTimeField()
>     parent = models.ForeignKey('self',null=True,blank=True)
>
> When I go to the Admin page, I would like to exclude Entries that have
> a parent set, I.E. Entries that have parents should not show up in the
> list.  I have read through the Admin pages and the Meta pages several
> times, and nothing has jumped out at me on how to do this.  Its
> probably there, it just didn't register.
>
> Can someone please lend me a hand and point me in the correct location?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



The SQL "IN" operator

2009-01-22 Thread Mihai Bazon

First off, hi everybody! ;-)  I'm new to Python and I'm new to
Django.  Just testing things out for now.  I have a huge experience
with Perl but I'm getting fed up with the overloaded syntax and all
those "$"-s and "@"-s and "%"-s and "@{ $ }"-s etc.  (though I
sometimes miss them in Python, but this is definitely for another
discussion group).

I have one quick question I couldn't find an answer for: I have two
model classes: Page and Tag.  They share a ManyToManyField relation
(that is a page can have more tags, and of course, one tag can select
multiple pages).

I was wondering how would I write a query (in Django's syntax, ofc)
that selects pages from multiple categories.

  class Page(M.Model):

tags   = M.ManyToManyField ("Tag")

  class Tag(M.Model): 

The following works:

  p = Page.objects.filter(tags = 'SomeTag')

But how can I do the following?:

  p = Page.objects.filter(tags in [ 'Tag1', 'Tag2' ])

(of course it doesn't work, but it hopefully explains what I need..)

Cheers,
-Mihai

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



Re: Possible Model Inheritance Issue? Error: [Model_Name] instance needs to have a primary key value before a many-to-many relationship can be used

2009-01-22 Thread Keyton Weissinger

Hi Malcolm,

Thank you VERY much for taking the time to explain this to me. It
makes perfect sense and since yesterday I've delved a bit deeper (than
ever) into the django code itself to understand a little more. You are
ABSOLUTELY right to point out that I'm in user-beware country. I don't
apologize for that so much. I think the batchimport project has some
usefulness to folks and it's worth the risk -- **IF** I do it
right. ;-) (if you think otherwise, PLEASE let me know)

Even since yesterday I've begun a good scouring of the project to
reduce touching the internals as much as possible.

I apologize for not giving more details. I am always trying to balance
giving enough information while trying to avoid scaring people away
with too much detail. I didn't think it through enough I suppose. I
kept being stymied by the thing "working" on the command line. My
mistake.

Anyway. I understand the whole thing MUCH better now and have already
spent a little time reviewing the really "cutting edge" aspects of
this project like, you know, "how lists work in python." ;-)

Ugh.

Kicking Myself Diligently,
Keyton

On Jan 22, 3:10 am, Malcolm Tredinnick 
wrote:
> On Wed, 2009-01-21 at 19:38 -0800,KeytonWeissinger wrote:
> > OK. I figured it out and it was VERY STRANGE. Maybe some one reading
> > this can tell me WWWHHHYYY my solution works. For now, it's voodoo to
> > me...
>
> You're going to kick yourself after this. The reason for the failure
> turns out to be really easy to understand, now that your show the
> code. :-)
>
>
>
> > Turns out that some of my code (in the view where I was having
> > trouble) called some code that looked sort of like this:
>
> Hmm .. you didn't exactly simplify your failing case to the smallest
> possible example, did you? All this extra stuff would have set off a lot
> of alarm bells about other places to look (although my first thought
> would have been whether you could do without it and retest to see if
> that changed anything).
>
> Before getting into the more-or-less two line explanation, some
> background information. Firstly, model._meta is obviously internal API,
> so there are some shortcuts taken for performance and maintainability
> reasons. We don't send the black helicopters after people who access it,
> but it's very much "user beware" country. It's one of the areas that is
> currently intentionally undocumented, for example (we'll eventually drop
> some documentation about internal datastructures into docs/internals/,
> but have had other things to do so far).
>
> Of relevance to this particular case, we use lists a lot internally and
> return references to them from certain methods. We use lists, rather
> than tuples, because they are updated a fair bit during creation and all
> the extra copying isn't free (updating a tuple requires a copy). Lists
> are just nicer to work with, generally.
>
> > field_list = model._meta.fields
>
> Have a look at the implementation here
> (django.db.models.options.Options._fields(), since _meta.fields is a
> property). It returns a reference to a list. A *reference*, not a copy!
>
> Your code would have worked if you wrote
>
>         # Work with a copy of the fields list.
>         field_list = model._meta.fields[:]
>
> > field_list.extend(model._meta.many_to_many)
>
> Here you update that reference in place. So you've just corrupted one of
> the internal data structures of self._meta.
>
> That's pretty much going to guarantee that the wheels will fall off at
> some point in the future. If not in the way you saw, in some other
> really hard to debug fashion.
>
> It's kind of a Python trap and if you're designing a public API, you
> would generally return a copy of the list if the caller wasn't expected
> to change the internal structure. In the Options class, we "know" (in
> quotes, because there are people who call it from public code, but
> that's their problem, not ours) that the only callers are functions that
> are read-only on the data structure, so we save a bit of time and code
> complexity. We could return a copy each time, but we access self._fields
> a *lot*, particularly in queryset operations. Things might have changed
> a bit in the last six months (although not dramatically), but when I was
> working on the queryset-refactor branch, I spent a lot of time profiling
> various common execution paths and a lot of the newer shared data
> structures in Options are implemented based on that work (self.fields
> used to be a simple list, for example, but when model inheritance came
> in, it became, internally, more complicated).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 

Fixtures in production use - best practices

2009-01-22 Thread Delta20

Fixtures are geared towards unit testing; I'm wondering if they are
considered a good way to populate the database with some initial
default values.

For example, say we have a model TicketState, and the applications
must be guaranteed to have two TicketStates representing the states
"Open" and "Closed", and we want to make it so the user can add more
TicketStates as needed.

Is this something that would best be addressed by using fixtures? In
particular, there doesn't seem to be a way to create fixtures
programmaticly (rather than importing JSON or YAML data), which means
that somewhere in the code you would need to have magic values to
refer to the default models that were loaded (a magic value is some
arbitrary string or number, rather than using constants or some other
more controlled approach that is less likely to break later in
mysterious ways). For example:

# if no state, assign the default state
if not ticket.status:
# Below is bad practice, uses a magic value
ticket.status = TicketStatus.objects.get(name='Open')

Would a different approach be better, such as a having a get_or_create
method that creates the default instance if it doesn't exist already
(rather than using fixtures)?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Facebook-like functionality for an Intranet

2009-01-22 Thread Ramdas S
http://pinaxproject.com/
On Fri, Jan 23, 2009 at 1:56 AM, Rodrigo C.  wrote:

>
> I need to create an Intranet for a client. I would like to include
> some facebook-like functionality, such as being able to create and
> join networks, setting permissions based on membership in said
> networks, being notified when a friend or someone in your network
> updates his status, writes something, uploads photographs, etc.
> Have you done something like this with Django? Do you know of some
> apps that already provide some of these functionalities, or any more
> general account & profile based applications? Any general advice or
> experience is welcome.
> >
>


-- 
Ramdas S
+91 9342 583 065

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



Facebook-like functionality for an Intranet

2009-01-22 Thread Rodrigo C.

I need to create an Intranet for a client. I would like to include
some facebook-like functionality, such as being able to create and
join networks, setting permissions based on membership in said
networks, being notified when a friend or someone in your network
updates his status, writes something, uploads photographs, etc.
Have you done something like this with Django? Do you know of some
apps that already provide some of these functionalities, or any more
general account & profile based applications? Any general advice or
experience is welcome.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



run function on session.flush()

2009-01-22 Thread Abe

I would like to run a function (in my case, send an email summarizing
recent activity) when a user logs out *or* when their session
expires.  Is there an easy way to do it without making a new version
of the Session class?

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



Confused by error messages

2009-01-22 Thread phoebebright

I managed to set debug to false and spend an hour trying to understand
this error:


  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/django/template/defaulttags.py", line 880, in
load
(taglib, e))

TemplateSyntaxError: 'openid_tags' is not a valid tag library: Could
not load template library from django.templatetags.openid_tags, No
module named openid_tags

But I'm not using openid_tags and no reference to openid anywhere in
my code! Then discovered what I'd done and set Debug to true.  Now the
error is:

DoesNotExist at /
Category matching query does not exist.
Request Method: GET
Request URL:http://127.0.0.1:8000/
Exception Type: DoesNotExist
Exception Value:
Category matching query does not exist.

Now that makes sense, but why the difference??

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



Re: Recommendation on understanding CSS

2009-01-22 Thread phoebebright

If you have a Mac I recommend CSSEdit which allows you to analyse the
css that applies to each element on a page (locally or online) and
changes show immediately.


On Jan 21, 8:52 am, Gath  wrote:
> Guys,
>
> Its seems the best way to do templates in Django is via plain html and
> css, but am having a problem in understanding css easily, can someone
> recommend some nice material/site on css i can read, i mean step by
> step till complex stuff.
>
> Paul

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



mod python child server won't start

2009-01-22 Thread May

Hello,

I set up a windows XP(python 2.5, apache 2.2) startproject called
myprograms and used this code in http.conf (this works and server
starts):

SetHandler python-program
PythonPath "['C:/django'] + sys.pat"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myprograms.settings
PythonDebug On

I then set up an application under myprograms called cpssite and
rewrote the http.conf code to this:

SetHandler python-program
PythonPath "['C:/django'] + sys.pat"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myprograms.settings
PythonDebug On



SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE cpssite.settings
PythonInterpreter cpssite
PythonDebug On


Now the server quits at child.

Any help is much appreciated.

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



Announcing release of WoodRanch Agile Projects written in Django

2009-01-22 Thread Ashish Gupta

Hi All,

I am pleased to announce the release of Agile Software Project and
Product Management tool -  WoodRanch Agile Projects (WRAP),  written
in Django.

http://wrap.woodranchtech.com

Please register here http://wrap.woodranchtech.com/register/  for the
free trial.

It is a pleasure developing in Django and we are glad we choose Django
as the framework. Thanks to all the  people from Django community who
participated in our Beta when we announced it on this list in October,
2008. Thanks to all the awesome Django developers and Django community
for their help.

Ashish Gupta
CTO, WoodRanch Technology, Inc

About WRAP:

WRAP provides best in class Agile Project Management, Requirements
Authoring and Management, Iteration Management, Defect Management,
Task Management, Release Management, Team Management, Unlimited Number
of Projects, BackLog with Drag and Drop Prioritization, Full Support
for Scrum, Story Authoring, Break down of Epics into Smaller Stories,
Burndown charts, Velocity chart, Track by Story points or hours,
Support for XP and other methodologies, Use Cases, Real Time Email and
Dashboard Alerts, Powerful Dashboards, Export to Excel and much more.

WRAP is a Secure, Highly Available, Highly Scalable, Globally
Available, On Demand Hosted SaaS solution. No need to purchase or
install any hardware or software. No maintenance costs.


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



Anyway to see full UrlConf list of available imported urls?

2009-01-22 Thread NoviceSortOf


* Is there a way to see a full URLConf list of all the imported URLs,
in
  an application?

This seems it would be a big debuging 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model.save() vs. ManyToMany

2009-01-22 Thread David Gordon

I'll try simplifying the example further in case anyone is able to
help...

> Here's the problem code:

class Xeme(models.Model):
    text = models.CharField(max_length=150, db_index=True)
    components = models.ManyToManyField(
        'self', symmetrical=False, blank=True,
        related_name='component_of')

    def update_components(self):
        # get a list of xemes which are contained
        # in this one
        self.get_component_xemes()
        # Add them as many-to-many references
        self.components.add(*components)

I've tried running the update_components method in Xeme.save (both
before and after calling Model.save), using the post_save signal and
using the Xeme's ModelAdmin.save_model() method, to no avail.

I tried printing the contents of db.connection.queries within
Xeme.save and saw the expected INSERT calls for update_components, but
without the expected result appearing in the database. I also noticed
that if I entered values for components myself in the admin interface,
they would appear, but I couldn't see any reference to them in the SQL
printed from Xeme.save(). That's how I got the idea it may be
happening elsewhere.

Thanks to anyone who can explain this for me - is it expected
behaviour or am I doing something wrong?

thanks,

David

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



Re: Cannot serve static files

2009-01-22 Thread john

Ok finally got it. David Zhou above, earlier mentioned adding static
file directory to css link (ie,  ) but when i did that it didn't work. I
must have had something wrong somewhere else. Anyway, i made some more
changes after reading info here:
http://stackoverflow.com/questions/446026/django-how-do-you-serve-media-stylesheets-and-link-to-them-within-templates

So given above directory structure i have this working now with the
following:
settings.py
MEDIA_ROOT = 'c:/dev/proj/app/media/' (i changed from 'c:\dev\proj\app
\media\' not sure if it mattered)
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX =  '/adminmedia/'
from what i gather, media and admin_media can't be the same directory

urls.py
(r'^media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),

base.html template


What a effin hassle this has been. Django needs inprovement here.
Nothing wrong with building a recommended directory structure and/or
publishing better instructions on this. This type of thing is very
different for people coming from standard page style development. Dir
structure and url routing seem to be built into most MVC systems (at
least the ones i looked into before django).


On Jan 22, 12:32 pm, john  wrote:
> ah ok. good catch. My MEDIA_ROOT = C:\dev\proj. But my media directory
> is actually in my app directory, one directory down. I fixed
> MEDIA_ROOT to equal C:\dev\proj\app and still not having any luck. my
> use of -\ in directory structure example is just to indicate a folder
> in directory tree. Let me clarify:
>
> C:\dev\proj is project directory
> C:\dev\proj\app is application directory. Under this i have
> 'adminmedia', 'media' and 'templates' directories. So static files are
> here: C:\dev\proj\app\media.
> css file is here: C:\dev\proj\app\media\css\styles.css
> settings file is here: C:\dev\proj\settings.py
>
> like i said i now have MEDIA_ROOT set to C:\dev\proj\app, but still
> not working. In template i was told to use  type="text/css" href="{{MEDIA_URL}}css/styles.css">.
>
> MEDIA_URL not MEDIA_ROOT
>
> regardless, do i have to pass context for MEDIA_URL in view so
> template knows what it is?? is that the problem?
>
> Thanks for helping, btw. Much appreciated.
>
> On Jan 22, 11:57 am, Puneet Madaan  wrote:
>
> > well at my side it works well on both *nix and windoof platforms... here is
> > what I use on my projects...
>
> > settings.py
> > --
> > import platform
> > import os
>
> > PROJECT_DIR = os.path.dirname( os.path.abspath(__file__))
> > MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static')
> > ---
>
> > urls.py
> > -
> > from django.conf.urls.defaults import *
> > from django.contrib import admin
> > from django.conf import settings
>
> > urlpatterns = patterns('',
> >     #urls for your project
> >     (r'^static/(?P.*)$', 'django.views.static.serve',
> >         {'document_root': settings.MEDIA_ROOT}),
> > )
> > 
> > where i use a directory named 'static' residing in same folder, where i have
> > my settings.py   can you please place 'print MEDIA_ROOT' inside your
> > settings.py and check the terminal the path is spilts out ? because your '-'
> > convention before '-\media' is sort confusing, and its missing before
> > manage.py and settings.py  is media folder residing really in the same
> > directory where settings.py ?
>
> > c:\dev
>
> > >   -\proj
> > >      __init__.py
> > >      manage.py
> > >      settings.py
> > >      urls.py
> > >      -\app
> > >      -__init__.py
> > >      -admin.py
> > >      -models.py
> > >      -views.py
> > >      -\adminmedia
> > >      -\media
> > >        -\css
> > >          -styles.css
> > >        -\images
> > >      -\templates
> > >        -base.html
> > >        -index.html
>
> > if 'print MEDIA_ROOT' spilts out a path different from your media folder,
> > then you know where is the problem ..
>
> > Greetings,
> > Puneet
>
> > On Thu, Jan 22, 2009 at 5:40 PM, john  wrote:
>
> > > Thanks but no change.
>
> > > On Jan 22, 11:30 am, Puneet Madaan  wrote:
> > > > beside  > > href="{MEDIA_URL}css/styles.css">
> > > > you need to correct settings.py to
>
> > > > SETTINGS_FILE_FOLDER = os.path.dirname( os.path.abspath(__file__))
>
> > > > On Thu, Jan 22, 2009 at 5:26 PM, john  wrote:
>
> > > > > Thanks but no change.
>
> > > > > On Jan 22, 11:02 am, Dj Gilcrease  wrote:
> > > > > > change
> > > > > > 
> > > > > > to
> > > > > >  > > href="{MEDIA_URL}css/styles.css">
>
> > > > > > Dj Gilcrease
> > > > > > OpenRPG Developer
> > > > > > ~~http://www.openrpg.com
>
> > > > > > On Thu, Jan 22, 2009 at 8:53 AM, john 
> > > wrote:
>
> > > > > > > No matter what i do i can't get my css to load. 100% Frustrated
> > > with
> > > > > > > Django. My index page loads when i requesthttp://
> > > 127.0.0.1:8000/but
> > > > > > > it is 

Re: Recommendation on understanding CSS

2009-01-22 Thread Skylar

I think getting the firebug plug-in for firefox and playing around and
looking at other people's code has been most beneficial to me
recently.

On Jan 21, 3:52 am, Gath  wrote:
> Guys,
>
> Its seems the best way to do templates in Django is via plain html and
> css, but am having a problem in understanding css easily, can someone
> recommend some nice material/site on css i can read, i mean step by
> step till complex stuff.
>
> Paul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cannot serve static files

2009-01-22 Thread john

ah ok. good catch. My MEDIA_ROOT = C:\dev\proj. But my media directory
is actually in my app directory, one directory down. I fixed
MEDIA_ROOT to equal C:\dev\proj\app and still not having any luck. my
use of -\ in directory structure example is just to indicate a folder
in directory tree. Let me clarify:

C:\dev\proj is project directory
C:\dev\proj\app is application directory. Under this i have
'adminmedia', 'media' and 'templates' directories. So static files are
here: C:\dev\proj\app\media.
css file is here: C:\dev\proj\app\media\css\styles.css
settings file is here: C:\dev\proj\settings.py

like i said i now have MEDIA_ROOT set to C:\dev\proj\app, but still
not working. In template i was told to use .

MEDIA_URL not MEDIA_ROOT

regardless, do i have to pass context for MEDIA_URL in view so
template knows what it is?? is that the problem?

Thanks for helping, btw. Much appreciated.



On Jan 22, 11:57 am, Puneet Madaan  wrote:
> well at my side it works well on both *nix and windoof platforms... here is
> what I use on my projects...
>
> settings.py
> --
> import platform
> import os
>
> PROJECT_DIR = os.path.dirname( os.path.abspath(__file__))
> MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static')
> ---
>
> urls.py
> -
> from django.conf.urls.defaults import *
> from django.contrib import admin
> from django.conf import settings
>
> urlpatterns = patterns('',
>     #urls for your project
>     (r'^static/(?P.*)$', 'django.views.static.serve',
>         {'document_root': settings.MEDIA_ROOT}),
> )
> 
> where i use a directory named 'static' residing in same folder, where i have
> my settings.py   can you please place 'print MEDIA_ROOT' inside your
> settings.py and check the terminal the path is spilts out ? because your '-'
> convention before '-\media' is sort confusing, and its missing before
> manage.py and settings.py  is media folder residing really in the same
> directory where settings.py ?
>
> c:\dev
>
>
>
> >   -\proj
> >      __init__.py
> >      manage.py
> >      settings.py
> >      urls.py
> >      -\app
> >      -__init__.py
> >      -admin.py
> >      -models.py
> >      -views.py
> >      -\adminmedia
> >      -\media
> >        -\css
> >          -styles.css
> >        -\images
> >      -\templates
> >        -base.html
> >        -index.html
>
> if 'print MEDIA_ROOT' spilts out a path different from your media folder,
> then you know where is the problem ..
>
> Greetings,
> Puneet
>
>
>
> On Thu, Jan 22, 2009 at 5:40 PM, john  wrote:
>
> > Thanks but no change.
>
> > On Jan 22, 11:30 am, Puneet Madaan  wrote:
> > > beside  > href="{MEDIA_URL}css/styles.css">
> > > you need to correct settings.py to
>
> > > SETTINGS_FILE_FOLDER = os.path.dirname( os.path.abspath(__file__))
>
> > > On Thu, Jan 22, 2009 at 5:26 PM, john  wrote:
>
> > > > Thanks but no change.
>
> > > > On Jan 22, 11:02 am, Dj Gilcrease  wrote:
> > > > > change
> > > > > 
> > > > > to
> > > > >  > href="{MEDIA_URL}css/styles.css">
>
> > > > > Dj Gilcrease
> > > > > OpenRPG Developer
> > > > > ~~http://www.openrpg.com
>
> > > > > On Thu, Jan 22, 2009 at 8:53 AM, john 
> > wrote:
>
> > > > > > No matter what i do i can't get my css to load. 100% Frustrated
> > with
> > > > > > Django. My index page loads when i requesthttp://
> > 127.0.0.1:8000/but
> > > > > > it is not styled. Django dev server returns 404 in console for "GET
> > /
> > > > > > css/styles.css HTTP/1.1"
>
> > > > > > In my base template i have:
> > > > > > 
>
> > > > > > In my urls.py I have:
> > > > > > urlpatterns = patterns('',
> > > > > >     (r'^$', 'proj.app.views.index'),
> > > > > >     (r'^admin/(.*)', admin.site.root),
> > > > > >     (r'^media/(?P.*)$', 'django.views.static.serve',
> > > > > > {'document_root': settings.MEDIA_ROOT}),
> > > > > > )
>
> > > > > > In my settings.py i have (among other things):
> > > > > > import os
> > > > > > SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
> > > > > > MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
> > > > > > MEDIA_URL = 'http://127.0.0.1:8000/media/'
> > > > > > ADMIN_MEDIA_PREFIX =  'adminmedia'
>
> > > > > > my directory structure in windows is:
>
> > > > > > c:\dev
> > > > > >   -\proj
> > > > > >      __init__.py
> > > > > >      manage.py
> > > > > >      settings.py
> > > > > >      urls.py
> > > > > >      -\app
> > > > > >      -__init__.py
> > > > > >      -admin.py
> > > > > >      -models.py
> > > > > >      -views.py
> > > > > >      -\adminmedia
> > > > > >      -\media
> > > > > >        -\css
> > > > > >          -styles.css
> > > > > >        -\images
> > > > > >      -\templates
> > > > > >        -base.html
> > > > > >        -index.html
>
> > > --
> > > If you spin an oriental man, does he become disoriented?
> > > (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
>
> > > is der 

problems getting urls to import

2009-01-22 Thread NoviceSortOf

Looking at mysite.myproject.urls I have...

urlpatterns += patterns('', (r'^profiles/', include
('profiles.urls')), )

But can't get the profiles.urls to import

My URLconf list includes

# ^accounts/ ^activate/(?P\w+)/$
# ^accounts/ ^login/$
# ^accounts/ ^logout/$
# ^accounts/ ^register/$
# ^accounts/ ^register/complete/$
...(and so on, but for profiles only shows
# ^profiles/

Please advise

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



Re: Apache server won't start

2009-01-22 Thread May

Oh, Thank you, Karen!!  Yes, that was the problem.

May

On Jan 22, 9:12 am, Karen Tracey  wrote:
> On Thu, Jan 22, 2009 at 11:55 AM, May  wrote:
>
> > Hello,
>
> > I'm trying to set up the Apache server with mod_python.  The Apache
> > server works, until I had the following code to the bottom of
> > http.conf file:
>
> > SetHandler python-program
> > PythonPath "['C:/django'] + sys.path"
>
> If this is a literal cut-and-paste one problem is that you have curly quotes
> around the PythonPath.  Apache doesn't understand curly quotes, use straight
> typewriter quotes.
>
>
>
>
>
> > PythonHandler django.core.handlers.modpython
> > SetEnv DJANGO_SETTINGS_MODULE myprojects.settings
> > PythonDebug On
>
> > SetHandler None
>
> > SetHandler None
>
> > When I try to start Apache the error is "The requested operation has
> > failed!
>
> > My path is C:/django/myprojects
>
> > Thank you for any help!
>
> Looking in the error log for clues is always a good idea also.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Apache server won't start

2009-01-22 Thread Karen Tracey
On Thu, Jan 22, 2009 at 11:55 AM, May  wrote:

>
> Hello,
>
> I'm trying to set up the Apache server with mod_python.  The Apache
> server works, until I had the following code to the bottom of
> http.conf file:
>
> SetHandler python-program
> PythonPath "['C:/django'] + sys.path"


If this is a literal cut-and-paste one problem is that you have curly quotes
around the PythonPath.  Apache doesn't understand curly quotes, use straight
typewriter quotes.


>
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE myprojects.settings
> PythonDebug On
>
> SetHandler None
>
> SetHandler None
>
> When I try to start Apache the error is "The requested operation has
> failed!
>
> My path is C:/django/myprojects
>
> Thank you for any help!
>

Looking in the error log for clues is always a good idea also.

Karen

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



Re: Cannot serve static files

2009-01-22 Thread Dj Gilcrease

Sorry that should be {{MEDIA_URL}}


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com



On Thu, Jan 22, 2009 at 9:30 AM, Puneet Madaan  wrote:
> beside  you need to correct settings.py to
>
> SETTINGS_FILE_FOLDER = os.path.dirname( os.path.abspath(__file__))
>
>
> On Thu, Jan 22, 2009 at 5:26 PM, john  wrote:
>>
>> Thanks but no change.
>>
>> On Jan 22, 11:02 am, Dj Gilcrease  wrote:
>> > change
>> > 
>> > to
>> > 
>> >
>> > Dj Gilcrease
>> > OpenRPG Developer
>> > ~~http://www.openrpg.com
>> >
>> > On Thu, Jan 22, 2009 at 8:53 AM, john  wrote:
>> >
>> > > No matter what i do i can't get my css to load. 100% Frustrated with
>> > > Django. My index page loads when i requesthttp://127.0.0.1:8000/but
>> > > it is not styled. Django dev server returns 404 in console for "GET /
>> > > css/styles.css HTTP/1.1"
>> >
>> > > In my base template i have:
>> > > 
>> >
>> > > In my urls.py I have:
>> > > urlpatterns = patterns('',
>> > > (r'^$', 'proj.app.views.index'),
>> > > (r'^admin/(.*)', admin.site.root),
>> > > (r'^media/(?P.*)$', 'django.views.static.serve',
>> > > {'document_root': settings.MEDIA_ROOT}),
>> > > )
>> >
>> > > In my settings.py i have (among other things):
>> > > import os
>> > > SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
>> > > MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
>> > > MEDIA_URL = 'http://127.0.0.1:8000/media/'
>> > > ADMIN_MEDIA_PREFIX =  'adminmedia'
>> >
>> > > my directory structure in windows is:
>> >
>> > > c:\dev
>> > >   -\proj
>> > >  __init__.py
>> > >  manage.py
>> > >  settings.py
>> > >  urls.py
>> > >  -\app
>> > >  -__init__.py
>> > >  -admin.py
>> > >  -models.py
>> > >  -views.py
>> > >  -\adminmedia
>> > >  -\media
>> > >-\css
>> > >  -styles.css
>> > >-\images
>> > >  -\templates
>> > >-base.html
>> > >-index.html
>>
>
>
>
> --
> If you spin an oriental man, does he become disoriented?
> (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
>
> is der net süß » ε(●̮̮̃•̃)з
> -PM
>
> >
>

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



Re: Apache server won't start

2009-01-22 Thread May

Hello Tonu,

Yes, I tried that as well and still the server won't start.

Thanks,

May

On Jan 22, 9:01 am, Tonu  wrote:
> I wonder if you need SetHandler None?  Try eliminating those two
> lines.  Other source of information for troubleshooting is apache
> error log file.
>
> Tonu
>
> On Jan 22, 10:55 am, May  wrote:
>
> > Hello,
>
> > I'm trying to set up the Apache server with mod_python.  The Apache
> > server works, until I had the following code to the bottom of
> > http.conf file:
>
> > SetHandler python-program
> > PythonPath “['C:/django'] + sys.path”
> > PythonHandler django.core.handlers.modpython
> > SetEnv DJANGO_SETTINGS_MODULE myprojects.settings
> > PythonDebug On
>
> > SetHandler None
>
> > SetHandler None
>
> > When I try to start Apache the error is "The requested operation has
> > failed!
>
> > My path is C:/django/myprojects
>
> > Thank you for any help!
>
> > May
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Apache server won't start

2009-01-22 Thread Tonu

I wonder if you need SetHandler None?  Try eliminating those two
lines.  Other source of information for troubleshooting is apache
error log file.

Tonu

On Jan 22, 10:55 am, May  wrote:
> Hello,
>
> I'm trying to set up the Apache server with mod_python.  The Apache
> server works, until I had the following code to the bottom of
> http.conf file:
>
> SetHandler python-program
> PythonPath “['C:/django'] + sys.path”
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE myprojects.settings
> PythonDebug On
>
> SetHandler None
>
> SetHandler None
>
> When I try to start Apache the error is "The requested operation has
> failed!
>
> My path is C:/django/myprojects
>
> Thank you for any help!
>
> May
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cannot serve static files

2009-01-22 Thread Puneet Madaan
well at my side it works well on both *nix and windoof platforms... here is
what I use on my projects...

settings.py
--
import platform
import os

PROJECT_DIR = os.path.dirname( os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static')
---

urls.py
-
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings

urlpatterns = patterns('',
#urls for your project
(r'^static/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)

where i use a directory named 'static' residing in same folder, where i have
my settings.py   can you please place 'print MEDIA_ROOT' inside your
settings.py and check the terminal the path is spilts out ? because your '-'
convention before '-\media' is sort confusing, and its missing before
manage.py and settings.py  is media folder residing really in the same
directory where settings.py ?

c:\dev
>   -\proj
>  __init__.py
>  manage.py
>  settings.py
>  urls.py
>  -\app
>  -__init__.py
>  -admin.py
>  -models.py
>  -views.py
>  -\adminmedia
>  -\media
>-\css
>  -styles.css
>-\images
>  -\templates
>-base.html
>-index.html
>

if 'print MEDIA_ROOT' spilts out a path different from your media folder,
then you know where is the problem ..

Greetings,
Puneet

On Thu, Jan 22, 2009 at 5:40 PM, john  wrote:

>
> Thanks but no change.
>
> On Jan 22, 11:30 am, Puneet Madaan  wrote:
> > beside  href="{MEDIA_URL}css/styles.css">
> > you need to correct settings.py to
> >
> > SETTINGS_FILE_FOLDER = os.path.dirname( os.path.abspath(__file__))
> >
> >
> >
> > On Thu, Jan 22, 2009 at 5:26 PM, john  wrote:
> >
> > > Thanks but no change.
> >
> > > On Jan 22, 11:02 am, Dj Gilcrease  wrote:
> > > > change
> > > > 
> > > > to
> > > >  href="{MEDIA_URL}css/styles.css">
> >
> > > > Dj Gilcrease
> > > > OpenRPG Developer
> > > > ~~http://www.openrpg.com
> >
> > > > On Thu, Jan 22, 2009 at 8:53 AM, john 
> wrote:
> >
> > > > > No matter what i do i can't get my css to load. 100% Frustrated
> with
> > > > > Django. My index page loads when i requesthttp://
> 127.0.0.1:8000/but
> > > > > it is not styled. Django dev server returns 404 in console for "GET
> /
> > > > > css/styles.css HTTP/1.1"
> >
> > > > > In my base template i have:
> > > > > 
> >
> > > > > In my urls.py I have:
> > > > > urlpatterns = patterns('',
> > > > > (r'^$', 'proj.app.views.index'),
> > > > > (r'^admin/(.*)', admin.site.root),
> > > > > (r'^media/(?P.*)$', 'django.views.static.serve',
> > > > > {'document_root': settings.MEDIA_ROOT}),
> > > > > )
> >
> > > > > In my settings.py i have (among other things):
> > > > > import os
> > > > > SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
> > > > > MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
> > > > > MEDIA_URL = 'http://127.0.0.1:8000/media/'
> > > > > ADMIN_MEDIA_PREFIX =  'adminmedia'
> >
> > > > > my directory structure in windows is:
> >
> > > > > c:\dev
> > > > >   -\proj
> > > > >  __init__.py
> > > > >  manage.py
> > > > >  settings.py
> > > > >  urls.py
> > > > >  -\app
> > > > >  -__init__.py
> > > > >  -admin.py
> > > > >  -models.py
> > > > >  -views.py
> > > > >  -\adminmedia
> > > > >  -\media
> > > > >-\css
> > > > >  -styles.css
> > > > >-\images
> > > > >  -\templates
> > > > >-base.html
> > > > >-index.html
> >
> > --
> > If you spin an oriental man, does he become disoriented?
> > (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
> >
> > is der net süß » ε(●̮̮̃•̃)з
> > -PM
> >
>


-- 
If you spin an oriental man, does he become disoriented?
(-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu

is der net süß » ε(●̮̮̃•̃)з
-PM

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



Re: Apache server won't start

2009-01-22 Thread May

Ad addendum to message:

This is a windows XP server.

May

On Jan 22, 8:55 am, May  wrote:
> Hello,
>
> I'm trying to set up the Apache server with mod_python.  The Apache
> server works, until I had the following code to the bottom of
> http.conf file:
>
> SetHandler python-program
> PythonPath “['C:/django'] + sys.path”
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE myprojects.settings
> PythonDebug On
>
> SetHandler None
>
> SetHandler None
>
> When I try to start Apache the error is "The requested operation has
> failed!
>
> My path is C:/django/myprojects
>
> Thank you for any help!
>
> May
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need help changing the ordering of a queryset stored in session

2009-01-22 Thread Brandon Taylor

Thanks Malcom,

Looks like sorted in combination with the operator module is the key
to my problem. Now I can do:

import operator

vehicle_list = Vehicle.objects.all().select_related(depth=1)
vehicles = list(sorted(vehicle_list, key=operator.attrgetter
('model_year or whatever')))

...and do vehicles.reverse() to toggle ascending or descending.

Thanks for getting me on the right track, I appreciate it!
Brandon

On Jan 22, 2:19 am, Malcolm Tredinnick 
wrote:
> On Wed, 2009-01-21 at 21:40 -0800, Brandon Taylor wrote:
> > Hi everyone,
>
> > I need to do some table sorting and paging. To reduce trips to the DB,
> > I'm storing my initial queryset in a session using the file system
> > backend for local development.
>
> > I was thinking I might be able to use the dictsort filter and just
> > pass in the column as a variable to do the column sorting, but I can't
> > seem to convert a queryset into a dictionary to use with the dictsort
> > filter. Calling dict(queryset) returns an error.
>
> Simplest solution will be to write your own "sort" filter. In your
> template, that will then look like:
>
>         {{ my_queryset|sort }}
>
> A template filter is very easy to write, particularly when the filter
> takes no arguments. It's basically just a Python function that accepts
> the lhs object as a parameter. You can then use Python's sorted()
> function and pass in a comparison function or a "key" function. Have a
> read of the Python documentation for details, if you aren't familiar
> with sorted() -- it's incredibly useful.
>
> Refer to [1] for how to write template filters.
>
> [1]http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writ...
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Apache server won't start

2009-01-22 Thread May

Hello,

I'm trying to set up the Apache server with mod_python.  The Apache
server works, until I had the following code to the bottom of
http.conf file:

SetHandler python-program
PythonPath “['C:/django'] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myprojects.settings
PythonDebug On

SetHandler None

SetHandler None

When I try to start Apache the error is "The requested operation has
failed!

My path is C:/django/myprojects

Thank you for any help!

May


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



Re: Cannot serve static files

2009-01-22 Thread john

Thanks but no change.

On Jan 22, 11:30 am, Puneet Madaan  wrote:
> beside  href="{MEDIA_URL}css/styles.css">
> you need to correct settings.py to
>
> SETTINGS_FILE_FOLDER = os.path.dirname( os.path.abspath(__file__))
>
>
>
> On Thu, Jan 22, 2009 at 5:26 PM, john  wrote:
>
> > Thanks but no change.
>
> > On Jan 22, 11:02 am, Dj Gilcrease  wrote:
> > > change
> > > 
> > > to
> > > 
>
> > > Dj Gilcrease
> > > OpenRPG Developer
> > > ~~http://www.openrpg.com
>
> > > On Thu, Jan 22, 2009 at 8:53 AM, john  wrote:
>
> > > > No matter what i do i can't get my css to load. 100% Frustrated with
> > > > Django. My index page loads when i requesthttp://127.0.0.1:8000/but
> > > > it is not styled. Django dev server returns 404 in console for "GET /
> > > > css/styles.css HTTP/1.1"
>
> > > > In my base template i have:
> > > > 
>
> > > > In my urls.py I have:
> > > > urlpatterns = patterns('',
> > > >     (r'^$', 'proj.app.views.index'),
> > > >     (r'^admin/(.*)', admin.site.root),
> > > >     (r'^media/(?P.*)$', 'django.views.static.serve',
> > > > {'document_root': settings.MEDIA_ROOT}),
> > > > )
>
> > > > In my settings.py i have (among other things):
> > > > import os
> > > > SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
> > > > MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
> > > > MEDIA_URL = 'http://127.0.0.1:8000/media/'
> > > > ADMIN_MEDIA_PREFIX =  'adminmedia'
>
> > > > my directory structure in windows is:
>
> > > > c:\dev
> > > >   -\proj
> > > >      __init__.py
> > > >      manage.py
> > > >      settings.py
> > > >      urls.py
> > > >      -\app
> > > >      -__init__.py
> > > >      -admin.py
> > > >      -models.py
> > > >      -views.py
> > > >      -\adminmedia
> > > >      -\media
> > > >        -\css
> > > >          -styles.css
> > > >        -\images
> > > >      -\templates
> > > >        -base.html
> > > >        -index.html
>
> --
> If you spin an oriental man, does he become disoriented?
> (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
>
> is der net süß » ε(●̮̮̃•̃)з
> -PM
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



running shell commands from a file

2009-01-22 Thread Tonu

I am trying to write a small program that imports delicious bookmarks
into the Django project's database.  When I try the commands using
manage.py shell , then they work, but when I put the commands into a
file "feed.py" and try them I receive an error: " ImportError: No
module named django_bookmarks.bookmarks".  The error occurs on line
#11 (user = User.objects.get(id=1)).

I tried to make sure in my file that I include the necessary path
information to the settings file.  I wonder if anyone has insight into
what I am doing wrong.  Here is the file that I am using.  It resides
in the django_bookmarks folder.

Thank you,
Tonu

#!/usr/local/bin/python
import feedparser
import os.path
os.environ['DJANGO_SETTINGS_MODULE']='settings'
from django.contrib.auth.models import User
from bookmarks.models import *
d = feedparser.parse('http://feeds.delicious.com/v2/rss/utools')

link9 = Link(url=d.entries[2].link)
link9.save()
user = User.objects.get(id=1)
link = Link.objects.get(id=9)
bookmark = Bookmark (
title = d.entries[2].title,
desc = d.entries[2].description,
link = link,
)
bookmark.save()

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



Re: Convert iso-8859-1 queryset to utf-8

2009-01-22 Thread matehat

You can also replace the following steps by the 'render_to_string'
shortcut method available in the 'django.template.loader' module:

> - explicitely load the template
> - render it and store the result

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



Re: Cannot serve static files

2009-01-22 Thread Puneet Madaan
beside 
you need to correct settings.py to

SETTINGS_FILE_FOLDER = os.path.dirname( os.path.abspath(__file__))


On Thu, Jan 22, 2009 at 5:26 PM, john  wrote:

>
> Thanks but no change.
>
> On Jan 22, 11:02 am, Dj Gilcrease  wrote:
> > change
> > 
> > to
> > 
> >
> > Dj Gilcrease
> > OpenRPG Developer
> > ~~http://www.openrpg.com
> >
> > On Thu, Jan 22, 2009 at 8:53 AM, john  wrote:
> >
> > > No matter what i do i can't get my css to load. 100% Frustrated with
> > > Django. My index page loads when i requesthttp://127.0.0.1:8000/but
> > > it is not styled. Django dev server returns 404 in console for "GET /
> > > css/styles.css HTTP/1.1"
> >
> > > In my base template i have:
> > > 
> >
> > > In my urls.py I have:
> > > urlpatterns = patterns('',
> > > (r'^$', 'proj.app.views.index'),
> > > (r'^admin/(.*)', admin.site.root),
> > > (r'^media/(?P.*)$', 'django.views.static.serve',
> > > {'document_root': settings.MEDIA_ROOT}),
> > > )
> >
> > > In my settings.py i have (among other things):
> > > import os
> > > SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
> > > MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
> > > MEDIA_URL = 'http://127.0.0.1:8000/media/'
> > > ADMIN_MEDIA_PREFIX =  'adminmedia'
> >
> > > my directory structure in windows is:
> >
> > > c:\dev
> > >   -\proj
> > >  __init__.py
> > >  manage.py
> > >  settings.py
> > >  urls.py
> > >  -\app
> > >  -__init__.py
> > >  -admin.py
> > >  -models.py
> > >  -views.py
> > >  -\adminmedia
> > >  -\media
> > >-\css
> > >  -styles.css
> > >-\images
> > >  -\templates
> > >-base.html
> > >-index.html
> >
>


-- 
If you spin an oriental man, does he become disoriented?
(-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu

is der net süß » ε(●̮̮̃•̃)з
-PM

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



Re: Cannot serve static files

2009-01-22 Thread john

Thanks but no change.

On Jan 22, 11:02 am, Dj Gilcrease  wrote:
> change
> 
> to
> 
>
> Dj Gilcrease
> OpenRPG Developer
> ~~http://www.openrpg.com
>
> On Thu, Jan 22, 2009 at 8:53 AM, john  wrote:
>
> > No matter what i do i can't get my css to load. 100% Frustrated with
> > Django. My index page loads when i requesthttp://127.0.0.1:8000/but
> > it is not styled. Django dev server returns 404 in console for "GET /
> > css/styles.css HTTP/1.1"
>
> > In my base template i have:
> > 
>
> > In my urls.py I have:
> > urlpatterns = patterns('',
> >     (r'^$', 'proj.app.views.index'),
> >     (r'^admin/(.*)', admin.site.root),
> >     (r'^media/(?P.*)$', 'django.views.static.serve',
> > {'document_root': settings.MEDIA_ROOT}),
> > )
>
> > In my settings.py i have (among other things):
> > import os
> > SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
> > MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
> > MEDIA_URL = 'http://127.0.0.1:8000/media/'
> > ADMIN_MEDIA_PREFIX =  'adminmedia'
>
> > my directory structure in windows is:
>
> > c:\dev
> >   -\proj
> >      __init__.py
> >      manage.py
> >      settings.py
> >      urls.py
> >      -\app
> >      -__init__.py
> >      -admin.py
> >      -models.py
> >      -views.py
> >      -\adminmedia
> >      -\media
> >        -\css
> >          -styles.css
> >        -\images
> >      -\templates
> >        -base.html
> >        -index.html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-22 Thread Thomas Guettler

Tim Daniel schrieb:
> I read something that it would be more
> efficient to store only the query and doing pickle?? I don't know how
> to do that, I've been looking in the docs and other posts but no clear
> explanation. So what I really want to know: which is the best way of
> handling this problem?
I have my own paginator, too.

I use request.GET and create a new URL with the item
'page_number' changed.

Here is a snippet. It disables the [next] link, if there is no next page.


qs=dict(request.GET)
def qs2url(qs):
new={}
for key, value in qs.items():
if isinstance(value, (list, tuple)):
value=[v.encode('utf8') for v in value]
elif isinstance(value, (int, long)):
value=str(value)
else:
value=value.encode('utf8')
new[key]=value
return escape(django.http.urlencode(new, doseq=True))
if page.has_next():
qs['page_number']=page_number+1
next='' % qs2url(qs)
qs['page_number']=paginator.num_pages
last='' % qs2url(qs)
else:
next=''
last=''
if page.has_previous():
qs['page_number']=page_number-1
prev='' % qs2url(qs)
qs['page_number']=1
first='' % qs2url(qs)
else:
prev=''
first=''
   
first=mark_safe(first)
prev=mark_safe(prev)
next=mark_safe(next)
last=mark_safe(last)


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Cannot serve static files

2009-01-22 Thread Dj Gilcrease

change

to


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com



On Thu, Jan 22, 2009 at 8:53 AM, john  wrote:
>
> No matter what i do i can't get my css to load. 100% Frustrated with
> Django. My index page loads when i request http://127.0.0.1:8000/ but
> it is not styled. Django dev server returns 404 in console for "GET /
> css/styles.css HTTP/1.1"
>
> In my base template i have:
> 
>
> In my urls.py I have:
> urlpatterns = patterns('',
> (r'^$', 'proj.app.views.index'),
> (r'^admin/(.*)', admin.site.root),
> (r'^media/(?P.*)$', 'django.views.static.serve',
> {'document_root': settings.MEDIA_ROOT}),
> )
>
> In my settings.py i have (among other things):
> import os
> SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
> MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
> MEDIA_URL = 'http://127.0.0.1:8000/media/'
> ADMIN_MEDIA_PREFIX =  'adminmedia'
>
> my directory structure in windows is:
>
> c:\dev
>   -\proj
>  __init__.py
>  manage.py
>  settings.py
>  urls.py
>  -\app
>  -__init__.py
>  -admin.py
>  -models.py
>  -views.py
>  -\adminmedia
>  -\media
>-\css
>  -styles.css
>-\images
>  -\templates
>-base.html
>-index.html
>
>
>
>
> >
>

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



Re: Cannot serve static files

2009-01-22 Thread David Zhou

On Thu, Jan 22, 2009 at 10:53 AM, john  wrote:
>
> No matter what i do i can't get my css to load. 100% Frustrated with
> Django. My index page loads when i request http://127.0.0.1:8000/ but
> it is not styled. Django dev server returns 404 in console for "GET /
> css/styles.css HTTP/1.1"

Try doing:




-- dz

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



Cannot serve static files

2009-01-22 Thread john

No matter what i do i can't get my css to load. 100% Frustrated with
Django. My index page loads when i request http://127.0.0.1:8000/ but
it is not styled. Django dev server returns 404 in console for "GET /
css/styles.css HTTP/1.1"

In my base template i have:


In my urls.py I have:
urlpatterns = patterns('',
 (r'^$', 'proj.app.views.index'),
 (r'^admin/(.*)', admin.site.root),
 (r'^media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)

In my settings.py i have (among other things):
import os
SETTINGS_FILE_FOLDER = os.path.dirname(__file__)
MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER, 'media')
MEDIA_URL = 'http://127.0.0.1:8000/media/'
ADMIN_MEDIA_PREFIX =  'adminmedia'

my directory structure in windows is:

c:\dev
   -\proj
  __init__.py
  manage.py
  settings.py
  urls.py
  -\app
  -__init__.py
  -admin.py
  -models.py
  -views.py
  -\adminmedia
  -\media
-\css
  -styles.css
-\images
  -\templates
-base.html
-index.html




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



Re: TypeError: Related Field has invalid lookup: icontains

2009-01-22 Thread Karen Tracey
On Thu, Jan 22, 2009 at 3:01 AM, Alessandro Ronchi <
alessandro.ron...@soasi.com> wrote:

>
> 2009/1/21 Karen Tracey :
>
> > Egads, they're huge.  Any way you could cut that down to a small failing
> > example?  Or at least mention which model you are trying the search on?
> > Also a traceback instead of just the last error message would probably
> help,
> > as it might give some clue where to start looking.
>
> It falls on SchedaBilancioGenere model. I cannot replicate on a smaller
> model.
>
> They're huge, but all the fields are not important: it seems if falls
> on a related field.
>
> This is the trackback:
> http://dpaste.com/111757/
>
>
Ah, you have in your search_fields for SchedaBilancioGenereOptions 'impresa',
which is a ForeignKey.  You need to specify what field within the related
model you want to search, so 'impresa__fieldname'.  (If there are multiple
fields you need to list each explicitly, using the standard
double-underscore syntax.)

Karen

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



Re: Ongoing problems with django-registration installation.

2009-01-22 Thread NoviceSortOf


It seems to me the that automatic mechanism mentioned in the docs
does not exist in django-registration but in its component
django-profiles, reading the source code I see this...

def create_profile(request, form_class=None, success_url=None,
   template_name='profiles/create_profile.html',
   extra_context=None):
"""
Create a profile for the current user, if one doesn't already
exist.

Now my problem is how to import the profile urls.py urls...

Looking at mysite.myproject.urls I have...

urlpatterns += patterns('',
(r'^accounts/', include('registration.urls')),
(r'^profiles/', include('profiles.urls')),
)

But seem to be missing some of the links that should be supplied by
them.

I seem to be missing all of the django-profiles.urls

The only links available are...

Using the URLconf defined in mysite.urls, Django tried these URL
patterns, in this order:
# ^accounts/ ^activate/(?P\w+)/$
# ^accounts/ ^login/$
# ^accounts/ ^logout/$
# ^accounts/ ^password/change/$
# ^accounts/ ^password/change/done/$
# ^accounts/ ^password/reset/$
# ^accounts/ ^password/reset/confirm/(?P[0-9A-Za-z]+)-(?
P.+)/$
# ^accounts/ ^password/reset/complete/$
# ^accounts/ ^password/reset/done/$
# ^accounts/ ^register/$
# ^accounts/ ^register/complete/$
# ^profiles/

The needed profiles urls do not appear even though called in urls.py,

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



Re: AUTH_PROFILE_MODULE confusion

2009-01-22 Thread NoviceSortOf


Although unmentioned in the django-registration docs, reading the
django-profiles code I see
a method called create_profile...which is intended for this purpose,
for now I'll try giving
that a try.

def create_profile(request, form_class=None, success_url=None,
   template_name='profiles/create_profile.html',
   extra_context=None):
"""
Create a profile for the current user, if one doesn't already
exist...


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



Python Web Development/ Programmers with Django_Mumbai

2009-01-22 Thread Maple Solutions
Only Candidates  from Mumbai/ India candidates can apply

We are having an Urgent opening for a leading MNC.

We are looking for Python Web Development/ programmers with Django.
LOCATION: Mumbai/ Andheri (E)

Looking for a quick response!
Talk to us on 9820160656 and send your CV's with your current and expected
salary on
maplesolutions...@gmail. com 

Kindly refer this mail to your friends….

Best Regards,
Rupali
HR Consulting. IT Recruitment. Staffing Solutions
For more information to register a vacancy with Maple Solutions please
e-mail: maplesolutions. h...@gmail.
com




-- 
For more information on recruitment or to register a vacancy with Maple
Solutions please e-mail: maplesolutions...@gmail.com

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



Re: Port large webapp from PHP to Django: tips, experiences, links needed

2009-01-22 Thread Dj Gilcrease

On Fri, Jan 2, 2009 at 6:17 AM, Berco Beute  wrote:
> - Stack. What would currently be a good combination webserver/protocol/
> database? Possible options: Lighttpd, Cherokee, apache, FastCGI,
> mod_python, wsgi, mysql, progress... I realize there is no 'best'
> solution, but I would like to hear your recommendation.

I use Apache with mod_wsgi for django and lighttpd for the media with
PostgreSQL as the DB

>
> - Database optimization. The database layer is currently the major
> bottleneck. There is currently one database with over 150 tables, some
> of which are quite large. Some queries take close to minute to execute
> (yes, it's that bad). For redundancy reasons the database is
> replicated to another server (master/slave), but that doesn't help
> speeding up the response time. In the new version of the web
> application the database layer should be as scalable and maintainable
> as possible. This probably means using techniques such as 'sharding'
> and partitioning. The question is what both Python and Django offer in
> that respect.
>
> - Advantages of an ORM. Currently the web application doesn't use an
> ORM, but it would make development and maintanance a lot easier if it
> would. The question is whether an ORM is a wise choice for such large
> systems. Will what you gain in development speed and maintainability
> outweigh what you (possibly) loose in speed, 'optimizability' and
> adaptability?
>
> - SQL optimization. When using an ORM the SQL gets abstracted away,
> but as discussed above a certain amount of optimization is
> unavoidable. How well does Django support SQL optimization? And if you
> optimize your SQL, how do you then migrate to a new version?

For all of these I would recommend redesigning the DB around the ORM.
If you just directly try to port the old PHP sites DB layer you will
likely run into the same issues you are now, but if you redesign it
around the ORM by trying to group data into logical Objects by usage
then you will likely need to do less custom SQL optimization


> - Switching a development team to Python/Django. I'm familiar with
> Python/Django myself, but three other developers not (although they
> are eager to learn it). Although Python is one of the most 'learnable'
> languages, it still takes time to find your way in the standard
> library and to become a real Pythonista. Does anyone here have
> experience switching a small development team to Python/Django?

Redesign the site from scratch to be functionally (for the user) the
same but ignoring your old code completely, then write a data
migration script to bring your old data over to the new DB

>
> - Bzr or Hg? :)

I use HG, maybe in a slightly strange manner. I have my live server as
a HG server and my dev server as an HG server with a script on my live
server that I run when I wish to update code that pulls from the Dev
server and updates to a specified tag.

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



Re: Multiple images in form

2009-01-22 Thread A Melé

DragonSlayre,

django-thumbs fields act exactly the same way as any ImageField (the
inherit from ImageFIeld), so they can be blank and null. That
shouldn't be a problem.

Regards,

Antonio Melé
http://django.es/blog/


On 20 ene, 19:21, DragonSlayre  wrote:
> Yeah, I had to add a related_name to my ForeignKeys e.g:
>     first_photo = models.ForeignKey(Image, blank=True, null=True,
> related_name="first photo")
>
> The problem now is that with foreign keys, it generates a drop down
> list to select the images - whereas, I want a browse type text box to
> choose an image. - is there anyway to tell the foreignkey field to
> render the items pointed to by the foreign key, rather than just
> render a drop down list?
>
> On Jan 21, 3:14 am, "Karen Tracey"  wrote:
>
> > On Tue, Jan 20, 2009 at 2:28 AM, DragonSlayre  wrote:
> > > [snip details of problem]
>
> > > This gives me loads of errors - i'm pretty sure it's because of the
> > > ForeignKeys.
>
> > Without trying it, I'm guessing you got four errors.  If they are the errors
> > I think they are, the error message actually tries pretty hard to point you
> > in the right direction of fixing them.  Did you try following the advice in
> > the error message?  If you do not understand the error message, it would
> > help if you included it with your question as well as what it is you don't
> > understand in what it is trying to say, which would help people try to frame
> > an answer to address whatever misunderstanding is causing the confusion.  As
> > it is I'm just guessing that if you read and follow the advice in the error
> > messages you can make the errors go away pretty easily.
>
> > Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to use turbogears widget on Django?

2009-01-22 Thread issin

I want to use FusionCharts on Django, and I know a widget
TGFusionCharts for turbogears. How to use it for Django?
Thanks.

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



Re: AUTH_PROFILE_MODULE confusion

2009-01-22 Thread NoviceSortOf


creecode:

I've tried your 2 suggestions with one with no results, and the second
suggestion perhaps i
did not understand enough of where the code should go to make it work.


** Trigger adding instance to userprofile via passing profile_callback
in url.py

Tried this solution in both ...registration.url.py and
myproject.url.py but had syntax errors.

* 'profile_callback' as added to url.
ie.
url ( r'^accounts/register/$',
'registration.views.register',
{ 'profile_callback': UserProfile.objects.create },
name = 'registration_register' ),
( r'^accounts/', include ( 'registration.urls' ) ),

This provided numerous syntax errors, I tried it in both
mysite.myproject.url.py
and in the ...registration.url.py but to no avail. I tried it with 2
versions of registration, in the end though it seems ver .07 no
longer
uses this method.
**

2nd Suggestion sounds elegant and since I'm using django 1
this method may work but I'm not sure where you mean to
put the code.

I would assume this code would be in mysite.myproject.models.py

class UserProfile.

def add_user_profile ( sender, instance, created, **kwargs ):

if created:

user_profile = UserProfile ( user = instance )

user_profile.save ( )

# Now this last line here confuses me is this supposed to go in
  registration.model.py  or ...myproject.model.py

models.signals.post_save.connect ( add_user_profile, sender = User )

whatever the case i've tried it in both and get nothing from
myproject.model.py
and when calling it from  registration.model.py  it returns an error
like
add_user_profile is not a global object.

Please advise

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



Re: Ongoing problems with django-registration installation.

2009-01-22 Thread NoviceSortOf


Django 1.0/django-registration .07 problems continue

***
Issue 1 - No module named urls occuring during registration form
completion.


Via the methodology listed by Karen above I was able to trace my
missing url error.

The only way I could correct the error in registration was to hardcode
modify
line 142 in ...site-packages.registration.views.py to point to
"complete"

For now though this is what it took to get it working.
 ( r'^accounts/', include ( 'registration.urls' ) ),
is in my url.py file but somehow this "complete" link is not part of
that set.

No worries,  I want to draw close to my main goal.


Issue 2. * Objective, how to add records to my custom UserProfile
table?

I've read the django-registration docs numerous times and still can't
figure out how it is supposed to work.

So I attempted adding my own code to create_inactive_user in
registration.models.py

# Original code
 def create_inactive_user(self, username, password, email,
 send_email=True):
...
   from registration.signals import user_registered

new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()

registration_profile = self.create_profile(new_user)

# My code to add records to the custom mysite.myproject.userprofile
table

get_user_id  = int(registration_profile.id) # returning long
integer like 140L must be converted to int
from mysite.myproject.models import UserProfile
p1 = UserProfile( user_id = get_user_id )
p1.save()

*

Results = No errors, but no records added via the process to auth_user
or my own
UserProfile table either.

To quote the django-registration documentation .07 docs

"a mechanism for automatically creating an instance of a
 site-specific profile model is provided via
the ``create_inactive_user`` on ``RegistrationManager``.

Can someone tell me where is that automatic mechanism?


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



Setting a field based on foreign key data

2009-01-22 Thread jason.t.stein

Perhaps this is an sql question, and not a Django question so please
have patience. I am writing a student management app that keeps track
of student events. The relevant tables are:

class Student(models.Model):
  first_name = models.CharField(max_length=32)
  last_name = models.CharField(max_length=32)
  birth_date = models.DateField('Student Birth Date')
  gender = models.CharField(max_length=1, choices = GENDER_CHOICES)
  school = models.ForeignKey(School)

class Competitor(models.Model):
  student = models.ForeignKey(Student)
  track_meet = models.ForeignKey(TrackMeet)
  age_category = models.CharField(max_length=1, choices =
AGE_CATEGORY_CHOICES)
  event = models.CharField(max_length=16, choices = EVENT_CHOICES)

I want to set age_category, based on the age of a student on a certain
date. I can calculate the appropriate age, but am interested how to
set the age_category based on this calculation.

Any help is greatly appreciated. Thank you for your time.

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



Re: MultiValueDictKeyError when accessing POST items

2009-01-22 Thread workingbird

"login_username" should be the attribute named "name", not "id".

On Dec 23 2008, 11:03 am, DragonSlayre  wrote:
> I've created my own form:
>
> 
>   Login:
>   Username: 
>   
>   Password:
>   
>   
> 
>
> I am mappying /accounts/login/ to a view of mine, which is then
> calling:
>
> if request.method == 'POST':
>         username = request.POST['login_username']
>
> I have no idea why I'm getting the error - "Key 'login_username' not
> found in ".
>
> What am I doing wrong?

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



OS X problem with an egg (maybe!)

2009-01-22 Thread arbi

Hello every one,

I am a new member in the Django community... But very beginner.
I spent my whole day yesterday trying to run the "python manage.py
syncdb" key but no success. I looked at many forums and this post
seemed to be nice :
http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/

Now I have : Python 2.3 and 2.5 and mysql 32bits. Moreover I installed
the "mysql-python 1.2.2" folder to tell Python where mysql is.
I also did it : $ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/
mysql for compilation
So I have everything!...


...But when I did "python manage.py syncdb" the terminal answers me :

Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/Library/Python/2.5/site-packages/django/core/management/
__init__.py", line 340, in execute_manager
utility.execute()
  File "/Library/Python/2.5/site-packages/django/core/management/
__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.5/site-packages/django/core/management/
base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/Library/Python/2.5/site-packages/django/core/management/
base.py", line 218, in execute
self.validate()
  File "/Library/Python/2.5/site-packages/django/core/management/
base.py", line 246, in validate
num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.5/site-packages/django/core/management/
validation.py", line 22, in get_validation_errors
from django.db import models, connection
  File "/Library/Python/2.5/site-packages/django/db/__init__.py", line
16, in 
backend = __import__('%s%s.base' % (_import_path,
settings.DATABASE_ENGINE), {}, {}, [''])
  File "/Library/Python/2.5/site-packages/django/db/backends/mysql/
base.py", line 13, in 
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: dlopen(/Users/brouard/.python-eggs/MySQL_python-1.2.2-py2.5-
macosx-10.5-i386.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/
mysql/lib/libmysqlclient_r.16.dylib
  Referenced from: /Users/brouard/.python-eggs/MySQL_python-1.2.2-
py2.5-macosx-10.5-i386.egg-tmp/_mysql.so
  Reason: image not found

I did not find the solution and I lost my hairs!
Thanks for helping me! :)

Arbi


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



Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-22 Thread Tim Daniel

Hi django-pros,
I'm nearly finishing my django web-app and I've got some questions:

1. I'm using pagination: from django.core.paginator import Paginator,
and then handling it all by myself, I do not want to use any other
modules or snipetts or so on. I'm using it to paginate the result of a
query, the problem was when I went to the second page the query was
lost and it displayed a blank page. I fixed it by storing the queryset
resulting by the first query in the session variable of the user, so
for the next pages (which aren't called by POST again) it uses the
existing queryset from session. I read something that it would be more
efficient to store only the query and doing pickle?? I don't know how
to do that, I've been looking in the docs and other posts but no clear
explanation. So what I really want to know: which is the best way of
handling this problem?? Isn't the way I solved it(using session)
causing some overhead?

2. It's related to the query in the first point. The user introduces
some keywords and selects some radiobuttons and some select boxes,
then he clicks on search. The results are displayed but all the
keywords and so on aren't. How should I handle this? I mean if the
user just wants to adjust some parameters from the search he needs to
introduce the whole thing again. Is storing it in session a solution?

With the 2 first points there is another problem, when the user leaves
this view (by clicking some of the serch results or another link on
the sidebar) I should delete the useless stuff for other pages stored
in session. Now I have to add a clear, flush, or delete session
sentence at the beginning of every view which is accesible from this
one?? Is there no way of saying if this guy leaves this view delete
this session data. In anycase if I delete the whole session wouldn't
be the user forced to log out?(as I can see from the docs it doesn't
looks like, but just to ensure).

3.A different performance thing: I'm having all my code now in django-
html and some css. By deleting an item I want to display a
confirmation like: Are you sure yo want to proceed? with the typical
yes/no buttons, I have done these by making the whole thing hidden in
the template:  passing from the
view 'button_type' = "hidden", and when the user clicks delete for the
first time making it visible, from the view 'button_type' = "submit".
It works well and I do not want to integrate any javascript if it's
not strictly neccesary. Is this the best way to handle it? I mean
there is an extra request which wouldn't have been done by using js.
Thats a thing thats been bothering me since I'm using django (nearly
half a year now), for every click the user does you send a request,
isn't that going to cause some overhead on the server?(in production
pages I'm a noob, sorry).

Thanks in advance and sorry for the long post I just wanted to point
out everything as clear as possible ;)

Regards,
TDG

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



Re: Multiple managers for reverse-links between subclasses

2009-01-22 Thread Aneurin Price

On Wed, Jan 21, 2009 at 7:27 PM, Mackenzie Kearl
 wrote:
>
> On Jan 21, 11:14 am, Aneurin Price  wrote:
>> (Apologies for the vague subject; I couldn't think how to summarise this :P)
>>
>> Hello all,
>>
>> I have an application where some models are inherited from others, like so:
>>Foo
>>   /   \
>> Bar  Baz
>> Each object has (or may have) a parent object, which is a Foo (it might be a 
>> Bar
>> or a Baz, or some other subclass, but it's definitely a Foo). I'd like to be
>> able to find the children of an object, both overall and by subclass, using
>> 'foo_object.children.all()', or 'foo_object.bars.all()' and so on.
>>
>> Originally I set up parent links in Foo, as something like
>> "parent=models.ForeignKey('self', related_name='children')", but when I 
>> realised
>> that I mostly want to get the children in groups, I changed the way I was 
>> doing
>> this. Now I have per-class links like "parent=models.ForeignKey('Foo',
>> related_name='bars')", etc. This allows me to have the parent/child hierarchy
>> that I want, and access the children in the appropriate groups, but it feels
>> rathr ugly, and I'd still like an aggregate 'children' set so that I don't 
>> have
>> to use each set individually (and update every use if I ever add new
>> subclasses).
>>
>> Additionally, I don't know if I'll need this, but I'm interested in how I 
>> might
>> get a link to 'children_of_same_type', so in Foo it would be an alias to
>> 'children', but in Bar it would be an alias to 'bars', etc. I can't just do
>> 'children_of_same_type = bars' because 'bars' is autogenerated so hasn't been
>> defined yet.
>>
>> I hope that makes sense, but if not I can come up with a few more examples to
>> try to clarify it.
>>
>> Does anybody have any suggestions as to how I should structure this? Would I 
>> be
>> best to leave the parent links as they are and define custom Managers for
>> 'children' and 'children_of_same_type'? If so, pointers on how to go about 
>> this
>> would be appreciated.
>>
>> Thanks,
>> Nye
>
> Why don't you instead of subclass Foo just create a foreignkey to Foo
> or a OneToOne with foo.
>
> 'foo_object.children.all()'
> I don't think that this is possible because it contains different
> models in the query.
>
> The other option that you could try is a generic relation something
> like the way django-tagging works.
>
> I hope this is a help
>

It occurred to me last night that I could get the behaviour I want rather more
simply. I've now gone back to using "parent=models.ForeignKey('self',
related_name='children')" in Foo, and added a couple of properties for the rest
like so:

@property
def bars(self):
return Bar.objects.get_query_set().filter(parent=self)

One thing I'm unsure about here is the get_query_set() - Ive used it because
all the examples I've seen doing something similar have used it, but so far as
I can tell the result is exactly the same as Bar.objects.filter(parent=self).
Could somebody en;ighten me here?

This approach can't handle the children_of_same_type case, but it's a start.

Unfortunately it appears that the ORM doesn't provide any real polymorphism for
models, so I may have to rethink what I'm doing anyway. I'm beginning to think I
may be trying to write C++ in Python...

Actually, part of what I want to do is covered by this:
http://lazypython.blogspot.com/2008/11/timeline-view-in-django.html
So I've got a lot to think about.

Thanks,
Nye

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



Re: trying unsuccessfully to access django admin

2009-01-22 Thread Peter Herndon

Well, first things first:  set DEBUG=True in your settings.

The traceback you got there is saying there's an HTTP 500 error
somewhere, so it's looking for a 500.html template to use to display
that error.  Django only tries to show that page if you have set
DEBUG=False.  In this case, you need to find out what the underlying
error is, so set DEBUG=True and try /admin/ again.

Here's the docs on the 500.html page:

http://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views

---Peter


On Thu, Jan 22, 2009 at 9:44 AM, bconnors  wrote:
>
> when I typed in: http://127.0.0.1:8000/admin/
>
> I got:
>
> Traceback (most recent call last):
>
>  File "C:\Python26\Lib\site-packages\django\core\servers
> \basehttp.py", line 278, in run
>self.result = application(self.environ, self.start_response)
>
>  File "C:\Python26\Lib\site-packages\django\core\servers
> \basehttp.py", line 635, in __call__
>return self.application(environ, start_response)
>
>  File "C:\Python26\Lib\site-packages\django\core\handlers\wsgi.py",
> line 239, in __call__
>response = self.get_response(request)
>
>  File "C:\Python26\Lib\site-packages\django\core\handlers\base.py",
> line 116, in get_response
>return self.handle_uncaught_exception(request, resolver,
> sys.exc_info())
>
>  File "C:\Python26\Lib\site-packages\django\core\handlers\base.py",
> line 160, in handle_uncaught_exception
>return callback(request, **param_dict)
>
>  File "C:\Python26\Lib\site-packages\django\views\defaults.py", line
> 23, in server_error
>t = loader.get_template(template_name) # You need to create a
> 500.html template.
>
>  File "C:\Python26\Lib\site-packages\django\template\loader.py", line
> 80, in get_template
>source, origin = find_template_source(template_name)
>
>  File "C:\Python26\Lib\site-packages\django\template\loader.py", line
> 73, in find_template_source
>raise TemplateDoesNotExist, name
>
> TemplateDoesNotExist: 500.html
>
> >
>

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



trying unsuccessfully to access django admin

2009-01-22 Thread bconnors

when I typed in: http://127.0.0.1:8000/admin/

I got:

Traceback (most recent call last):

  File "C:\Python26\Lib\site-packages\django\core\servers
\basehttp.py", line 278, in run
self.result = application(self.environ, self.start_response)

  File "C:\Python26\Lib\site-packages\django\core\servers
\basehttp.py", line 635, in __call__
return self.application(environ, start_response)

  File "C:\Python26\Lib\site-packages\django\core\handlers\wsgi.py",
line 239, in __call__
response = self.get_response(request)

  File "C:\Python26\Lib\site-packages\django\core\handlers\base.py",
line 116, in get_response
return self.handle_uncaught_exception(request, resolver,
sys.exc_info())

  File "C:\Python26\Lib\site-packages\django\core\handlers\base.py",
line 160, in handle_uncaught_exception
return callback(request, **param_dict)

  File "C:\Python26\Lib\site-packages\django\views\defaults.py", line
23, in server_error
t = loader.get_template(template_name) # You need to create a
500.html template.

  File "C:\Python26\Lib\site-packages\django\template\loader.py", line
80, in get_template
source, origin = find_template_source(template_name)

  File "C:\Python26\Lib\site-packages\django\template\loader.py", line
73, in find_template_source
raise TemplateDoesNotExist, name

TemplateDoesNotExist: 500.html

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



Re: why not load the index first?

2009-01-22 Thread Kenneth Gonsalves

On Thursday 22 Jan 2009 7:31:07 pm Malcolm Tredinnick wrote:
>  But please do understand that this isn't a
> change that is necessarily universally better for everybody. It does
> harm the content presentation, for example.

ok - I wont raise this again - but please check out the comments on the IRC 
channel about the docs. End users are not happy.

-- 
regards
KG
http://lawgon.livejournal.com

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



Re: Convert iso-8859-1 queryset to utf-8

2009-01-22 Thread Polat Tuzla

You may also want to make sure that you know whether your Flash/
ActionScript components require UTF-8 with BOM (Byte-order Mark) or
not.

Let me try to explain more clearly:
In my case, I had i18n problems when a flash component rendered my
utf-8 encoded templates.
I had saved my templates as utf-8, had set the response headers as:

response = HttpResponse(mimetype='text/xml; charset=utf-8')

Nevertheless all of the characters that are out of ascii range were
not displayed correctly.
It turned out to be that my text editor (TextMate) was saving the file
as UTF-8 without BOM for some good reasons.
(http://blog.macromates.com/2005/handling-encodings-utf-8/)
And the flash component required UTF-8 with BOM in order to display
correctly.
So I had to save my xml templates in an other text editor.

Regards,
Polat Tuzla


On Jan 21, 1:55 pm, Anders  wrote:
> My django site uses iso-8859-1 as default output of all the web pages
> (due to ssi intergration with other iso-8859-1 pages).
>
> So I have set:
> DEFAULT_CHARSET = 'iso-8859-1'
> FILE_CHARSET = 'iso-8859-1'
>
> and this works fine for alle the pages I serve.
>
> But now I have to serve an xml output for use with actionscript in a
> Flash. This xml should be UTF-8 encoded.
>
> Is there som way I can convert the queryset to utf-8 so that this will
> work? Or can I convert each string as I output it in the template
> (yeah, I use the template to create xml - not good, I know).
>
> In addition the render_to_response uses the default charset, is is
> possible to override this default and use UTF-8?
>
> Thnx
> Anders
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: why not load the index first?

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 19:17 +0530, Kenneth Gonsalves wrote:
> On Thursday 22 Jan 2009 6:48:11 pm Malcolm Tredinnick wrote:
> > I think you have not described whatever problem it is that you're trying
> > to solve particularly well. "Index" has at least three different
> > meanings for the documentation. I'm assuming you mean the content index
> > (/dev/genindex/), but maybe you mean something else.
> 
> ok, the problem is simple: in the old days it was dead easy to find relevant 
> parts of the docs. Now it is not.

Debateable as to the realtive ease. Certainly things are different now
and takes some time to get used to. We are also steadily improving
things as concrete problems are pointed out. Realise that the earlier
versions of the documentation were also becoming quite hard to find
things in as individual pages became longer and longer.

After the docs refactor the follow-up idea is that we now need to fill
in a lot of places with cross-references and with extra documentation so
that it can serve the purpose of being both reference and tutorial (for
multiple levels of ability) documentation.

>  I thought it was only me, but I have seen 
> enough comments on IRC to find that it is general. The main document page for 
> before restructuring was good. Now the only way to find anything is through 
> google search. So my request is very simple: if we cannot go back to the old 
> structure, at least put google search and the module/global index as the 
> *first* items on the left hand side of the page so we can go there.

Okay, so you were talking about the sidebar, not the index pages.

>  After a 
> gap, I am coding a new django site, and decided to do it from scratch with no 
> copy/paste and checking the docs. It is proving difficult. Please do not 
> think I am criticising the docs - I am not. But I *am* viewing the docs as an 
> end user and putting forward my feedback.

Firstly, I explained in my original post why that meta information is on
the right-hand side, not the left (along with it being a design
decision). This is one of those things where reasonable people will have
different opinions. Having to scroll right if you're on some kind of
narrower screen-width browser window just to read the content is kind of
painful, too, I'm sure you'll agree.

Secondly, if things are hard to find without search (and that is
something that is improving over time), a much better fix is to work
where the difficulties are and improve them by fixing the docs (via
ticket reports with patches). Adrian did that a few months back, for
example, when he reorganised the content on the front page.

Moving the search box to occupy prime real-estate has drawbacks and
doesn't save an enormous amount of time. However, if that does really
help you out, one solution that springs to mind is easy: use different
stylesheets (or remove the Django stylesheets and just use the default
Sphinx ones) on your local build of the docs. You can organise things
however you like there. But please do understand that this isn't a
change that is necessarily universally better for everybody. It does
harm the content presentation, for example.

Regards,
Malcolm


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



Re: I don't even know where to begin writing this template-tags

2009-01-22 Thread Andrew Ingram

That works great, thanks!

bruno desthuilliers wrote:
> http://www.djangosnippets.org/snippets/1293/
> This may 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problem with django-tagging and with_all/with_any

2009-01-22 Thread Andrew Ingram

Hi all,

I'm using django-tagging for a Banner model and since it's fairly widely 
used I thought some people here may be able to help. I want to achieve 
two things: find all the Banners related to ALL of a list of tags, and 
final all the Banners related to ANY of a list of tags

This is my banner model (irrelevant bits excluded):

class Banner(models.Model):
tag_objects = tagging.managers.ModelTaggedItemManager()
tags = TagField()
tagging.register(Banner)

I have a single banner, with the tags 'listing', 'foo', and 'bar'.

But when I run this:
Banner.tag_objects.with_all(('listing','joe'))
It returns the banner, when by my understanding it shouldn't.

It's returning the same result as:
Banner.tag_objects.with_any(('listing','joe'))

Have I completely misunderstood how this is supposed to work?

Regards,
Andrew Ingram

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



Re: why not load the index first?

2009-01-22 Thread Kenneth Gonsalves

On Thursday 22 Jan 2009 6:48:11 pm Malcolm Tredinnick wrote:
> I think you have not described whatever problem it is that you're trying
> to solve particularly well. "Index" has at least three different
> meanings for the documentation. I'm assuming you mean the content index
> (/dev/genindex/), but maybe you mean something else.

ok, the problem is simple: in the old days it was dead easy to find relevant 
parts of the docs. Now it is not. I thought it was only me, but I have seen 
enough comments on IRC to find that it is general. The main document page for 
before restructuring was good. Now the only way to find anything is through 
google search. So my request is very simple: if we cannot go back to the old 
structure, at least put google search and the module/global index as the 
*first* items on the left hand side of the page so we can go there. After a 
gap, I am coding a new django site, and decided to do it from scratch with no 
copy/paste and checking the docs. It is proving difficult. Please do not 
think I am criticising the docs - I am not. But I *am* viewing the docs as an 
end user and putting forward my feedback.

-- 
regards
KG
http://lawgon.livejournal.com

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



Re: How do i display a count of items related to a model?

2009-01-22 Thread ltcstyle
Are you sure it is not just a property of that question class?
Storing a count property for that answers, and increase it every time got
new response?
It would be faster than go through the entire db for each question.

I am just guessing.


On Thu, Jan 22, 2009 at 1:37 PM, Gath  wrote:

>
> In Django how can i return the total number of items (count) that a
> related to another model, e.g the way stackoverflow.com does a list of
> questions then on the side it shows the count on the answers related
> to that question.
>
> This is easy if i get the questionid, i can return all answers related
> to that question but when am displaying the entire list of question it
> becomes a bit tricky to display on the side the count showing the
> total answer count.
>
> I don't know if am clear but just think how www.stackoverflow.com
> displays its questions with answer,views count next to each question!
>
> >
>

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



Re: ManyToManyField in both models

2009-01-22 Thread Evgeniy Ivanov (powerfox)

On Jan 22, 1:20 am, Malcolm Tredinnick 
wrote:
>
> How is it wrong that when you want a custom form you have to actually
> write some code? Django cannot read your mind. It cannot possibly
> accommodate every single use-case of every person on the planet out of
> the box. It's designed to be extensible for precisely that reason.
>
> "I have to write some code" is not a bad thing. Django is a library for
> programmers.

I understand. But you know, every developer has own opinion. Maybe in
this case it's a bad taste of mine.
And I agree that django is a very cute, well designed and powerful
library. Since I came from C++ world I call django "Qt for web
development" :)

> > I think it would be much better to specifybothM2M fields with the
> > same table name.
>
> Well, have lots of fun implementing your own field type to do this, if
> it's what you want.
>
> Django's ManyToManyField is, and always will be, specified on exactly on
> model. That describes the data and the programmatic API. Trying to hack
> that to modify the presentation of a form is still attacking the wrong
> end of the problem.

Sorry, but I can disagree a bit. I've written what can be done to make
it work in a way I've described here:
http://groups.google.com/group/django-developers/t/6a91f3523a69c2b
And it is a kind of ManyToManyField.through, isn't it? If we return to
the beginning of discussion:

class User(models.Model):
groups = models.ManyToManyField('Group', related_name='groups',
db_table=u'USERS_TO_GROUPS')
class Group(models.Model):
users = models.ManyToManyField(User, related_name='users',
db_table=u'USERS_TO_GROUPS')

I don't feel it abnormal. Yes, it can be my fault and also I work with
DB and django only about one month, so please forgive my arguing.
This code works fine with django, but with the only exception: syncdb
tries to generate 2 tables. It would be nice to specify something like
"create_table=False" in the second M2M, and it will be very like
"through" option. It's my humble opinion.

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



How do i display a count of items related to a model?

2009-01-22 Thread Gath

In Django how can i return the total number of items (count) that a
related to another model, e.g the way stackoverflow.com does a list of
questions then on the side it shows the count on the answers related
to that question.

This is easy if i get the questionid, i can return all answers related
to that question but when am displaying the entire list of question it
becomes a bit tricky to display on the side the count showing the
total answer count.

I don't know if am clear but just think how www.stackoverflow.com
displays its questions with answer,views count next to each question!

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



update_object acting strangely

2009-01-22 Thread bax...@gretschpages.com

I think this just started, and may be related to updating to 1.0.2.
Lately I've noticed update_object not updating properly. In
particular, I've noticed boolean fields changing. For example, I'll
have an "approved" field that's True, but when the user update the
info, "approved" is changing to False. This is happening on at least
two different models, and I've never noticed it until the past week or
so. Suggestions?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to send custom value to the SelectMultiple Widget

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 04:58 -0800, Lee wrote:
> Thanks a lot.
> 
> I'd like to pass the dynamic value to the choices, like what you said
> in the last situation.
> 
> Could you please give me some more instructions, I'm new in python and
> django.

I've given you a code fragment already to show how to do it in __init__.
In the first reply I gave in this thread, I gave a link to another
thread that also had a similar code fragment. So could you at least read
those and ask specific questions about what you don't understand.

I'm not going to write your code for you. That won't help you learn
anything. I have taken the time to show similar code (twice now!), so
without more details as to what is confusing you, I doubt I can help any
further.

Regards,
Malcolm



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



Re: Port large webapp from PHP to Django: tips, experiences, links needed

2009-01-22 Thread Almad

Well, I'd like to write some docs first, but hey ,)

I'm developing something on top of nose, to express my feelings, I
call it django-sane-testing. Grab nose 0.10 and sane testing from
http://devel.almad.net/trac/django-sane-testing/wiki/Releases and
enjoy usual nose features (test selection, profiling plugin et al)
together with:

 * support for unit tests (yeah, no database handling when not needed
- subclass from UnitTestCase)
 * selenium integration (subclass SeleniumTestCase and enjoy
self.selenium)
 * live server (yup, you can use urllib2 now)
 * and hey, even TEST_RUNNER='djangosanetesting.testrunner.run_tests'
works

Well, docs and setuptools thinigies is what's left ;)

Almad

On Jan 22, 11:32 am, Malcolm Tredinnick 
wrote:
> It's a little disappointing that there aren't a lot more people blogging
> about using their test library of choice with Django. It's certainly
> possible and would perhaps fill a gap in the accumulated knowledge-base.
> Specifics of things that you (webchemist) find hard to emulate with your
> favourite framework would obviously be useful to know about, probably in
> a separate thread, but I think testing is an area where Django adopts a
> nice unobtrusive behaviour and doesn't require any particular framework
> for tests.
>
> Regards,
> Malcolm

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



Re: why not load the index first?

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 18:31 +0530, Kenneth Gonsalves wrote:
> hi,
> 
> wrt django documentation, why not load the index first - on the left?

Do you mean the thing labelled as "general index"? It would use up
valuable horizontal screen real-estate without adding a lot of value. On
every single page. If you want the index, it's one click away (or
bookmark it directly). The same reason (at least one of the reasons)
we've shifted the contents sidebar on each page to the righthand side:
it's secondary content for the page and our eyes naturally gravitate
(when reading English) to the top-left of the screen, so the most
important content, the stuff that we are actually visiting the page to
read, is in that primary location.

Django's documentation strives hard to be readable. As in, you can sit
down and read it without it being too distracting or looking like some
kind of internet portal landing page. Books and magazines are the most
familiar things we read and they don't have huge wordlists down the left
hand side of any page.

Although it would make things look more like Javadoc, which would drive
a lot of us insane, but make things more comfortable for a small group
of migrators, I guess. ;-)


>  Also it 
> would be helpful if the following links are at the top of the index:
> 
> Search
> 
> * Latest
> * 1.0
> * 0.96
> * All

Those are there.

> 
> Browse
> 
> * Prev: django.contrib.webdesign
> * Next: django-admin.py and manage.py

Why are these needed on the index page? You're there to look up some
arbitrary section. Next and previous don't make much sense.

> * Table of contents
> * General Index
> * Global Module Index

They are already there.

I think you have not described whatever problem it is that you're trying
to solve particularly well. "Index" has at least three different
meanings for the documentation. I'm assuming you mean the content index
(/dev/genindex/), but maybe you mean something else.

Regards,
Malcolm



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



why not load the index first?

2009-01-22 Thread Kenneth Gonsalves

hi,

wrt django documentation, why not load the index first - on the left? Also it 
would be helpful if the following links are at the top of the index:

Search

* Latest
* 1.0
* 0.96
* All

Browse

* Prev: django.contrib.webdesign
* Next: django-admin.py and manage.py
* Table of contents
* General Index
* Global Module Index

it would be immensely helpful.
-- 
regards
KG
http://lawgon.livejournal.com

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



Re: How to send custom value to the SelectMultiple Widget

2009-01-22 Thread Lee

Thanks a lot.

I'd like to pass the dynamic value to the choices, like what you said
in the last situation.

Could you please give me some more instructions, I'm new in python and
django.

regards
Lee



On Jan 22, 11:21 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-01-22 at 03:54 -0800, Lee wrote:
> > Hi, Malcolm
>
> > Thanks for you reply. However, I'm still not clear.
>
> > My code is :
>
> > from django import forms
>
> > class TestForm(forms.Form):
> >   title = forms.CharField( max_length=10 )
> >   selection = forms.CharField( widget=forms.Select )
>
> > f = TestForm(initial={"title": 'Test', 'selection':{'1':'a','2':'b'}})
>
> Since you haven't specified any choices for the form field, this isn't
> going to be very useful. The initial values for any multiple choice
> field (like Select) have to be a subset of the choices that the field
> provides. Since your field provides precisely no choices, your initial
> data for the "selection" attribute will have no effect.
>
> The output you are seeing when you print this form is correct, based on
> what you have told the form you want.
>
> > print f
>
> > I want output like:
>
> > a
> > b
>
> For a start, that isn't a valid HTML form. The option elements have to
> be wrapped inside something. Do you mean that is what you are hoping to
> see for the "selection" field? If so, specifying some choices will
> certainly help things along.
>
> Either you have to write (just writing out the "selection" line):
>
>         selection = forms.CharField(widget=forms.Select(
>                             choices={'1': 'a', '2': 'b'})
>
> or you need to set up the "choices" attribute as part of your form's
> __init__ method. By default, you cannot modify the choices for a form
> field via the constructor, only the initial values that are selected
> ("initial" for a form means the initial set values, not all the
> possibilities).
>
> Thus, if you want to pass in the choices, you have to write code to do
> that yourself. For example:
>
>         class TestForm(forms.Form):
>            def __init__(self, *args, **kwargs):
>               choices = kwargs.pop('choices')
>               super(TestForm, self).__init__(*args, **kwargs)
>               self.fields["selection"].widget.choices = choices
>
>            # ...
>
> and then TestForm(choices={...}) will set up the choices.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Compare the fields of the same model

2009-01-22 Thread Costin Stroie

I have implemented a very basic Q object. Under controlled conditions,
it works great. Here it is:

class QCompare(models.Q):
""" QCompare object allows you to compare two fields of one or two
models

Example: queryset.filter(QCompare('>', Model1, 'field1', Model2,
'field2'))
"""

def __init__(self, op, model1, field1, model2, field2):
""" Init the Q object """

if isinstance(model1, models.base.ModelBase):
if field1 is None or field1 == 'pk':
field1 = model1._meta.pk.name
try:
field1 = model1._meta.get_field(field1).column
except AttributeError, e:
raise AttributeError, "%s: %s" % (e, "model: %s,
field: %s" % model1, field1)
model1 = model1._meta.db_table

if isinstance(model2, models.base.ModelBase):
if field2 is None or field2 == 'pk':
field2 = model2._meta.pk.name
try:
field2 = model2._meta.get_field(field2).column
except AttributeError, e:
raise AttributeError, "%s: %s" % (e, "model: %s,
field: %s" % model1, field1)
model2 = model2._meta.db_table

# Create the WHERE clause
self.where = "%s.%s %s %s.%s" % (model1, field1, op, model2,
field2)

def get_sql(self, opts):
""" Return the SQL clause """
return ({}, [self.where,], [])


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



Re: How to send custom value to the SelectMultiple Widget

2009-01-22 Thread Malcolm Tredinnick

On Thu, 2009-01-22 at 03:54 -0800, Lee wrote:
> Hi, Malcolm
> 
> Thanks for you reply. However, I'm still not clear.
> 
> My code is :
> 
> from django import forms
> 
> class TestForm(forms.Form):
>   title = forms.CharField( max_length=10 )
>   selection = forms.CharField( widget=forms.Select )
> 
> f = TestForm(initial={"title": 'Test', 'selection':{'1':'a','2':'b'}})

Since you haven't specified any choices for the form field, this isn't
going to be very useful. The initial values for any multiple choice
field (like Select) have to be a subset of the choices that the field
provides. Since your field provides precisely no choices, your initial
data for the "selection" attribute will have no effect.

The output you are seeing when you print this form is correct, based on
what you have told the form you want.

> print f
> 
> I want output like:
> 
> a
> b

For a start, that isn't a valid HTML form. The option elements have to
be wrapped inside something. Do you mean that is what you are hoping to
see for the "selection" field? If so, specifying some choices will
certainly help things along.

Either you have to write (just writing out the "selection" line):

selection = forms.CharField(widget=forms.Select(
choices={'1': 'a', '2': 'b'})

or you need to set up the "choices" attribute as part of your form's
__init__ method. By default, you cannot modify the choices for a form
field via the constructor, only the initial values that are selected
("initial" for a form means the initial set values, not all the
possibilities).

Thus, if you want to pass in the choices, you have to write code to do
that yourself. For example:

class TestForm(forms.Form):
   def __init__(self, *args, **kwargs):
  choices = kwargs.pop('choices')
  super(TestForm, self).__init__(*args, **kwargs)
  self.fields["selection"].widget.choices = choices

   # ...

and then TestForm(choices={...}) will set up the choices.

Regards,
Malcolm


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



Re: ManyToManyFieldManager in post_save signal

2009-01-22 Thread Alessandro

2008/10/12 Alex Koshelev :
>
> There is not way track M2M field change with post_save signal. You can
> write your own derived M2M field class with needed hooks.
>
> On Oct 12, 9:01 pm, Viktor  wrote:
>> Hi,
>>
>> I have three simple models Project and Member, where Project.member is
>> a ManyToManyField to User through Member
>>
>> then I would like to add some post save action when a new member is
>> added to a project. Should I connect this signal to Project or to
>> Member? Of course, new members can be added on creation and later as
>> well, and I use the generic view create_object for this.
>>
>> I've actually tried both, but with Project instance.members is an
>> "empty" ManyToManyFieldManager, that is instance.members.all() gives
>> [ ] (an empty queryset), while the signal on Member never gets called
>>
>> how would you do this post_save signal?


Is there any example I can read to do the same thing? I want to email
M2M content after an instance save.

I thought a post_save should be raised when M2M field table update is completed.
Is there any way to make a method call after that?



-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

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



Re: How to send custom value to the SelectMultiple Widget

2009-01-22 Thread Lee

Hi, Malcolm

Thanks for you reply. However, I'm still not clear.

My code is :

from django import forms

class TestForm(forms.Form):
  title = forms.CharField( max_length=10 )
  selection = forms.CharField( widget=forms.Select )

f = TestForm(initial={"title": 'Test', 'selection':{'1':'a','2':'b'}})
print f

I want output like:

a
b

However, the real output is:

Title:
Selection:



regards
Lee


On Jan 22, 7:32 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-01-21 at 21:41 -0800, Lee wrote:
> > Hi, everyone.
>
> > I have some trouble in SelectMultiple Widget. The detailed information
> > is that:
>
> > In the form.py, I have defined a TestForm which contain a
> > SelectMultiple Widget called selection
>
> > #form.py
> > class TestForm(forms.Form):
> >   selection = forms.CharField( widget=forms.SelectMultiple() )
>
> > Howvever, if I want to assign values to that widget, how to do that in
> > the views.py?
>
> If you want to assign the choices will appear in the HTML form, assign
> to self.fields["selection"].choices in the __init__ method of the form.
> See [1] for a recent thread on that (scroll down to the end of the
> thread, because it starts at as a "how do I...?" question and the answer
> is only in one of the final posts).
>
> If you want to set up the initial selection values, pass in an "initial"
> parameter when you construct the form. See [2] (the Django docs for
> that) and [3] (another recent thread about setting initial values on
> multi-select stuff -- I don't know why it only shows my replies and not
> the original poster, but the info is there).
>
> [1]http://groups.google.com/group/django-users/browse_frm/thread/b4dadbc...
>
> [2]http://docs.djangoproject.com/en/dev/ref/forms/fields/#dynamic-initia...
>
> [3]http://groups.google.com/group/django-users/browse_frm/thread/2d5595d...
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >