Re: Problems witch Apache - KeyError at / - 'HOME'

2009-12-09 Thread edward9
Yes. I restart Apache every configuration change.

Error from text box:
Environment:

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


Traceback:
File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py" in
get_response
  77. request.path_info)
File "/usr/lib/pymodules/python2.5/django/core/urlresolvers.py" in
resolve
  179. for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/pymodules/python2.5/django/core/urlresolvers.py" in
_get_urlconf_module
  198. self._urlconf_module = __import__
(self.urlconf_name, {}, {}, [''])
File "/mysite/urls.py" in 
  18.   (r'^$',main_page),

Exception Type: NameError at /
Exception Value: name 'main_page' is not defined


Apache:

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
#PythonOption django.root /mysite
PythonDebug Off
PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
#PythonPath "['/'] + sys.path"


On development server works fine. On Apache not working. I have tried
to create new project but same situation.

Regards
Edward9


On Dec 10, 12:41 am, Karen Tracey  wrote:
> Did you restart Apache after making all your code changes?
>
> Please click the Switch to copy-and-paste view link and cut and paste the
> contents of the text box that will appear.  The other version is not good
> for pasting into email.
>
> Karen

--

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




Django documentation error? (minor, but misleading)

2009-12-09 Thread chefsmart
On the page http://www.djangoproject.com/documentation/models/many_to_many/
under Sample API Usage

where it says: -

"
# Add a Publication directly via publications.add by using keyword
arguments.
>>> new_publication = a2.publications.create(title='Highlights for Children')
"

I think it should say: -

"
# Add a Publication directly via publications.create by using keyword
arguments.
>>> new_publication = a2.publications.create(title='Highlights for Children')
"

The distinction between "add" and "create" should be emphasized,
especially for people new to Django.

Also where it says: -

"
# Adding a second time is OK
>>> a2.publications.add(p3)
"

It should be made clear what "OK" means here. Does it mean it has no
effect, or does it mean that another record is created? Right now to
find out the meaning of "OK" people have to go into the Django shell.

Regards.

--

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




design starting question

2009-12-09 Thread Mike Dewhirst
I want to design a site to replace an existing one running on my 
client's Windows 2008 server.

Currently, external users are given manually generated basic auth login 
credentials to view their own directory on the server. It is running 
Apache 2.2 and there is zero html and no database.

The documents in the customer directories are pdf consignment notes and 
delivery dockets which form a rudimentary proof of delivery system.

The new requirement is for external users to have a search facility for 
documents in their own branch of the directory tree. For example, the 
customers know some or all of the filename (document numbers are in the 
filenames) and want to go directly to the pdf file. They also know the 
date (perhaps roughly) of a document.

The documents are produced by a separate system and just appear in the 
customer directories. There is no way to actively link that production 
event with a new app.

I'm not sure what to do.

Is there a way to treat the Windows directory structure like a database?

If so, is that a Django thing or just Python?

I like the URLConf potential for a customer to type in the base URL, a 
slash and a fragment of the document name to trigger a direct display if 
there is only one search result but a list if there is more than one.

Thanks for any ideas

Mike

--

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

2009-12-09 Thread Mikhail Korobov
Performance monitoring doesn't have to be related to django itself.
There are external projects that cant do performance monitoring (CPU,
i/o, memory usage over time). You may give munin (http://
munin.projects.linpro.no/) a chance.

On Dec 10, 7:43 am, Kegan Gan  wrote:
> Hi,
>
> Google App Engine provides a rather extensive set of tools to monitor
> the performance of your applications running in App Engine. Is there
> something similar 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Could Django model dynamically create new class with new table?

2009-12-09 Thread HUANG Dong
Sorry, my original description may be a bit misleading.  In summary,
all I want is to create multiple table through Django's "Model" way.

Yes, I know this can be done using metaclass.  I just did not know how
to integrate it into Django's model, and the impacts.  Fortunately, it
seems Django has already covered this.  Here is an entry on their
wiki:

http://code.djangoproject.com/wiki/DynamicModels

Anyway, thank you all for the help.

Huang

On Thu, Dec 10, 2009 at 5:16 AM, bruno desthuilliers
 wrote:
> On 9 déc, 20:18, HUANG Dong  wrote:
>> Thank you, Bruno.  Your answer is really helpful and covered another
>> issue I hadn't noticed yet.  But my question may be related to
>> different topic.  In my example, number of "libraries" is unknown in
>> develop time, neither does the classification of "books".
>
> You explicitely mentionned that the reason to "partition" the books in
> different tables was to speed up queries - and FWIW, I can't think of
> any other reason to do so. If all you want is classification then
> using different tables is not the correct solution.
>
>> To be more specific, I want to employ some kind of "introspective"
>> class in python to model my data, and these dynamic classes should be
>> associated to individual TABLEs in the database respectively.
>
> Yes, that's clearly what I understood. But this looks like a wrong
> solution to a (potentially) real problem, hence my mention of RDBMS-
> level table partitionning.
>
>
>> So far what I know about Django is that each class inheriting from
>> models.Model will be associated to a TABLE, and each instance of the
>> class becomes an item when calling instance.save().  What if I create
>> an introspective object in run-time?  And when to call synchronization
>> function to write the table into database?  How to sync if there's
>> concurrent creation of classes?  What about the performance?  All
>> above are still unknown to me...
>
> Creating model classes at runtime is of course possible - if a bit
> involved - since Python's "class" statement is an executable
> statement. I'll even give you a couple hint: read the doc for the
> 'type' type, and google for "metaclass".
>
> But I do insist on the fact that whether your _real_ problem is sql
> queries performances tuning or classification, what you're trying to
> achieve is _not_ the appropriate solution.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




strange error :'NoneType' object has no attribute 'source'

2009-12-09 Thread gganesh
hi group,
I am struck with this strange error message

Request Method: GET
Request URL:http://127.0.0.1:8000/admissions/enquiry/add/
Exception Type: AttributeError
Exception Value:

'NoneType' object has no attribute 'source'

