can't show admin interface

2009-09-25 Thread pengwupeng

the environment is  apache+django, accessing   my app is ok,but i
can't access the admin interface.
the configuration  of the httpd.conf  is likes this below:
Listen 127.0.0.1:


SetHandler python-program
PythonPath "sys.path+['c:/']"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE Djangoproject.settings
PythonInterpreter books
PythonDebug On


#Alias /site_media
Alias /site_media c:/Djangoproject/media

AllowOverride None
Options FollowSymLinks MultiViews Indexes
Order allow,deny
Allow from all


   SetHandler None


#Alias /media
Alias /media C:/Python25/Lib/site-packages/django/contrib/admin/media

AllowOverride None
Options FollowSymLinks MultiViews Indexes
Order allow,deny
Allow from all


   SetHandler None

# file types we want to serve statically
# case insensative match

   SetHandler None





Environment:

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


Template error:
In template c:\python25\lib\site-packages\django\contrib\admin
\templates\admin\base.html, error at line 30
   Caught an exception while rendering: Could not import
Djangoproject.books.search. Error was: No module named books.models
   20 : 


   21 : 


   22 : 


   23 : {% block branding %}{% endblock %}


   24 : 


   25 : {% if user.is_authenticated and user.is_staff %}


   26 : 


   27 : {% trans 'Welcome,' %}


   28 : {% firstof user.first_name user.username %}
.


   29 : {% block userlinks %}


   30 :  {% url django-admindocs-docroot as docsroot
%}


   31 : {% if docsroot %}


   32 : {% trans
'Documentation' %} /


   33 : {% endif %}


   34 : {% url admin:password_change as
password_change_url %}


   35 : {% if password_change_url %}


   36 : 


   37 : {% else %}


   38 : 


   39 : {% endif %}


   40 : {% trans 'Change password' %} /


Traceback:
File "C:\Python25\Lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\Lib\site-packages\django\contrib\admin\sites.py" in
wrapper
  196. return self.admin_view(view, cacheable)(*args,
**kwargs)
File "C:\Python25\Lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python25\Lib\site-packages\django\contrib\admin\sites.py" in
inner
  186. return view(request, *args, **kwargs)
File "C:\Python25\Lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python25\Lib\site-packages\django\contrib\admin\sites.py" in
index
  374. context_instance=context_instance
File "C:\Python25\Lib\site-packages\django\shortcuts\__init__.py" in
render_to_response
  20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "C:\Python25\Lib\site-packages\django\template\loader.py" in
render_to_string
  108. return t.render(context_instance)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in
render
  178. return self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in
render
  779. bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py" in
render_node
  71. result = node.render(context)
File "C:\Python25\Lib\site-packages\django\template\loader_tags.py" in
render
  97. return compiled_parent.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in
render
  178. return self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in
render
  779. bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py" in
render_node
  71. result = node.render(context)
File "C:\Python25\Lib\site-packages\django\template\loader_tags.py" in
render
  97. return compiled_parent.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in
render
  178. return self.nodelist.render(context)
File 

Re: Need help with a filter in a view

2009-09-25 Thread Derek Willis

