Re: value taken through textarea is being displayed in one line

2008-08-26 Thread John Lenton

Also, you could use css to set whitespace to pre-wrap.



On 2008-08-26, Daniel Roseman <[EMAIL PROTECTED]> wrote:
>
> On Aug 26, 10:12 am, Will Rocisky <[EMAIL PROTECTED]> wrote:
>> I am taking an input from user in text area, like comments.
>> but when I print them, they all display in one line.
>> how can I format them to display exactly how use entered them? (new
>> lines, tabs etc)
>
> When you say 'print' I presume you mean on a web page.
> HTML ignores white space like carriage returns - so you need to mark
> up the line breaks specifically. Luckily Django has a filter to do
> this: linebreaks. So you just do {{ comment|linebreaks }}
>
> --
> DR
> >
>

-- 
Sent from Gmail for mobile | mobile.google.com

John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Regex assistance

2008-07-01 Thread John Lenton

On Tue, Jul 1, 2008 at 12:12, mike171562 <[EMAIL PROTECTED]> wrote:
>
> Hello,
>   I am trying to build a regex for a query that excludes local phone
> numbers from a list of calls thus leaving only long distance.  I dont
> have alot of experience with the "re" module
>
> local numbers start with 281, 832, 713 , or 1281, 1832, or 1713, my
> regex which isnt working looks like this

in other words, local numbers match the regex

  r'^(?:281|832|713|1281|1832|1713)'


-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: accessing dictionary elements in opening tag of django template for loop

2008-05-14 Thread John Lenton

On Wed, May 14, 2008 at 6:33 PM, John <[EMAIL PROTECTED]> wrote:
>
> I'm having trouble accessing dictionary elements within a nested for
> loop.  here are some code snippets:
>
> [...]
>
> # so far so good, but then I try to iterate over the documents and
> their associated tags in a template
> # here is the template with the html stripped out for readability
> {% for document in documents %}
>  {{ document.content }}
>  {% for doctag in tag_dict[document.uid] %} {{ doctag.tagid }} {%
> endfor % }
> {% endfor %}
>
> # document.content is fine, but when I try to access tag_dict within
> the template's for loop, it complains:
> TemplateSyntaxError: Could not parse the remainder: [document.uid]

right, templates are not python :) you can't do that, and it's on
purpose: that kind of fiddling around with the model is best done in
the view, not in the template.

So... instead of doing e.g.

documents = Document.objects.all()
tag_dict = {}
for document in documents:
tag_dict[document.uid] = DocumentTag.objects.filter(docid=document.uid)

and passing those two into the template, you could do something along
the lines of

documents = [dict(object=document,
  tags=DocumentTag.objects.filter(docid=document.uid))
 for document in Document.objects.all()]

and then in the template, you do

{% for document in documents %}
  {{ document.object.content }}
  {% for doctag in document.tags %} {{ doctag.tagid }} {% endfor %}
{% endfor %}

this is assuming there is some reason for you not to modify the
Document class to give it the appropriate methods or attributes to
access the related DocumentTag directly; if you could do that, life
would be much easier :)

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Building filter strings dynamically

2008-05-09 Thread John Lenton

On Fri, May 9, 2008 at 6:19 PM, Greg Fuller <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I'm trying to build filter strings dynamically.
>
> The normal way works:
>qry = qry.filter(sections__name__exact='printing')
>
> This does not work:
>filter_str = "sections__name__exact='shooting'"
>qry = qry.filter(filter_str)
> .
> The error is "too many values to unpack" at django/db/models/sql/
> query.py in add_filter, line 933
>
> I realize something outside normal name-spacing is probably happening,
> since "sections__name__exact"  doesn't have to be defined anywhere.
>
> But is there any way to build the parameter to the filter dynamically?

the usual python way of building dynamic args:

filter = {'sections__name__exact': 'shooting'}
qry = qry.filter(**filter)

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Combating submission form Spam

2007-12-05 Thread John Lenton

On Dec 5, 2007 9:50 PM, Darryl Ross <[EMAIL PROTECTED]> wrote:
> Hey All,
>
> One of the websites I run has started getting spam via the contact form.
>
> What is the recommended way of dealing with this? Do I need to go the
> route of using something like django-captcha?
>
> Thanks for any insight.

you might be interested in using recaptcha; not only is it (in my
experience) easier to integrate, it also makes captchas not be a
complete waste of human cpu :)

recaptcha:
http://recaptcha.net/
an example of integrating django and recaptcha (not sure how accurate
or up to date, although it looks about right; just saving you the
google):
http://chewpichai.blogspot.com/2007/10/how-to-integrate-recaptcha-with-django.html


-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: order_by with foreign keys

2007-09-10 Thread John Lenton

On 9/10/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> that helps, thanks very much...
>
> i got a bit confused by all the tickets concerning this issue. also
> the documentation doesn't mention any bugs, well bad luck ;)