Exception Location: /usr/local/lib/python2.6/dist-packages/django/
template/debug.py in extend_nodelist, line 56
Python Executable:  /usr/bin/python
Python Version: 2.6.4
Python Path:['/home/ganesh/Workspace-software/Djangoprojects/
schooltools', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/
python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/
python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/
gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-
packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/local/
lib/python2.6/dist-packages']

I assume this could be something to do with python version because
previously i was using python 2.5 version with django 1.1 ,and
everything worked fine .I got this error when I switched to python
2.6 .Please correct me if i am wrong



Thanks
Ganesh

--

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

2009-12-09 Thread Sam Walters
You can always place some more performance testing code inside your views:

import time
t = time.time()
search_time=0.00
#
#place some code which hits the database here
#
search_time+=time.time()-t
search_time="%.3f"%(search_time)

This does not test the memory footprint of your application though.
Put all your db calls into a unit test sort of framework is what i did
when developing a search engine for the site im developing.



On Thu, Dec 10, 2009 at 3:53 PM, Andy McKay  wrote:
> On 09-12-09 8:43 PM, Kegan Gan wrote:
>> Thanks for reply, Andy.
>>
>> I am aware of django-debug-toolbar. I am looking something to run with
>> production.
>>
>> How do people monitor Django application performance in production
>> environment today?
>
> Hmm I guess if I knew what you were looking for I could help more. Like
> I say I've run a sql query recording tool, its v. simple. But most of
> the time I rely on system tools like munin or monit.
> --
>   Andy McKay, @clearwind
>   Training: http://clearwind.ca/training/
>   Whistler conference: http://clearwind.ca/djangoski/
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: Performance monitoring

2009-12-09 Thread Andy McKay
On 09-12-09 8:43 PM, Kegan Gan wrote:
> Thanks for reply, Andy.
>
> I am aware of django-debug-toolbar. I am looking something to run with
> production.
>
> How do people monitor Django application performance in production
> environment today?

Hmm I guess if I knew what you were looking for I could help more. Like 
I say I've run a sql query recording tool, its v. simple. But most of 
the time I rely on system tools like munin or monit.
-- 
   Andy McKay, @clearwind
   Training: http://clearwind.ca/training/
   Whistler conference: http://clearwind.ca/djangoski/

--

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

2009-12-09 Thread Kegan Gan
Thanks for reply, Andy.

I am aware of django-debug-toolbar. I am looking something to run with
production.

How do people monitor Django application performance in production
environment today?

Thanks.

On Dec 10, 12:28 pm, Andy McKay  wrote:
> On 09-12-09 6:43 PM, Kegan Gan wrote:
>
> > Google App Engine provides a rather extensive set of tools to monitor
> > the performance of your applications running in App Engine. Is there
> > something similar for Django?
>
> Not that I know of. There's django-debug-toolbar and a quick hack I
> wrote to track the time of each sql query. But I would classify both as
> debugging tools. Is there anything specific you are looking for?
> --
>    Andy McKay, @clearwind
>    Training:http://clearwind.ca/training/
>    Whistler conference:http://clearwind.ca/djangoski/

--

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




Re: Expiry Date

2009-12-09 Thread Djangobot
Thank you Daniel for your kind help. I will use your method as I think
it would be the best solution.

Have a great day.

On Dec 9, 5:37 pm, Daniel Roseman  wrote:
> On Dec 9, 12:07 pm, Djangobot  wrote:
>
>
>
>
>
>
>
> > Hi all
>
> > I am very new to Django and Python and I was wondering if anyone could
> > help me on here as I am desperate for help.
>
> > I am designing a mobi. site and I need to somehow set an expiry date
> > on the competitions that will be run on the site.
>
> > I have added the field expiry date as a DateField in the admin section
> > but I do not know how to produce the code that will check if the
> > competition's expiry date has been reached and then make it invisible
> > in other words set the boolean field for live ad to false?
>
> > I have imported datetime but I need the app to verify when the expiry
> > has been reached. I do not know about signals and the most basic steps
> > would be really a great help.
>
> > Thank you and have a great day!
>
> Signals are not the answer to this.
>
> One way to do it would be to only show competitions whose expiry date
> is greater than today:
>    Competition.objects.filter(expiry_date__gt=datetime.date.today())
>
> Or, if you really need to use a separate boolean, you'll need a
> separate cron job that runs every day, does a filter to get expired
> comps (similar to the above, but use __lte instead of __gt) and sets
> them all to live=False.
> --
> DR.

--

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




Re: Performance monitoring

2009-12-09 Thread Andy McKay
On 09-12-09 6:43 PM, Kegan Gan wrote:
> Google App Engine provides a rather extensive set of tools to monitor
> the performance of your applications running in App Engine. Is there
> something similar for Django?

Not that I know of. There's django-debug-toolbar and a quick hack I 
wrote to track the time of each sql query. But I would classify both as 
debugging tools. Is there anything specific you are looking for?
-- 
   Andy McKay, @clearwind
   Training: http://clearwind.ca/training/
   Whistler conference: http://clearwind.ca/djangoski/

--

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




Re: newbie question on 'clean_' functions

2009-12-09 Thread Rishabh Manocha
On Thu, Dec 10, 2009 at 12:12 PM, Rishabh Manocha  wrote:
> On Thu, Dec 10, 2009 at 11:21 AM, Kenneth McDonald
>  wrote:
>>
>>> And the code to create and validate the form is...?  That might help
>>> in figuring out what is wrong.
>>>
>> Sure. It's just:
>>
>>
>>
>> def buysell(request):
>>     form = BuySellForm()
>>     return render_to_response('buysellform.html', {'form': form})
>
> Here is the problem. As of now, `form` is an unbound form (see docs
> [1]). You need to do something like:
>
> form = BuySellForm(request.POST)
>
> This will trigger all the validation functions,

Correction here. You'll need to call `form.is_valid()` to trigger validation.

>  including clean_shares. You should rewrite your `buysell` view to be 
> something
> along the lines of:
>
> def buysell(request):
>    if request.method == "POST":
>        form = BuySellForm(request.POST)
>        if form.is_valid():
>            #do something...
>        else:
>            #return an error
>     else:
>         form = BuySellForm()
>         return render_to_response('buysellform.html', {'form': form})
>
> Also, unless you haven't posted all the code from BuySellForm's
> definition, clean_shares will throw an error because there is no field
> called `data` defined in the form.
>
> [1] - 
> http://docs.djangoproject.com/en/dev/ref/forms/api/#bound-and-unbound-forms
>
>>
>>
>>
>> in file 'buysell.py', and is referenced as http://.../buysell, as per
>> the urls.py file:
>>
>>
>>
>> from django.conf.urls.defaults import *
>> from mysite import buysell
>>
>> # Uncomment the next two lines to enable the admin:
>> # from django.contrib import admin
>> # admin.autodiscover()
>>
>> urlpatterns = patterns('',
>>     (r'^buysell/$', buysell.buysell),
>>     (r'^boughtsold/$', buysell.boughtsold),
>>
>>
>> and for good measure the HTML is:
>>
>>
>>
>> 
>> 
>> 
>>        Symbol:
>>        Shares:
>>        Price:
>>        
>>        
>> 
>> 
>> 
>>
>>
>> Thanks!
>> Ken
>>
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>
>
>
> --
>
> Best,
>
> R
>



-- 

Best,

R

--

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




Re: newbie question on 'clean_' functions

2009-12-09 Thread Rishabh Manocha
On Thu, Dec 10, 2009 at 11:21 AM, Kenneth McDonald
 wrote:
>
>> And the code to create and validate the form is...?  That might help
>> in figuring out what is wrong.
>>
> Sure. It's just:
>
>
>
> def buysell(request):
>     form = BuySellForm()
>     return render_to_response('buysellform.html', {'form': form})

Here is the problem. As of now, `form` is an unbound form (see docs
[1]). You need to do something like:

form = BuySellForm(request.POST)

This will trigger all the validation functions, including
clean_shares. You should rewrite your `buysell` view to be something
along the lines of:

def buysell(request):
if request.method == "POST":
form = BuySellForm(request.POST)
if form.is_valid():
#do something...
else:
#return an error
 else:
 form = BuySellForm()
         return render_to_response('buysellform.html', {'form': form})

Also, unless you haven't posted all the code from BuySellForm's
definition, clean_shares will throw an error because there is no field
called `data` defined in the form.

[1] - 
http://docs.djangoproject.com/en/dev/ref/forms/api/#bound-and-unbound-forms

>
>
>
> in file 'buysell.py', and is referenced as http://.../buysell, as per
> the urls.py file:
>
>
>
> from django.conf.urls.defaults import *
> from mysite import buysell
>
> # Uncomment the next two lines to enable the admin:
> # from django.contrib import admin
> # admin.autodiscover()
>
> urlpatterns = patterns('',
>     (r'^buysell/$', buysell.buysell),
>     (r'^boughtsold/$', buysell.boughtsold),
>
>
> and for good measure the HTML is:
>
>
>
> 
> 
> 
>        Symbol:
>        Shares:
>        Price:
>        
>        
> 
> 
> 
>
>
> Thanks!
> Ken
>
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>



-- 

Best,

R

--

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




Re: newbie question on 'clean_' functions

2009-12-09 Thread Karen Tracey
On Wed, Dec 9, 2009 at 10:21 PM, Kenneth McDonald <
kenneth.m.mcdon...@sbcglobal.net> wrote:

>
> > And the code to create and validate the form is...?  That might help
> > in figuring out what is wrong.
> >
> Sure. It's just:
>
>
>
> def buysell(request):
> form = BuySellForm()
> return render_to_response('buysellform.html', {'form': form})
>
>
>
That code would not result in any clean methods being called because it
simply creates an unbound form. You don't seem to have included the code
that creates the bound version of the form -- bound to the posted data, that
you can validate.  That's when clean methods are called -- when you call
is_valid on a bound form.

Note that splitting the "create and display a form" function from the
"process the posted data" function is not the normal idiom.  The normal way
views that handle forms are written in Django is described here:

http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

A single view function, with different paths depending on whether the
request is a GET or a POST.

Karen

--

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




django-tagging - how to retrieve individual tags for specific models without duplicates

2009-12-09 Thread neridaj
Hello,

I can't figure out how to retrieve tags for specific models i.e., I
would like to show tags for entries if I'm on a blog/entry page, tags
for links if I'm on a blog/links page, etc. If I use {{ entry.tags }}
in the templates I get duplicate tags and if an entry has more than
one tag those tags wind up on the same line e.g.,

audio, audiodev, audiotrack,
audio, audiodev,
audio,

I've been trying to query the TaggedItems model in order to get the
related content_type i.e., entry, link, etc. in order to get the
related tags individually but I don't understand how to a) get the
tags, and b) remove duplicates. Essentially I want this
TaggedItem.objects.filter(content_type='entry') and then to be able to
remove duplicates.

TaggedItems has these relationships:

tag  = models.ForeignKey(Tag, verbose_name=_('tag'),
related_name='items')
content_type = models.ForeignKey(ContentType, verbose_name=_
('content type'))
object_id= models.PositiveIntegerField(_('object id'),
db_index=True)
object   = generic.GenericForeignKey('content_type',
'object_id')

Thanks for any help,

Jason

--

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




Re: newbie question on 'clean_' functions

2009-12-09 Thread Kenneth McDonald
Oops, wrong HTML down there. The actual HTML is:







{{ form.as_table }}









On Dec 9, 2009, at 9:21 PM, Kenneth McDonald wrote:

>
>> And the code to create and validate the form is...?  That might help
>> in figuring out what is wrong.
>>
> Sure. It's just:
>
>
>
> def buysell(request):
> form = BuySellForm()
> return render_to_response('buysellform.html', {'form': form})
>
>
>
> in file 'buysell.py', and is referenced as http://.../buysell, as per
> the urls.py file:
>
>
>
> from django.conf.urls.defaults import *
> from mysite import buysell
>
> # Uncomment the next two lines to enable the admin:
> # from django.contrib import admin
> # admin.autodiscover()
>
> urlpatterns = patterns('',
> (r'^buysell/$', buysell.buysell),
> (r'^boughtsold/$', buysell.boughtsold),
>
>
> and for good measure the HTML is:
>
>
>
> 
> 
> 
>   Symbol:
>   Shares:
>   Price:
>   
>   
> 
> 
> 
>
>
> Thanks!
> Ken
>
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en 
> .
>
>

--

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




Jobs for DJango newbies?

2009-12-09 Thread Kenneth McDonald
Where would one find such beasties? Once I've taught myself Django,  
I'd like to think I might be able to get some sort of job with it,  
albeit a very junior one.

Thanks,
Ken

--

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




Re: newbie question on 'clean_' functions

2009-12-09 Thread Kenneth McDonald

> And the code to create and validate the form is...?  That might help  
> in figuring out what is wrong.
>
Sure. It's just:



def buysell(request):
 form = BuySellForm()
 return render_to_response('buysellform.html', {'form': form})



in file 'buysell.py', and is referenced as http://.../buysell, as per  
the urls.py file:



from django.conf.urls.defaults import *
from mysite import buysell

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
 (r'^buysell/$', buysell.buysell),
 (r'^boughtsold/$', buysell.boughtsold),


and for good measure the HTML is:






Symbol:
Shares:
Price:







Thanks!
Ken


--

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




Re: newbie question on 'clean_' functions

2009-12-09 Thread Karen Tracey
On Wed, Dec 9, 2009 at 9:16 PM, Kenneth McDonald <
kenneth.m.mcdon...@sbcglobal.net> wrote:

> In the following bit of code:
>
>
>
> from django import forms
>
> class BuySellForm(forms.Form):
> symbol = forms.CharField()
> shares = forms.CharField()
> price = forms.CharField()
> print "DATA"
>
> def clean_shares(self):
> print "DATA KEYS", self.data.keys()
>
>
> the BuySellForm constructor is being called and everything happens
> correctly in the browser, but the 'clean_shares' function is not being
> called. Could someone please point out my newbie error? According to
> the Django Apress book, starting the name of the function with
> 'clean_' should be enough to ensure it is called.
>

And the code to create and validate the form is...?  That might help in
figuring out what is wrong.

Karen

--

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




Re: Django 1.1 - comments - ‘render_comment_form ’ returns TemplateSyntaxError

2009-12-09 Thread Karen Tracey
On Wed, Dec 9, 2009 at 8:24 PM, Kenny Meyer  wrote:

>
> /urls.py[shortened]:
> urlpatterns = patterns('',
>(r'', include('posts.urls')),
>(r'^comments/$', include('django.contrib.comments.urls')),
> )
>
>
Remove the $ from the end of the pattern for the comment urls.

Karen

--

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




Performance monitoring

2009-12-09 Thread Kegan Gan
Hi,

Google App Engine provides a rather extensive set of tools to monitor
the performance of your applications running in App Engine. Is there
something similar 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: newbie question on 'clean_' functions

2009-12-09 Thread Kenneth McDonald
P.S. Yes, the form was correctly submitted.

Thanks,
Ken

On Dec 9, 2009, at 8:16 PM, Kenneth McDonald wrote:

> In the following bit of code:
>
>
>
> from django import forms
>
> class BuySellForm(forms.Form):
> symbol = forms.CharField()
> shares = forms.CharField()
> price = forms.CharField()
> print "DATA"
>
> def clean_shares(self):
> print "DATA KEYS", self.data.keys()
>
>
> the BuySellForm constructor is being called and everything happens
> correctly in the browser, but the 'clean_shares' function is not being
> called. Could someone please point out my newbie error? According to
> the Django Apress book, starting the name of the function with
> 'clean_' should be enough to ensure it is called.
>
> Thanks,
> Ken
>
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en 
> .
>
>

--

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




newbie question on 'clean_' functions

2009-12-09 Thread Kenneth McDonald
In the following bit of code:



from django import forms

class BuySellForm(forms.Form):
 symbol = forms.CharField()
 shares = forms.CharField()
 price = forms.CharField()
 print "DATA"

 def clean_shares(self):
 print "DATA KEYS", self.data.keys()


the BuySellForm constructor is being called and everything happens  
correctly in the browser, but the 'clean_shares' function is not being  
called. Could someone please point out my newbie error? According to  
the Django Apress book, starting the name of the function with  
'clean_' should be enough to ensure it is called.

Thanks,
Ken


--

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

2009-12-09 Thread Shawn Milochik
If you assign the output of the save() method, you'll get the created object.

Instead of:

form.save()

do:

current_order = form.save()

Then you can do whatever you like with current_order, which will be an instance 
of whatever the class 'meta' is of your OrderForm, assuming that OrderForm is a 
forms.ModelForm.

Shawn


--

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




Django 1.1 - comments - ‘render_comment_for m’ returns TemplateSyntaxError

2009-12-09 Thread Kenny Meyer
Hello,

I want to simply render a built-in comment form in a template, using
Django's builtin commenting module, but this returns a
TemplateSyntaxError Exception.

I need help debugging this error, please, because after googling and
using the Django API reference, I'm still not getting any farther.

Info [http://pastebin.com/m189a1af3]: 

This is the template '_post.html'[shortened]:


{{ object.title }}
{{ object.pub_date|timesince }} ago

{{ object.body }}
{% load comments %}
{% get_comment_count for object as comment_count %}
{{ comment_count }}

{% render_comment_form for object %}


This is the Exception output, when rendering:

Caught an exception while rendering: Reverse for
'django.contrib.comments.views.comments.post_comment' with arguments
'()' and keyword arguments '{}' not found.1 {% load comments i18n %}

  {% if next %}{% endif %} {% for field in form %}
{% if field.is_hidden %}
  {{ field }}
{% else %}
  {% if field.errors %}{{ field.errors }}{% endif %}
   {{ field.label_tag }} {{ field }}

/posts/urls.py[shortened]:
queryset = {'queryset': Post.objects.all(),
'extra_context' : {"tags" : get_tags}
   }   
urlpatterns = patterns('django.views.generic.list_detail',
url('^$',   'object_list',  queryset,
name='posts'),
url('^blog/(?P\d+)/$',   'object_detail',queryset,
name='post'),
)

/urls.py[shortened]:
urlpatterns = patterns('',
(r'', include('posts.urls')),
(r'^comments/$', include('django.contrib.comments.urls')),
)



  .'  `.knny [d0t] myer [at] gmail [d0t] com 
  |a_a  |   http://kenny.paraguayinfos.de | gpg key ID: 0x00F56BA1B2
  \<_)__/    
  /(   )\   Everything should be made as simple as possible, but not 
 |\`> < /\simpler.
 \_|=='|_/-- Albert Einstein 


signature.asc
Description: PGP signature


Re: how to produce XML output from a test run?

2009-12-09 Thread Russell Keith-Magee
On Thu, Dec 10, 2009 at 9:02 AM, Phlip  wrote:
> On Dec 9, 4:52 pm, Russell Keith-Magee  wrote:
>
>> If you want to use an XML test runner instead of the default
>> Text-based runner, take a copy of django.test.simple.run_tests() and
>> modify to suit your requirements.
>>
>> I will admit that this isn't a great solution
>
> It is because it's easy after I understand I'm required to do it.

Ahem [1].

[1] 
http://docs.djangoproject.com/en/dev/topics/testing/#using-different-testing-frameworks

> Whatever is in there will show me how to then plug into XmlTestRunner.
> I don't want to duplicate too much effort - hence all the questions. A
> fully mature platform would have covered every one of these details...

I've already given you the open source volunteer lecture. I'd kindly
ask you to keep your snarky comments about the "maturity" of Django to
yourself until such time as you've actually made a substantial
contribution, or you've created a similarly sized project that has
achieved a level of community and commercial adoption comparable to
that achieved by Django.

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-us...@googlegroups.com.
To unsubscribe from this group, send 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 produce XML output from a test run?

2009-12-09 Thread Phlip
On Dec 9, 4:52 pm, Russell Keith-Magee  wrote:

> If you want to use an XML test runner instead of the default
> Text-based runner, take a copy of django.test.simple.run_tests() and
> modify to suit your requirements.
>
> I will admit that this isn't a great solution

It is because it's easy after I understand I'm required to do it.
Whatever is in there will show me how to then plug into XmlTestRunner.
I don't want to duplicate too much effort - hence all the questions. A
fully mature platform would have covered every one of these details...

However, we just discovered...

   python manage.py test --xml

in http://github.com/garethr/django-test-extensions

That also answers my next question - where to either get or add
asserts like assertMatch that I should invent...

--

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

2009-12-09 Thread Russell Keith-Magee
On Thu, Dec 10, 2009 at 8:24 AM, Phlip  wrote:
> Djangoes:
>
> Here's a sketch of an XmlTestRunner.
>
> http://pypi.python.org/pypi/XmlTestRunner/0.16654
>
> The point is to decorate all the test names (and asserts?), and show
> them off, probably with XSLT to HTML to a web page.
>
> To plug a new test runner into Django, you apparently add to
> settings.py:
>
> TEST_RUNNER='doj.test.xmlrunner.run_tests'

This is correct - assuming that xmlrunner has a run_tests method.

> However, the above module has no run_tests() method.
>
> Is there some way to adapt it? Or is there some other way to get
> structured output for formatting?

The run_tests method is a Django specific method - it isn't part of
the standard Test Runner api. It coordinates test discovery and setup
of the Django test environment.

If you want to use an XML test runner instead of the default
Text-based runner, take a copy of django.test.simple.run_tests() and
modify to suit your requirements.

I will admit that this isn't a great solution - copying and modifying
code isn't a great solution to any problem. Backwards-compatible
suggestions welcome.

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-us...@googlegroups.com.
To unsubscribe from this group, 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 choose one row of data

2009-12-09 Thread Andy
This is a very beginner question:

Say a user has just filled out a form and hit the submit button.  They
are redirected to an order confirmation page.  How can I retrieve the
one row of data the user just submitted and display it on the order
confirmation page?

Here is my simple View so far, but it currently displays all the user
inputed data, not the specific row the user just entered:

articles = Context({'articles': Articles.objects.all()})
order_info = Context({'order_data': Order_Info.objects.all()})

def order(request):
if request.method == 'POST':
form = OrderForm(request.POST)
if form.is_valid():
form.save()

return HttpResponseRedirect('/order_complete/')
else:
form = OrderForm()

return render_to_response('order.html', {'form': form}, articles)

def order_complete(request):
return render_to_response('order_complete.html', order_info,
articles)

Thanks for your help!

--

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




Re: how to avoid pk collisions at loaddata time

2009-12-09 Thread Russell Keith-Magee
On Thu, Dec 10, 2009 at 7:59 AM, Phlip  wrote:
> On Dec 9, 3:10 pm, Russell Keith-Magee  wrote:
>
>> Ok; using some non-pk value for PK references is certainly one way to
>> handle this. There is an issue around how to resolve a hash into an
>> actual pk value, but that shouldn't be impossible.
>
> In Rails, a YAML (JSON) fixture like this...
>
>   norbert:
>       name: the nark
>
> ...expands into this...
>
>   norbert:
>      id: <%= hash('norbert') %>
>      name: the nark
>
> ...hence this:
>
>  norbert:
>    id: 39779393
>    name: the nark
>
> Then the id stamps into the database as that record's pk.

Holy mother of what? Randomly inventing a PK and hoping you don't have
a collision? Ah, no. No. Not ever.

>> The big issue is how to format a hash so that it can be differentiated
>> from a primary key value. To shortcut a couple of obvious (but wrong)
>> solutions:
>>   * "just use hash values all the time" isn't an acceptable answer,
>> because we have backwards compatibility to consider
>>  * "if it's an int, use pk, if it's a string, use hash" doesn't work,
>> because Django allows strings as primary keys. It isn't common, but it
>> is possible.
>
> That's why I suggested adding the templating layer to the JSONs.
>
> In general, Django "encourages" screwing with the Admin, then
> extruding sample records, while RoR "encourages" writing very terse,
> very templated YAML files as test code source.

What rubbish. Django encourages nothing of the sort. Django provides
an admin tool. It's a useful tool, especially as - surprise surprise -
an administration interface. You *can* use it to generate data for
fixtures if you want to. I challenge you to find anywhere in the docs
that say the admin interface is *the* way to generate fixtures.

Personally, I never use the admin to build my test fixtures - I hand
write them. Django's fixture format is simple (at least, in JSON and
YAML it is - XML is verbose, but that's XML for you). When you're in
complete control of all the data (as you should be during testing),
hard coding primary keys isn't a problem.

On the subject of which - Why on earth do you even *need* pk-less
objects in a test fixture? If you're in control of all the data - as
you should be during testing - the original problem you describe of
avoiding PK collisions at run time doesn't really exist.

I accept that this problem exists for loading new data into the
database - i.e., "create 10 new people - here are their names and
addresses, but I don't have pks for them " - but for testing? Not as
far as I can see.

>> > The problem now, at loaddata time in production, is the hashes still
>> > might (one in a million chance) collide with a preexisting PK. And the
>> > next problem is the hashes will bump their PK incrementors way up,
>> > throwing away whole ranges of valid fictitious IDs, when the next
>> > natural record inserts.
>
>> Hash collisions aren't a huge concern to me. As long as whatever you
>> are hashing has sufficient entropy that collisions on *input* to the
>> hash aren't possible (or especially likely).
>
> But abandoning all those fictitious numbers, say between our highest
> record of 204 and our hash of 39779393. The auto-incrementor will use
> 39779394 next, and so on. Then all of those numbers between 204 and
> 39779393 will feel bad, because they never got to index a record.

We're on a completely different page here. I have no problem with
using a hash as an fixture-internal reference to an object until such
time as the object is assigned a real pk by the databse. Using a hash
of content as an actual primary key values is a completely different
matter (and, to reinforce my previous point - no, no, not ever).

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-us...@googlegroups.com.
To unsubscribe from this group, 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 produce XML output from a test run?

2009-12-09 Thread Phlip
Djangoes:

Here's a sketch of an XmlTestRunner.

http://pypi.python.org/pypi/XmlTestRunner/0.16654

The point is to decorate all the test names (and asserts?), and show
them off, probably with XSLT to HTML to a web page.

To plug a new test runner into Django, you apparently add to
settings.py:

TEST_RUNNER='doj.test.xmlrunner.run_tests'

However, the above module has no run_tests() method.

Is there some way to adapt it? Or is there some other way to get
structured output for formatting?

(I'm charged with building a test server, if anyone hasn't noticed
yet! ;)

--
  Phlip

--

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




Django Sites in Admin Forms

2009-12-09 Thread bfrederi
In one of my models, I have a foreign key to Django's Site model. When
I view my model in admin, it displays the Site entries by their domain
(in the __unicode__ method). Is there any way to display the name of
the Site instead of the domain in admin?

--

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




Re: how to avoid pk collisions at loaddata time

2009-12-09 Thread Phlip
On Dec 9, 3:10 pm, Russell Keith-Magee  wrote:

> Ok; using some non-pk value for PK references is certainly one way to
> handle this. There is an issue around how to resolve a hash into an
> actual pk value, but that shouldn't be impossible.

In Rails, a YAML (JSON) fixture like this...

   norbert:
   name: the nark

...expands into this...

   norbert:
  id: <%= hash('norbert') %>
  name: the nark

...hence this:

  norbert:
id: 39779393
name: the nark

Then the id stamps into the database as that record's pk.

> The big issue is how to format a hash so that it can be differentiated
> from a primary key value. To shortcut a couple of obvious (but wrong)
> solutions:
>   * "just use hash values all the time" isn't an acceptable answer,
> because we have backwards compatibility to consider
>  * "if it's an int, use pk, if it's a string, use hash" doesn't work,
> because Django allows strings as primary keys. It isn't common, but it
> is possible.

That's why I suggested adding the templating layer to the JSONs.

In general, Django "encourages" screwing with the Admin, then
extruding sample records, while RoR "encourages" writing very terse,
very templated YAML files as test code source.

> > The problem now, at loaddata time in production, is the hashes still
> > might (one in a million chance) collide with a preexisting PK. And the
> > next problem is the hashes will bump their PK incrementors way up,
> > throwing away whole ranges of valid fictitious IDs, when the next
> > natural record inserts.

> Hash collisions aren't a huge concern to me. As long as whatever you
> are hashing has sufficient entropy that collisions on *input* to the
> hash aren't possible (or especially likely).

But abandoning all those fictitious numbers, say between our highest
record of 204 and our hash of 39779393. The auto-incrementor will use
39779394 next, and so on. Then all of those numbers between 204 and
39779393 will feel bad, because they never got to index a record.

> > How about you add a argument to loaddata, such as --gentle, which
> > throws an error (and rolls everything back) if a new PK collides. Then
> > the new feature can wait while programmers fix their (hardcoded) PKs
> > and try again.
>
> > That argument would also work at test time, because the unit tests are
> > expected to always get all PKs right, so the --gentle would be always
> > turned on, and would be a kind of assertion.
>
> There's one other minor flaw in your proposal - the phrase "How about
> you add...". If this is your itch, either *you* need to scratch it, or
> *you* find someone else that will. :-) This is a volunteer project,

I apologize for triggering the "that's how open source works" lecture.

--

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




Re: Strange django behaviour

2009-12-09 Thread Karen Tracey
On Wed, Dec 9, 2009 at 3:09 PM, Maksymus007  wrote:

> For a few weeks I observe strange django behaviour - from time to time
> I get mails about
>
> AttributeError: 'NoneType' object has no attribute 'company'
>
> in line 121, which is:
>
> cursor.execute("SELECT * FROM interface.stats_sms_errors(%d,
> '%s'::timestamp with time zone, '%s'::timestamp with time zone, '%s')"
> % (request.account.company.company_id, stats_time_start,
> stats_time_end, stats_truncate))
>
> looks like request.account is None.
>
> But one line above,line 120 is
>
> cursor.execute("SELECT * FROM interface.stats_sms_mms(%d,
> '%s'::timestamp with time zone, '%s'::timestamp with time zone, '%s')"
> % (request.account.company.company_id, stats_time_start,
> stats_time_end, stats_truncate))
>
> which uses the same request.account which, one line later is empty.
>
> This view is called about 500 times a day and it works, but one or two
> times a day it generates aboved message.
>
> Looks like something "wipes" by request objects in the middle of a
> view. This additional member of request is initialized in my own
> middleware - however its not possible to have this a None value (this
> would display user login form, not executing views).
>
> Same situations can be spoted in few other places in code - every time
> situations is similar - in line n request.account is object, in line
> n+1 its None. What may be important - this always happen in the same
> lines.
>
>
Are all of these places where you are calling cursor.execute on line n?

The description is very reminiscent of rogue pointer use causing
quasi-random memory corruption in C programs.  If it's always popping up
after a cursor.execute, and your database adapter is a C extension, I would
begin to suspect the database adapter.

Karen

--

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




Re: Problems witch Apache - KeyError at / - 'HOME'

2009-12-09 Thread Karen Tracey
Did you restart Apache after making all your code changes?

Please click the Switch to copy-and-paste view link and cut and paste the
contents of the text box that will appear.  The other version is not good
for pasting into email.

Karen

--

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




Re: Stuck trying integrate jinja2 - need compatibility extensions

2009-12-09 Thread Michael Elsdörfer
Todd,

I recommend that you have a look at Coffin:

http://github.com/dcramer/coffin

It comes with a {% url %} that should work out of the box.

The snippets you linked are not tags, but functions, that is, you
would do something like:

{{ url('my_view') }}

You  need the pass the functions in those snippets into the context,
or add them as globals (not sure how to do with with chouwa). However,
it seems like chouwa has it's own url() global:

http://bitbucket.org/trevor/chouwa/changeset/857d017f8c47/

So the template syntax above might just work

Michael

--

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




Re: Testing and request META data

2009-12-09 Thread Russell Keith-Magee
On Thu, Dec 10, 2009 at 2:06 AM, Phlip  wrote:
> On Aug 14 2008, 5:39 am, "Hajo Smulders" 
> wrote:
>
>> I need to set the HTTP_REFERER in the request.META data of a test client so
>> that i can unit test a view.
>> How do I do this? ie: How do i fake an HTTP header on a test client?
>
> Bump? I just hit this problem, and the above question is the only
> traffic on it...

>From the testing docs [1]:

"""
The extra keyword arguments parameter can be used to specify headers
to be sent in the request. For example:

>>> c = Client()
>>> c.get('/customers/details/', {'name': 'fred', 'age': 7},
...   HTTP_X_REQUESTED_WITH='XMLHttpRequest')
"""

[1] 
http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.get

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-us...@googlegroups.com.
To unsubscribe from this group, send 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 avoid pk collisions at loaddata time

2009-12-09 Thread Russell Keith-Magee
On Thu, Dec 10, 2009 at 1:23 AM, Phlip  wrote:
> On Dec 8, 5:13 pm, Russell Keith-Magee  wrote:
>
>> fixture)? As always, suggestions are welcome.
>
> The suggestion is
>
>  - template the json

I'm not sure how this helps. We already have a 100% reliable method
for generating JSON - it's called SimpleJSON, and it's part of the
Python standard library.

>  - name each record

Where exactly does the name come from when data is being dumped programatically?

>  - the PK is the hash of the name
>  - link FKs by name, so they get the same hash

Ok; using some non-pk value for PK references is certainly one way to
handle this. There is an issue around how to resolve a hash into an
actual pk value, but that shouldn't be impossible.

The big issue is how to format a hash so that it can be differentiated
from a primary key value. To shortcut a couple of obvious (but wrong)
solutions:
  * "just use hash values all the time" isn't an acceptable answer,
because we have backwards compatibility to consider
 * "if it's an int, use pk, if it's a string, use hash" doesn't work,
because Django allows strings as primary keys. It isn't common, but it
is possible.

> That way a reader can see an PK or FK, stick in its hash, and keep
> going, without the need to read the other table and find the matching
> FK or PK, respectively.
>
> (the way >cough< Rails does it)
>
> The problem now, at loaddata time in production, is the hashes still
> might (one in a million chance) collide with a preexisting PK. And the
> next problem is the hashes will bump their PK incrementors way up,
> throwing away whole ranges of valid fictitious IDs, when the next
> natural record inserts.

Hash collisions aren't a huge concern to me. As long as whatever you
are hashing has sufficient entropy that collisions on *input* to the
hash aren't possible (or especially likely).

> How about you add a argument to loaddata, such as --gentle, which
> throws an error (and rolls everything back) if a new PK collides. Then
> the new feature can wait while programmers fix their (hardcoded) PKs
> and try again.
>
> That argument would also work at test time, because the unit tests are
> expected to always get all PKs right, so the --gentle would be always
> turned on, and would be a kind of assertion.

There's one other minor flaw in your proposal - the phrase "How about
you add...". If this is your itch, either *you* need to scratch it, or
*you* find someone else that will. :-) This is a volunteer project,
and code gets written by people that want it. It's worth sticking the
idea in Trac, but that doesn't mean that the feature will magically
get implemented.

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




Re: python manage.py list_apps

2009-12-09 Thread Phlip
> > Given a large application with many apps (could have been called
> > Packages), how to rip out a list of all of them?
>
> Aren't they listed in settings.py?

Hmm. I could have just done python shell -> INSTALLED_APPS

instead, I used find .. -name tests.py, and then some cuts and greps.
Silly me! C-:

--

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




Re: Blocking services in django

2009-12-09 Thread Russell Keith-Magee
On Wed, Dec 9, 2009 at 11:50 PM, David Koblas  wrote:
> I'm trying to get a better understanding of django performance in a
> production setting.
>
> Specifically I've seen notes that say that operations like sending mail will
> block all production traffic to your server for the duration of the send.
> That got me thinking about other backend calls, like sending email call
> external URLs etc?

That's a bit of a simplistic analysis, and it's only completely true
if your production web server can only accept a single connection -
something that isn't true of any real production web server (or just
about any web server *other* than Django's development server).

The issue here is the resources that are being consumed to serve a
request, and the time at which they are released. When a client
connects to a web server, they consume one of the available
threads/processes that the server uses to satisfy clients. That
specific thread or process will not be able to serve other clients -
i.e., it will be blocked - until it returns a response. It doesn't
matter what you do to construct the response - call a database, send
mail, or calculate Pi to 1 decimal places - until the response is
returned the thread/process won't be released.

Then you then need to deal with contention *between*
threads/processes. For example, if your mail server can only accept a
single connection at a time, having 10 webserver threads
simultaneously try to send mail will cause slowdown in each of those
threads.

> Is this right, or is there some magic that makes MySQL "better" than just a 
> urllib call.

In short, this is correct. There isn't any magic difference between
urllib vs mysql vs email in terms of raw server performance.

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




Admin two-field ordering resorted by table template: way to turn off?

2009-12-09 Thread Jennifer Bell
I would like my objects to be ordered by two (or more) fields when
viewed in the admin changelist.  However, I noticed that ordering only
works for the first field listed.

I'm pretty sure this is because the order of the objects given to the
template is overridden by the javascript sort in the default admin
changelist template.  Is there any way I can turn this off without
modifying admin templates in the django install?

Jennifer

--

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




Re: python manage.py list_apps

2009-12-09 Thread Christophe Pettus

On Dec 9, 2009, at 2:11 PM, Phlip wrote:
> Given a large application with many apps (could have been called
> Packages), how to rip out a list of all of them?

Aren't they listed in settings.py?

--
-- Christophe Pettus
x...@thebuild.com

--

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




python manage.py list_apps

2009-12-09 Thread Phlip
Djangoids:

Given a large application with many apps (could have been called
Packages), how to rip out a list of all of them?

My initial guess, in the subject line, naturally did not work.

--
  Phlip
  http://c2.com/cgi/wiki?MoreliaViridis

--

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

2009-12-09 Thread tezro
That was really smart of you, thanks... Here's the traceback, hope it
helps.

---
Traceback (most recent call last):
  File "", line 1, in 
  File "robot_parser.py", line 383, in update
news = Element(source = the_source, title = title, date =
date_published, short = short, full = full, link = link, slug =
the_slug)
news.save()
  File "/lib/python2.5/django/db/models/base.py", line 323, in
__init__
raise TypeError, "'%s' is an invalid keyword argument for this
function" % kwargs.keys()[0]
TypeError: 'slug' is an invalid keyword argument for this function
---


On Dec 10, 12:21 am, bruno desthuilliers
 wrote:
> On 9 déc, 18:58, tezro  wrote:
> (snip)
>
>
>
> > That throws an error: TypeError: 'slug' is an invalid keyword argument
> > for this function.
>
> > What am I doing wrong?
>
> Not posting the full traceback - tracebacks are here to help debugging
> a problem, not to fill your term with random gibberish !-)

--

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

2009-12-09 Thread bruno desthuilliers


On 9 déc, 18:58, tezro  wrote:
(snip)
>
> That throws an error: TypeError: 'slug' is an invalid keyword argument
> for this function.
>
> What am I doing wrong?

Not posting the full traceback - tracebacks are here to help debugging
a problem, not to fill your term with random gibberish !-)

--

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




Re: Could Django model dynamically create new class with new table?

2009-12-09 Thread bruno desthuilliers
On 9 déc, 20:18, HUANG Dong  wrote:
> Thank you, Bruno.  Your answer is really helpful and covered another
> issue I hadn't noticed yet.  But my question may be related to
> different topic.  In my example, number of "libraries" is unknown in
> develop time, neither does the classification of "books".

You explicitely mentionned that the reason to "partition" the books in
different tables was to speed up queries - and FWIW, I can't think of
any other reason to do so. If all you want is classification then
using different tables is not the correct solution.

> To be more specific, I want to employ some kind of "introspective"
> class in python to model my data, and these dynamic classes should be
> associated to individual TABLEs in the database respectively.

Yes, that's clearly what I understood. But this looks like a wrong
solution to a (potentially) real problem, hence my mention of RDBMS-
level table partitionning.


> So far what I know about Django is that each class inheriting from
> models.Model will be associated to a TABLE, and each instance of the
> class becomes an item when calling instance.save().  What if I create
> an introspective object in run-time?  And when to call synchronization
> function to write the table into database?  How to sync if there's
> concurrent creation of classes?  What about the performance?  All
> above are still unknown to me...

Creating model classes at runtime is of course possible - if a bit
involved - since Python's "class" statement is an executable
statement. I'll even give you a couple hint: read the doc for the
'type' type, and google for "metaclass".

But I do insist on the fact that whether your _real_ problem is sql
queries performances tuning or classification, what you're trying to
achieve is _not_ the appropriate solution.

--

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




Stuck trying integrate jinja2 - need compatibility extensions

2009-12-09 Thread Todd Blanchard
OK, first let me start by saying I tried to live with the django template 
processor.  But I need more power.  I like jinja2's macros - much slicker than 
having to write a custom tag.

So I've downloaded jinja2 and installed it.  Good.

After trying a couple of integration recipes on the web that "almost but not 
quite worked" I've found and downloaded chouwa and started using that.  This 
works.  Good.

I have templates I want to inherit from that were written for the default 
template processor that use tags with names like 'url'.  Amazingly, jinja2 
lacks this and a few other commonly used tags.  So I'm looking for 
compatibility extensions.

I found: http://www.djangosnippets.org/snippets/1062/

Which looks like it might solve my problem - if I could get it recognized by 
jinja2's initialization.  I've copied this code to a file at the root level of 
myapp called tags.py

I've added the following to my settings.py file

JINJA_EXTS = (
'jinja2.ext.i18n',
'jinja2.ext.do',
'jinja2.ext.loopcontrols',
'from myapp.tags import *',
)


JINJA2_ENVIRONMENT_OPTIONS = {
'extensions': JINJA_EXTS,
}

I've tried half a dozen incantations trying to get these functions imported as 
extensions to jinja2 and nothing seems to work.  I've tried
'myapp.tags'
'myapp.tags.url' (this one produces a scary error 'no patterns in myapp.urls' 
and the entire app dies)

and a few others.  I'm stuck.  What's the trick to getting compatibility tags 
for django installed into jinja2?

-Todd Blanchard

--

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




Strange django behaviour

2009-12-09 Thread Maksymus007
For a few weeks I observe strange django behaviour - from time to time
I get mails about

AttributeError: 'NoneType' object has no attribute 'company'

in line 121, which is:

cursor.execute("SELECT * FROM interface.stats_sms_errors(%d,
'%s'::timestamp with time zone, '%s'::timestamp with time zone, '%s')"
% (request.account.company.company_id, stats_time_start,
stats_time_end, stats_truncate))

looks like request.account is None.

But one line above,line 120 is

cursor.execute("SELECT * FROM interface.stats_sms_mms(%d,
'%s'::timestamp with time zone, '%s'::timestamp with time zone, '%s')"
% (request.account.company.company_id, stats_time_start,
stats_time_end, stats_truncate))

which uses the same request.account which, one line later is empty.

This view is called about 500 times a day and it works, but one or two
times a day it generates aboved message.

Looks like something "wipes" by request objects in the middle of a
view. This additional member of request is initialized in my own
middleware - however its not possible to have this a None value (this
would display user login form, not executing views).

Same situations can be spoted in few other places in code - every time
situations is similar - in line n request.account is object, in line
n+1 its None. What may be important - this always happen in the same
lines.

Does anyone have an idea why this happed, what may couse it? Of course
I tried to debug, but cannot reproduce it.

We use mod_wsgi and apache2 if this matters.

--

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




Re: Could Django model dynamically create new class with new table?

2009-12-09 Thread Nick Arnett
On Wed, Dec 9, 2009 at 11:18 AM, HUANG Dong  wrote:

> Thank you, Bruno.  Your answer is really helpful and covered another
> issue I hadn't noticed yet.  But my question may be related to
> different topic.  In my example, number of "libraries" is unknown in
> develop time, neither does the classification of "books".


I suspect you could use a raw SQL command - "ADD PARTITION" - in MySQL to
create a partition for each new library and/or classification.  Then the
database would take care of everything else (assuming that the library or
classification is a column on which you define the partitioning), which
would be a Good Thing (because this really doesn't belong at the application
level if at all possible).

Nick

--

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




Re: newbie following intro-tutorial01 snag -- mysql login fails from python manage.py syncdb

2009-12-09 Thread John Griessen
The problem logging in to mysql was with how I created the new user.

Nevermind  :-)

JG

--

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




Re: Could Django model dynamically create new class with new table?

2009-12-09 Thread HUANG Dong
Thank you, Bruno.  Your answer is really helpful and covered another
issue I hadn't noticed yet.  But my question may be related to
different topic.  In my example, number of "libraries" is unknown in
develop time, neither does the classification of "books".

To be more specific, I want to employ some kind of "introspective"
class in python to model my data, and these dynamic classes should be
associated to individual TABLEs in the database respectively.  Surely
writing my own modeling middleware is an approach.  However, I am not
sure whether Django's model has such a feature already.  If so, I need
not to reinvent the wheel.

So far what I know about Django is that each class inheriting from
models.Model will be associated to a TABLE, and each instance of the
class becomes an item when calling instance.save().  What if I create
an introspective object in run-time?  And when to call synchronization
function to write the table into database?  How to sync if there's
concurrent creation of classes?  What about the performance?  All
above are still unknown to me...

Thanks,
Huang

On Thu, Dec 10, 2009 at 12:42 AM, bruno desthuilliers
 wrote:
> On 9 déc, 17:26, Huang Dong  wrote:
>> Suppose I have a class "Book".  Typically Django will create a table
>> in database for the class.  If there are millions or even billions of
>> books, I don't want to place them into one large table.  Instead, I
>> want to group them into different tables ("libraries"), in order to
>> speed up querying given the user explicitly knows which library to
>> query.  But I don't know how to do so after browsing the Django
>> documentation.  Could anybody help me?
>
> This is named "horizontal partitioning", and is probably better solved
> at the RDBMS level when possible - decoupling data access (logical
> level) from data storage (physical level) so your application is not
> impacted being one of the goals of a RDBMS...
>
> Good news is that PGSql and MySQL do support partitionning:
>
> http://www.postgresql.org/docs/8.1/interactive/ddl-partitioning.html
> http://dev.mysql.com/tech-resources/articles/performance-partitioning.html
>
> HTH
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Problems witch Apache - KeyError at / - 'HOME'

2009-12-09 Thread edward9
Hello everybody

I'm new and i want to say Hello to Everybody.


I have problem with Apache. I install python, django, apache,
mod_apache and all what is necessary.

Apache configuration is:

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug Off
#PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
PythonPath "['/'] + sys.path"


I created an application i root folder:
django-admin.py startproject mysite
and i started development(runserver). All works fine. "Configurations
on your first Django-powered page". Running on apache also works fine.

But when i create Django app:
manage.py startapp inet
views.py:
# Create your views here.
from django.http import HttpResponse
from django.db import connection
from django.conf import settings
from datetime import datetime

def main_page(request):
output = '''

%s

%s%s%s


''' % (
'1','a','b','c'
)
return HttpResponse(output)



urls.py
from django.conf.urls.defaults import *
from inet.views import *

urlpatterns = patterns('',
(r'^$',main_page),
)

on development server works fine but started on apache i get:

KeyError at /

'HOME'

Request Method: GET
Request URL:http://127.0.0.1/
Exception Type: KeyError
Exception Value:

'HOME'

Exception Location: /usr/lib/python2.5/UserDict.py in __getitem__,
line 22
Python Executable:  /usr/bin/python
Python Version: 2.5.4
Python Path:['/', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-
linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-
dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/
python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/
usr/lib/python2.5/site-packages/gst-0.10', '/usr/lib/pymodules/
python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/usr/lib/
pymodules/python2.5/gtk-2.0']
Server time:Wed, 9 Dec 2009 11:54:14 -0600
Traceback Switch to copy-and-paste view

* /usr/lib/pymodules/python2.5/django/core/handlers/base.py in
get_response
70.
71. # Get urlconf from request object, if available. Otherwise
use default.
72. urlconf = getattr(request, "urlconf",
settings.ROOT_URLCONF)
73.
74. resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
75. try:
76. callback, callback_args, callback_kwargs = resolver.resolve
(
77. request.path_info) ...
78.
79. # Apply view middleware
80. for middleware_method in self._view_middleware:
81. response = middleware_method(request, callback,
callback_args, callback_kwargs)
82. if response:
83. return response
  ▶ Local vars
  Variable  Value
  exc_info
  (, KeyError('HOME',), )



Can somebody help me? I dont have any ideas how to solve this problem.

Thnask for help!
Regards
Edward9

--

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




Testing and request META data

2009-12-09 Thread Phlip
On Aug 14 2008, 5:39 am, "Hajo Smulders" 
wrote:

> I need to set the HTTP_REFERER in the request.META data of a test client so
> that i can unit test a view.
> How do I do this? ie: How do i fake an HTTP header on a test client?

Bump? I just hit this problem, and the above question is the only
traffic on it...

--

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




Error creating and saving a Django-object from the other script

2009-12-09 Thread tezro
Hi everyone. I'm using Django 1.1.0, importing it and using in another
file "robot_parser.py". I've been using it for months.

The script aggregates news from different sources and saves them using
Django ORM. Presently I used primary key for urls (http://www.site.com/
news/2009/jan/12/72828/), but then decided to use "slugs" (http://
www.site.com/news/2009/jan/12/slug-of-the-news/).

I changed the model adding slug field.
---
class Element(models.Model):
date = models.DateTimeField()
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200)
---

Also I added a field to MySQL table.

Here's the code that adds an element from the "robot_parser.py".
---
title = "test title"
slug = slugify(title)
new_element = Element(title=title, slug=slugify(title),
date=datetime.now())
new_element.save()
---

That throws an error: TypeError: 'slug' is an invalid keyword argument
for this function.

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




Override length of CharField on admin form

2009-12-09 Thread derek
After much searching, the closest answer I can find for this is here:
http://groups.google.com/group/django-users/browse_thread/thread/24edd54c637f19a7

with the "solution" being:
text = forms.CharField(label="text", max_length=10,
widget=forms.TextInput(
attrs={'size':'10', 'class':'inputText'}))

This does not work for an admin form:

class Test(models.Model):
id = models.AutoField(primary_key=True)
comments =
models.CharField(label="comment",max_length=250,blank=True,null=True,\
widget=forms.TextInput(attrs={'size':'50', 'class':'inputText'}))
...

So how do I set it here?

(Sidebar:  it strikes me that I likely do not grok the differences between
model and form in this circumstance.)

--

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

2009-12-09 Thread Phlip
On Dec 8, 5:13 pm, Russell Keith-Magee  wrote:

> fixture)? As always, suggestions are welcome.

The suggestion is

 - template the json
 - name each record
 - the PK is the hash of the name
 - link FKs by name, so they get the same hash

That way a reader can see an PK or FK, stick in its hash, and keep
going, without the need to read the other table and find the matching
FK or PK, respectively.

(the way >cough< Rails does it)

The problem now, at loaddata time in production, is the hashes still
might (one in a million chance) collide with a preexisting PK. And the
next problem is the hashes will bump their PK incrementors way up,
throwing away whole ranges of valid fictitious IDs, when the next
natural record inserts.

How about you add a argument to loaddata, such as --gentle, which
throws an error (and rolls everything back) if a new PK collides. Then
the new feature can wait while programmers fix their (hardcoded) PKs
and try again.

That argument would also work at test time, because the unit tests are
expected to always get all PKs right, so the --gentle would be always
turned on, and would be a kind of assertion.

--
  Phlip
  http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1

--

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




Re: Question about forms in templates

2009-12-09 Thread Daniel Roseman
On Dec 9, 5:14 pm, jul  wrote:
> Hi,
>
> I'm not very clear on how forms work.
> In the form below, both fields are required. When not filling anything
> and clicking submit, I got the error messages.
> Since I didn't specified any action, how can the form know that the
> form is not valid and get the error messages?
>
> Thanks for any explanation/pointer.
> jul
>
> 
> Name:{{form.name.errors}}
> {{ form.name }} 
> Country:{{form.country.errors}}
> {{ form.country }} 
> 
>  value="Submit" />

Action is just the URL the form is POSTed to. Since you left it blank,
it posts back to the same URL you used to display it in the first
place - and if you followed the standard structure for that view as
shown in the documentation, it will validate and redisplay itself if
it has errors.
--
DR.

--

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




Question about forms in templates

2009-12-09 Thread jul
Hi,

I'm not very clear on how forms work.
In the form below, both fields are required. When not filling anything
and clicking submit, I got the error messages.
Since I didn't specified any action, how can the form know that the
form is not valid and get the error messages?

Thanks for any explanation/pointer.
jul


Name:{{form.name.errors}}
{{ form.name }} 
Country:{{form.country.errors}}
{{ form.country }} 



--

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




Re: Could Django model dynamically create new class with new table?

2009-12-09 Thread bruno desthuilliers
On 9 déc, 17:26, Huang Dong  wrote:
> Suppose I have a class "Book".  Typically Django will create a table
> in database for the class.  If there are millions or even billions of
> books, I don't want to place them into one large table.  Instead, I
> want to group them into different tables ("libraries"), in order to
> speed up querying given the user explicitly knows which library to
> query.  But I don't know how to do so after browsing the Django
> documentation.  Could anybody help me?

This is named "horizontal partitioning", and is probably better solved
at the RDBMS level when possible - decoupling data access (logical
level) from data storage (physical level) so your application is not
impacted being one of the goals of a RDBMS...

Good news is that PGSql and MySQL do support partitionning:

http://www.postgresql.org/docs/8.1/interactive/ddl-partitioning.html
http://dev.mysql.com/tech-resources/articles/performance-partitioning.html

HTH

--

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




Could Django model dynamically create new class with new table?

2009-12-09 Thread Huang Dong
Suppose I have a class "Book".  Typically Django will create a table
in database for the class.  If there are millions or even billions of
books, I don't want to place them into one large table.  Instead, I
want to group them into different tables ("libraries"), in order to
speed up querying given the user explicitly knows which library to
query.  But I don't know how to do so after browsing the Django
documentation.  Could anybody help me?

Thanks,
Huang

--

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




Blocking services in django

2009-12-09 Thread David Koblas
I'm trying to get a better understanding of django performance in a 
production setting.

Specifically I've seen notes that say that operations like sending mail 
will block all production traffic to your server for the duration of the 
send.  That got me thinking about other backend calls, like sending 
email call external URLs etc?   Just to make it very specific:

Is there any difference in the performance in a django application between:

* A MySQL call that takes 0.1 seconds
* Sending email to your local server that takes 0.1 seconds to complete
* Making a urllib.open() call that takes 0.1 seconds

My general understanding is that all three are equal in terms of the 
performance impact on your site yielding a theortical performance of 10 
pages / second.

Is this right, or is there some magic that makes MySQL "better" than 
just a urllib call.

--koblas

--

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




Re: Expiry Date

2009-12-09 Thread Daniel Roseman
On Dec 9, 12:07 pm, Djangobot  wrote:
> Hi all
>
> I am very new to Django and Python and I was wondering if anyone could
> help me on here as I am desperate for help.
>
> I am designing a mobi. site and I need to somehow set an expiry date
> on the competitions that will be run on the site.
>
> I have added the field expiry date as a DateField in the admin section
> but I do not know how to produce the code that will check if the
> competition's expiry date has been reached and then make it invisible
> in other words set the boolean field for live ad to false?
>
> I have imported datetime but I need the app to verify when the expiry
> has been reached. I do not know about signals and the most basic steps
> would be really a great help.
>
> Thank you and have a great day!

Signals are not the answer to this.

One way to do it would be to only show competitions whose expiry date
is greater than today:
   Competition.objects.filter(expiry_date__gt=datetime.date.today())

Or, if you really need to use a separate boolean, you'll need a
separate cron job that runs every day, does a filter to get expired
comps (similar to the above, but use __lte instead of __gt) and sets
them all to live=False.
--
DR.

--

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




Re: Help me with django templates

2009-12-09 Thread Daniel Roseman
On Dec 9, 2:18 pm, Biju Varghese  wrote:
> 
>                 {%for jobsp in jobspecs%}
>                         {%ifequal jobsp.id jobtitle.jobspec_id %}
>                                 {{jobsp.id}}
>                         {%endifequal%}
>                 {%endfor%}
>                                 -select-
>                         {%for jobspec in jobspecs%}
>                          value="{{jobspec.id}}">{{jobspec.jobspec_name}}
>                         {%endfor%}
> 
>
> I am trying to nest ifequal with for loop .my problem is i am not able
> to get value of (jobsp.id)  ie value of jobsp is not available in the
> ifequal block is there any other way to do this..

Why is it not available in the ifequal tag? It should be. Have you
checked that it actually has a value?

You should also consider doing this whole thing using the forms
framework, which will output select fields for you.
--
DR.

--

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




newbie following intro-tutorial01 snag -- mysql login fails from python manage.py syncdb

2009-12-09 Thread john_griessen
When I login to mysql from a shell as user django_editor, I can change
tables in a database I've called django_server.

settings.py contains

DATABASE_NAME = 'django_server' # Or path to database file
if using sqlite3.
DATABASE_USER = 'django_editor'

python manage.py syncdb

results in:

_mysql_exceptions.OperationalError: (1044, "Access denied for user
'django_editor'@'%' to database 'django_server'")

/var/log/syslog shows nothing new after that command.

I had to add the root user and user django_editor to my installation
of debian mysql version
mysql-server-5.1  That seemed odd.  probably related to installing 5.1
after wiping 5.0

Thanks for any ideas,

John


--

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




Re: django error page: traceback too shallow?

2009-12-09 Thread Larrik Jaerico
I've definitely experienced missing levels in the traceback. I don't
have anything reproducible, but notcourage isn't making it up.

On Dec 8, 8:37 am, Karen Tracey  wrote:
> On Thu, Dec 3, 2009 at 1:24 AM, notcourage  wrote:
> > def home (request):
>
> >        if (request.user.is_authenticated()):
> >                artifacts = Artifact.objects.filter
> > (member__exact=request.user.profile.id)
> > ...
> >        else:
> > ...
>
> > In this case, the user is authenticated but the predicate is failing
> > as expected because user.profile is NULL. The traceback is just odd.
>
> I have not seen anything like missing levels in a traceback, nor can I
> recreate anything like what you are reporting based on the information
> provided.  If you can post a complete small example (models, url patterns,
> view) that demonstrates what you see, someone might be able to help more.
>
> Karen

--

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




Re: How can child objects inherit data from parents?

2009-12-09 Thread bruno desthuilliers
On 9 déc, 14:10, Eric Chamberlain  wrote:
> Hello,
>
> We're not sure how can we represent the following data structure in the 
> django model?
>
> Grandparent Object
>         First Name - NULL
>         Last Name - NULL
>         City - Anytown
>         Ancestor Object - NULL
>
> Parent Object
>         First Name - Bob
>         Last Name - Smith
>         City - NULL
>         Ancestor Object - Grandparent
>
> Child Object
>         First Name - Jill
>         Last Name - NULL
>         City - NULL
>         Ancestor Object - Parent


Took me some times to understand this was about model instances, not
classes :-/


First point, you have a tree structure. There are a couple ways to
handle trees in a relational model, each has pros and cons. The most
obvious one is the recursive relationship (also known as 'adjacency
list'):

create table Person(
   id integer primary key auto increment,
   first_name varchar(50) NULL,
   last_name varchar(50) NULL,
   city varchar(50) NULL,
   ancestor_id integer NULL
   )

where ancestor_id refers to the Person.id of the 'ancestor'.

The problem with this solution is that SQL has no way to let you
retrieve a whole 'branch' in one single query.

Other solutions I wont explain here are the "Materialized Path" and
the "Modified Preorder Tree Traversal" (mptt). You'll find more on
this topic here:

http://articles.sitepoint.com/print/hierarchical-data-database

These solutions are somewhat more complex, but allow to fetch a whole
branch in a single query. OTHO, they usually imply way more work when
modifying the tree, so there's no "absolutely better" solution - which
one will yield the best results depends on your application's needs
and tree depth.


> We'd like to be able to use the child object with the NULL fields coming from 
> the ancestor objects.

I assume that what you mean is you want to lookup values on the
related 'parent' object for fields that have a NULL value in the
'child' object. The usual way to handle this in Python is to use
computed attributes.


>  We need to update the parent field and have all the child objects return the 
> new value.  The parent object behaves like a template, some users have write 
> access to the child, but not the parent object or some users may not have 
> write access to all the child fields.

Hmmm... sorry but this part isn't quite clear to me. Care to provide a
bit more (or clearer) explanations ? (sorry for being that dumb).

> We'd like to keep database calls to a minimum and avoid looping lookups if 
> possible.

Then you want a materialized path or MPTT.

> Is there a better way  to implement this?


"better" than what ??? You didn't say anything about your
implementation ?

--

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

2009-12-09 Thread BlueBird

Hi,

I have a setup where I need to create manually a connection to a
SQLite DB. I haven't really
succeeded in doing that so far.

More precisely, I am running a test suite which uses
django.test.utils.setup_test_environment() and
the test DB defined settings.TEST_DATABASE_NAME. That works well in a
single process with SQLite.

However, my program launches another process using
multiprocessing.Process() (on windows) and here
starts the trouble. In the new process, django keeps using
settings.DATABASE_NAME instead of the
test DB. I have tried giving several hints without success.

Here is the function that I launch through Process() :

def doJob( jobname, testMode, jobfunc, *jobargs, **jobkwargs ):
'''Function executed by the new process. '''

import settings

if testMode:
info( 'Process job is in test mode.' )
settings.DATABASE_NAME = settings.TEST_DATABASE_NAME
dbg( 'DB used for Process: %s' % settings.DATABASE_NAME )
setup_test_environment()
django.db.connection.close()
# call_command('syncdb', verbosity=1, interactive=False)
reload( django.db )
django.db.connection.cursor()

# ...

As you can see, my various attempts were not successful. Can somebody
give me a hint on how to
create manually the connection with the test DB ?

I am pretty sure that the problem comes from using
multiprocessing.Process on Windows. On unix, fork() duplicates the
memory content of the process to the new process so the problem
probably don't show up. But on
Windows, Process() starts an empty process and multiprocessing does
some magic to import the same
list of modules that the parent process had. While importing this
list, my guess is that settings is
imported directly and that the setup_test_environment() has then no
action.

I really believe that the proper fix is to setup the DB link manually
but I haven't really figured
out how to do so.

thanks in advance,

Philippe

--

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




Help me with django templates

2009-12-09 Thread Biju Varghese

{%for jobsp in jobspecs%}
{%ifequal jobsp.id jobtitle.jobspec_id %}
{{jobsp.id}}
{%endifequal%}
{%endfor%}
-select-
{%for jobspec in jobspecs%}
{{jobspec.jobspec_name}}
{%endfor%}


I am trying to nest ifequal with for loop .my problem is i am not able
to get value of (jobsp.id)  ie value of jobsp is not available in the
ifequal block is there any other way to do this..

--

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




jsonpickle

2009-12-09 Thread elminio
Hi,
I downloaded and installed on windows Jsonpickle

In normal python script everything works fine (import jsonpickle)

but I dont know how to use it in my django app (in views import
jsonpickle doesnt work) - no module named jsonpickle

thanks for help

--

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




Re: Coltrane Weblog Practical Django Projects 2nd Ed, page not found for http://127.0.0.1:8000/weblog/

2009-12-09 Thread Mark Freeman
Bernard,

I originally replied by email, so this may get double posted. Your
problem is that you have the URL for the flat pages module above the
one for the weblog. The empty string '' is basically a catch all,
which is stopping it from ever seeing the weblog. When Django parses
the URLs, it does so in the order you have them listed.

Mark

On Dec 8, 7:39 am, bernard  wrote:
> Hi all,
>
> I am reading through the Practical Django Projects 2nd Edition book
> and i am now on the weblog entries_index part (page 84) where im
> trying to view the weblog entry index but I get an error No FlatPage
> matches the given query.
>
> I followed exactly what's written in the book.
> Please help, I'm new to Django and Python:
>
> Here's my views.py
> from django.shortcuts import render_to_response
> from coltrane.models import Entry
>
> def entries_index(request):
>     return render_to_response('coltrane/entry_index.html',
>                     { 'entry_list': Entry.objects.all() })
>
> urls.py
> from django.conf.urls.defaults import *
> from coltrane.models import Entry
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>
>     (r'^admin/', include(admin.site.urls)),
>     (r'^tiny_mce/(?P.*)$', 'django.views.static.serve',
>                 { 'document_root': '/home/bernard/Django/cms/
> tiny_mce/' }),
>     (r'^search/$', 'cms.search.views.search'),
>     (r'', include('django.contrib.flatpages.urls')),
>     (r'^weblog/$', 'coltrane.views.entries_index'), s
>
> )
>
> Thank you!!!

--

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




Re: Coltrane Weblog Practical Django Projects 2nd Ed, page not found for http://127.0.0.1:8000/weblog/

2009-12-09 Thread Mark Freeman
Bernard,

You need to put the url for weblog above flat pages. The empty string
'' is catching everything and it never sees your weblog url.

Mark

On Dec 8, 7:39 am, bernard  wrote:
> Hi all,
>
> I am reading through the Practical Django Projects 2nd Edition book
> and i am now on the weblog entries_index part (page 84) where im
> trying to view the weblog entry index but I get an error No FlatPage
> matches the given query.
>
> I followed exactly what's written in the book.
> Please help, I'm new to Django and Python:
>
> Here's my views.py
> from django.shortcuts import render_to_response
> from coltrane.models import Entry
>
> def entries_index(request):
>     return render_to_response('coltrane/entry_index.html',
>                     { 'entry_list': Entry.objects.all() })
>
> urls.py
> from django.conf.urls.defaults import *
> from coltrane.models import Entry
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>
>     (r'^admin/', include(admin.site.urls)),
>     (r'^tiny_mce/(?P.*)$', 'django.views.static.serve',
>                 { 'document_root': '/home/bernard/Django/cms/
> tiny_mce/' }),
>     (r'^search/$', 'cms.search.views.search'),
>     (r'', include('django.contrib.flatpages.urls')),
>     (r'^weblog/$', 'coltrane.views.entries_index'), s
>
> )
>
> Thank you!!!

--

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

2009-12-09 Thread Eric Chamberlain
Hello,

We're not sure how can we represent the following data structure in the django 
model?

Grandparent Object
First Name - NULL
Last Name - NULL
City - Anytown
Ancestor Object - NULL

Parent Object
First Name - Bob
Last Name - Smith
City - NULL
Ancestor Object - Grandparent

Child Object
First Name - Jill
Last Name - NULL
City - NULL
Ancestor Object - Parent

We'd like to be able to use the child object with the NULL fields coming from 
the ancestor objects.  We need to update the parent field and have all the 
child objects return the new value.  The parent object behaves like a template, 
some users have write access to the child, but not the parent object or some 
users may not have write access to all the child fields.

We'd like to keep database calls to a minimum and avoid looping lookups if 
possible.

Is there a better way to implement this?

--
Eric Chamberlain



--

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




Expiry Date

2009-12-09 Thread Djangobot
Hi all

I am very new to Django and Python and I was wondering if anyone could
help me on here as I am desperate for help.

I am designing a mobi. site and I need to somehow set an expiry date
on the competitions that will be run on the site.

I have added the field expiry date as a DateField in the admin section
but I do not know how to produce the code that will check if the
competition's expiry date has been reached and then make it invisible
in other words set the boolean field for live ad to false?

I have imported datetime but I need the app to verify when the expiry
has been reached. I do not know about signals and the most basic steps
would be really a great help.

Thank you and have a great day!

--

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




Re: import twice when run test

2009-12-09 Thread Doug Blank
On Thu, Nov 26, 2009 at 6:01 AM, Tom Evans  wrote:
> On Thu, Nov 26, 2009 at 2:35 AM, fallhunter  wrote:
>>
>> i have this code in my tests.py:
>>
>> from models import *
>>
>> and in the models.py I have a signal handler and register it with
>>
>> post_save.connect( post_save_note, sender=Note )
>>
>> and when i run test with ./manage.py test main
>>
>> I found the signal handler was registered twice and executed twice,
>> and I found it's because the models was imported twice.
>>
>> can't i put "from models import *" in the test code? what should i do?
>>
>
> This happens if you import the same file using two different names. Eg, here
> you are importing it as 'from models import *'. In some other part of your
> code, you probably have 'from foo.models import *'. Python treats them as
> two different files, and hence the signal is attached twice.

BTW, this is not true for regular Python imports:

$ cat > mytest.py
print "hello"
$ python
>>> import mytest
hello
>>> from mytest import *
>>>
>>> import mytest as yourtest
>>>

It may be loaded twice (or more) by different threads or by another
import mechanism (which seems to be the case here):

http://code.djangoproject.com/wiki/Signals

See section on "Help, post_save seems to be emitted twice for each save!"

-Doug

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

--

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




Re: import twice when run test

2009-12-09 Thread Dan Fairs
Hi David,

> models.signals.post_save.connect(flaggedentry_post_save,
> sender=FlaggedEntry, dispatch_uid='mofin.store.models')

Top tip - this worked perfectly. I see this is documented only on the
wiki, I couldn't find it in the official docs.

> I've found a useful place to put signal registrations is django app dir
> __init__.py file. Otherwise they're sometimes not found until a bit
> late, but each app's __init__.py is hit quite early on (so long as
> they're in INSTALLED_APPS I guess)

Yeah, I've always been in a bit of a quandry where to put them. I note
that the docs now recommend models.py as 'a good candidate' - although
the more specific notes for things like the post_syncdb signal mention
putting that one in particular in your app's management package.

Thanks again.

Cheers,
Dan

--

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




Re: import twice when run test

2009-12-09 Thread David De La Harpe Golden
>> Python treats them as
>> two different files, and hence the signal is attached twice.

> -> models.signals.post_save.connect(flaggedentry_post_save,
> sender=FlaggedEntry)

> Or is there likely to be something else we've got wrong
> in our app?
> 

Well, just in case - watch out for the dispatch_uid kwarg to connect().
This can be used to quietly prevent double signal registrations from the
same connect() running twice:

models.signals.post_save.connect(flaggedentry_post_save,
sender=FlaggedEntry, dispatch_uid='mofin.store.models')

- it'll then only register the signal once even if the module
is loaded twice, inadvertently or otherwise, since the connect()
sees the same dispatch_uid both times.

I've found a useful place to put signal registrations is django app dir
__init__.py file. Otherwise they're sometimes not found until a bit
late, but each app's __init__.py is hit quite early on (so long as
they're in INSTALLED_APPS I guess)

















--

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




Re: import twice when run test

2009-12-09 Thread Dan Fairs
Hi,

>
> > can't i put "from models import *" in the test code? what should i do?
>
> This happens if you import the same file using two different names. Eg, here
> you are importing it as 'from models import *'. In some other part of your
> code, you probably have 'from foo.models import *'. Python treats them as
> two different files, and hence the signal is attached twice.
>

Actually - it may not only be that. I've just run into this, too. I
stuck a pdb just before our signal connect, call, and saw that
models.py was indeed imported twice during the phase where Django's
test runner looks for tests to run. Compare these two stack traces,
from each time my pdb was hit:

(Pdb) w
  /home/dan/virtual/mofin/trunk/bin/django(40)()
-> djangorecipe.manage.main('mofinproject.settings')
  /home/dan/.buildout/eggs/djangorecipe-0.19.1-py2.6.egg/djangorecipe/
manage.py(16)main()
-> management.execute_manager(mod)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
__init__.py(362)execute_manager()
-> utility.execute()
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
__init__.py(303)execute()
-> self.fetch_command(subcommand).run_from_argv(self.argv)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
base.py(195)run_from_argv()
-> self.execute(*args, **options.__dict__)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
base.py(222)execute()
-> output = self.handle(*args, **options)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
commands/test.py(23)handle()
-> failures = test_runner(test_labels, verbosity=verbosity,
interactive=interactive)
  /home/dan/virtual/mofin/trunk/parts/django/django/test/simple.py(176)
run_tests()
-> suite.addTest(build_test(label))
  /home/dan/virtual/mofin/trunk/parts/django/django/test/simple.py(85)
build_test()
-> app_module = get_app(parts[0])
  /home/dan/virtual/mofin/trunk/parts/django/django/db/models/
loading.py(114)get_app()
-> self._populate()
  /home/dan/virtual/mofin/trunk/parts/django/django/db/models/
loading.py(58)_populate()
-> self.load_app(app_name, True)
  /home/dan/virtual/mofin/trunk/parts/django/django/db/models/
loading.py(74)load_app()
-> models = import_module('.models', app_name)
  /home/dan/virtual/mofin/trunk/parts/django/django/utils/importlib.py
(35)import_module()
-> __import__(name)
> /home/dan/virtual/mofin/trunk/mofin/store/models.py(514)()
-> models.signals.post_save.connect(flaggedentry_post_save,
sender=FlaggedEntry)
(Pdb)

... and ...

(Pdb) w
  /home/dan/virtual/mofin/trunk/bin/django(40)()
-> djangorecipe.manage.main('mofinproject.settings')
  /home/dan/.buildout/eggs/djangorecipe-0.19.1-py2.6.egg/djangorecipe/
manage.py(16)main()
-> management.execute_manager(mod)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
__init__.py(362)execute_manager()
-> utility.execute()
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
__init__.py(303)execute()
-> self.fetch_command(subcommand).run_from_argv(self.argv)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
base.py(195)run_from_argv()
-> self.execute(*args, **options.__dict__)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
base.py(222)execute()
-> output = self.handle(*args, **options)
  /home/dan/virtual/mofin/trunk/parts/django/django/core/management/
commands/test.py(23)handle()
-> failures = test_runner(test_labels, verbosity=verbosity,
interactive=interactive)
  /home/dan/virtual/mofin/trunk/parts/django/django/test/simple.py(176)
run_tests()
-> suite.addTest(build_test(label))
  /home/dan/virtual/mofin/trunk/parts/django/django/test/simple.py(90)
build_test()
-> test_module = get_tests(app_module)
  /home/dan/virtual/mofin/trunk/parts/django/django/test/simple.py(16)
get_tests()
-> test_module = __import__('.'.join(app_path + [TEST_MODULE]), {},
{}, TEST_MODULE)
  /home/dan/virtual/mofin/trunk/mofin/store/tests/__init__.py(3)
()
-> from mofin.store.tests.test_models import TestFeed
  /home/dan/virtual/mofin/trunk/mofin/store/tests/__init__.py(3)
()
-> from mofin.store.tests.test_models import TestFeed
  /home/dan/virtual/mofin/trunk/mofin/store/tests/test_models.py(31)
()
-> from mofin.store.models import Content
> /home/dan/virtual/mofin/trunk/mofin/store/models.py(514)()
-> models.signals.post_save.connect(flaggedentry_post_save,
sender=FlaggedEntry)
(Pdb)

The eagle-eyed will spot a difference there in django/test/simple.py.
The relevant code snippet is as follows:

parts = label.split('.')
if len(parts) < 2 or len(parts) > 3:
raise ValueError("Test label '%s' should be of the form
app.TestCase or app.TestCase.test_method" % label)

app_module = get_app(parts[0])
TestClass = getattr(app_module, parts[1], None)

# Couldn't find the test class in models.py; look in tests.py
if TestClass is None:
test_module = get_tests(app_module)
if test_module:
TestClass = 

Re: Help with apache mod rewrite engine

2009-12-09 Thread Graham Dumpleton


On Dec 9, 6:16 pm, Lakshman Prasad  wrote:
> You can just replace the regex ^/comments/$ with ^/sees/comments/$ within
> the urls.py
>
> Why can't you do that?

Because it will not work.

Based on description he is mounting Django application on /sees in
Apache, likely as:

  WSGIScriptAlias /sees /some/path/django.wsgi

This means that only URLs under /sees will get passed to Django.
Further, when mounted at sub URL, you should not have the mount point,
ie.. /sees, mentioned in urls.py patterns anyway. The patterns should
always be relative to the mount point. This is because PATH_INFO,
which is what is matched against the patterns, doesn't include /sees.
The /sees is in SCRIPT_NAME only for that configuration.

> > Hi all , I need some help understanding the mod rewrite module of apache .
> > What I wished to do want that i had a comments folder by the name of
> > /comments/ . Now i run a django project on /sees and i want all the call to
> > /comments/ be redirected to /sees/comments and than be handled by the wsgi
> > file but the rewriting is not happening is it possible to rewrite url and
> > than route it through wsgi script

A tricky way of handling the problem with mod_wsgi is to use (from
memory and untested):

  WSGIScriptAliasMatch ^/(sees|comments)(/.*)?$ /some/path/django/wsgi/
$1$2

In this case, because of how $1 also passed to last argument,
SCRIPT_NAME will actually be empty, meaning Django will think it is
actually mounted at root of web site. Only the sub URLs /sees and /
comments will get passed through to Django though.

Because the mount point has shifted, your urls.py do have to take that
into consideration though, and so you would have patterns starting
with:

  ^sees
  ^comments

Doing this avoids all the problems that can arise with using
mod_rewrite. It does mean though your primary sub URL mount point is
in the patterns in urls.py.

Graham

--

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




Re: question about modelform lifecycle

2009-12-09 Thread chefsmart
Brilliant! Thanks.

Just to make it clear for anyone else reading, doing self.instance.pk
gives me what I want.

I am not really an expert at any level, have no formal training, and
am just poking around the "dark alley of code" to find my way, so am
just hoping what I am doing is right ;)

Regards,
CM

On Dec 9, 2:50 pm, bruno desthuilliers 
wrote:
> On 9 déc, 06:29, chefsmart  wrote:
>
> > At what point in a modelform's lifecycle does the underlying object
> > become accessible?
> > Specifically, can I access the underlying object in
> > a modelform's "clean" method?
> >  Or is it only after one does form.save
> > () with or without commit = False?
>
> Use the source, Luke !-)
>
> Reading the code for the BaseModelForm class, it appears that if no
> instance is provided (you can obviously access the instance from any
> method if you passed one...), one is created in the __init__ method.
> So you do have access to the instance anywhere after to call to
> ModelForm.__init__.
>
> *BUT*
>
> > I basically need to do some custom validation and need to access the
> > object's pk attribute in "clean". Can this be done?
>
> The pk will only be set if the instance has already been saved at
> least once (stating the obvious, yes). So if you didn't pass an
> instance, the one you'll get will have None as pk value.
>
> HTH

--

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




Re: ManyToOne to auth.models.User

2009-12-09 Thread Itay Donenhirsch
use a userprofile
see http://docs.djangoproject.com/en/dev/topics/auth/, search for "userprofile"
also take a look at
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/


On Tue, Dec 8, 2009 at 11:53 PM, TiNo  wrote:
> On Tue, Dec 8, 2009 at 12:58, Itay Donenhirsch  wrote:
>>
>> one to many from year to user is same as many to one from a
>> user to a year.
>
> Yes, but how? :D I can't place a FK on the User...
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--

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




Re: question about modelform lifecycle

2009-12-09 Thread bruno desthuilliers
On 9 déc, 06:29, chefsmart  wrote:
> At what point in a modelform's lifecycle does the underlying object
> become accessible?
> Specifically, can I access the underlying object in
> a modelform's "clean" method?
>  Or is it only after one does form.save
> () with or without commit = False?

Use the source, Luke !-)

Reading the code for the BaseModelForm class, it appears that if no
instance is provided (you can obviously access the instance from any
method if you passed one...), one is created in the __init__ method.
So you do have access to the instance anywhere after to call to
ModelForm.__init__.

*BUT*

> I basically need to do some custom validation and need to access the
> object's pk attribute in "clean". Can this be done?

The pk will only be set if the instance has already been saved at
least once (stating the obvious, yes). So if you didn't pass an
instance, the one you'll get will have None as pk value.

HTH

--

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




Django-admin edit-form & change-list doesn't show to_field column

2009-12-09 Thread Kostas M
Lets consider a simple case with a ForeignKeyField:

class Model1(models.Model):
code1 = models.IntegerField()
code2 = models.CharField()

def __unicode__(self):
return unicode(self.code1)

class Model2(models.Model):
mycode = models.ForeignKey(Model1, to_field='code2')
mydata = models.IntegerField()


the command syncdb correctly creates Model2 table, with the column
'mycode' as CharField corresponding to Mode1.code2.
When we try to add a new Model2 row through the admin 'add' command,
the
'mycode' dropdown menu presents the Model1.code1 list, instead
of the Model1.code2.
Is it possible to list in the dropdown menu the code2 data, other than
changing the __unicode__ function of Model1 class to 'return unicode
(self.code2)' ?

The same is happening at the admin-list page. The 'mycode' column of
Model2 lists
code1 data instead of code2.

It seems like Django-admin doesn't take in account the 'to_field'
directive.

(Django Version 1.1.0)

--

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




Re: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-09 Thread bruno desthuilliers
On 8 déc, 19:21, germ  wrote:
> > The point is that utf8 can use up to 3 bytes per character...
>
> i appreciate your reply. interesting distinction between bytes and
> chars.

Been here, done that :-/

> i think i still need some more guidance. still not sure how to
> resolve with your suggestion to consdier the character set.

Well, my suggestion wrt/ charset is to use utf-8 everywhere (os,
shells, source codes, templates and all text files, databases, default
encoding for Apache, etc) - but this won't obviously solve your
problem !-)

> just looking for a simple way to specify a url field in models.py that
> will allow creation with django 1.1.1 syncdb and mysql 5.0.67. want
> this url text/char field to be as large as permitted and unique.

IE won't accept urls longer than 2083 characters IIRC - and a 2083
characters urls is neither very practical nor something you meet
everyday. Also, as Karen said, a unique index on a 2000+ characters
field might not be such a good idea - at least depending on how you're
using it.

Anyway... There's at least one workaround I can think of that imply a
little denormalization: using a text field for the url - without
uniqueness constraint -, and storing the hash() value (or some md5 sum
or like) of the url in another field, this one with a unique
constraint. The hash or md5 would be computed in the model save()
method. This is not totally dry and not as robust as a real unique
constraint on the url field itself, but that's the better solution I
can come with.




> thanks all for your time and assistance!

--

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




Re: Viewing uploaded files via the admin interface

2009-12-09 Thread Lukas
Yay, big thanks. It works now.

On 9 Dez., 07:30, Karen Tracey  wrote:
> On Tue, Dec 8, 2009 at 4:42 PM, Lukas  wrote:
> > Hi everyone,
>
> > i've a problem viewing uploaded files via the admin interface. When I
> > try to view the file, everything I get is a ValueError exception:
> > invalid literal for int() with base 10...
> > I know it goes wrong, when your MEDIA_URL is not set correctly.
>
> > The link to the file in the admin interface is:
> >http://localhost:8000/admin/myModel/attachment/1/files/my-file.pdf/
>
> > should be:
> >http://localhost:8000/media/files/my-file.pdf/<- this one works
>
> > Here's are my related code:
>
> > settings.py
> > [...]
> > MEDIA_ROOT = os.path.join(PROJECT_DIR,'media')
> > MEDIA_URL = 'localhost:8000/media/'
>
> Get rid of the localhost:8000 here.  Make MEDIA_URL just '/media/'.
>
> Karen

--

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