Jim's right, but I'd also suggest redoing your CurrentRanking model so
it has just one foreign key, to SchoolSeason (since that in turn has
fk's to the School model):

class League(models.Model):
league_name = models.CharField(max_length=100)

class School(models.Model):
school_name = models.CharField(max_length=100)

class SchoolSeason(models.Model):
season = models.IntegerField()
school = models.ForeignKey(School)
league = models.ForeignKey(League)

class CurrentRanking(models.Model):
school_season = models.ForeignKey(SchoolSeason)
wins = models.IntegerField()
losses = models.IntegerField()
rating = models.FloatField()

CurrentRanking.objects.filter
(schoolseason__school__league__league_name="League Name").order_by('-
rating')

And if this is college sports you're dealing with, if you intend to
keep this data for a period of years, you may want to have League be a
FK from SchoolSeason, not School, since colleges sometimes leave one
conference to join another.

Derek

On Sep 25, 8:24 pm, Jim McGaw  wrote:
> What you might be asking for is the following syntax, that allows you
> to perform queries against the data in more than one table:
>
> CurrentRanking.objects.filter
> (school__schoolseason__league__league_name="League Name").order_by('-
> rating')
>
> Those are double underscores between the model names and the field
> name. Based on how your models are linked, you might need to play
> around with this a little bit to get exactly what you want, but this
> is basically how you create JOINs in your queries.
>
> Hope it helps!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need help with a filter in a view

2009-09-25 Thread Jim McGaw

What you might be asking for is the following syntax, that allows you
to perform queries against the data in more than one table:

CurrentRanking.objects.filter
(school__schoolseason__league__league_name="League Name").order_by('-
rating')

Those are double underscores between the model names and the field
name. Based on how your models are linked, you might need to play
around with this a little bit to get exactly what you want, but this
is basically how you create JOINs in your queries.

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



Re: Need help with a filter in a view

2009-09-25 Thread jeffself

Oops. I should have said my current view returns a list of rankings
(school_name, rating) rather than all schools.

On Sep 25, 7:59 pm, jeffself  wrote:
> I've got the following models:
>
> class League(models.Model):
>     league_name = models.CharField(max_length=100)
>
> class School(models.Model):
>     school_name = models.CharField(max_length=100)
>
> class SchoolSeason(models.Model):
>     season = models.IntegerField()
>     school = models.ForeignKey(School)
>     league = models.ForeignKey(League)
>
> class CurrentRanking(models.Model):
>     season = models.IntegerField()
>     school = models.ForeignKey(School)
>     wins = models.IntegerField()
>     losses = models.IntegerField()
>     rating = models.FloatField()
>
> I've created a view with the following:
> def rankings_index(request):
>     ranking_list = CurrentRanking.objects.order_by('-rating')
>     return render_to_response('college/rankings_index.html',
> {'ranking_list':ranking_list})
>
> That returns all schools. But I want the view to return all schools
> who belong to a specific League.  How would I do that? Do I need to
> write a custom query with SQL or can it be done with Django/Python?
> I'm still trying to train myself to think from an object point of view
> rather than what I'm used to (SQL).
>
> Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Need help with a filter in a view

2009-09-25 Thread jeffself

I've got the following models:

class League(models.Model):
league_name = models.CharField(max_length=100)

class School(models.Model):
school_name = models.CharField(max_length=100)

class SchoolSeason(models.Model):
season = models.IntegerField()
school = models.ForeignKey(School)
league = models.ForeignKey(League)

class CurrentRanking(models.Model):
season = models.IntegerField()
school = models.ForeignKey(School)
wins = models.IntegerField()
losses = models.IntegerField()
rating = models.FloatField()

I've created a view with the following:
def rankings_index(request):
ranking_list = CurrentRanking.objects.order_by('-rating')
return render_to_response('college/rankings_index.html',
{'ranking_list':ranking_list})

That returns all schools. But I want the view to return all schools
who belong to a specific League.  How would I do that? Do I need to
write a custom query with SQL or can it be done with Django/Python?
I'm still trying to train myself to think from an object point of view
rather than what I'm used to (SQL).

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



Re: Files in MEDIA_ROOT not getting accessed on Windows

2009-09-25 Thread Karen Tracey
On Fri, Sep 25, 2009 at 2:59 PM, Aaron  wrote:

>
> I have a Django 1.1 project under Windows, and I am using an app that
> uses JavaScript (specifically, Page CMS). The JavaScript is in the js
> folder of the media folder, and I've set MEDIA_ROOT in my settings to
> the full path to the media folder (with backslashes replaced by
> forward slashes). MEDIA_URL is blank.
>
> The problem is that the JavaScript isn't working. When I go to a page
> with controls that use JavaScript, the controls aren't there and
> there's a "jQuery is not defined" error in my browser's error console.
>
> The strange thing is that the same code works perfectly on our Linux
> machines with no apparent differences to the configuration beyond the
> the contents of MEDIA_ROOT.
>

You don't say how you are serving these files.  Are you running the
development server?  If so what does your static server config look like?

Karen

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



Re: Unable to delete inline model in admin that contains a FileField (...attribute has no file associated with it)

2009-09-25 Thread Karen Tracey
On Fri, Sep 25, 2009 at 11:34 AM, DavidA  wrote:

>
> Thanks, Karen. You were right - I had overridden it. If I delete the
> __unicode__ method it works now. What's odd is that I can't seem to
> catch any exception. If I try the code below, the admin still breaks.
> And what's also odd is that I never see my models.py file in the stack
> trace.
>
>
Then it doesn't sound like you can't catch the exception but rather that a
different problem is being hit.  Without the new stack trace, though, I
don't have any idea what it might be...

Karen   def __unicode__(self):

>try:
>return self.document.url
>except:
>return u'File deleted'
>
> Thanks,
> -Dave
>
>

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



Re: starting a new site with django

2009-09-25 Thread Gonzalo Delgado
El Fri, 25 Sep 2009 15:30:02 -0700 (PDT)
Ronen Gal  escribió:

> I would like to build a website which sells videos (music lessons).
> The site would include ~50 videos, 150MB each.
> I need some kind of shopping cart, and the ability to recieve payment.
> I also need user accounts, so I can learn my users flavour and offer
> them appropriate videos.
> I need some mailing API, to allow me to send mails to my customers.
> 
> I am sure that there someone have already written most of this
> website.
> User's accounts, shopping cart, paypal and mails all look very
> standard.
> Can you please point me to where can I find code that do all those
> stuff?

I'd take a look at Pinax[0]

> How can I connect that code to a specific hosting server (with a
> specific data base and mail API for instance)?

You're lucky, Django's documentation[1] explains how to connect to a hosting
server!
Not only that, Django provides its own mail API[2]!!!

Good luck with your site!

[0] http://pinaxproject.com/
[1] 
http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index
[2] http://docs.djangoproject.com/en/dev/topics/email/#topics-email
-- 
P.U. Gonzalo Delgado 
http://gonzalodelgado.com.ar/


pgpdQ34axVa7t.pgp
Description: PGP signature


starting a new site with django

2009-09-25 Thread Ronen Gal

Hi,

I would like to build a website which sells videos (music lessons).
The site would include ~50 videos, 150MB each.
I need some kind of shopping cart, and the ability to recieve payment.
I also need user accounts, so I can learn my users flavour and offer
them appropriate videos.
I need some mailing API, to allow me to send mails to my customers.

I am sure that there someone have already written most of this
website.
User's accounts, shopping cart, paypal and mails all look very
standard.
Can you please point me to where can I find code that do all those
stuff?
How can I connect that code to a specific hosting server (with a
specific data base and mail API for instance)?

Thanks in advance,
Ronen

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



redirect to enter page

2009-09-25 Thread Dan Cox

Django Users,

I'm pretty new to django so please excuse my ignorance.

I'd like to redirect users to an "enter" page no matter where they
entered the site. The enter page would have the user read/check a
disclaimer type of box and then return to the page they were originally
going to.

Any suggestions on the best way to approach this.

Thanks in advance.

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



Re: TemplateSyntaxError: VariableDoesNotExist

2009-09-25 Thread Florian Schweikert
2009/9/24 Brian McKeever 

>
> I would write a custom tag that wraps ugettext but checks for None.
>
> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters
> http://docs.djangoproject.com/en/dev/topics/i18n/#standard-translation
>
> On Sep 24, 10:14 am, Florian Schweikert 
> wrote:
> > Hello,
> >
> > {% trans Pagetitle %} produces TemplateSyntaxError when there is no
> > Pagetitle given, without translation django ignores it.
> > Why i18n can't translate/ignore NoneType? I don't want to use if around
> all
> > this varibles. Is there any more confortable way?
> >
> > greetings,
> > Florian
> >
> That's a good idea, thanks for the tip.

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



Overriding verbose_name in contrib or 3rd-party apps?

2009-09-25 Thread ringemup

Is there an easy way to override strings like help_text or
verbose_name or __unicode__ methods for models in contrib or third-
party apps?  I can't seem to find anything on Google.

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



Re: Error Message regarding len()

2009-09-25 Thread Nick

You were exactly right, it was a sloppy mistake.  Thanks for looking
at this.  Time to move on to the next error I just got.

On Sep 25, 3:40 pm, Brian McKeever  wrote:
> I'd guess that you didn't set AWS_SECRET_ACCESS_KEY correctly in your
> settings.
>
> http://code.welldev.org/django-storages/wiki/S3Storage
>
> On Sep 25, 2:12 pm, Nick  wrote:
>
> > something like this?
>
> > Environment:
>
> > Request Method: POST
> > Request URL:http://localhost:8000/admin/StoryWall/statefair/16/
> > Django Version: 1.2 pre-alpha SVN-11434
> > Python Version: 2.5.4
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'django.contrib.admin',
> >  'django.contrib.admin',
> >  'MMprojects.StoryWall']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Traceback:
> > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >   92.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> > in wrapper
> >   226.                 return self.admin_site.admin_view(view)(*args,
> > **kwargs)
> > File "C:\Python25\lib\site-packages\django\views\decorators\cache.py"
> > in _wrapped_view_func
> >   44.         response = view_func(request, *args, **kwargs)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
> > inner
> >   186.             return view(request, *args, **kwargs)
> > File "C:\Python25\lib\site-packages\django\db\transaction.py" in
> > _commit_on_success
> >   240.                 res = func(*args, **kw)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> > in change_view
> >   830.                 self.save_model(request, new_object, form,
> > change=True)
> > File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> > in save_model
> >   557.         obj.save()
> > File "C:\Python25\lib\site-packages\django\db\models\base.py" in save
> >   410.         self.save_base(force_insert=force_insert,
> > force_update=force_update)
> > File "C:\Python25\lib\site-packages\django\db\models\base.py" in
> > save_base
> >   473.                         values = [(f, None, (raw and getattr
> > (self, f.attname) or f.pre_save(self, False))) for f in non_pks]
> > File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
> > in pre_save
> >   252.             file.save(file.name, file, save=False)
> > File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
> > in save
> >   91.         self.name = self.storage.save(name, content)
> > File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
> > save
> >   46.         name = self.get_available_name(name)
> > File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
> > get_available_name
> >   71.         while self.exists(name):
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \backends\s3.py" in exists
> >   105.         response = self.connection._make_request('HEAD',
> > self.bucket, name)
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \S3.py" in _make_request
> >   273.             self._add_aws_auth_header(final_headers, method,
> > bucket, key, query_args)
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \S3.py" in _add_aws_auth_header
> >   299.             "AWS %s:%s" % (self.aws_access_key_id, encode
> > (self.aws_secret_access_key, c_string))
> > File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> > \S3.py" in encode
> >   84.     b64_hmac = base64.encodestring(hmac.new
> > (aws_secret_access_key, str, sha).digest()).strip()
> > File "C:\Python25\lib\hmac.py" in new
> >   121.     return HMAC(key, msg, digestmod)
> > File "C:\Python25\lib\hmac.py" in __init__
> >   64.         if len(key) > blocksize:
>
> > Exception Type: TypeError at /admin/StoryWall/statefair/16/
> > Exception Value: object of type 'NoneType' has no len()
>
> > On Sep 25, 2:54 pm, Brian McKeever  wrote:
>
> > > A stack trace would be more useful.
>
> > > On Sep 25, 12:07 pm, Nick  wrote:
>
> > > > I'm using the django-storages backends from David Larlet to upload
> > > > images to s3 from inside the admin.  When i try to run everything I
> > > > get an error:
>
> > > > object of type 'NoneType' has no len()
>
> > > > Here is my model:
>
> > > > from django.db import models
> > > > from django.core.files.storage import default_storage as s3_storage
>
> > > > class StateFair (models.Model):
> > > >     Content_Choices = (
> > > >         ('photo', 'Photo'),
> > > >         ('video', 'Video'),
> > > >         ('text', 'Text'),
> > > >         

Re: Urls.py: Match a leading Question Mark

2009-09-25 Thread mike

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



Re: Error Message regarding len()

2009-09-25 Thread Brian McKeever

I'd guess that you didn't set AWS_SECRET_ACCESS_KEY correctly in your
settings.

http://code.welldev.org/django-storages/wiki/S3Storage

On Sep 25, 2:12 pm, Nick  wrote:
> something like this?
>
> Environment:
>
> Request Method: POST
> Request URL:http://localhost:8000/admin/StoryWall/statefair/16/
> Django Version: 1.2 pre-alpha SVN-11434
> Python Version: 2.5.4
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'django.contrib.admin',
>  'MMprojects.StoryWall']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> get_response
>   92.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> in wrapper
>   226.                 return self.admin_site.admin_view(view)(*args,
> **kwargs)
> File "C:\Python25\lib\site-packages\django\views\decorators\cache.py"
> in _wrapped_view_func
>   44.         response = view_func(request, *args, **kwargs)
> File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
> inner
>   186.             return view(request, *args, **kwargs)
> File "C:\Python25\lib\site-packages\django\db\transaction.py" in
> _commit_on_success
>   240.                 res = func(*args, **kw)
> File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> in change_view
>   830.                 self.save_model(request, new_object, form,
> change=True)
> File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
> in save_model
>   557.         obj.save()
> File "C:\Python25\lib\site-packages\django\db\models\base.py" in save
>   410.         self.save_base(force_insert=force_insert,
> force_update=force_update)
> File "C:\Python25\lib\site-packages\django\db\models\base.py" in
> save_base
>   473.                         values = [(f, None, (raw and getattr
> (self, f.attname) or f.pre_save(self, False))) for f in non_pks]
> File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
> in pre_save
>   252.             file.save(file.name, file, save=False)
> File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
> in save
>   91.         self.name = self.storage.save(name, content)
> File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
> save
>   46.         name = self.get_available_name(name)
> File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
> get_available_name
>   71.         while self.exists(name):
> File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> \backends\s3.py" in exists
>   105.         response = self.connection._make_request('HEAD',
> self.bucket, name)
> File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> \S3.py" in _make_request
>   273.             self._add_aws_auth_header(final_headers, method,
> bucket, key, query_args)
> File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> \S3.py" in _add_aws_auth_header
>   299.             "AWS %s:%s" % (self.aws_access_key_id, encode
> (self.aws_secret_access_key, c_string))
> File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
> \S3.py" in encode
>   84.     b64_hmac = base64.encodestring(hmac.new
> (aws_secret_access_key, str, sha).digest()).strip()
> File "C:\Python25\lib\hmac.py" in new
>   121.     return HMAC(key, msg, digestmod)
> File "C:\Python25\lib\hmac.py" in __init__
>   64.         if len(key) > blocksize:
>
> Exception Type: TypeError at /admin/StoryWall/statefair/16/
> Exception Value: object of type 'NoneType' has no len()
>
> On Sep 25, 2:54 pm, Brian McKeever  wrote:
>
> > A stack trace would be more useful.
>
> > On Sep 25, 12:07 pm, Nick  wrote:
>
> > > I'm using the django-storages backends from David Larlet to upload
> > > images to s3 from inside the admin.  When i try to run everything I
> > > get an error:
>
> > > object of type 'NoneType' has no len()
>
> > > Here is my model:
>
> > > from django.db import models
> > > from django.core.files.storage import default_storage as s3_storage
>
> > > class StateFair (models.Model):
> > >     Content_Choices = (
> > >         ('photo', 'Photo'),
> > >         ('video', 'Video'),
> > >         ('text', 'Text'),
> > >         ('audio', 'Audio'),
> > >     )
> > >     Name = models.CharField(max_length=30, blank=False, unique=True)
> > >     contentType = models.CharField('Type of Content', max_length=5,
> > > choices=Content_Choices, blank=True)
> > >     thumbNailUpload = models.ImageField('Thumbnail Upload',
> > > storage=s3_storage, upload_to='/news', height_field=None,
> > > width_field=None, max_length=100, blank=True, 

Re: Error Message regarding len()

2009-09-25 Thread Nick

something like this?

Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/StoryWall/statefair/16/
Django Version: 1.2 pre-alpha SVN-11434
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.admin',
 'MMprojects.StoryWall']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
in wrapper
  226. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "C:\Python25\lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" in
inner
  186. return view(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\transaction.py" in
_commit_on_success
  240. res = func(*args, **kw)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
in change_view
  830. self.save_model(request, new_object, form,
change=True)
File "C:\Python25\lib\site-packages\django\contrib\admin\options.py"
in save_model
  557. obj.save()
File "C:\Python25\lib\site-packages\django\db\models\base.py" in save
  410. self.save_base(force_insert=force_insert,
force_update=force_update)
File "C:\Python25\lib\site-packages\django\db\models\base.py" in
save_base
  473. values = [(f, None, (raw and getattr
(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
in pre_save
  252. file.save(file.name, file, save=False)
File "C:\Python25\lib\site-packages\django\db\models\fields\files.py"
in save
  91. self.name = self.storage.save(name, content)
File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
save
  46. name = self.get_available_name(name)
File "C:\Python25\lib\site-packages\django\core\files\storage.py" in
get_available_name
  71. while self.exists(name):
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\backends\s3.py" in exists
  105. response = self.connection._make_request('HEAD',
self.bucket, name)
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\S3.py" in _make_request
  273. self._add_aws_auth_header(final_headers, method,
bucket, key, query_args)
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\S3.py" in _add_aws_auth_header
  299. "AWS %s:%s" % (self.aws_access_key_id, encode
(self.aws_secret_access_key, c_string))
File "c:\python25\lib\site-packages\django_storages-1.0-py2.5.egg
\S3.py" in encode
  84. b64_hmac = base64.encodestring(hmac.new
(aws_secret_access_key, str, sha).digest()).strip()
File "C:\Python25\lib\hmac.py" in new
  121. return HMAC(key, msg, digestmod)
File "C:\Python25\lib\hmac.py" in __init__
  64. if len(key) > blocksize:

Exception Type: TypeError at /admin/StoryWall/statefair/16/
Exception Value: object of type 'NoneType' has no len()


On Sep 25, 2:54 pm, Brian McKeever  wrote:
> A stack trace would be more useful.
>
> On Sep 25, 12:07 pm, Nick  wrote:
>
> > I'm using the django-storages backends from David Larlet to upload
> > images to s3 from inside the admin.  When i try to run everything I
> > get an error:
>
> > object of type 'NoneType' has no len()
>
> > Here is my model:
>
> > from django.db import models
> > from django.core.files.storage import default_storage as s3_storage
>
> > class StateFair (models.Model):
> >     Content_Choices = (
> >         ('photo', 'Photo'),
> >         ('video', 'Video'),
> >         ('text', 'Text'),
> >         ('audio', 'Audio'),
> >     )
> >     Name = models.CharField(max_length=30, blank=False, unique=True)
> >     contentType = models.CharField('Type of Content', max_length=5,
> > choices=Content_Choices, blank=True)
> >     thumbNailUpload = models.ImageField('Thumbnail Upload',
> > storage=s3_storage, upload_to='/news', height_field=None,
> > width_field=None, max_length=100, blank=True, null=True)
> >     ThumbNail = models.CharField('Thumbnail Name', max_length=50,
> > blank=True)
> >     imageUpload = models.ImageField('Full Size Image Upload',
> > storage=s3_storage, upload_to='/news, height_field=None,
> > width_field=None, max_length=100, blank=True, null=True)
> >     Image = models.CharField('Image name (use jpg, png, etc.)',
> > max_length=30, blank=True)
> >     Cutline = 

Re: Error Message regarding len()

2009-09-25 Thread Brian McKeever

A stack trace would be more useful.

On Sep 25, 12:07 pm, Nick  wrote:
> I'm using the django-storages backends from David Larlet to upload
> images to s3 from inside the admin.  When i try to run everything I
> get an error:
>
> object of type 'NoneType' has no len()
>
> Here is my model:
>
> from django.db import models
> from django.core.files.storage import default_storage as s3_storage
>
> class StateFair (models.Model):
>     Content_Choices = (
>         ('photo', 'Photo'),
>         ('video', 'Video'),
>         ('text', 'Text'),
>         ('audio', 'Audio'),
>     )
>     Name = models.CharField(max_length=30, blank=False, unique=True)
>     contentType = models.CharField('Type of Content', max_length=5,
> choices=Content_Choices, blank=True)
>     thumbNailUpload = models.ImageField('Thumbnail Upload',
> storage=s3_storage, upload_to='/news', height_field=None,
> width_field=None, max_length=100, blank=True, null=True)
>     ThumbNail = models.CharField('Thumbnail Name', max_length=50,
> blank=True)
>     imageUpload = models.ImageField('Full Size Image Upload',
> storage=s3_storage, upload_to='/news, height_field=None,
> width_field=None, max_length=100, blank=True, null=True)
>     Image = models.CharField('Image name (use jpg, png, etc.)',
> max_length=30, blank=True)
>     Cutline = models.TextField('Caption or Cutline', blank=True)
>     VideoID = models.IntegerField(max_length=30, null=True,
> blank=True)
>     TextBlock = models.TextField('Text Block', blank=True)
>     AudioID = models.CharField('Audio FileName', max_length=40,
> blank=True)
>     pubDate = models.DateTimeField('updated', blank=True)
>
>     class Meta:
>         ordering = ("?")
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: are django applications portable?

2009-09-25 Thread Kevin Teague



On Sep 25, 9:59 am, dijxtra  wrote:
> Hi everybody,
>
> Django applications, as I understood them should be pluginable on
> project basis. That is, I should be able to install them to my
> *project*, not to my django installation. So I downloaded django-
> tagging and run the python setup.py install. And it failed:
> n...@rilmir:~/code/my_project/django-tagging-0.3$ python setup.py
> install
> [...]
> creating /usr/local/lib/python2.6/dist-packages/tagging
> error: could not create '/usr/local/lib/python2.6/dist-packages/
> tagging': Permission denied
>
> Now, why is django-tagging trying to mess with my python directory?
> Does that mean that when I commit my project to my repository and
> checkout it on a different django installation django-tagging won't
> work untill I install django-tagging on that machine? I thought that
> when I install an django app, then I install it in my project and my
> project is still portable. But, if django-tagging is putting files in
> directories outside my project directory, doesn't that make my project
> un-portable?
>
> Could someone please clear this up for me?
>

First, this issue is a python packaging and distribution issue. There
is nothing specific to Django or Django apps which makes dependency
handling any easier over working with any other non-django python
distributions.

When you do:

 $ python setup.py install

You are manually installing the django-tagging distribution. The
setup.py for a distribution will either invoke distutils or setuptools
to install this distribution in a global location for your python
interpreter. There are additional command-line switch you can supply
to install this distribution in a non-global location. Then you can
inform your Python interpreter of that location of this non-global
locatin using the PYTHONPATH environment variable. There are a variety
of home-grown solutions for managing this type of dependency
installation (shell scripts, symlinks, etc.).

But home-grown package handling tends to be rather unwieldy. The ideal
way to handle dependencies is to make your project a proper python
distribution (i.e. has a setup.py file), and then use one of the
python package installation tools (Buildout or Pip) to automatically
handle downloading and installation. Inside the setup.py file you can
use the 'install_requires' field (only supported by setuptools ATM,
but should be officially supported in Python 2.7/3.2). Your setup.py
would have a line such as:

  install_requires = ['django-tagging','Django']

When Pip or Buildout install your project, it will read the
install_requires and automatically install Django and django-tagging.
You can further limit the versions selected for a particular install
(dev install or production install) by specifiying specific versions
of packages picked from specific package repositories, typically you
may pin down all versions in a production setting, where as you
development installs will freely pull down the newest releases of all
dependencies so you can test them in advance of promoting those
packages into production.

But again, there is nothing Django-specific about this, so if you have
other questions about python packaging, you may find (more or better)
answers on the Distutils-SIG mailing list.



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



Re: Named URL Patterns -- Syntax Error

2009-09-25 Thread W3

Thanks, that was it. Bit of a simple one I probably should have
spotted.

Andrew

On 25 Sep, 19:42, Tim Chase  wrote:
> > Can somebody tell me why i get a syntax error with this named URL
> > pattern?
>
> > urlpatterns = patterns('',
> >     url(r'^feed/(?P.*)/$',
> >     'django.contrib.syndication.views.feed',
> >     {'feed_dict': feeds}
>
> looks like a missing comma here...
>
> >     name="feed"),
> > )
>
> -tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Files in MEDIA_ROOT not getting accessed on Windows

2009-09-25 Thread Aaron

I have a Django 1.1 project under Windows, and I am using an app that
uses JavaScript (specifically, Page CMS). The JavaScript is in the js
folder of the media folder, and I've set MEDIA_ROOT in my settings to
the full path to the media folder (with backslashes replaced by
forward slashes). MEDIA_URL is blank.

The problem is that the JavaScript isn't working. When I go to a page
with controls that use JavaScript, the controls aren't there and
there's a "jQuery is not defined" error in my browser's error console.

The strange thing is that the same code works perfectly on our Linux
machines with no apparent differences to the configuration beyond the
the contents of MEDIA_ROOT.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Named URL Patterns -- Syntax Error

2009-09-25 Thread Tim Chase

> Can somebody tell me why i get a syntax error with this named URL
> pattern?
> 
> urlpatterns = patterns('',
> url(r'^feed/(?P.*)/$',
> 'django.contrib.syndication.views.feed',
> {'feed_dict': feeds}

looks like a missing comma here...

> name="feed"),
> )

-tim




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



Re: opener.dismissAddAnotherPopup error tinymce

2009-09-25 Thread Joost Cassee

On 24 sep, 15:36, Ali Rıza KELEŞ  wrote:

> But i just defined document.domain in my tinymce initializer, nowhere
> else.. Is there anywhere else should I define it?

Yes, because *all* Javascript code that needs to work together must
have the same document.domain value. There are Javascript snippets in
the HTML, so there must be something like document.domain =
"..." in there too.

Regards,

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



Re: are django applications portable?

2009-09-25 Thread dijxtra

On Sep 25, 7:54 pm, Javier Guerra  wrote:
> On Fri, Sep 25, 2009 at 11:59 AM, dijxtra  wrote:
>
> > Hi everybody,
>
> > Django applications, as I understood them should be pluginable on
> > project basis. That is, I should be able to install them to my
> > *project*, not to my django installation.
>
> 'portable' means 'use from any project', not "copy to every project".
> for that, it has to be accessible from the python path, since it's
> just a couple of python modules

So, since it is not "copied to every project" it means that every
person which wants to run my project has to install django-tagging on
it's machine first?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Error Message regarding len()

2009-09-25 Thread Nick

I'm using the django-storages backends from David Larlet to upload
images to s3 from inside the admin.  When i try to run everything I
get an error:

object of type 'NoneType' has no len()

Here is my model:

from django.db import models
from django.core.files.storage import default_storage as s3_storage




class StateFair (models.Model):
Content_Choices = (
('photo', 'Photo'),
('video', 'Video'),
('text', 'Text'),
('audio', 'Audio'),
)
Name = models.CharField(max_length=30, blank=False, unique=True)
contentType = models.CharField('Type of Content', max_length=5,
choices=Content_Choices, blank=True)
thumbNailUpload = models.ImageField('Thumbnail Upload',
storage=s3_storage, upload_to='/news', height_field=None,
width_field=None, max_length=100, blank=True, null=True)
ThumbNail = models.CharField('Thumbnail Name', max_length=50,
blank=True)
imageUpload = models.ImageField('Full Size Image Upload',
storage=s3_storage, upload_to='/news, height_field=None,
width_field=None, max_length=100, blank=True, null=True)
Image = models.CharField('Image name (use jpg, png, etc.)',
max_length=30, blank=True)
Cutline = models.TextField('Caption or Cutline', blank=True)
VideoID = models.IntegerField(max_length=30, null=True,
blank=True)
TextBlock = models.TextField('Text Block', blank=True)
AudioID = models.CharField('Audio FileName', max_length=40,
blank=True)
pubDate = models.DateTimeField('updated', blank=True)

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



Named URL Patterns -- Syntax Error

2009-09-25 Thread When ideas fail

Can somebody tell me why i get a syntax error with this named URL
pattern?

urlpatterns = patterns('',
url(r'^feed/(?P.*)/$',
'django.contrib.syndication.views.feed',
{'feed_dict': feeds}
name="feed"),
)


This is the traceback:

Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
  83. request.path_info)
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
resolve
  216. for pattern in self.url_patterns:
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
_get_url_patterns
  245. patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
_get_urlconf_module
  240. self._urlconf_module = import_module
(self.urlconf_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py" in
import_module
  35. __import__(name)

Exception Type: SyntaxError at /
Exception Value: ('invalid syntax', ('C:\\Apache2.2\\myapp\\urls.py',
28, 73, '{\'feed_dict
\': feeds} name="feed"),\n'))


Thanks,

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



Re: are django applications portable?

2009-09-25 Thread Javier Guerra

On Fri, Sep 25, 2009 at 11:59 AM, dijxtra  wrote:
>
> Hi everybody,
>
> Django applications, as I understood them should be pluginable on
> project basis. That is, I should be able to install them to my
> *project*, not to my django installation.

'portable' means 'use from any project', not "copy to every project".
for that, it has to be accessible from the python path, since it's
just a couple of python modules

-- 
Javier

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



Re: are django applications portable?

2009-09-25 Thread Brian McKeever

I'm not familiar with the plugin, but I would guess that it's trying
to add itself to the python path. That way it's easily available for
any django project without having to include it in an individual
project.

I would bet that it'd work just fine included manually in your project
without running the install script.

But again, it depends on the plugin.
On Sep 25, 10:59 am, dijxtra  wrote:
> Hi everybody,
>
> Django applications, as I understood them should be pluginable on
> project basis. That is, I should be able to install them to my
> *project*, not to my django installation. So I downloaded django-
> tagging and run the python setup.py install. And it failed:
> n...@rilmir:~/code/my_project/django-tagging-0.3$ python setup.py
> install
> [...]
> creating /usr/local/lib/python2.6/dist-packages/tagging
> error: could not create '/usr/local/lib/python2.6/dist-packages/
> tagging': Permission denied
>
> Now, why is django-tagging trying to mess with my python directory?
> Does that mean that when I commit my project to my repository and
> checkout it on a different django installation django-tagging won't
> work untill I install django-tagging on that machine? I thought that
> when I install an django app, then I install it in my project and my
> project is still portable. But, if django-tagging is putting files in
> directories outside my project directory, doesn't that make my project
> un-portable?
>
> Could someone please clear this up for me?
>
> Thanks,
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Brian McKeever

Oh, it's just a preference. I don't like calculating stuff in the
template. It violates the MVT pattern to some minor degree.

On Sep 25, 6:41 am, Bryan  wrote:
> I can't think of a reason, if nothing else its a matter or taste/
> preference.  He said "I would probably...", so he may have been
> implying that there was a technical reason but most likely he was just
> stating his preference.
>
> On Sep 25, 5:03 am, Chris Withers  wrote:
>
> > Jani Tiainen wrote:
> > > Chris Withers kirjoitti:
> > >> Brian McKeever wrote:
> > >>> .count is definitely the way to go. Although, I would probably pass it
> > >>> to your template instead of determining it there.
> > >> What difference does it make?
>
> > > len(qs) evaluates queryset - thus pulling in _every_ object from DB to
> > > Python - which you might not want specially if queryset is large.
>
> > > .count() executes count query on DB side returing only single scalar
> > > value to Python.
>
> > > Figure out which one is faster...
>
> > Er, I was asking what the difference was between calling .count in the
> > view and in the template. I can't think why it would make a difference,
> > but Brian suggested it did...
>
> > Chris
>
> > --
> > Simplistix - Content Management, Batch Processing & Python Consulting
> >             -http://www.simplistix.co.uk
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Brian McKeever

.count uses a sql function that just counts the rows.

Doing len(model.objects.all()) pulls ALL of the objects from the
database including all of the associated data and then counts them.

It should be a significant performance difference for any large data
set.

On Sep 24, 11:12 am, Chris Withers  wrote:
> Brian McKeever wrote:
> > .count is definitely the way to go. Although, I would probably pass it
> > to your template instead of determining it there.
>
> What difference does it make?
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             -http://www.simplistix.co.uk
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



are django applications portable?

2009-09-25 Thread dijxtra

Hi everybody,

Django applications, as I understood them should be pluginable on
project basis. That is, I should be able to install them to my
*project*, not to my django installation. So I downloaded django-
tagging and run the python setup.py install. And it failed:
n...@rilmir:~/code/my_project/django-tagging-0.3$ python setup.py
install
[...]
creating /usr/local/lib/python2.6/dist-packages/tagging
error: could not create '/usr/local/lib/python2.6/dist-packages/
tagging': Permission denied

Now, why is django-tagging trying to mess with my python directory?
Does that mean that when I commit my project to my repository and
checkout it on a different django installation django-tagging won't
work untill I install django-tagging on that machine? I thought that
when I install an django app, then I install it in my project and my
project is still portable. But, if django-tagging is putting files in
directories outside my project directory, doesn't that make my project
un-portable?

Could someone please clear this up for me?

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



Re: Unable to delete inline model in admin that contains a FileField (...attribute has no file associated with it)

2009-09-25 Thread DavidA

Thanks, Karen. You were right - I had overridden it. If I delete the
__unicode__ method it works now. What's odd is that I can't seem to
catch any exception. If I try the code below, the admin still breaks.
And what's also odd is that I never see my models.py file in the stack
trace.

def __unicode__(self):
try:
return self.document.url
except:
return u'File deleted'

Thanks,
-Dave

On Sep 25, 10:36 am, Karen Tracey  wrote:
> On Fri, Sep 25, 2009 at 9:05 AM, DavidA  wrote:
>
> > I'm getting this error when I try to remove an inline model instance
> > in the Django admin:
>
> >    Traceback:
> >    File "C:\Python25\lib\site-packages\django\core\handlers\base.py"
> > in get_response
> >      92.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> >    File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py"
> > in root
> >      490.                 return self.model_page(request, *url.split
> > ('/', 2))
> >    File "C:\Python25\lib\site-packages\django\views\decorators
> > \cache.py" in _wrapped_view_func
> >      44.         response = view_func(request, *args, **kwargs)
> >    File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py"
> > in model_page
> >      509.         return admin_obj(request, rest_of_url)
> >    File "C:\Python25\lib\site-packages\django\contrib\admin
> > \options.py" in __call__
> >      1098.             return self.change_view(request, unquote(url))
> >    File "C:\Python25\lib\site-packages\django\db\transaction.py" in
> > _commit_on_success
> >      240.                 res = func(*args, **kw)
> >    File "C:\Python25\lib\site-packages\django\contrib\admin
> > \options.py" in change_view
> >      835.                 change_message =
> > self.construct_change_message(request, form, formsets)
> >    File "C:\Python25\lib\site-packages\django\contrib\admin
> > \options.py" in construct_change_message
> >      535.                                              'object':
> > force_unicode(deleted_object)})
> >    File "C:\Python25\Lib\site-packages\django\utils\encoding.py" in
> > force_unicode
> >      71.                 s = unicode(s)
> >    File "C:\private\src\itweb\..\itweb\controls\models.py" in
> > __unicode__
> >      160.         return self.document.url
>
> You don't include this __unicode__ method in the code below, but this is
> likely where the problem is.  What the admin is trying to log is the unicode
> value of your deleted object.  I think you need to change your model's
> unicode method so that it does not trigger an exception when it is called
> for an instance that has no associated file.
>
> Karen
>
>
>
> >    File "C:\Python25\lib\site-packages\django\db\models\fields
> > \files.py" in _get_url
> >      68.         self._require_file()
> >    File "C:\Python25\lib\site-packages\django\db\models\fields
> > \files.py" in _require_file
> >      46.             raise ValueError("The '%s' attribute has no file
> > associated with it." % self.field.name)
>
> >    Exception Type: ValueError at /admin/controls/review/24/
> >    Exception Value: The 'document' attribute has no file associated
> > with it.
>
> > I can see that the file is being deleted on disk, but then it looks
> > like this error is being thrown when the admin is trying to display a
> > summary message of what was done, and that triggers a _require_file()
> > call which raises an exception.
>
> > I have the following models:
>
> >    class Review(models.Model):
> >        name = models.CharField(max_length=80)
> >        review_type = models.CharField(max_length=20,
> > choices=REVIEW_TYPE_CHOICES)
> >        frequency = models.CharField(max_length=20,
> > choices=FREQUENCY_CHOICES,
> >                                     null=True, blank=True)
> >        description = models.TextField(null=True, blank=True)
>
> >    class Evidence(models.Model):
> >        review = models.ForeignKey(Review)
> >        review_time = models.DateTimeField(null=True, blank=True)
> >        reviewed_by = models.ForeignKey(User, null=True, blank=True)
> >        document = models.FileField(upload_to='evidence/%Y/%m/%d')
>
> > And admin classes:
>
> >    class EvidenceInline(admin.TabularInline):
> >        model = Evidence
>
> >    class ReviewAdmin(admin.ModelAdmin):
> >        list_display = ['name', 'review_type', 'frequency',
> > 'description']
> >        list_filter = ['review_type', 'frequency']
> >        search_fields = ['name', 'description']
> >        fieldsets = [
> >            (None,      {'fields':['name', 'review_type',
> > 'frequency']}),
> >            ('Details', {'fields':['description']}),
> >            ]
> >        inlines = [EvidenceInline]
>
> >    admin.site.register(Review, ReviewAdmin)
>
> > Am I doing something wrong?
>
> > Thanks,
> > -Dave
--~--~-~--~~~---~--~~
You received this message because you are subscribed to 

URL resolving of patterns including 0 or 1 operator fails.......

2009-09-25 Thread Lewis Taylor

Here it goes:

I wanted a clean url structure so i tried to abstract as much as i
could in one url pattern. it looks something like this:

url(r'^approved/((?P[a-zA-Z ,-]+)?)(/?)((?P[0-9]+)?)
(/?)
$', get_approved_images, name='approved_images')

this in theory should allow the return of
1) all images - /approved/
2) pagination options for all images - /approved/2/
3) images from a specific country - /approved/china/
4) pagination for countries - /approved/china/3/

this works fine, but when trying to resolve the url with no page or
country there are problems i.e.

{% url approved_images %}

i thought as there can be 0 or 1 of both country and page as specified
in the url pattern there shouldn't be a problem, however it doesn't
seem that way. I haven't looked inside the code as i have higher
priority things to do at present, but if anyone could help with a
solution or a reason why it doesn't work that would be appreciated, if
not i suggest a patch as it makes sense that allowing url's to match a
particular pattern should also mean that any url that matches that
pattern should be resolvable :-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django-lean for a/b split-testing

2009-09-25 Thread Erik Wright

Hi folks,

My team has recently begun following a product development approach
modeled heavily on Customer Development and Lean Startup concepts. In
particular, we are now using a/b split-test experiments to measure the
impact of all visible changes on our users.

When we started out, we found that there were few tools to help us do
this. Google Website Optimizer looked promising but had a number of
shortcomings that prevented us from using it.

Instead, we chose to create our own tool. Today, I'm happy to tell you
that we have open-sourced that tool under the name 'django-lean'.
Check it out at http://bitbucket.org/akoha/django-lean/

django-lean allows you to define split-test experiments in JavaScript,
Python, or Django template code and to measure the impact of those
experiments on your custom-defined conversion or engagement
statistics. Over time we hope this project will grow to encompass
other Lean Startup tools including cohort analysis, net promoter
score, etc.

If you are thinking of entering the world of split testing I hope you
will give a look to django-lean! The URL, again: 
http://bitbucket.org/akoha/django-lean/

Thanks,

Erik Wright
Director of Engineering, Akoha

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



Re: Unable to delete inline model in admin that contains a FileField (...attribute has no file associated with it)

2009-09-25 Thread Karen Tracey
On Fri, Sep 25, 2009 at 9:05 AM, DavidA  wrote:

>
> I'm getting this error when I try to remove an inline model instance
> in the Django admin:
>
>Traceback:
>File "C:\Python25\lib\site-packages\django\core\handlers\base.py"
> in get_response
>  92. response = callback(request, *callback_args,
> **callback_kwargs)
>File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py"
> in root
>  490. return self.model_page(request, *url.split
> ('/', 2))
>File "C:\Python25\lib\site-packages\django\views\decorators
> \cache.py" in _wrapped_view_func
>  44. response = view_func(request, *args, **kwargs)
>File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py"
> in model_page
>  509. return admin_obj(request, rest_of_url)
>File "C:\Python25\lib\site-packages\django\contrib\admin
> \options.py" in __call__
>  1098. return self.change_view(request, unquote(url))
>File "C:\Python25\lib\site-packages\django\db\transaction.py" in
> _commit_on_success
>  240. res = func(*args, **kw)
>File "C:\Python25\lib\site-packages\django\contrib\admin
> \options.py" in change_view
>  835. change_message =
> self.construct_change_message(request, form, formsets)
>File "C:\Python25\lib\site-packages\django\contrib\admin
> \options.py" in construct_change_message
>  535.  'object':
> force_unicode(deleted_object)})
>File "C:\Python25\Lib\site-packages\django\utils\encoding.py" in
> force_unicode
>  71. s = unicode(s)
>File "C:\private\src\itweb\..\itweb\controls\models.py" in
> __unicode__
>  160. return self.document.url
>

You don't include this __unicode__ method in the code below, but this is
likely where the problem is.  What the admin is trying to log is the unicode
value of your deleted object.  I think you need to change your model's
unicode method so that it does not trigger an exception when it is called
for an instance that has no associated file.

Karen



>File "C:\Python25\lib\site-packages\django\db\models\fields
> \files.py" in _get_url
>  68. self._require_file()
>File "C:\Python25\lib\site-packages\django\db\models\fields
> \files.py" in _require_file
>  46. raise ValueError("The '%s' attribute has no file
> associated with it." % self.field.name)
>
>Exception Type: ValueError at /admin/controls/review/24/
>Exception Value: The 'document' attribute has no file associated
> with it.
>
> I can see that the file is being deleted on disk, but then it looks
> like this error is being thrown when the admin is trying to display a
> summary message of what was done, and that triggers a _require_file()
> call which raises an exception.
>
> I have the following models:
>
>class Review(models.Model):
>name = models.CharField(max_length=80)
>review_type = models.CharField(max_length=20,
> choices=REVIEW_TYPE_CHOICES)
>frequency = models.CharField(max_length=20,
> choices=FREQUENCY_CHOICES,
> null=True, blank=True)
>description = models.TextField(null=True, blank=True)
>
>class Evidence(models.Model):
>review = models.ForeignKey(Review)
>review_time = models.DateTimeField(null=True, blank=True)
>reviewed_by = models.ForeignKey(User, null=True, blank=True)
>document = models.FileField(upload_to='evidence/%Y/%m/%d')
>
> And admin classes:
>
>class EvidenceInline(admin.TabularInline):
>model = Evidence
>
>class ReviewAdmin(admin.ModelAdmin):
>list_display = ['name', 'review_type', 'frequency',
> 'description']
>list_filter = ['review_type', 'frequency']
>search_fields = ['name', 'description']
>fieldsets = [
>(None,  {'fields':['name', 'review_type',
> 'frequency']}),
>('Details', {'fields':['description']}),
>]
>inlines = [EvidenceInline]
>
>admin.site.register(Review, ReviewAdmin)
>
> Am I doing something wrong?
>
> Thanks,
> -Dave
>
> >
>

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



Unable to delete inline model in admin that contains a FileField (...attribute has no file associated with it)

2009-09-25 Thread DavidA

I'm getting this error when I try to remove an inline model instance
in the Django admin:

Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py"
in get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py"
in root
  490. return self.model_page(request, *url.split
('/', 2))
File "C:\Python25\lib\site-packages\django\views\decorators
\cache.py" in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py"
in model_page
  509. return admin_obj(request, rest_of_url)
File "C:\Python25\lib\site-packages\django\contrib\admin
\options.py" in __call__
  1098. return self.change_view(request, unquote(url))
File "C:\Python25\lib\site-packages\django\db\transaction.py" in
_commit_on_success
  240. res = func(*args, **kw)
File "C:\Python25\lib\site-packages\django\contrib\admin
\options.py" in change_view
  835. change_message =
self.construct_change_message(request, form, formsets)
File "C:\Python25\lib\site-packages\django\contrib\admin
\options.py" in construct_change_message
  535.  'object':
force_unicode(deleted_object)})
File "C:\Python25\Lib\site-packages\django\utils\encoding.py" in
force_unicode
  71. s = unicode(s)
File "C:\private\src\itweb\..\itweb\controls\models.py" in
__unicode__
  160. return self.document.url
File "C:\Python25\lib\site-packages\django\db\models\fields
\files.py" in _get_url
  68. self._require_file()
File "C:\Python25\lib\site-packages\django\db\models\fields
\files.py" in _require_file
  46. raise ValueError("The '%s' attribute has no file
associated with it." % self.field.name)

Exception Type: ValueError at /admin/controls/review/24/
Exception Value: The 'document' attribute has no file associated
with it.

I can see that the file is being deleted on disk, but then it looks
like this error is being thrown when the admin is trying to display a
summary message of what was done, and that triggers a _require_file()
call which raises an exception.

I have the following models:

class Review(models.Model):
name = models.CharField(max_length=80)
review_type = models.CharField(max_length=20,
choices=REVIEW_TYPE_CHOICES)
frequency = models.CharField(max_length=20,
choices=FREQUENCY_CHOICES,
 null=True, blank=True)
description = models.TextField(null=True, blank=True)

class Evidence(models.Model):
review = models.ForeignKey(Review)
review_time = models.DateTimeField(null=True, blank=True)
reviewed_by = models.ForeignKey(User, null=True, blank=True)
document = models.FileField(upload_to='evidence/%Y/%m/%d')

And admin classes:

class EvidenceInline(admin.TabularInline):
model = Evidence

class ReviewAdmin(admin.ModelAdmin):
list_display = ['name', 'review_type', 'frequency',
'description']
list_filter = ['review_type', 'frequency']
search_fields = ['name', 'description']
fieldsets = [
(None,  {'fields':['name', 'review_type',
'frequency']}),
('Details', {'fields':['description']}),
]
inlines = [EvidenceInline]

admin.site.register(Review, ReviewAdmin)

Am I doing something wrong?

Thanks,
-Dave

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



Re: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Bryan

I can't think of a reason, if nothing else its a matter or taste/
preference.  He said "I would probably...", so he may have been
implying that there was a technical reason but most likely he was just
stating his preference.

On Sep 25, 5:03 am, Chris Withers  wrote:
> Jani Tiainen wrote:
> > Chris Withers kirjoitti:
> >> Brian McKeever wrote:
> >>> .count is definitely the way to go. Although, I would probably pass it
> >>> to your template instead of determining it there.
> >> What difference does it make?
>
> > len(qs) evaluates queryset - thus pulling in _every_ object from DB to
> > Python - which you might not want specially if queryset is large.
>
> > .count() executes count query on DB side returing only single scalar
> > value to Python.
>
> > Figure out which one is faster...
>
> Er, I was asking what the difference was between calling .count in the
> view and in the template. I can't think why it would make a difference,
> but Brian suggested it did...
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             -http://www.simplistix.co.uk
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: same session on more than 1 website

2009-09-25 Thread Hinnack
please add to the documentation:every site has to have the same SECRET_KEY,
too when you want to get session vars from a different host, as
the cookie-data is encoded by this key.

-- Hinnack

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



Re: Multi table inheritance and reverse lookup

2009-09-25 Thread Bogdan I. Bursuc

Don't know if this is the solution for you, but you could take a look
here: http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1

and do something like this:

class Product(models.Model):
name = models.CharField(max_length=64)

class Meta:
abstract = True

class SubProduct1(Product):
prop1 = models.FloatField()

class SubProduct2(Product):
prop1 = models.EmailField()

class OrderProduct(models.Model):
order = models.ForeignKey(Order)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
product = generic.GenericForeignKey()

Good luck!


On Tue, 2009-09-22 at 18:56 +0300, Jani Tiainen wrote:
> model.py:
> 
> from django.db import models
> 
> class Order(models.Model):
>  name = models.CharField(max_length=64)
> 
>  def __unicode__(self):
>  return self.name
> 
> class Product(models.Model):
>  name  = models.CharField(max_length=64)
> 
>  def __unicode__(self):
>  return self.name
> 
> class SubProduct1(Product):
>  prop1 = models.FloatField()
> 
>  def __unicode__(self):
>  return self.name
> 
> class SubProduct2(Product):
>  prop2 = models.EmailField()
> 
>  def __unicode__(self):
>  return self.name
> 
> class OrderProduct(models.Model):
>  order = models.ForeignKey(Order)
>  product = models.ForeignKey(Product)
> 
>  amount = models.IntegerField()
> 
>  def __unicode__(self):
>  return u'%s - %s - %s' % (self.order.name, self.product.name, 
> self.amount)
> 
> 
> Now it's trivial play with sub products and add spesific subproducts to 
> orderproduct.
> 
> But, then, how to list all SubProducts that belongs to spesific order?
> 
> Specially thing stops at "Product", it doesn't know which one of those 
> two subproducts it actually is.
> 
> I did following quick hack to get around this problem (added this to 
> Product model):
> 
>  def _get_subproduct(self):
>  for attr in ['subproduct1', 'subproduct2', ]:
>  try:
>  return getattr(self, attr)
>  except ObjectDoesNotExist:
>  pass
> 
>  subproduct = property(_get_subproduct)
> 
> 
> This just don't feel optimal solution, specially it hits database for 
> every subitem tried.
> 
> Any better way to achieve same without hitting that much database?
> 


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



Re: The emergence of captcha after several incorrect logins

2009-09-25 Thread Sam Lai

Not much you can do apart from track IP addresses and enable recaptcha
for it for a certain period of time. The client can manipulate
everything else they send to you.

Sure you'll end up annoying some innocent people, but because you're
only enabling it for a limited period of time, it shouldn't annoy that
many innocent people.

2009/9/25 chegivara :
>
> Hi all,
>
> I use this code to show a recaptcha after several incorrect logins.
>
> The essence of the work is this:
> It creates the session to count the number of invalid logins and after
> 3 times wrong authentication emergence recaptcha. But you can simply
> delete the session and thus bypass a recaptcha.
> How to make display captcha could not get around?
>
> Thanks.
>
> Code:
> html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)
> def auth(request):
>    if request.method == 'POST':
>        if 'captcha_on' in request.session:
>            check_captcha = captcha.submit(request.POST
> ['recaptcha_challenge_field'],
>                                           request.POST
> ['recaptcha_response_field'],
>
> settings.RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR'])
>            if check_captcha.is_valid is False:
>                form = AuthForm()
>                return render_to_response('registration/login.html',
> {'form' : form, 'error_captcha' : 1, 'html_captcha' : html_captcha})
>        form = AuthForm(request.POST)
>        if form.is_valid():
>            username = form.cleaned_data['username']
>            password = form.cleaned_data['password']
>            user = authenticate(username=username, password=password)
>            if user is not None:
>                if user.is_active:
>                    login(request, user)
>                    # Redirect to a success page.
>                    return HttpResponseRedirect('/')
>                else:
>                    # Return a 'disabled account' error message
>                    return render_to_response('registration/
> login.html', {'form' : form, 'html_captcha' : html_captcha,
> 'error_login': 1})
>            else:
>                # Return an 'invalid login' error message.
>                if 'bad_login' in request.session:
>                    count_bad_login = request.session.get('bad_login')
>                    if count_bad_login == 3:
>                        request.session['captcha_on'] = True
>                        return render_to_response('registration/
> login.html', {'form' : form, 'html_captcha' : html_captcha,
> 'error_login': 1})
>                    request.session['bad_login'] = count_bad_login + 1
>                    print count_bad_login
>                    return render_to_response('registration/
> login.html', {'form' : form, 'error_login': 1})
>                request.session['bad_login'] = True
>                return render_to_response('registration/login.html',
> {'form' : form, 'error_login': 1})
>        return render_to_response('registration/login.html', {'form' :
> form, 'error_login': 1})
>    else:
>        form = AuthForm()
>    return render_to_response('registration/login.html', {'form':
> form})
>
> >
>

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



Re: Django point field

2009-09-25 Thread please smile
Thanks a lot Nabil servais. its works for me too

On Fri, Sep 25, 2009 at 2:06 PM, Nabil Servais wrote:

>
> Hello,
>
> I use json for output instead of cvs, and it works. Also I convert the
> lattitude and longitude into float.
>
> enjoy
>
> def get_lat_long(location):
> key = settings.GOOGLE_API_KEY
>  output = "json"
>  location = urllib.quote_plus(location)
> request =
> "http://maps.google.com/maps/geo?q=%s=%s=%s
> " % (location,
> output, key)
> data = urllib.urlopen(request).read()
>  dlist = simplejson.loads(data)
> if dlist['Status']['code'] == 200:
>  lat = float(dlist['Placemark'][0]['Point']['coordinates'][0])
>  long = float(dlist['Placemark'][0]['Point']['coordinates'][1])
> return (lat, long)
> else
> return ''
>
>
>
> Le 25/09/2009 09:47, please smile a écrit :
> > Hi all,
> > I have a problem to convert latitude and longitude values into
> > point field value.
> >
> >
> > def get_lat_long(location):
> > key = settings.GOOGLE_API_KEY
> > output = "csv"
> > location = urllib.quote_plus(location)
> > request =
> > "http://maps.google.com/maps/geo?q=%s=%s=%s
> > " % (location,
> > output, key)
> > data = urllib.urlopen(request).read()
> > dlist = data.split(',')
> > if dlist[0] == '200':
> > #return "%s, %s" % (dlist[2], dlist[3])
> > return (dlist[2], dlist[3])
> > else:
> > return ''
> >
> >
> > My models.py
> > --
> > class Person(models.Model):
> > address = models.CharField(_('address'), max_length=200,
> > blank=True)
> > city = models.CharField(_('city'), max_length=100, blank=True)
> > state = USStateField(_('state'), blank=True)
> > zipcode = models.CharField(_('zip code'), max_length=5,
> > blank=True)
> > point = models.PointField(blank=True, null=True)
> >
> > objects = models.GeoManager()
> >
> >
> >
> > def save(self, force_insert=False, force_update=False):
> >
> > if self.point == None:
> > location = "%s+%s+%s+%s" % (self.address, self.city,
> > self.state, self.zipcode)
> > point_lat, point_long = get_lat_long(location)
> > pnt = Point(point_long, point_lat)
> > self.point = pnt
> >
> > Here I convert latitude , longitude value into point field value. But
> > i am getting   "Exception Value: Invalid parameters given for Point
> > initialization."
> >
> > please advise...
> > Thank you
> >
> >  Trace back
> >  ---
> >  Environment:
> >
> > Request Method: POST
> > Request URL: http://192.168.1.57:8000/admin/people/person/add/
> > Django Version: 1.1
> > Python Version: 2.5.2
> > Installed Applications:
> > ['peoplesearch.people',
> >  'django.contrib.admin',
> >  'django.contrib.gis',
> >  'django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'django.contrib.databrowse',
> >  'peoplesearch.haystack']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
> >
> >
> > Traceback:
> > File "/root/myprojects/directory/django/core/handlers/base.py" in
> > get_response
> >   92. response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "/root/myprojects/directory/django/contrib/admin/options.py" in
> > wrapper
> >   226. return self.admin_site.admin_view(view)(*args,
> > **kwargs)
> > File "/root/myprojects/directory/django/views/decorators/cache.py" in
> > _wrapped_view_func
> >   44. response = view_func(request, *args, **kwargs)
> > File "/root/myprojects/directory/django/contrib/admin/sites.py" in inner
> >   186. return view(request, *args, **kwargs)
> > File "/root/myprojects/directory/django/db/transaction.py" in
> > _commit_on_success
> >   240. res = func(*args, **kw)
> > File "/root/myprojects/directory/django/contrib/admin/options.py" in
> > add_view
> >   734. self.save_model(request, new_object, form,
> > change=False)
> > File "/root/myprojects/directory/django/contrib/admin/options.py" in
> > save_model
> >   557. obj.save()
> > File "/root/myprojects/peoplesearch/../peoplesearch/people/models.py"
> > in save
> >   118. pnt = Point(point_long, point_lat)
> > File "/root/myprojects/directory/django/contrib/gis/geos/point.py" in
> > __init__
> >   32. raise TypeError('Invalid parameters given for Point
> > initialization.')
> >
> > Exception Type: TypeError at /admin/people/person/add/
> > Exception Value: Invalid parameters given for Point 

Re: Django point field

2009-09-25 Thread Nabil Servais

Hello,

I use json for output instead of cvs, and it works. Also I convert the 
lattitude and longitude into float.

enjoy

def get_lat_long(location):
 key = settings.GOOGLE_API_KEY
 output = "json"
 location = urllib.quote_plus(location)
 request = 
"http://maps.google.com/maps/geo?q=%s=%s=%s 
" % (location, 
output, key)
 data = urllib.urlopen(request).read()
 dlist = simplejson.loads(data)
 if dlist['Status']['code'] == 200:
 lat = float(dlist['Placemark'][0]['Point']['coordinates'][0])
 long = float(dlist['Placemark'][0]['Point']['coordinates'][1])
 return (lat, long)
 else
 return ''