fortunately you can add a comment to the documentation, mentioning the
bug, and pointing to the ticket with the patch that fixes the bug,
right?

:-D

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: application/xhtml+xml MIME won't take

2007-08-13 Thread John Lenton

On 8/13/07, TheMaTrIx <[EMAIL PROTECTED]> wrote:
>
> I'm developing a site that needs to be xhtml 1.1, my page validates
> just fine except that the server keeps spitting it out as text/html
> instead of application/xhtml+xml.
>
> How the heck do I make django set application/xhtml+xml for the pages
> it serves?
>
> I tried changing the text/html entry in my mime.types file for apache
> to application/xhtml+xml but that does squat.

do you want to do that, given that a large portion of your (average)
clients will now get a download dialog instead of a web page?

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Encoding in models.py (and maybe other files too)

2007-04-18 Thread John Lenton

On 4/18/07, ashwoods <[EMAIL PROTECTED]> wrote:
>
> maybe a little off-topic, but why do you need special characters in
> code? it makes code maintainance and reusability a bit more difficult,
> while there are not really  a lot of situations where its necesary.
>
> just asking :)

I don't know about Nicolas, but I'm writing something for a
Spanish-speaking customer, so I might have a TelephoneField
("teléfono") in there, for example.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: newb: Newform conditional regexField

2007-03-16 Thread John Lenton

On 3/16/07, johnny <[EMAIL PROTECTED]> wrote:
>
> In newform, how do I allow a single regexField to accept either a
> whole number, or number with decimal places?

doesn't r"\d+(\.\d*)?" work?

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Types of projects Django is not well suited for?

2006-12-29 Thread John Lenton


On 12/26/06, mamcxyz <[EMAIL PROTECTED]> wrote:

- You can't do a single-exe deployment, except if discover a way to
hack the thing very much


I wouldn't be so sure. You could almost certainly use PyInstaller to
build a sqlite-backed django app down to a single exe.

--
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: "Decimal not JSON serializable"?

2006-12-19 Thread John Lenton

On 12/19/06, DavidA <[EMAIL PROTECTED]> wrote:
>
>
> 176   elif isinstance(key, float) or isinstance(key,
> decimal.Decimal):
> 177key = floatstr(key, allow_nan)

isinstance can take an iterable of classes as its second argument, so
that you could write that as isinstance(key, (float, decimal.Decimal))

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: select_related() with the ForeignKey in the same table

2006-12-18 Thread John Lenton

On 12/15/06, leanmeandonothingmachine
<[EMAIL PROTECTED]> wrote:
>
> I have a model where the foreign key refers to it self.
> parent = models.ForeignKey('self', core=True, null=True, blank=True)
>
> What i want to do is to be able to run a query with select_related and
> get all the parents of that row. When I run test =
> content.objects.select_related().get(pk=3) and if I knew how many
> parents there are I can get them all using test.parent then
> test.parent.parent... etc.. But I need to be able to iterate though and
> get the full list. Does anyone how I can do that?

