Re: Callable hooks for generic views after validation with no errors?

2006-10-04 Thread wam


James Bennett wrote:
> This is probably the way to do it; adding special-case hooks to the
> generic views doesn't sound like a good solution to me.

Well, callables  which can be sent into generic views and are executed
just prior to handing off to the template in order to populate
additional context to the form. I'm trying to get (near) equivalent
functionality to occur just prior to the database save. I certainly
wouldn't call it an elegant solution, but  the status quo doesn't seem
to provide this functionality which is even less elegant. I'd ideally
like to see the generic views for creation and modification of an
object  be powerful enough to be used for the admin interface, but
without some way of attaching functionality into the view prior to key
events like object saves, I think generic views just don't have the
power at this point.

Another use case for this kind of functionality might be to perform
auto slugification for fields, so that end users wouldn't have to
create their own slugs.

> For getting access to the object, I believe that when the 'post_save'
> dispatcher signal is sent after saving, one of the included attributes
> of the signal is the object itself.

Yes, but you'd still have to associate that with with the request
object that was passed to the generic view so that the user id of the
creator/modifier of the object can be associated with the log record.
It also wouldn't seem to give an indication of what the object's state
was before being modified.

I guess I see the fact that  a callable can be sent into a generic view
to be run as part of the extra_context parameter as a usefull pre_ hook
for a generic view when the view is called as a 'GET' and I'm wishing
similar functionality existed when the view is called as a POST.

  -- William


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Re: Callable hooks for generic views after validation with no errors?

2006-10-04 Thread James Bennett

On 10/4/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> There is some documentation on how Django's signals system works and how
> to hook into it here: http://code.djangoproject.com/wiki/Signals

I just went through and completely re-wrote that to cover signals in
as much detail as I could muster. I *think* I've got them all
documented in there now, but if anybody sees a signal I missed, please
add it to the list on that page.

I hope Tyson won't mind that I pretty much left nothing of his
original write-up...

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: how could i weakly protect comments

2006-10-04 Thread coulix

nice !
thanks everyone

On Oct 5, 1:22 pm, "Waylan Limberg" <[EMAIL PROTECTED]> wrote:
> On 10/4/06, coulix <[EMAIL PROTECTED]> wrote:
>
> > Hello, i am using free comments in my app and starting to getting spam
> > :)
> > I dont want to use captcha yet and instead, use some content string
> > scanning method.
> > (sex, viagra, $$$ and other crap will not post the message).
> > What is the best way to this ?
> > exends comments view.py ?
> > Thanks :)This [1] should get you going on that. It actually uses a stronger
> method, but the basics should be similar. Just use your own code
> rather than the Akismet code in the example.
>
> [1]:http://www.b-list.org/weblog/2006/07/16/django-tips-hacking-freecomment
> 
> --
> 
> Waylan Limberg
> [EMAIL PROTECTED]


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: how could i weakly protect comments

2006-10-04 Thread Waylan Limberg

On 10/4/06, coulix <[EMAIL PROTECTED]> wrote:
>
> Hello, i am using free comments in my app and starting to getting spam
> :)
> I dont want to use captcha yet and instead, use some content string
> scanning method.
> (sex, viagra, $$$ and other crap will not post the message).
> What is the best way to this ?
> exends comments view.py ?
> Thanks :)
>
This [1] should get you going on that. It actually uses a stronger
method, but the basics should be similar. Just use your own code
rather than the Akismet code in the example.

[1]: http://www.b-list.org/weblog/2006/07/16/django-tips-hacking-freecomment


-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: how could i weakly protect comments

2006-10-04 Thread Malcolm Tredinnick

On Thu, 2006-10-05 at 03:05 +, coulix wrote:
> Hello, i am using free comments in my app and starting to getting spam
> :)
> I dont want to use captcha yet and instead, use some content string
> scanning method.
> (sex, viagra, $$$ and other crap will not post the message).
> What is the best way to this ?
> exends comments view.py ?

You can do this without needing to touch the Django source, but the
effect is the same. Put an explicit entry in your URL configuration to
handle the post URL for comments. Then check the content for whatever
you like and, if it's fine, just pass off handling to
contrib.comments.views.comments.post_free_comment (which is what would
normally handle this).

If you do catch content you don't like in your initial view, then you
might have to replicate some of the logic in post_free_comment (or not).

I hooked up something like this for a client recently who wanted to have
the possibility of both registered and unregistered comments (and
unregistered users saw a captcha challenge). Overriding the URL and
putting in a preliminary view worked fairly smoothly in the end.

Regards,
Malcolm



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



how could i weakly protect comments

2006-10-04 Thread coulix

Hello, i am using free comments in my app and starting to getting spam
:)
I dont want to use captcha yet and instead, use some content string
scanning method.
(sex, viagra, $$$ and other crap will not post the message).
What is the best way to this ?
exends comments view.py ?
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



ForeignKey field with null = True and blank = True

2006-10-04 Thread Seemant Kulleen
Hi All,

Now I'm at ForeignKey funkiness.  So I have the Services model which
has a ForeignKey field to the Sermon model.  The funny thing is that
if I choose a sermon object when I first create a new service object,
all is well.  If, on the other hand, I don't choose one, then it turns
out that I can never choose one.  That is to say, I can choose one,
and hit save and when I come back in it's unchosen.  Happens every
single time.  I've attached the services/models.py and
sermons/models.py if that helps.

Thanks!

Seemant


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---
from django.db import models
from django.contrib.auth.models import User
from people.models import Person, Role
from sermons.models import Sermon
import constants