Le 25/09/2009 09:47, please smile a écrit :
> Hi all,
> I have a problem to convert latitude and longitude values into 
> point field value.
>
>
> def get_lat_long(location):
> key = settings.GOOGLE_API_KEY
> output = "csv"
> location = urllib.quote_plus(location)
> request = 
> "http://maps.google.com/maps/geo?q=%s=%s=%s 
> " % (location, 
> output, key)
> data = urllib.urlopen(request).read()
> dlist = data.split(',')
> if dlist[0] == '200':
> #return "%s, %s" % (dlist[2], dlist[3])
> return (dlist[2], dlist[3])
> else:
> return ''
>
>
> My models.py
> --
> class Person(models.Model):
> address = models.CharField(_('address'), max_length=200, 
> blank=True)
> city = models.CharField(_('city'), max_length=100, blank=True)
> state = USStateField(_('state'), blank=True)
> zipcode = models.CharField(_('zip code'), max_length=5, 
> blank=True)
> point = models.PointField(blank=True, null=True)
>
> objects = models.GeoManager()
>
>
>
> def save(self, force_insert=False, force_update=False):
>
> if self.point == None:
> location = "%s+%s+%s+%s" % (self.address, self.city, 
> self.state, self.zipcode)
> point_lat, point_long = get_lat_long(location)
> pnt = Point(point_long, point_lat)
> self.point = pnt
>
> Here I convert latitude , longitude value into point field value. But 
> i am getting   "Exception Value: Invalid parameters given for Point 
> initialization."
>
> please advise...
> Thank you
>
>  Trace back
>  ---
>  Environment:
>
> Request Method: POST
> Request URL: http://192.168.1.57:8000/admin/people/person/add/
> Django Version: 1.1
> Python Version: 2.5.2
> Installed Applications:
> ['peoplesearch.people',
>  'django.contrib.admin',
>  'django.contrib.gis',
>  'django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.databrowse',
>  'peoplesearch.haystack']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "/root/myprojects/directory/django/core/handlers/base.py" in 
> get_response
>   92. response = callback(request, *callback_args, 
> **callback_kwargs)
> File "/root/myprojects/directory/django/contrib/admin/options.py" in 
> wrapper
>   226. return self.admin_site.admin_view(view)(*args, 
> **kwargs)
> File "/root/myprojects/directory/django/views/decorators/cache.py" in 
> _wrapped_view_func
>   44. response = view_func(request, *args, **kwargs)
> File "/root/myprojects/directory/django/contrib/admin/sites.py" in inner
>   186. return view(request, *args, **kwargs)
> File "/root/myprojects/directory/django/db/transaction.py" in 
> _commit_on_success
>   240. res = func(*args, **kw)
> File "/root/myprojects/directory/django/contrib/admin/options.py" in 
> add_view
>   734. self.save_model(request, new_object, form, 
> change=False)
> File "/root/myprojects/directory/django/contrib/admin/options.py" in 
> save_model
>   557. obj.save()
> File "/root/myprojects/peoplesearch/../peoplesearch/people/models.py" 
> in save
>   118. pnt = Point(point_long, point_lat)
> File "/root/myprojects/directory/django/contrib/gis/geos/point.py" in 
> __init__
>   32. raise TypeError('Invalid parameters given for Point 
> initialization.')
>
> Exception Type: TypeError at /admin/people/person/add/
> Exception Value: Invalid parameters given for Point initialization.
>
>
> >


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

The emergence of captcha after several incorrect logins

2009-09-25 Thread chegivara

Hi all,

I use this code to show a recaptcha after several incorrect logins.

The essence of the work is this:
It creates the session to count the number of invalid logins and after
3 times wrong authentication emergence recaptcha. But you can simply
delete the session and thus bypass a recaptcha.
How to make display captcha could not get around?

Thanks.

Code:
html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)
def auth(request):
if request.method == 'POST':
if 'captcha_on' in request.session:
check_captcha = captcha.submit(request.POST
['recaptcha_challenge_field'],
   request.POST
['recaptcha_response_field'],
 
settings.RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR'])
if check_captcha.is_valid is False:
form = AuthForm()
return render_to_response('registration/login.html',
{'form' : form, 'error_captcha' : 1, 'html_captcha' : html_captcha})
form = AuthForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# Redirect to a success page.
return HttpResponseRedirect('/')
else:
# Return a 'disabled account' error message
return render_to_response('registration/
login.html', {'form' : form, 'html_captcha' : html_captcha,
'error_login': 1})
else:
# Return an 'invalid login' error message.
if 'bad_login' in request.session:
count_bad_login = request.session.get('bad_login')
if count_bad_login == 3:
request.session['captcha_on'] = True
return render_to_response('registration/
login.html', {'form' : form, 'html_captcha' : html_captcha,
'error_login': 1})
request.session['bad_login'] = count_bad_login + 1
print count_bad_login
return render_to_response('registration/
login.html', {'form' : form, 'error_login': 1})
request.session['bad_login'] = True
return render_to_response('registration/login.html',
{'form' : form, 'error_login': 1})
return render_to_response('registration/login.html', {'form' :
form, 'error_login': 1})
else:
form = AuthForm()
return render_to_response('registration/login.html', {'form':
form})

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



Re: Django point field

2009-09-25 Thread Nabil Servais

Hello,

I solve your probleme in changing the output format into json, then I
convert the coordinates into Float.

def get_lat_long(location):
key = ''
output = "json"
location = urllib.quote_plus(location)
request = "http://maps.google.com/maps/geo?q=%s=%s; %
(location, output)
data = urllib.urlopen(request).read()
dlist = simplejson.loads(data)
lat = float(dlist['Placemark'][0]['Point']['coordinates'][0])
lon = float(dlist['Placemark'][0]['Point']['coordinates'][1])
if dlist['Staut']['code'] == 200:
return (lat,lon)
I've tested and it works. Good luck

On 25 sep, 09:47, please smile  wrote:
> Hi all,
>     I have a problem to convert latitude and longitude values into point
> field value.
>
>     def get_lat_long(location):
>         key = settings.GOOGLE_API_KEY
>         output = "csv"
>         location = urllib.quote_plus(location)
>         request = "http://maps.google.com/maps/geo?q=%s=%s=%s; %
> (location, output, key)
>         data = urllib.urlopen(request).read()
>         dlist = data.split(',')
>         if dlist[0] == '200':
>             #return "%s, %s" % (dlist[2], dlist[3])
>             return (dlist[2], dlist[3])
>         else:
>             return ''
>
>     My models.py
>     --
>     class Person(models.Model):
>         address = models.CharField(_('address'), max_length=200, blank=True)
>         city = models.CharField(_('city'), max_length=100, blank=True)
>         state = USStateField(_('state'), blank=True)
>         zipcode = models.CharField(_('zip code'), max_length=5, blank=True)
>         point = models.PointField(blank=True, null=True)
>
>         objects = models.GeoManager()
>
>         def save(self, force_insert=False, force_update=False):
>
>         if self.point == None:
>             location = "%s+%s+%s+%s" % (self.address, self.city, self.state,
> self.zipcode)
>             point_lat, point_long = get_lat_long(location)
>             pnt = Point(point_long, point_lat)
>             self.point = pnt
>
> Here I convert latitude , longitude value into point field value. But i am
> getting   "Exception Value: Invalid parameters given for Point
> initialization."
>
> please advise...
> Thank you
>
>  Trace back
>  ---
>  Environment:
>
> Request Method: POST
> Request URL:http://192.168.1.57:8000/admin/people/person/add/
> Django Version: 1.1
> Python Version: 2.5.2
> Installed Applications:
> ['peoplesearch.people',
>  'django.contrib.admin',
>  'django.contrib.gis',
>  'django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.databrowse',
>  'peoplesearch.haystack']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/root/myprojects/directory/django/core/handlers/base.py" in
> get_response
>   92.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/root/myprojects/directory/django/contrib/admin/options.py" in wrapper
>   226.                 return self.admin_site.admin_view(view)(*args,
> **kwargs)
> File "/root/myprojects/directory/django/views/decorators/cache.py" in
> _wrapped_view_func
>   44.         response = view_func(request, *args, **kwargs)
> File "/root/myprojects/directory/django/contrib/admin/sites.py" in inner
>   186.             return view(request, *args, **kwargs)
> File "/root/myprojects/directory/django/db/transaction.py" in
> _commit_on_success
>   240.                 res = func(*args, **kw)
> File "/root/myprojects/directory/django/contrib/admin/options.py" in
> add_view
>   734.                 self.save_model(request, new_object, form,
> change=False)
> File "/root/myprojects/directory/django/contrib/admin/options.py" in
> save_model
>   557.         obj.save()
> File "/root/myprojects/peoplesearch/../peoplesearch/people/models.py" in
> save
>   118.             pnt = Point(point_long, point_lat)
> File "/root/myprojects/directory/django/contrib/gis/geos/point.py" in
> __init__
>   32.             raise TypeError('Invalid parameters given for Point
> initialization.')
>
> Exception Type: TypeError at /admin/people/person/add/
> Exception Value: Invalid parameters given for Point initialization.

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



Re: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Chris Withers

Jani Tiainen wrote:
> Chris Withers kirjoitti:
>> Brian McKeever wrote:
>>> .count is definitely the way to go. Although, I would probably pass it
>>> to your template instead of determining it there.
>> What difference does it make?
> 
> len(qs) evaluates queryset - thus pulling in _every_ object from DB to 
> Python - which you might not want specially if queryset is large.
> 
> .count() executes count query on DB side returing only single scalar 
> value to Python.
> 
> Figure out which one is faster...

Er, I was asking what the difference was between calling .count in the 
view and in the template. I can't think why it would make a difference, 
but Brian suggested it did...

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

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



Re: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Daniel Roseman

On Sep 25, 9:08 am, Jani Tiainen  wrote:
> Chris Withers kirjoitti:
>
> > Brian McKeever wrote:
> >> .count is definitely the way to go. Although, I would probably pass it
> >> to your template instead of determining it there.
>
> > What difference does it make?
>
> len(qs) evaluates queryset - thus pulling in _every_ object from DB to
> Python - which you might not want specially if queryset is large.
>
> .count() executes count query on DB side returing only single scalar
> value to Python.
>
> Figure out which one is faster...
>
> --
> Jani Tiainen

Beware that it's not always as clear-cut as you might think. Django is
clever enough that if you've already evaluated the queryset, .count()
uses len() internally rather than going back to the database. But if
you need the count *before* evaluating the queryset, but will still
need to evaluate it later, using .count() initially will result in an
unnecessary database call. If you care about that level of
optimisation, it's worth bearing in mind.
--
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



assign dynamic value to form field in django admin

2009-09-25 Thread Joru

Hi

I need to assign one form field dynamically inside django admin when
user change value in select box

class One(models.Model):
name = models.CharField(max_length=200)
code =  models.CharField(max_length=100)

class Two(models.Model):
   two_name = models.CharField(max_length=200)
   oner = models.ForeignKey(One)
   oner_code = models.CharField(max_length=100)

Is it possible if suppose when user add "Two" record, then he change
value in "oner" dropdown and "oner_code" can dynamically change it
value according to what "oner" that being selected?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django 1.0 cannot handle ManyToOne inheritance in two apps

2009-09-25 Thread Daniel Roseman

On Sep 25, 3:30 am, luciferleo  wrote:
> Hi, I am using Django 1.0
> Suppose I have two models in one file:
>
> class BaseModel(models.Model):
>     # attrs
>     creator = models.ForeignKey('User', related_name='%(class)
> s_creator_set')
>
> class User(BaseModel):
>     # attrs
>
> That's perfectly OK.
>
> But if I split them into two apps, say,
> core/models.py: from accounts.models import User
>
> and accounts/models.py: from core.models import BaseModel
>
> Django will raise ImportError

You've got a circular reference which Python can't resolve. However
you don't need to import the User model from core, since you refer to
it as a string, rather than with the class itself, so remove that
import. You will also need to add the app name to the string:
creator = models.ForeignKey('accounts.User', related_name='%
(class)
--
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Urls.py: Match a leading Question Mark

2009-09-25 Thread Jarek Zgoda

Wiadomość napisana w dniu 2009-09-25, o godz. 10:16, przez mike:

>
> Hi. Im migrating from an old PHP piece of junk to Django (hooray) and
> this client is very insistent on maintaining all of his old PHP-based
> URLs, which will be 301 redirected so as to not lose SEO.  As there
> are 1000s of these links, mod_rewrite might not be the best solution,
> especially since we've got HttpResponsePermanentRedirect
>
> Old Link:
> www.somesite.com/app/?product=1234
>
> New Link:
> www.somesite.com/app/slugged-text
>
> Urls.py Line:
> (r'^app/\?product=(?P)$','site.app.views.xxx'),
>
> Now the problem is, Django wont match an escaped starting question
> mark (?) or am I missing something?  (it works fine if I were to
> exclude the ?, as in "product=1234" but is a pre-processed url via
> "re.sub" possible?)


GET parameters are not matched by patterns. I'd catch all these with  
single view and return redirects, like:

def my_view(request):
   product_id = request.GET['product']
   product = Product.objects.get(pk=product_id)
   return HttpResponseRedirect(product.get_absolute_url(),  
permanent=True)

And that's all.

-- 
Artificial intelligence stands no chance against natural stupidity

Jarek Zgoda, R, Redefine
jarek.zg...@redefine.pl


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



Urls.py: Match a leading Question Mark

2009-09-25 Thread mike

Hi. Im migrating from an old PHP piece of junk to Django (hooray) and
this client is very insistent on maintaining all of his old PHP-based
URLs, which will be 301 redirected so as to not lose SEO.  As there
are 1000s of these links, mod_rewrite might not be the best solution,
especially since we've got HttpResponsePermanentRedirect

Old Link:
www.somesite.com/app/?product=1234

New Link:
www.somesite.com/app/slugged-text

Urls.py Line:
(r'^app/\?product=(?P)$','site.app.views.xxx'),

Now the problem is, Django wont match an escaped starting question
mark (?) or am I missing something?  (it works fine if I were to
exclude the ?, as in "product=1234" but is a pre-processed url via
"re.sub" possible?)

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



Re: is this a sane way to show total number of objects in pagination?

2009-09-25 Thread Jani Tiainen

Chris Withers kirjoitti:
> Brian McKeever wrote:
>> .count is definitely the way to go. Although, I would probably pass it
>> to your template instead of determining it there.
> 
> What difference does it make?

len(qs) evaluates queryset - thus pulling in _every_ object from DB to 
Python - which you might not want specially if queryset is large.

.count() executes count query on DB side returing only single scalar 
value to Python.

Figure out which one is faster...

-- 
Jani Tiainen

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



Re: Firefox search plugin for Django documents

2009-09-25 Thread taijirobot

I feel happy that it can you:)

On Sep 25, 2:47 am, dimitri pater - serpia 
wrote:
> 2009/9/24 玉东 :
>
>
>
> > Hi, guys,
>
> > I've made afirefoxsearch plugin for django documents. It can save your
> > time if you often search the official django documents because you don't
> > have to visit the djangoproject.com first. Just type in the search box,
> > press enter and you'll see the page of the results.
>
> > It is useful to me because I often need to search the documents and that's
> > the reason why I made it. And I think it might be useful to you if you have
> > the same demand, too.
>
> > You can check it here:
> >https://addons.mozilla.org/en-US/firefox/addon/14474
>
> > It is experimental right now but it can work perfectly under common windows
> > and linux distributions. If you meet problems, please tell me.
>
> > Thank you.
> > --
> > 来自 广玉东
> > from Guang Yudong / Dennis
> > BUAA
> > guangyudongb...@gmail.com
> > cellphone: (+86)138-1174-5701
>
> Thank you very much, nice work!
>
>
>
> --
> ---
> You can't have everything. Where would you put it? -- Steven Wright
> ---
> please visitwww.serpia.org
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django point field

2009-09-25 Thread please smile
Hi all,
I have a problem to convert latitude and longitude values into point
field value.


def get_lat_long(location):
key = settings.GOOGLE_API_KEY
output = "csv"
location = urllib.quote_plus(location)
request = "http://maps.google.com/maps/geo?q=%s=%s=%s; %
(location, output, key)
data = urllib.urlopen(request).read()
dlist = data.split(',')
if dlist[0] == '200':
#return "%s, %s" % (dlist[2], dlist[3])
return (dlist[2], dlist[3])
else:
return ''


My models.py
--
class Person(models.Model):
address = models.CharField(_('address'), max_length=200, blank=True)
city = models.CharField(_('city'), max_length=100, blank=True)
state = USStateField(_('state'), blank=True)
zipcode = models.CharField(_('zip code'), max_length=5, blank=True)
point = models.PointField(blank=True, null=True)

objects = models.GeoManager()



def save(self, force_insert=False, force_update=False):

if self.point == None:
location = "%s+%s+%s+%s" % (self.address, self.city, self.state,
self.zipcode)
point_lat, point_long = get_lat_long(location)
pnt = Point(point_long, point_lat)
self.point = pnt

Here I convert latitude , longitude value into point field value. But i am
getting   "Exception Value: Invalid parameters given for Point
initialization."

please advise...
Thank you

 Trace back
 ---
 Environment:

Request Method: POST
Request URL: http://192.168.1.57:8000/admin/people/person/add/
Django Version: 1.1
Python Version: 2.5.2
Installed Applications:
['peoplesearch.people',
 'django.contrib.admin',
 'django.contrib.gis',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.databrowse',
 'peoplesearch.haystack']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/root/myprojects/directory/django/core/handlers/base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/root/myprojects/directory/django/contrib/admin/options.py" in wrapper
  226. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "/root/myprojects/directory/django/views/decorators/cache.py" in
_wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/root/myprojects/directory/django/contrib/admin/sites.py" in inner
  186. return view(request, *args, **kwargs)
File "/root/myprojects/directory/django/db/transaction.py" in
_commit_on_success
  240. res = func(*args, **kw)
File "/root/myprojects/directory/django/contrib/admin/options.py" in
add_view
  734. self.save_model(request, new_object, form,
change=False)
File "/root/myprojects/directory/django/contrib/admin/options.py" in
save_model
  557. obj.save()
File "/root/myprojects/peoplesearch/../peoplesearch/people/models.py" in
save
  118. pnt = Point(point_long, point_lat)
File "/root/myprojects/directory/django/contrib/gis/geos/point.py" in
__init__
  32. raise TypeError('Invalid parameters given for Point
initialization.')

Exception Type: TypeError at /admin/people/person/add/
Exception Value: Invalid parameters given for Point initialization.

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



Simple database replication app for Django

2009-09-25 Thread Roberto Rosario

I needed a simple way to append new records from many Oracle dbs to
one Mysql db, and came up with this solution.   As part of the mantra
"Release Early, Release Often" I'm putting it into a separate app,
making it more generic and releasing it on google code.

Code is at:  http://code.google.com/p/django-replication

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



same session on more than 1 website

2009-09-25 Thread hinnack

hi,

I do have only set SESSION_COOKIE_DOMAIN = '.dev.miadi.net' in both
sites
and now I am expecting to be able to set a value under
host1.dev.miadi.net and to read it under host2.dev.miadi.net - but
this does not work.

the browser does send the cookie he got from host1 to host2, but the
site sets a new one. Because of this
the site can not find the value.

I am sitting on TRUNK.
session-data is store in DB.

reading and setting session vars inside each site works well

what am I doing wrong?

-- Hinnack

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