FWIW, one thing I have done when storing trees in sql (particularly in
postgres; I don't know if mysql and/or sqlite support this) is have an
attribute "path" which is the colon-separated list of ids of the
parents. The bit that possibly postgres-dependent is that I then added
a constraint that checked that the path is the empty string if parent
is null, and equal to that of the parent plus the id of the parent
plus a colon otherwise (I could've made it happen automagically with a
stored procedure, but I don't like those things).

The nice thing of having the path in there is that most operations on
the tree that would typically involve a traversal are really trivial,
and keeping the path synchronized is not at all hard. For example, to
check if node A is an ascendant of node B:

  B.path.startswith(A.path)

to pull all the descendants of node A from the database:

  Node.objects.filter(path__startswith=A.path)

the ugly thing is that now your database is denormalized, and your
friends that teach Databases at the university will sneer.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: Property overrides

2006-12-12 Thread John Lenton

On 12/12/06, Nathan R. Yergler <[EMAIL PROTECTED]> wrote:
>
> Note that the property built-in takes the "getter" as the first,
> required argument and the "setter" as the optional, second argument.

A nit: none of the arguments of property are required.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: Optimizing Templates

2006-12-07 Thread John Lenton

On 12/7/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Well it's none of that. The template process time is literally
> 150-500ms using the profiling stuff...

me myself, I'd split that huge template into a hierarchy, and profile
each chunk separately. That might give you a better clue as to what is
wrong...

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: Re: Suggestion: Aggregate/Grouping/Calculated methods in Django ORM

2006-12-04 Thread John Lenton

On 12/1/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> One way to think about the problem is to consider how you would write
> the documentation for it. "Django implements an object based SQL
> wrapper... except for the aggregations stuff, which you will need to
> know SQL to use properly". If the documentation sounds like it will be
> ugly, so is the implementation :-)
>
> So; lots to think about, but don't let that discourage you. As this
> thread has shown, there is plenty of interest in having aggregates -
> the discussion will probably be long, but if we can get something
> productive out of it, Django will be all the better for it.

Me myself, I think that the "group by" functionality isn't a problem;
if you look at how itertools.groupby works, it would be both easy and
natural (ie pythonic) to give querysets a groupby function with
similar semantics and laziness.

The "max", "min" and other such functions might be a little more
problematic, unless groupby returned, rather than a generic iterator,
a special "queryset group" and give _it_ the max/min/etc methods. This
way it would be clear that max() returns a tuple (value, queryset) (to
me, at least...). Also, ...groupby('foo').max() would return the same
result as max(...groupby('foo')), but less efficiently.

Talking through my hat?

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: [patch] Generating slug for words with accents

2006-11-16 Thread John Lenton

On 11/16/06, Aidas Bendoraitis <[EMAIL PROTECTED]> wrote:
> German ß should be translated to ss
> ä to ae
> ö to oe
> ü to ue

but «ü» in Spanish should be just «u» (as in pingüino -> pinguino).

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
 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?hl=en
-~--~~~~--~~--~--~---



Re: directed graph in default admin

2006-10-27 Thread John Lenton

On 10/27/06, Waylan Limberg <[EMAIL PROTECTED]> wrote:
>
> I couldn't help but notice that in your example, it is also sorted by
> Sink *descending*. What happens if you click on "Sink" again? If I'm
> not mistaken, it should sort *ascending*. Then again, this just may be
> a coincidence of a poorly written example in which case you can ignore
> me.

sorry, just a poor example. The real table has rather long names and
over 15k entries, so I can't exactly paste it here.

Well, I just copy and paste the first few rows... yeah. Here goes:

when it first comes up, it starts like this:



 Source   Sink
 ALDENE 13 KV SK NUG   AECO
 ELRAMA 13 KV UNIT1HREA - AP
 ALDENE 13 KV SK NUG   APS
MITCHELL 24 KV GEN 3   DUQ
 ALDENE 13 KV SK NUG   BGE


then I click on Source, and I get


  Source   Sink
ALDENE 13 KV SK NUG  WILLIAMSPORT - AP
ALDENE 13 KV SK NUG  WESTERN HUB
ALDENE 13 KV SK NUG  WEST INT HUB
ALDENE 13 KV SK NUG  WELLSBORO


and I click on Sink, and get

  Source   Sink
ALDENE 13 KV SK NUG  WILLIAMSPORT - AP
ALDENE 13 KV SK NUG  WESTERN HUB
ALDENE 13 KV SK NUG  WEST INT HUB
ALDENE 13 KV SK NUG  WELLSBORO


which is exactly the same as the previous one, if you look :(
-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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: directed graph in default admin

2006-10-26 Thread John Lenton

On 10/26/06, Guillermo Fernandez Castellanos
<[EMAIL PROTECTED]> wrote:
>
> Cheers,
>
> have a look at the Meta options order_with_respect_to and ordering:
> http://www.djangoproject.com/documentation/model_api/#order-with-respect-to

no, that's not it. Or I didn't understand how to use it; at any rate,
it didn't work. Let me explain a little better the situation: Here is
the admin screen as it comes up:

Source | Sink
 Cnode | Bnode
 Anode | Cnode
 Xnode | Anode
 Mnode | Anode

if you click on "Source", it sorts by the source's name, as expected:

Source v | Sink
 Anode   | Cnode
 Cnode   | Bnode
 Mnode   | Anode
 Xnode   | Anode

this is as expected; but if you click on "Sink", you get

Source | Sink v
 Anode | Cnode
 Cnode | Bnode
 Mnode | Anode
 Xnode | Anode

i.e., it still sorts by Source instead of Sink. Is this a bug in
django, or am I forgetting something?

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



directed graph in default admin

2006-10-24 Thread John Lenton

Hi all.
I've got an app where I have a table of nodes, and a table of directed
edges between those nodes. I.e,

-8<--
class Node(models.Model):
name = models.CharField(maxlength=20, core=True, blank=False)
def __str__(self):
return self.name

class Admin:
pass

class Path(models.Model):
source = models.ForeignKey(Node, core=True, related_name='source_set')
sink = models.ForeignKey(Node, core=True, related_name='sink_set')

def __str__(self):
return "from %s to %s" % (self.source, self.sink)

class Admin:
list_display = ['source', 'sink']
-->8-

that works very nicely. Or does it? The link on the sink column in the
admin interface sorts by source :(

What am I missing? Oh, python2.4, django from svn, linux.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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: Batch record processing

2006-07-27 Thread John Lenton

On 7/27/06, Joe <[EMAIL PROTECTED]> wrote:
>
> You could just strip the path out and get the filename when you extract
> the file from the database.  Something like:
>
> def get_file_without_path(self):
> start=self.file.rfind('/')
>
> return self.file[start+1:]

umm.. os.path.basename() would probably be better than assuming '/'
(or anything else) is the path delimiter, no?

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---