class Service( models.Model ):
	day  = models.CharField  (maxlength = 200)
	date = models.DateField ('date')
	time = models.TimeField ('time')
	slug = models.SlugField (prepopulate_from = ('time',), blank = True)

	priest = models.ForeignKey (
			Person,
			related_name = 'priest',
			limit_choices_to = { 'role__name': 'Priest' },
	)

	celebrant = models.ForeignKey (
			Person,
			related_name = 'celebrant',
			limit_choices_to = { 'role__name': 'Priest' },
	)

	sermon = models.ForeignKey (
			Sermon,
			null = True,
			blank = True,
	)

	crucifer = models.ManyToManyField (
			Person,
			related_name = 'crucifer',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Acolyte' },
	)

	left_torch = models.ManyToManyField (
			Person,
			related_name = 'left_torch',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Acolyte' },
	)
	right_torch = models.ManyToManyField (
			Person,
			related_name = 'right_torch',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Acolyte' },
	)
	banner_bearer = models.ManyToManyField (
			Person,
			related_name = 'banner_bearer',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Acolyte' },
	)

	LEM = models.ManyToManyField (
			Person,
			related_name = 'LEM',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'LEM' },
	)

	lector = models.ManyToManyField (
			Person,
			related_name = 'lector',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Lector' },
	)

	usher = models.ManyToManyField (
			Person,
			related_name = 'usher',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Usher' },
	)

	greeter = models.ManyToManyField (
			Person,
			related_name = 'greeter',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Greeter' },
	)

	childrens_chapel = models.ManyToManyField (
			Person,
			related_name = 'childrens_chapel',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Childrens Chapel' },
			blank = True, null = True,
	)

	altar_flowers = models.ManyToManyField (
			Person,
			related_name = 'altar_flowers',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Flower Guild' },
	)

	flower_delivery = models.ManyToManyField (
			Person,
			related_name = 'flower_delivery',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Flower Deliverer' },
	)

	altar_guild = models.ManyToManyField (
			Person,
			related_name = 'altar_guild',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Altar Guild' },
	)

	food_delivery = models.ManyToManyField (
			Person,
			related_name = 'food_delivery',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Food Deliverer' },
			blank = True, null = True,
	)

	summer_punch = models.ManyToManyField (
			Person,
			related_name = 'summer_punch',
			filter_interface = models.HORIZONTAL,
			limit_choices_to = { 'role__name': 'Punch Server' },
			blank = True, null = True,
	)

	def __str__( self ):
		return self.date.__str__() + self.time.__str__()

	def save( self ):
		if self.slug == '':
			self.slug = '%s%s' % (self.time.hour, self.time.minute)
			super(Service, self).save()
	
	def get_absolute_url( self ):
		return "/services/%s/%s/" % (self.date.strftime("%Y/%b/%d").lower(), self.slug)


	class Meta:
		get_latest_by = 'date'
		ordering = ['-date']

	class Admin:
		list_display = ('date', 'time', 'priest',)
		search_fields = ('priest', 'celebrant')
		list_filter = ('date',)

		fields = (
('Date Information', {'fields': ('day', 'date', 'time', 'slug')}),
('Officials', {'fields': ('priest', 'celebrant',)}),
('Sermon', {'fields': ('sermon',)}),
('Acolytes', {'fields': 

Re: TypeError: argument 1 must be string without null bytes, not str, repr() unavailable

2006-10-04 Thread Ned Batchelder




I haven't managed to reproduce it.  I was hoping maybe others had seen
it on their servers and knew it's cause.

--Ned.

Malcolm Tredinnick wrote:

  On Wed, 2006-10-04 at 16:27 -0400, Ned Batchelder wrote:
  
  
Every once in a while, we get a stack trace from our production Django
servers with this error:

  ...
  File "/apps/mine/views/mine.py", line 481, in my_view
params = request.REQUEST

  File "/site-packages/django/core/handlers/modpython.py", line 38, in _get_request
self._request = datastructures.MergeDict(self.POST, self.GET)

  File "/site-packages/django/core/handlers/modpython.py", line 51, in _get_post
self._load_post_and_files()

  File "/site-packages/django/core/handlers/modpython.py", line 34, in _load_post_and_files
self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict()

  File "/site-packages/django/http/__init__.py", line 82, in __init__
for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True

TypeError: argument 1 must be string without null bytes, not str


Request repr() unavailable

Does anyone know what causes this, and what to do about it?

  
  
I haven't seen it with Django, but I have seen this sort of error on
other projects when trying to log arbitrary information and the string
ended up containing zero bytes (because of a bad third-party producer of
the data).

Can you trigger the error with a hand-crafted URL that contains "%00"
fragments, perhaps?

Sorry, not too helpful, but it's going to be hard to guess what is
causing this without being in your position and able to know what is
happening at the time.

Regards,
Malcolm





.

  


-- 
Ned Batchelder, http://nedbatchelder.com


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





Re: Relevance

2006-10-04 Thread Andy Dustman

On 10/4/06, Beau Hartshorne <[EMAIL PROTECTED]> wrote:
>
> On 4-Oct-06, at 6:12 PM, Andy Dustman wrote:
>
> > I'm not sure this will fix your problem, but it might from my reading
> > of the code. Try reversing the order of the filter() and extra()
> > methods, i.e.
> >
> > qs = Place.objects.all().extra(select={'relevance': match_expr},
> > params=[query]).filter(name__search=query)
>
> That doesn't seem to fix it for me. The problem seems to be that the
> code strips all of the column names when it does the SELECT COUNT(*),
> but doesn't strip the parameters from the list it passes to execute
> (). It breaks even without any other filters.
>
> A simpler example might be something like:
>
>  >>> qs = Place.objects.all().extra(select={'hello': '%s'}, params=
> ['world',])
>  >>> qs.count()
> Traceback (most recent call last):
>File "", line 1, in ?
>File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/
> query.py", line 202, in count
>  cursor.execute("SELECT COUNT(*)" + sql, params)
>File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/
> util.py", line 19, in execute
>  self.db.queries.append({
> TypeError: not all arguments converted during string formatting

Oh, *that's* interesting. It's not really execution of the query
that's causing the problem but the debug code that retains all
executed queries. Although the execution could be raising the same
exception: The part we are seeing above is in a finally clause. You
may have to examine your local variables in that last frame to see
what the values of sql and params are, and that may make the problem
more obvious. Use the little triangle on the left to open it up;
apparently it's not completely obvious to everyone that they do
something.

-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: TypeError: argument 1 must be string without null bytes, not str, repr() unavailable

2006-10-04 Thread Malcolm Tredinnick

On Wed, 2006-10-04 at 16:27 -0400, Ned Batchelder wrote:
> Every once in a while, we get a stack trace from our production Django
> servers with this error:
> 
>   ...
>   File "/apps/mine/views/mine.py", line 481, in my_view
> params = request.REQUEST
> 
>   File "/site-packages/django/core/handlers/modpython.py", line 38, in 
> _get_request
> self._request = datastructures.MergeDict(self.POST, self.GET)
> 
>   File "/site-packages/django/core/handlers/modpython.py", line 51, in 
> _get_post
> self._load_post_and_files()
> 
>   File "/site-packages/django/core/handlers/modpython.py", line 34, in 
> _load_post_and_files
> self._post, self._files = http.QueryDict(self.raw_post_data), 
> datastructures.MultiValueDict()
> 
>   File "/site-packages/django/http/__init__.py", line 82, in __init__
> for key, value in parse_qsl((query_string or ''), True): # 
> keep_blank_values=True
> 
> TypeError: argument 1 must be string without null bytes, not str
> 
> 
> Request repr() unavailable
> 
> Does anyone know what causes this, and what to do about it?

I haven't seen it with Django, but I have seen this sort of error on
other projects when trying to log arbitrary information and the string
ended up containing zero bytes (because of a bad third-party producer of
the data).

Can you trigger the error with a hand-crafted URL that contains "%00"
fragments, perhaps?

Sorry, not too helpful, but it's going to be hard to guess what is
causing this without being in your position and able to know what is
happening at the time.

Regards,
Malcolm


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



Re: Passing a processed model field in a View to a Template

2006-10-04 Thread Malcolm Tredinnick

Hi Julian,

On Wed, 2006-10-04 at 01:54 -0700, [EMAIL PROTECTED] wrote:
> Hi,
> 
> I recently started using Django.  I'm still getting a bit confused with
> the interaction between the Views and the Template.  I understand or
> figure that pretty much all the data processing should be handled
> within the View.
> 
> I'm using render_to_response sort of like this:
> 
> from django.shortcuts import get_object_or_404, render_to_response
> from my_site.property.models import Data
> 
> def index(request):
> object_list = Data.objects.filter(job =
> "Accountant").order_by('-salary')[:5]
> return render_to_response('employees/employees_index.html',
> {'object_list': object_list})
> 
> 
> How would you process the Salary field of the Data model such that it
> returns the value so that it's processed and is comma separated.  So
> '8' for Salary would become '80,000'?

Since this is a presentation issue, rather than a data collection issue,
it is something you would probably do directly in the template.

There are a set of filters you can use in your template to do things
like this. They are in the "humanize" template tag package:
http://www.djangoproject.com/documentation/add_ons/#humanize

In you case, the intcomma filter does what you want, so
{{ object.Salary|intcomma }} or something similar.

Regards,
Malcolm



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



Re: Relevance

2006-10-04 Thread Beau Hartshorne

On 4-Oct-06, at 6:12 PM, Andy Dustman wrote:

> I'm not sure this will fix your problem, but it might from my reading
> of the code. Try reversing the order of the filter() and extra()
> methods, i.e.
>
> qs = Place.objects.all().extra(select={'relevance': match_expr},
> params=[query]).filter(name__search=query)

That doesn't seem to fix it for me. The problem seems to be that the  
code strips all of the column names when it does the SELECT COUNT(*),  
but doesn't strip the parameters from the list it passes to execute 
(). It breaks even without any other filters.

A simpler example might be something like:

 >>> qs = Place.objects.all().extra(select={'hello': '%s'}, params= 
['world',])
 >>> qs.count()
Traceback (most recent call last):
   File "", line 1, in ?
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/ 
query.py", line 202, in count
 cursor.execute("SELECT COUNT(*)" + sql, params)
   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ 
python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/ 
util.py", line 19, in execute
 self.db.queries.append({
TypeError: not all arguments converted during string formatting

Thanks!
Beau

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Support for static content?

2006-10-04 Thread Andy Dustman

On 10/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> Django's database-centric approach seems to make certain kinds of
> mostly-static sites harder to build.  For example, most of what I want
> to put on my site is probably going to come from RestructuredText
> source, but that source isn't going to change in response to user
> interaction.  Yes, I could set up a ReST_page model and store the text
> in the database, but that has some real disadvantages as compared with
> keeping the content in my SVN repository along with the rest of the
> code, css, images, and other elements that are not going to be changed
> by user interaction: it gets harder to keep track of what I've done to
> the site, test changes on a beta site before they go live, etc.  I
> need a clean separation between the data that is changed by
> interacting with apps and data that isn't.
>
> Yes, Django is a framework, so I could build components that make this
> possible, but it seems to me that it should be a fundamental, built-in
> part of the system.  Has anyone already addressed these issues?

I've done a site using Apache 2.0 plus mod_python and mod_rewrite such
that most of the site (particularly the root) goes into Plone (via
mod_rewrite with proxying) but selected top-level directories are
either short-circuited out into local files or else directed into
other things like Trac or Django, i.e.


SetHandler python-program
PythonPath "['/usr/local/lib/django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE MYAPP.settings


You may only need the above section, but I have some rewrite rules after this:

RewriteRule ^/(foo|bar|baz)/ - [L]
RewriteRule ^/(.*)
http://localhost:8001/VirtualHostBase/http/sitename:80/VirtualHostRoot/$1
[P,L]

The first rule prevents any further rewriting on directories that
should be handled by Django via mod_python. The second rule proxies
everything else to a local Zope server.

You can either take the approach that only a few directories get sent
to Django and the rest are local static files, or else say that just a
few are static files and everything else is handled by Django,
depending on your site layout.

-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Relevance

2006-10-04 Thread Andy Dustman

On 9/15/06, mrstone <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> I'm fiddling around with MySQL fulltext search and run into a problem.
>
> Using the below code works:
>
> match_expr = "MATCH(name) AGAINST (%s IN BOOLEAN MODE)"
> qs =
> Place.objects.all().filter(name__search=query).extra(select={'relevance':
> match_expr}, params=[query])
>
>
> But when calling qs.count() I get:
> TypeError at /
> not all arguments converted during string formatting
>
> Is this a bug or am I using the extra in a wrong way?

I'm not sure this will fix your problem, but it might from my reading
of the code. Try reversing the order of the filter() and extra()
methods, i.e.

qs = Place.objects.all().extra(select={'relevance': match_expr},
params=[query]).filter(name__search=query)

-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Support for static content?

2006-10-04 Thread John M

Curious, does that give you the full user context too?  I noticed with
render_to_response() does not 'easily' use the user context.

J

On Oct 4, 1:35 pm, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I
> > need a clean separation between the data that is changed by
> > interacting with apps and data that isn't.You can store your data in the 
> > form of templates and use
> 'direct_to_template' to bind it to certain 
> urls:http://www.djangoproject.com/documentation/generic_views/#django-view...
> 
> Will this work for you?


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



Re: Support for db declaration of "on cascade delete"?

2006-10-04 Thread Russell Keith-Magee

On 10/5/06, Greg Plesur <[EMAIL PROTECTED]> wrote:
>
> Waylan Limberg wrote:
> >> Do any of you know if there's a way to tell Django to specify "on
> > cascade delete" for foreign key references, when it creates DB tables?

Django doesn't use ON DELETE CASCADE in its table definitions, due to
some database backends not fully supporting the operation. To
compensate, when you delete an object through the Django ORM, it
calculates the dependent objects, and deletes them as well.

However, if you _really_ want to have ON DELETE CASCADE in your model,
your best bet is to use the custom SQL handlers. If you create an
'sql' directory in your models directory, and put a file called
'mymodel.sql' in that directory (where mymodel is the name of your
model), the contents of that file will be executed on the database
when syncdb installs the model.

If you put some ALTER statements in the file, you can add the cascade
directive, or any other table modifications/triggers you want to the
table after it has been created.

> > I don't believe you can. However, you can use sql or sqlall [1] to
> > output the table creation sql to a file for editing.  For example:
> >
> > manage.py sqlall myapp > myapp.sql
>
> I was looking at this, but:  Does anyone know why "manage.py sqlall"
> rearranges the order of the table-creates from what's in the models?
>
> I can't find the reason for the new ordering; it looks kind of random,
> and it causes the table-creates to fail because of foreign key constraints.

It isn't random - it's hashtable order. There's no particular reason
for it, other than the fact that we need to have a dictionary to store
the models.

However, you shouldn't be having any problems with foreign key
constraints. The model creation process should be able to identify and
avoid any problems with forward declared foreign key constraints.

That said, I am aware (and am working on fixing) a slight problem with
install/sqlall dealing with multiple applications; specificially if
you try to run:

manage.py sqlall app1 app2
or
manage.py install app1 app2

and app1 has a dependency on app2, sqlall reports problems with model
creation. manage.py syncdb doesn't have this problem.

Is this the problem you are experiencing? If not, can you provide more
details (backend, models etc)

Yours,
Russ Magee %-)

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



Re: Callable hooks for generic views after validation with no errors?

2006-10-04 Thread James Bennett

On 10/4/06, wam <[EMAIL PROTECTED]> wrote:
> The closest I've been able to figure out is to create a custom view and
> call create_object from my view. Then, depending on whether the
> returned object from create_object is an instance of
> HttpResponseRedirect() I can determine if the addition/edit was
> successful; however, I still don't have access to the new/editted
> object.

This is probably the way to do it; adding special-case hooks to the
generic views doesn't sound like a good solution to me.

For getting access to the object, I believe that when the 'post_save'
dispatcher signal is sent after saving, one of the included attributes
of the signal is the object itself.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Re: Ajax Jquery

2006-10-04 Thread James Bennett

On 9/29/06, patrickk <[EMAIL PROTECTED]> wrote:
> however, I´ve been a little bit disappointed at first that django
> doesn´t come with a js-library and that the django-developers refused
> to agree on a js-framework.

It isn't that there's a "refusal to agree", it's that there's a
recognition that the server-side app framework:

1. Shouldn't be trying to force a choice of client-side coding tools on you.
2. Shouldn't be trying to write client-side code (in the form of
"javascript helpers") for you.
3. Probably can't ever make a choice for JavaScript toolkit that will
satisfy enough end users. If we go with Dojo, Prototype fans will be
angry. If we go with Prototype, YUI fans will be angry. If we go with
YUI, JQuery fans will be angry.

This is a case where the only way to "win" is not to play the game at
all, which means not bundling or "integrating" a JS toolkit.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: [win2k] Can't get install to work

2006-10-04 Thread Eugene Lazutkin

Snirp wrote:
> 
> Is there no friendly windows binary around? Is there a way to get this
> to work?

Write to me and I'll mail you back a Windows installer --- by some 
reasons it's not a part of Django download page yet.

Thanks,

Eugene


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Relevance

2006-10-04 Thread mrstone

Hi Beau

No, I'm afraid not.

I did not have time to look into it further so it's still an open thing
for me.


Regards
Sten


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Re: Ajax Jquery

2006-10-04 Thread Brandon Aaron

On 9/29/06, patrickk <[EMAIL PROTECTED]> wrote:
> well, this is not really a question.
> however, I´ve been a little bit disappointed at first that django
> doesn´t come with a js-library and that the django-developers refused
> to agree on a js-framework.
> in the meantime, I totally understand that decision and I´m very
> happy with it. we are currently using jquery and we´ve been using
> dojo before. so, we switched the js-library - and it was very easy
> because it has nothing to do with django.
>
> patrick.

I think it is best to keep the JavaScript library out of the core. I
would rather not be stuck using dojo, prototype or even stuck using
jQuery. However, if a choice has to be made, my vote is for jQuery. :)

--
Brandon Aaron

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Callable hooks for generic views after validation with no errors?

2006-10-04 Thread wam

I make extensive use of generic views in one of my apps. Now that the
app is nearly finished, I'm being asked to do change tracking/audit
trail on the objects managed in the generic views. Recognizing that I
could just create and save django.contrib.admin.models.LogEntry()
objects and possibly create a view or two to view only the audit
records associated with my application. The trouble comes in from not
having a particularly good insertion point to create the LogEntry()
objects while using a generic view.

The closest I've been able to figure out is to create a custom view and
call create_object from my view. Then, depending on whether the
returned object from create_object is an instance of
HttpResponseRedirect() I can determine if the addition/edit was
successful; however, I still don't have access to the new/editted
object.

I did consider creating a custom view that would be called via access
to a URL accessed as result of a post_save_redirect parameter on the
generic view; however, I'm uncomfortable depending upon a redirect to
create audit records. For one, it'd be easy for a browser to disregard
the redirect in order to avoid log creation. Additionally, it would be
easy to "forge" audit records by direct access to the URL attached to
the audit records creation view.

Would it be possible to add a generic view parameter along the lines of
'post_save_hook' which is expected to be callable object which is
passed the newly created object (in the case of create_object()) and
ideally a copy of the original (non-updated) object along with the
updated object in the case of update_object. These hooks would only be
called in case of a successful model validation and database save.

If there is agreement that the post_save_hook would provide value and
is the proper way to accomplish what I would assume is a fairly common
need (do something with the newly updated/created object from a generic
view), then I'll go ahead and submit it as a bug feature and may even
be able to submit a patch along with the request.

  -- William


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: How about a Django apps public repository?

2006-10-04 Thread Jeff Forcier

Howdy folks,

This issue came up yet again on the IRC channel today, and myself,
jesusphreak and a couple of others did yet more brainstorming, partly
recycling earlier topics and partly moving things forward even more.
It started about here:

   http://simon.bofh.ms/logger/django/2006/10/04/15/30/

and then the "meat" of the discussion--skipping me being dense about
Amazon S3, and some rehashing of earlier arguments--here:

   http://simon.bofh.ms/logger/django/2006/10/04/16/09/

Please take the few minutes to read through that discussion, as I
doubt I'll remember to touch on everything in this email.


Before getting into specifics, I have two requests:

Sean, if you're still listening, can you please contact me to
negotiate transfer of the domain names? Even if I'm not the eventual
recipient of the registration, I'd be glad to at least take them off
your hands for the time being.

Ian, if/when you get time to read this stuff over and examine your own
code, I'd just like to know what it looks like so I know how much we'd
be duplicating work already done. No pressure, though! :) I tend to
like writing my own stuff anyways (then again I think we're all like
that to some degree).


The basic gist is as follows:

* Set up a combination Trac farm / web-app directory system.
* Each app/project is stored in a Trac instance, complete with all the
Trac goodness that is a SVN repository, wiki, tickets, and etc.
* Each app *also* has an entry in a front-end directory, which
contains:
   * metadata about the app - author[s], categor(y|ies)/tags, etc
   * a direct package download - ideally, one automatically generated
from a tagged release in the SVN repository
   * a link to the "backend" Trac instance for the project
   * a comments section for those who just want to leave a note about
the app without really contributing full-fledged documentation to the
Trac wiki
* The directory front-end app will necessarily aggregate the info for
all the apps, providing various views to the data (e.g. "list all
blog-related apps, and snippets", "show recently added apps", etc).

Such a setup would provide the following benefits:

* Ease of use/accessibility:
   * For users, the ability for one-stop shopping for pluggable apps,
via the package download. The fact that apps are stored in SVN doesn't
matter - they will still be able to grab the latest version of the
app, with access to older versions if desired (similar to Sourceforge)
as a ZIP or TGZ or egg or whatever.
   * For developers who want to just donate a singular version of an
app and never touch it again, and/or who are not SVN-literate,
curators (or an automated system, theoretically) can take an archive
file and create a new project out of it, with no further action on the
part of the original dev.
   * For developers who are SVN-literate, it will be the same as any
other SVN or CVS like setup--they will get the keys to their
particular Trac kingdom and can go to town.
* Flexibility in storage: some folks don't like the idea of having to
use SVN to get access to things, others don't like the fact that
flatfile-based storage is terrible at versioning and so forth. This
approach mixes both so that folks who just want to grab a .zip, can,
and those who want to get SVN access, can.
* The usual *forge-like directory interface: unlike *just* a Trac
farm, as I originally mentioned, this setup allows us to have a facade
in front of the Trac farm, so that we get all the metadata and
organization and searching that is useful for something like this.
   * Note that unlike actually using Sourceforge or Google Code, we
can customize this setup to behave the way we want. Google Code does
not provide even a tenth of the functionality Trac does, and
Sourceforge does not allow us to specify our own metadata for
organizational purposes (plus its interface is, IMHO, very cluttered).


I am willing to start hosting something like this as soon as it can be
built, on my own dinky little VPS; I recall that Marc Fargas and a few
others also volunteered hosting. In that case, I'd still like to
volunteer my time and what little expertise I have, to
running/curating the thing, as well as writing the front-end or
modifying what Ian has started with.

Thoughts?

Regards,
Jeff


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Passing a processed model field in a View to a Template

2006-10-04 Thread [EMAIL PROTECTED]

Hi,

I recently started using Django.  I'm still getting a bit confused with
the interaction between the Views and the Template.  I understand or
figure that pretty much all the data processing should be handled
within the View.

I'm using render_to_response sort of like this:

from django.shortcuts import get_object_or_404, render_to_response
from my_site.property.models import Data

def index(request):
object_list = Data.objects.filter(job =
"Accountant").order_by('-salary')[:5]
return render_to_response('employees/employees_index.html',
{'object_list': object_list})


How would you process the Salary field of the Data model such that it
returns the value so that it's processed and is comma separated.  So
'8' for Salary would become '80,000'?

Thanks,
Julian


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



[win2k] Can't get install to work

2006-10-04 Thread Snirp

- I have django 0.95.tar.gz dowloaded.
- I got python 2.5 installed.
- I have django unzipped


- When i run setup.py in contacts internet in search of setuptools
- I do however not see the setuptools saved anywhere and nothing
happens
- I manually downloaded the setuptools and saved it to the same
directory
- When i run setup.py, the same happens.

I do not get it to work |:-(

I also tried the commands suggested on the djanko site:

tar xzvf Django-0.95.tar.gz
cd Django-0.95
sudo python setup.py install

I do not really get these and neither does my computer.


Is there no friendly windows binary around? Is there a way to get this
to work?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Order by a field in a third table

2006-10-04 Thread Mario Gudelj

Hello django users,

Bit of a newbie question.

For model like this:

class X(models.Model):
name = models.CharField(maxlength=20)

class Y(models.Model):
name = models.CharField(maxlength=20)
x = models.ForeignKey(X)

class Z(models.Model):
name = models.CharField(maxlength=20)
y = models.ForeignKey(Y)

I do not know how to order by x.name in the view:

order_key = name#order by z.name, fine
order_key = y_table.name #order by y.name, fine
#order_key =  #order by x.name, i don't know how

the_list = Z.objects.order_by(order_key)

What would be the elegant soluton?

Thanks,
Mario Gudelj


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



from 1 to "pages" in django.views.generic.list_detail.object_list

2006-10-04 Thread [EMAIL PROTECTED]

In templates that use generic view - "
django.views.generic.list_detail.object_list" I have "pages" variable.
But how can I display in a for/loop links for each page (loop that will
display from 1 to "pages") ?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Pydev and Django

2006-10-04 Thread fabiofz

Hi All,

For those interested... Just wanted to post that I've recently covered
a little how-to on configuring pydev to work with django
http://pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html

Cheers,

Fabio


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: global template tags

2006-10-04 Thread Patrick J. Anderson

RajeshD wrote:
> Firstly, the statement "user = User.objects.get(id=request.user.id)" is
> redundant -- you could directly use request.user instead of that query
> with the same effect.
> 
> As far as the actual problem is concerned, your Queryset is returning
> multiple rows because request.user.id probably resolves to None (in
> that case the query will match all User records). This in turn implies
> that request.user is not good.
> 
> Have a look at:
> http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests
> 
> That will tell you what you need to setup in your project in order for
> Django to populate request.user for you.
> 
> Beware also that request.user may not always point to a logged in user.
> Always check this with the is_anonymous() call or other permission
> method calls before you use the user instance for anything serious.
> 
> Good luck!
> -Rajesh
> 
> 
> > 
> 
Thanks again, Rajesh. That worked. Below is my rudimentary userinfo tag:


from django.template import Library, Node
from django.contrib.auth.models import User

register = Library()

def user_info(context):
 """
 Get user information
 """
 request = context['request']
 if request.user.is_authenticated():
 # Do something for authenticated users.
 user = request.user
 else:
 # Do something for anonymous users.
 user = None

 return {'current_user': user,}

register.inclusion_tag('user_info.html', takes_context=True)(user_info)



I guess one thing to remember is to always use RequestContext


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Support for db declaration of "on cascade delete"?

2006-10-04 Thread Greg Plesur

Waylan Limberg wrote:
>> Do any of you know if there's a way to tell Django to specify "on
> cascade delete" for foreign key references, when it creates DB tables?
> 
> I don't believe you can. However, you can use sql or sqlall [1] to
> output the table creation sql to a file for editing.  For example:
> 
> manage.py sqlall myapp > myapp.sql

I was looking at this, but:  Does anyone know why "manage.py sqlall" 
rearranges the order of the table-creates from what's in the models?

I can't find the reason for the new ordering; it looks kind of random, 
and it causes the table-creates to fail because of foreign key constraints.



> 
> Then open myapp.sql in your favorite editor and alter the sql as you
> see fit. After saving, feed that file into your db.
> 
> [1]: 
> http://www.djangoproject.com/documentation/django_admin/#sql-appname-appname
>> I'm developing an application that is mostly using Django to touch my
>> DB, but that defines some SQL stored-procedures for manipulation of some
>> of its data by other clients.  I'd like the db-level "on cascade delete"
>> defined for these cases.
>>
>> Thanks,
>> Greg
>>
>>
> 
> 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Support for db declaration of "on cascade delete"?

2006-10-04 Thread Waylan Limberg

On 10/4/06, Greg Plesur <[EMAIL PROTECTED]> wrote:
>
> All,
>
> Do any of you know if there's a way to tell Django to specify "on
cascade delete" for foreign key references, when it creates DB tables?

I don't believe you can. However, you can use sql or sqlall [1] to
output the table creation sql to a file for editing.  For example:

manage.py sqlall myapp > myapp.sql

Then open myapp.sql in your favorite editor and alter the sql as you
see fit. After saving, feed that file into your db.

[1]: 
http://www.djangoproject.com/documentation/django_admin/#sql-appname-appname
>
> I'm developing an application that is mostly using Django to touch my
> DB, but that defines some SQL stored-procedures for manipulation of some
> of its data by other clients.  I'd like the db-level "on cascade delete"
> defined for these cases.
>
> Thanks,
> Greg
>
>
> >
>


-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: django db api: looking for "not-in select

2006-10-04 Thread RajeshD

Use exclude instead of filter:
http://www.djangoproject.com/documentation/db_api/#exclude-kwargs


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: global template tags

2006-10-04 Thread RajeshD

Firstly, the statement "user = User.objects.get(id=request.user.id)" is
redundant -- you could directly use request.user instead of that query
with the same effect.

As far as the actual problem is concerned, your Queryset is returning
multiple rows because request.user.id probably resolves to None (in
that case the query will match all User records). This in turn implies
that request.user is not good.

Have a look at:
http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests

That will tell you what you need to setup in your project in order for
Django to populate request.user for you.

Beware also that request.user may not always point to a logged in user.
Always check this with the is_anonymous() call or other permission
method calls before you use the user instance for anything serious.

Good luck!
-Rajesh


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



django db api: looking for "not-in select

2006-10-04 Thread Ulrich Nitsche

hi,

in the docs I found a method to
run a query like this:
MyObj.objects.filter(id__in=[1, 3, 4]).

My question is if there is a "negative"
to this like the following raw sql
"SELECT xxx FROM mytable WHERE xxx NOT IN (1, 2 ,4);"

Is there any hint in the docs that I missed?

Thanks

uli
__
Erweitern Sie FreeMail zu einem noch leistungsstärkeren E-Mail-Postfach!

Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Support for static content?

2006-10-04 Thread Ivan Sagalaev

[EMAIL PROTECTED] wrote:
> I
> need a clean separation between the data that is changed by
> interacting with apps and data that isn't.

You can store your data in the form of templates and use 
'direct_to_template' to bind it to certain urls: 
http://www.djangoproject.com/documentation/generic_views/#django-views-generic-simple-direct-to-template

Will this work for you?

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



Support for db declaration of "on cascade delete"?

2006-10-04 Thread Greg Plesur

All,

Do any of you know if there's a way to tell Django to specify "on 
cascade delete" for foreign key references, when it creates DB tables?

I'm developing an application that is mostly using Django to touch my 
DB, but that defines some SQL stored-procedures for manipulation of some 
of its data by other clients.  I'd like the db-level "on cascade delete" 
defined for these cases.

Thanks,
Greg


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: global template tags

2006-10-04 Thread Patrick J. Anderson

RajeshD wrote:
> You could use:
> 
> 1. a regular tag or
> 2. an inclusion tag  with takes_context=True
> (See:
> http://www.djangoproject.com/documentation/templates_python/#inclusion-tags)
> 
> In both cases, your render or tag function will get called with a
> context object from which you can obtain the request instance like so:
> request = context['request'] (assuming that you have done the necessary
> setup in your project to use a RequestContext instead of the default
> Context)
> 
> 
> > 
> 
Thanks for your lead, Rajesh. I followed your advice with this code:

from django.template import Library, Node
from django.contrib.auth.models import User

register = Library()

def user_info(context):
 """
 Get user and associated (if exists) profile information
 """
 request = context['request']
 user = User.objects.get(id = request.user.id)
 return {
 'current_user': user,
 }

register.inclusion_tag('user_info.html', takes_context=True)(user_info)


But I receive multiple user objects. I guess my request context doesn't work


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



TypeError: argument 1 must be string without null bytes, not str, repr() unavailable

2006-10-04 Thread Ned Batchelder




Every once in a while, we get a stack trace from our production Django
servers with this error:

  ...
  File "/apps/mine/views/mine.py", line 481, in my_view
params = request.REQUEST

  File "/site-packages/django/core/handlers/modpython.py", line 38, in _get_request
self._request = datastructures.MergeDict(self.POST, self.GET)

  File "/site-packages/django/core/handlers/modpython.py", line 51, in _get_post
self._load_post_and_files()

  File "/site-packages/django/core/handlers/modpython.py", line 34, in _load_post_and_files
self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict()

  File "/site-packages/django/http/__init__.py", line 82, in __init__
for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True

TypeError: argument 1 must be string without null bytes, not str


Request repr() unavailable

Does anyone know what causes this, and what to do about it?
-- 
Ned Batchelder, http://nedbatchelder.com


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





Re: Relevance

2006-10-04 Thread Beau Hartshorne

On 15-Sep-06, at 12:39 PM, mrstone wrote:

> I'm fiddling around with MySQL fulltext search and run into a problem.
>
> Using the below code works:
>
> match_expr = "MATCH(name) AGAINST (%s IN BOOLEAN MODE)"
> qs =
> Place.objects.all().filter(name__search=query).extra(select= 
> {'relevance':
> match_expr}, params=[query])
>
>
> But when calling qs.count() I get:
> TypeError at /
> not all arguments converted during string formatting
>
> Is this a bug or am I using the extra in a wrong way?

Hi Sten,

I just ran into this today. Did you ever figure out a workaround?

Thanks,
Beau


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Support for static content?

2006-10-04 Thread Tim Chase

> Django's database-centric approach seems to make certain kinds
> of mostly-static sites harder to build.
[cut]
> Yes, Django is a framework, so I could build components that
> make this possible, but it seems to me that it should be a
> fundamental, built-in part of the system.  Has anyone already
> addressed these issues?

Well, there's some documentation at

http://www.djangoproject.com/documentation/static_files/

with the lovely "big, fat warning" at the top.  I don't know how 
to interpret that, as to whether it contains known flaw(s), or if 
it just hasn't been audited for security, or what.

However, it looks like most of the heavy lifting has been done, 
but that you might want to review the code for vulnerabilities 
(and possibly contribute back any fixes).

Just my $0.02,

-tkc





--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Filter types in Admin index view alterable?

2006-10-04 Thread mauiblu

In case anyone replies, or to document my own progress incase helpful
to someone else..a little more info:

I found filter_specs.py which appears to define the filter types which
are presumably applied by field introspection to come up with either
pre-defined choices, as in the datefield filter, or by the creation of
a choice list.

I have also found the filter.html which appears to create the block
layout presenting the above-mentioned lists.

I would like to have the collapse behavior for each filter section..and
to present a multi-choice list or checklist allowing users to set a
variably complex filter.

Immediate screen refresh after each choice would be fine and, in my
case, might even be desrable.

But I'm not sure where to begin:

1) edit filter_specs.py and create a custom filter-type,i.e.,
multi-choice list

if so, will Django know when to apply this type, i.e., one2many

2) edit app/models.py..Class Admin to create fieldsets/collapse for the
filter section?

not likely

3) edit filter.html to provide collapse behavior thru javascript,i.e.,
moofx or Dojo?

Hmmm...maybe 1 and 3..but the question of how to get Django to
recognize a new filter type as appropriate is unknown.

Any help appreciated...
Jim


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Support for static content?

2006-10-04 Thread dave . abrahams


Django's database-centric approach seems to make certain kinds of
mostly-static sites harder to build.  For example, most of what I want
to put on my site is probably going to come from RestructuredText
source, but that source isn't going to change in response to user
interaction.  Yes, I could set up a ReST_page model and store the text
in the database, but that has some real disadvantages as compared with
keeping the content in my SVN repository along with the rest of the
code, css, images, and other elements that are not going to be changed
by user interaction: it gets harder to keep track of what I've done to
the site, test changes on a beta site before they go live, etc.  I
need a clean separation between the data that is changed by
interacting with apps and data that isn't.

Yes, Django is a framework, so I could build components that make this
possible, but it seems to me that it should be a fundamental, built-in
part of the system.  Has anyone already addressed these issues?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


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



Re: Use my own template system?

2006-10-04 Thread Waylan Limberg

On 10/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> Is there some straightforward way to plug my own template system into
> Django?
>
> Thanks in advance,
>
Short answer: Don't use the render_to_response() shortcut (it uses
Django's template system), but just import and use your template
system within your view and pass the result onto Django's HttpReponse
object.

This thread [1] should answer your questions more throughly (with
links to the docs, etc). I realize that the question in that thread is
specific to cheetah, but the answers are general enough to apply to
any templating system. In fact, my answer above basicly paraphrases a
couple paragraphs from that thread.

[1]: 
http://groups.google.com/group/django-users/browse_thread/thread/2e5746bdd3ef3efe/


-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Use my own template system?

2006-10-04 Thread dave . abrahams


Is there some straightforward way to plug my own template system into
Django?

Thanks in advance,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


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



Re: Rendering Many-to-Many with raw_id_admin=True in Template

2006-10-04 Thread Paul Childs

Sorry to be a pest folks.

I had forgotten that the {{object}} was still accessible.

So to get what I want I just had to do this:

{% for part in object.part.all %}
{{part}}
{% endfor %}


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



Re: creating models / performance issue

2006-10-04 Thread patrickk

that works (to my surprise). thanks a lot.

Am 04.10.2006 um 18:49 schrieb DavidA:

>
>
> va:patrick.kranzlmueller wrote:
>> I have a model with blog-postings, assigned to a specific user - the
>> user is stored in the table "posting" via foreignkey.
>>
>> the user is part of a grade, part of a school and part of a state -
>> all of which have overview-pages.
>> so, to get all the postings for a state I have to do the following:
>>
>> 1. search for schools in that state
>> 2. search for grades in that school
>> 3. search for users within that grade
>> 4. and finally, get all the postings for that user
>>
>> seems a little complicated.
>
> Not sure if I understand your models exactly, but you don't need to do
> four "searches" (queries), you just need to do one query with the
> constraint that spans the four relations. Assuming your models look
> something like this:
>
> class State(models.Model):
> code = models.CharField(maxlength=2)
>
> class School(models.Model):
> state = models.ForeignKey(State)
>
> class Grade(models.Model):
> school = models.ForeignKey(School)
>
> class User(models.Model):
> grade = models.ForeignKey(Grade)
>
> class Posting(models.Model):
> user = models.ForeignKey(User)
>
> Then you can just do this to find all postings for users in grades in
> schools in New York:
>
>Posting.objects.filter(user__grade__school__state__code='NY')
>
> Which will translate into one query looking something like this:
>
>   select * from posting
>   join user on posting.user_id = user.id
>   join grade on user.grade_id = grade.id
>   join school on grade.school_id = school.id
>   join state on school.state_id = state.id
>   where state.code = 'NY'
>
> (abbreviated - the actual Django version of the SQL will be quite a  
> bit
> more verbose due to fully qualified column names).
>
> Of course, I may have completely misunderstood your models and this  
> may
> be completely off base!
> -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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: global template tags

2006-10-04 Thread RajeshD

You could use:

1. a regular tag or
2. an inclusion tag  with takes_context=True
(See:
http://www.djangoproject.com/documentation/templates_python/#inclusion-tags)

In both cases, your render or tag function will get called with a
context object from which you can obtain the request instance like so:
request = context['request'] (assuming that you have done the necessary
setup in your project to use a RequestContext instead of the default
Context)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: global template tags

2006-10-04 Thread Patrick J. Anderson

Waylan Limberg wrote:
> On 10/4/06, Patrick J. Anderson <[EMAIL PROTECTED]> wrote:
>> Hi, everyone!
>>
>> I have a question I've been trying to find answers to in the docs, but
>> perhaps I'm not looking in the right places, because I can't find it.
>>
>> I'm wondering about the use of templatetags in project instead of
>> application scope. I put my applications in 'apps' subdirectory and
>> under each I created 'templatetags' directory to hold my template tags.
>>
>> I have a need for a tag that would display user and user-related
>> information (no. of posts and comments, etc.) in header of each page and
>> I thought that I could create a template tag for this purpose, which I
>> would load in the base template.
>>
>> I guess the question is simple : where should this template tag be
>> stored and can I import current RequestContext object to it?
>>
>>
> This was just answered the other day:
> 
> http://groups.google.com/group/django-users/browse_thread/thread/49e9669c64e353b2/
> 
> 

Well, yeah, I could put that tag probably in any installed app.

What about request object being available inside that tag, so to speak?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: DRY in templates

2006-10-04 Thread Rob Hudson

Unless I didn't read closely enough, this sounds to me like you could
use inclusion tags:
http://www.djangoproject.com/documentation/templates_python/#inclusion-tags


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: creating models / performance issue

2006-10-04 Thread DavidA


va:patrick.kranzlmueller wrote:
> I have a model with blog-postings, assigned to a specific user - the
> user is stored in the table "posting" via foreignkey.
>
> the user is part of a grade, part of a school and part of a state -
> all of which have overview-pages.
> so, to get all the postings for a state I have to do the following:
>
> 1. search for schools in that state
> 2. search for grades in that school
> 3. search for users within that grade
> 4. and finally, get all the postings for that user
>
> seems a little complicated.

Not sure if I understand your models exactly, but you don't need to do
four "searches" (queries), you just need to do one query with the
constraint that spans the four relations. Assuming your models look
something like this:

class State(models.Model):
code = models.CharField(maxlength=2)

class School(models.Model):
state = models.ForeignKey(State)

class Grade(models.Model):
school = models.ForeignKey(School)

class User(models.Model):
grade = models.ForeignKey(Grade)

class Posting(models.Model):
user = models.ForeignKey(User)

Then you can just do this to find all postings for users in grades in
schools in New York:

   Posting.objects.filter(user__grade__school__state__code='NY')

Which will translate into one query looking something like this:

  select * from posting
  join user on posting.user_id = user.id
  join grade on user.grade_id = grade.id
  join school on grade.school_id = school.id
  join state on school.state_id = state.id
  where state.code = 'NY'

(abbreviated - the actual Django version of the SQL will be quite a bit
more verbose due to fully qualified column names).

Of course, I may have completely misunderstood your models and this may
be completely off base!
-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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Implementing entity relationships that use compound keys in a Django application

2006-10-04 Thread David S .

Malcolm Tredinnick  pointy-stick.com> writes:

>
> documentation). As you have noted, you also then have to do something
> with limit_choices_to and possibly a validator to enforce this at the
> Python and form validation level, but it's shouldn't be too bad.

Does limit_choices_to work outside of the admin interface?  Even within the
admin interface, I could not figure out a way to refer, within limit_choices_to,
to fields on the record it was to limit for.  In other words, I can hard code
values in there, but not refer to the value of self.whatever_field.  Can
limit_choices_to take the name of a function that returns an iterator or
something?  It would be neat. 

Also, the validator stuff is in a state of flux, and I have been hesitant to
commit much time coding to the current implementation, but that's just me.

I ended up adding some Dojo javascript to get the legal values, in this case
sub-accounts for a buyer, and populate the html select options when the buyer
has been selected.

function fill_accounts(evt) {
el = document.getElementById("id_buyer");
function results_for_post(type, value, evt) {
eval('res='+value);
if (res['is_ok']==true) {
var account_sel = document.getElementById("id_account");
account_sel.innerHTML = res['html'];
} else {
alert ("Problem getting info for " + target.value + ".");
el.focus();
}
}
if (el.value != "") {
dojo.io.bind({
url:  
"/admin/manager/participants/"+el.value+"/accounts/?output=json",
method: "GET",
type: "text/javascript",
load: results_for_post,
error: function(type, error) { alert("Error getting accounts: "  +
error); },
});
}
return false;
}

It also makes it so they can not enter an illegal value in this view.  

Anyway, perhaps the SQLAlchemy branch might someday address this more
comprehensively.  

Peace,
David S.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Anal not Analog, Analysis: DB Question

2006-10-04 Thread Andy Dustman

On 10/4/06, Tom Smith <[EMAIL PROTECTED]> wrote:
>
> If I am looking for titles like "Anal Sex" or "Being Anal" then how
> do I construct this, ahem, query... to not return "Analysis" or
> "Analog"?

Two options: If your database supports it, try a full-text search:

object_list = Products.objects.filter(title__search=word)

Another option: MySQL at least has a REGEX search. To use it:

object_list = Products.objects.extra(where=["title REGEX %s"],
params=[r"\b%s\b" % word])

Above is untested in Django, but it should be what you want. \b
matches word boundaries.

-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: unique objects in list

2006-10-04 Thread Grigory Fateyev

Hello Malcolm Tredinnick!
On Wed, 04 Oct 2006 11:27:31 +1000 you wrote:

> 
> On Tue, 2006-10-03 at 18:21 +0400, Grigory Fateyev wrote:
> > Hello James Bennett!
> > On Tue, 3 Oct 2006 08:28:02 -0500 you wrote:
> > 
> > > 
> > > On 10/3/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote:
> > > > I have a list of ip in table, but this ip repeats many times. I
> > > > need to show each ip only once with some statistic. How to do
> > > > this?
> > > 
> > > http://www.djangoproject.com/documentation/db_api/#distinct
> > 
> > I don't get it, Blog.objects.all().distinct() is't working like sql
> > query: select distinct column from blog;?
> 
> In both SQL and Django, "distinct" means "select distinct rows". So if
> you run Blog.objects.all().distinct(), you will have every row
> returned, since each row has a distinct value in the primary key
> column and thus is not identical to any other row.
> 
> Something like Blog.objects.values('ip').distinct() will extract all
> the distinct values from the "ip" column, however, as Rajesh points
> out, elsewhere, if you also want to collect other statistics, you are
> going to need to use custom SQL.
> 
> Regards,
> Malcolm

Thanks Malcolm for helping!

-- 
÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! çÒÉÇÏÒÉÊ
greg [at] anastasia [dot] ru
ðÉÓØÍÏ ÏÔÐÒÁ×ÌÅÎÏ: 2006/10/04 20:06

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Anal not Analog, Analysis: DB Question

2006-10-04 Thread John DeRosa

heh.  so do we get to guess what your django-based site is about?

Tom Smith wrote:
> If I am looking for titles like "Anal Sex" or "Being Anal" then how  
> do I construct this, ahem, query... to not return "Analysis" or  
> "Analog"?
> 
> I tried adding spaces to the end of the word but it doesn't seem to  
> help...
> 
> object_list = Product.objects.filter( Q(title__contains=word + " ")| Q 
> (title__contains=" " + word )  )
> 
> regards
> 
> tom
> 
> 
> 
> > 
> 
> 


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



Anal not Analog, Analysis: DB Question

2006-10-04 Thread Tom Smith

If I am looking for titles like "Anal Sex" or "Being Anal" then how  
do I construct this, ahem, query... to not return "Analysis" or  
"Analog"?

I tried adding spaces to the end of the word but it doesn't seem to  
help...

object_list = Product.objects.filter( Q(title__contains=word + " ")| Q 
(title__contains=" " + word )  )

regards

tom



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



Re: Best way for multiple selectable options

2006-10-04 Thread Spider

Thanks Malcolm that's a nice approach.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: creating models / performance issue

2006-10-04 Thread RajeshD


> so, to get all the postings for a state I have to do the following:
>
> 1. search for schools in that state
> 2. search for grades in that school
> 3. search for users within that grade
> 4. and finally, get all the postings for that user
>
> seems a little complicated.

Actually, this is what RDBMS's are good for.

Django's Querysets should have no problems pulling user postings like
this by traversing through all your tables (using appropriate SQL
JOINs).

If you have already tried this and are having performance issues,
consider adding INDEXES on fields that were used in the Queryset
composition.

You can do this in your models using db_index=True on relevant fields
of each model. For example, add an index on the state field of School,
school field of Grade, and so on (assuming School, Grade are your
models/tables).


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: 2 questions

2006-10-04 Thread RajeshD

1. I am not sure about this one.

2. You will also need blank=True in addition to null=True in those
nullable fields.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Request data dissapearing after do_html2python

2006-10-04 Thread Carlos Yoder
Forgot to say, the model I'm  trying to create an object to has the user as a OneToOne relationship, which apparently MySQL does not like very much. Why? Because phpMyAdmin, when accessing the homepage for the model's datatable, says this:
PRIMARY and INDEX keys should not both be set for column `user_id`Does this run deeper than I thought?Thakns a million for your help,CarlosOn 10/4/06, 
Carlos Yoder <[EMAIL PROTECTED]> wrote:
Hello guys,I'm experiencing a weird thing. On my production setup, an OperationalError exception is being triggered while trying to invoke an AddManipulator.I've zeroed in down to this (excerpt of my view follows)
def userprofile_add(request):    """ Handle adding new userprofiles (one2one rel to User objects) """    from django import forms    manipulator = UserProfile.AddManipulator

()    if request.POST:        # If data was POSTed, we're trying to create a new UserProfile.        new_data = request.POST.copy()        # Check for errors.        errors = manipulator.get_validation_errors

(new_data)        if not errors:            # No errors. This means we can save the data!            manipulator.do_html2python(new_data)            new_userprofile = manipulator.save(new_data)

            # Redirect to the object's "edit" page. Always use a redirect            # after POST data, so that reloads don't accidently create            # duplicate entires, and so users don't see the confusing
            # "Repost POST data?" alert box in their browsers.            return HttpResponseRedirect("/my_data/")    else:        # No POST, so we want a brand new form without any data or errors.
        errors = new_data = {}As you can see, this is ver simple AddManipulator. For some reason my  request MultiValueDict has properly set a NOT NULL value I pass via a hidden HTML input field, but the new_data dict doesn't.  This field is the ubiquitous "user_id", that comes from 
request.user. As I said, it's properly passed from the form, and seen by request.POST... only new_data lacks it (it's set to None).So, this should be centered aroudn either request.POST.copy() or do_html2python(), right?
This is funny, since on my dev environment (sqlite+windows) everything runs smoothly. This error only occurs on the production environment, which is on Bluehost (mysql+Linux). Any ideas? I'm very very very close of finishing my first Django project, yay!
Best regards,-- Carlos Yoderhttp://blog.argentinaslovenia.com/


-- Carlos Yoderhttp://blog.argentinaslovenia.com/

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


Request data dissapearing after do_html2python

2006-10-04 Thread Carlos Yoder
Hello guys,I'm experiencing a weird thing. On my production setup, an OperationalError exception is being triggered while trying to invoke an AddManipulator.I've zeroed in down to this (excerpt of my view follows)
def userprofile_add(request):    """ Handle adding new userprofiles (one2one rel to User objects) """    from django import forms    manipulator = UserProfile.AddManipulator
()    if request.POST:        # If data was POSTed, we're trying to create a new UserProfile.        new_data = request.POST.copy()        # Check for errors.        errors = manipulator.get_validation_errors
(new_data)        if not errors:            # No errors. This means we can save the data!            manipulator.do_html2python(new_data)            new_userprofile = manipulator.save(new_data)
            # Redirect to the object's "edit" page. Always use a redirect            # after POST data, so that reloads don't accidently create            # duplicate entires, and so users don't see the confusing
            # "Repost POST data?" alert box in their browsers.            return HttpResponseRedirect("/my_data/")    else:        # No POST, so we want a brand new form without any data or errors.
        errors = new_data = {}As you can see, this is ver simple AddManipulator. For some reason my  request MultiValueDict has properly set a NOT NULL value I pass via a hidden HTML input field, but the new_data dict doesn't.  This field is the ubiquitous "user_id", that comes from 
request.user. As I said, it's properly passed from the form, and seen by request.POST... only new_data lacks it (it's set to None).So, this should be centered aroudn either request.POST.copy() or do_html2python(), right?
This is funny, since on my dev environment (sqlite+windows) everything runs smoothly. This error only occurs on the production environment, which is on Bluehost (mysql+Linux). Any ideas? I'm very very very close of finishing my first Django project, yay!
Best regards,-- Carlos Yoderhttp://blog.argentinaslovenia.com/

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


Re: global template tags

2006-10-04 Thread Waylan Limberg

On 10/4/06, Patrick J. Anderson <[EMAIL PROTECTED]> wrote:
>
> Hi, everyone!
>
> I have a question I've been trying to find answers to in the docs, but
> perhaps I'm not looking in the right places, because I can't find it.
>
> I'm wondering about the use of templatetags in project instead of
> application scope. I put my applications in 'apps' subdirectory and
> under each I created 'templatetags' directory to hold my template tags.
>
> I have a need for a tag that would display user and user-related
> information (no. of posts and comments, etc.) in header of each page and
> I thought that I could create a template tag for this purpose, which I
> would load in the base template.
>
> I guess the question is simple : where should this template tag be
> stored and can I import current RequestContext object to it?
>
>
This was just answered the other day:

http://groups.google.com/group/django-users/browse_thread/thread/49e9669c64e353b2/


-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Rendering Many-to-Many with raw_id_admin=True in Template

2006-10-04 Thread Paul Childs

I have a Many-to-Many relationship between two models, Action and Part
(see below).

Part has thousands of records so I am using "raw_id_admin=True".  This
works great in the admin.

I am using a generic view to create an update form for an Action. This
works fine but it only displays the part ids and does not include the
__str__ representation of the parts like the admin interface does. I
looked at the output of {% debug %} in the template and I couldn't see
anything that might contain those values.

Does anyone know how to do this? Thanks in advance.

-
Models:
-
from django.db import models

class Action(models.Model):
name = models.CharField(maxlength=10)
part = models.ManyToManyField(Part,raw_id_admin=True)

class Admin:
pass

def __str__(self):
return self.name


class Part(models.Model):

part_number = models.CharField(maxlength=20,db_index=True)
description = models.CharField(maxlength=50,blank=True)

class Admin:
pass

def __str__(self):
return '%s - %s' % (self.part_number, self.id)

--
Template:
--


   Name:{{form.name}}

 
   Parts: {{ form.part }}






--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



2 questions

2006-10-04 Thread dgk

1. I've changed the TIME_ZONE in settings.py to 'Europe/Moscow'. Time
values saved in the database are 3 hours lesser than the times of
writing (now should be 4 hours of difference). When I open records in
the admin I see the same values as in the database. Can I see the local
time values in the admin?

2. There are nullable fields in my models.py (an option null = True was
used), but I can't add a record with an empty field using the admin.
There're no problems to do it In the "python manage.py shell".


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



global template tags

2006-10-04 Thread Patrick J. Anderson

Hi, everyone!

I have a question I've been trying to find answers to in the docs, but 
perhaps I'm not looking in the right places, because I can't find it.

I'm wondering about the use of templatetags in project instead of 
application scope. I put my applications in 'apps' subdirectory and 
under each I created 'templatetags' directory to hold my template tags.

I have a need for a tag that would display user and user-related 
information (no. of posts and comments, etc.) in header of each page and 
I thought that I could create a template tag for this purpose, which I 
would load in the base template.

I guess the question is simple : where should this template tag be 
stored and can I import current RequestContext object to it?


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



Re: order admin list view

2006-10-04 Thread David S .

> some details 

So, I looked at the admin code and noticed that in the absence of any ordering
it orders by PK DESC.  I submitted a patch that would change the behavior to use
the ordering returned by a custom default manager.

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

Peace,
David S.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: class with a ForeignKey and ManyToManyField, empty sql IN () clause after admin save

2006-10-04 Thread L. Liddell

Thanks Russell.

Although the patch for that ticket did not work in my particular case,
I was able to modify the patch slightly to solve my problem. For anyone
else with the same problem, here's my patch for
django/db/models/query.py:

643 if lookup_type == 'in':
644 #return '%s%s IN (%s)' % (table_prefix, field_name,
','.join(['%s' for v in valu
645 ### MY CODE
646 ids = list(value)
647 if ids:
648 return '%s%s IN (%s)' % (table_prefix, field_name,
','.join(['%s' for id in
649 else:
650 return '%s%s IN (0)' % (table_prefix, field_name)
651 ### END OF MY CODE

I don't think this should cause problems anywhere else, but use at your
own risk! Hopefully by mid November when my site launches, the most
recent revision of Django will have solved this issue and there will be
no need for patched Django source code.

cheers,
Les Liddell


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



off-topic, Re: Unicode and django/db/backends/util.py

2006-10-04 Thread Michael Radziej

Gábor Farkas schrieb:

> explicit is better than implicit :)

Oh come on, I can't hear that particular one any more. Why does 
python have implicit storage handling with automatic reference 
counting? We'd use C or Assembler if we really believed in that 
Mantra.

But your advice is right, of course.

SCNR,

Michael


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



Re: User object available in base template

2006-10-04 Thread Patrick J. Anderson

Don Arbow wrote:
> On Oct 3, 2006, at 9:30 PM, Patrick J. Anderson wrote:
>> def main(request):
>>  posts = Post.objects.filter(is_approved =
>> True).order_by('-time_added')[:5]
>>  t = loader.get_template('homepage.html')
>>  c = RequestContext({
>>  'latest_posts': posts,
>>  })
>>  return HttpResponse(t.render(c))
>>
>> What am I doing wrong?
> 
> 
> 
> You have to pass the request object into the RequestContext  
> constructor. Then the user object will show up in your templates.
> 
> c= RequestContext(request, { ... })
> 
> Don
> 
> 
> 
> > 
> 

Thanks, guys!

I guess to create a user info box and make it available in all the 
templates, I'd create a template tag and load it in the base template, 
right?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode and django/db/backends/util.py

2006-10-04 Thread Gábor Farkas

Malcolm Tredinnick wrote:
> On Tue, 2006-10-03 at 22:26 -0700, Beau Hartshorne wrote:
>> On 3-Oct-06, at 7:36 PM, Malcolm Tredinnick wrote:
>>
>>> So this is the value that the string has right at the moment the
>>> exception occurs? Can you paste the traceback you see, please (and
>>> preferably the value of 'sql' and 'params' at that point as well).
>>>
>>> I'm a bit in the dark about what is happening right now, since
>>> subsituting a UTF-8 string into a Python string should work easily.
>>>
>> s = unicode('Djang\xc3\xa9', 'utf-8')
>> print "update foo set blah = '%s'" % s
>>> update foo set blah = 'Djangé'
>>>
>>> is an example of what should be happening. I suspect there is  
>>> something
>>> else important about what you are doing. Not accusing you of
>>> deliberately misleading or anything -- I have no idea what the  
>>> important
>>> thing is yet, either.
>> Actually, this is what I get:
>>
>>  >>> import sys
>>  >>> print sys.version
>> 2.4.3 (#1, Mar 30 2006, 11:02:16)
>> [GCC 4.0.1 (Apple Computer, Inc. build 5250)]
>>
>>  >>> s = unicode('Djang\xc3\xa9', 'utf-8')
>>  >>> print "update foo set blah = '%s'" % s
>> Traceback (most recent call last):
>>File "", line 1, in ?
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in  
>> position 28: ordinal not in range(128)
>>
>> But, if I do this:
>>
>>  >>> s = 'Djang\xc3\xa9'
>>  >>> print "update foo set blah = '%s'" % s
>> update foo set blah = 'Djangé'
>>
>> I haven't played with the default encoding at all.
> 
> Oh sod :-( It's also an environment locale thing. My system typically
> runs in en_AU.UTF-8 (so UTF-8 by default). If I run in the "C" or "en"
> locales, I get the same thing.
> 
> So, yeah, it looks like you have to run s.encode('utf-8') on your
> strings before trying to work with them in that case.
> 


explicit is better than implicit :)

well, this actual problem here is only because the "print", which uses 
the locale. the locale is not used when conversions happen "inside" of 
python.

but still, imho it's a very bad idea to pass unicode strings to the db 
layer in current django. they should all be converted into bytestring 
before sending them to the db... for example, psycopg1 does not quote 
unicode-strings correctly...


gabor

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: follow-the-tutorial.. little problem..

2006-10-04 Thread ian

Marco Amato wrote:
> Hi !
> 
> I am in the part 2 of the tutorial after add the class Admin in evere
> object and uncommenti in url.py the admin url
> 
> I receive this error from the server :
> 
> SuspiciousOperation at /admin/
> User tampered with session cookie.
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/admin/
> Exception Type:   SuspiciousOperation
> Exception Value:  User tampered with session cookie.
> Exception Location:
>   
> /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/contrib/sessions/models.py
> in get_decoded, line 65
> 
> I use svn version, where could be my error ?
> 
> Thanks
> 
> MA.
> 
> > 
> 
Ola,
I got this when i changed my secret key after I had created my models...
[]'s
Ian

-- 
Ian Lawrence
Centre for Bioinformatics
INSTITUTO NACIONAL DE PESQUISAS DA AMAZÔNIA-INPA
RUA ANDRÉ ARAÚJO N º .2936 , BAIRRO DO ALEIXO
MANAUS-AMAZONAS-BRAZIL
Research Program in Biodiversity
http://ppbio.inpa.gov.br
PHONE: 055-92-3643-3358
CEP. 69011 -970

| Please do not send me documents in a closed
| format.(*.doc,*.xls,*.ppt)
| Use the open alternatives. (*.pdf,*.html,*.txt)
http://www.gnu.org/philosophy/no-word-attachments.html

"We are all in the gutter, but some of us are looking at the stars."

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Unicode and django/db/backends/util.py

2006-10-04 Thread orestis

usually encode('utf-8') is needed only when printing the strings. You
can pass them aroung without problem.

BTW, unicode chars should appear like '\u0345' ... I'm not so sure
about that though.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



follow-the-tutorial.. little problem..

2006-10-04 Thread Marco Amato

Hi !

I am in the part 2 of the tutorial after add the class Admin in evere
object and uncommenti in url.py the admin url

I receive this error from the server :

SuspiciousOperation at /admin/
User tampered with session cookie.
Request Method: GET
Request URL:http://127.0.0.1:8000/admin/
Exception Type: SuspiciousOperation
Exception Value:User tampered with session cookie.
Exception Location:

/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/contrib/sessions/models.py
in get_decoded, line 65

I use svn version, where could be my error ?

Thanks

MA.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Using some of the admin functionality with ordinary users

2006-10-04 Thread MerMer

list_filter ('field_names') works very well in the admin area.  Is
there an easy way to use this same functionality to display information
to ordinary users visting the site?

Also, in the lists within admin you can sort each list by clicking on
the column header which is very useful.  However, this is only clear
once you have clicked on the header.  Is there a setting to each column
head on automatically so it is visible?

MerMer


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Importing models from each other.

2006-10-04 Thread Holger Schurig

> I try to import like: "import myproject" and then
> myproject.auth.models.User but no luck, Django throws error,
> that auth has no models class. Is there a way to make this to
> work?

For this kind of problem it helps sometimes to use the "-v" 
option to python, e.g.

python -v ./manage.py runserver

and then look what modules it wants to load.


Maybe it's also as simple as a missing empty __init__.py in the 
myproject/auth directory.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---