Re: django 1.1 performance versus django 1.2 performance

2011-04-25 Thread Peter Portante
But what changed in 1.2 vs. 1.1 that caused cloning to become slower? Is it
fixes for correctness that were missing?

And if 1.3 is slower than 1.2, why the slow down there?

If the slowness is for a good reason (correctness is about the only one I
can think of that is really valid), then fine. But if the slowdown is just
because it is slower and no one knows why, let's add a performance test for
cloning and make sure Django does not slow down (yeah, this is a hand wave
as performance is a tough thing to maintain, but well worth the effort).

Also, just simply creating a DB object is slower with get_or_create. See
attached script that I used to harp on 1.1 vs. 1.2.5 (slightly modified to
change the names, etc. and requires a proper django view to work). I ran
this against both sqlite and mysql.

-peter


On Mon, Apr 25, 2011 at 9:36 PM, Alexander Schepanovski
wrote:

> > Is there a way to identify which queries use cloning?
>
> Every filter, exclude, order_by, select_related and some other calls
> clones it. Slicing too.
>
> > Is there a way rewrite those queries to avoid cloning overhead?
>
> You can rewrite
> qs.filter(a=1).exclude(b=2) as qs.filter(Q(a=1) & !Q(b=2))
> or
> qs = qs.filter(a=1); ...; qs = qs.filter(b=2) as q = {}; q['a'] =
> 1; ...; q['b'] = 2; qs = qs.filter(**q)
>
> But you can't avoid several cloning procs for queryset not modifying
> django or monkey patching.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



pound.py
Description: Binary data


Re: django 1.1 performance versus django 1.2 performance

2011-04-25 Thread Alexander Schepanovski
> Is there a way to identify which queries use cloning?

Every filter, exclude, order_by, select_related and some other calls
clones it. Slicing too.

> Is there a way rewrite those queries to avoid cloning overhead?

You can rewrite
qs.filter(a=1).exclude(b=2) as qs.filter(Q(a=1) & !Q(b=2))
or
qs = qs.filter(a=1); ...; qs = qs.filter(b=2) as q = {}; q['a'] =
1; ...; q['b'] = 2; qs = qs.filter(**q)

But you can't avoid several cloning procs for queryset not modifying
django or monkey patching.

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



Re: Dynamically form modification - Is this possible?

2011-04-25 Thread Shawn Milochik
There are two pieces to this.

1. The Django form.

2. Whatever comes back in your HTML form's POST.

Your Django form will have zero or more fields in it. Your HTML form
will POST back those fields (if any) and possibly new ones. Your
Django form's __init__ will read the 'data' keyword argument passed in
from the view. From that data it will add to self.fields any fields
that were originally defined.

Within your HTML page you can either use JavaScript or you can require
one or more page submissions which will present the user with an
increasing number of form fields.

Each time a POST happens, your form's __init__ (if you write the code)
will read from that 'data' argument and dynamically create field
instances and add them to self.fields.

I hope this helps. If not, please ask a specific question. Even
better, post some code and explain where you're getting stuck. If you
want to give a higher-level explanation of what you're trying to
accomplish then maybe someone here will have already done it and be
able to suggest a more elegant solution.

Shawn

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



Re: Need advice on ecommerce app direction

2011-04-25 Thread Russell Keith-Magee
On Tuesday, April 26, 2011, Ernesto Guevara  wrote:
> I find for download "Beginning Django E-Commerce" in webmasterresourceskit 
> site. Look that.

No - don't do that. And don't ever suggest that again.

The site you have referenced is a pirate site, providing illegal
downloads of copyrighted material. Promoting theft of copyrighted
material isn't a practice that the Django project condones. Anyone
making a habit of suggesting copyright theft in this forum will have
their account banned.

Yours,
Russ Magee %-)

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



Re: Dynamically form modification - Is this possible?

2011-04-25 Thread BrendanC
I was hoping to use ajax and a customizable template with the additional 
fields that I'd added dynamically and then somehow update the form class 
with the info required to support form validation (however I'm not sure that 
this approach will work - I can get the initial display to work, but not the 
validation as the form class knows nothing about the additional data 
fields).  This approach would eliminate the need to enable client/browser 
Javascript.

 

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



Using different choices in different ModelAdmins

2011-04-25 Thread Juan Pablo Romero Méndez
Hello,

I'm developing several personalized admin sites (by subclassing
admin.ModelAdmin).

Is it possible to use different Field.choices in a particular field
for each admin site?

The problem is that the choices option is set within the model
definition, not in the ModelAdmin.

Regards,

  Juan Pablo

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



Re: URLs in error messages from form validation

2011-04-25 Thread Daniel Gerzo

On 25.4.2011 18:00, Jason Culverhouse wrote:


You only need to mark the string as safe as in:

http://docs.djangoproject.com/en/1.3/ref/utils/#module-django.utils.safestring

from django.utils.safestring import mark_safe

raise forms.ValidationError(mark_safe('We already have this
filehere'))


This indeed works, thank you very much!

PS: I'm just wondering where did you find this? I was looking around the 
documentation and was unable to get any trace of such a function...


--
Best regards
  Daniel Gerzo

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



Re: Need advice on ecommerce app direction

2011-04-25 Thread Ernesto Guevara
I find for download "Beginning Django E-Commerce" in webmasterresourceskit
site. Look that.

Regards.

2011/4/25 Shant Parseghian 

> Hi all, I'm aware of the choices out there for Django ecommerce apps but im
> confused about which to use. I need a simple shop that will do delivery only
> so no shipping needs to be calculated. I'm thinking that Satchmo will be
> overkill for this. Does anyone have any suggestions?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: {{ STATIC_URL }} and RequestContext()

2011-04-25 Thread Ernesto Guevara
Hello!

You need create a "static" folder in your project and inside in this folder
you create a "css" folder.
I use this configuration and works.

settings.py

import os.path

STATIC_ROOT = ''

# URL prefix for static files.
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'

TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)

And call a css for example, in base.html in this way:



Regards.



2011/4/25 Joakim Hove 

> Hello,
>
> I have just started using the {{ STATIC_URL }} template tag to insert
> proper url's to static resources in my templates. To use this tag I
> need to create the context for rendering as RequestContext() instance,
> which takes the request as a parameter for the initialisation.
>
> In my code I have several methods attached to models which create a
> suitable context for rendering that model instance in a specfied way:
>
> class MyModel( models.Model ):
>
>
>
>def create_xxx_context( self , **kwargs):
> 
>
>def create_yyy_context( self, ,**kwargs):
> 
>
> (Maybe that is a horrific design in the first place ???).
>
>
> Anyway - the methods create_???_context() do not have natural access
> to the request object (and I am reluctant to pass that argument on) -
> so I was wondering if I could achieve exactly the same by just
> "manually" adding the context variable STATIC_URL like:
>
> from django.conf import settings
> 
>
> def view(request, args):
>context = .
>context["STATIC_URL"] = settings.STATIC_URL
>return render_to_response( template , context )
>
> Or is there more magic to the {{ STATIC_URL }} tag when it comes as a
> RequestContext()?
>
>
> Joakim
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Dynamically form modification - Is this possible?

2011-04-25 Thread Shawn Milochik
I was assuming you'd use JavaScript to dynamically add elements to the
DOM during the user experience. How else would you do it?

Shawn

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



Re: Dynamically form modification - Is this possible?

2011-04-25 Thread BrendanC
I'm still not clear on how/whether it is possible to MODIFY the form once 
it's been initially displayed  - the __init__ method is invoked when the 
form is first created/constructed - what  I want to do is rerender/redisplay 
the form with new fields after it's initial display -since the form need's 
to 'self modify'.

Sorry for any confusion here, but I just want to understand/explore all the 
options.

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



Need advice on ecommerce app direction

2011-04-25 Thread Shant Parseghian
Hi all, I'm aware of the choices out there for Django ecommerce apps but im
confused about which to use. I need a simple shop that will do delivery only
so no shipping needs to be calculated. I'm thinking that Satchmo will be
overkill for this. Does anyone have any suggestions?

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



Need a OneToOne form inside another form

2011-04-25 Thread Guevara
Hello!
I have a OneToOne relationship between employee and address, and I
need that form of address appears in the form of employee.
I saw that Django creates a ComboBox address and load all the
addresses of the batabase, what is wrong.
I can not use inline because the OneToOne is in employee class and not
in address.
How can I change this and have a form instead of a combobox?
Regards!

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



{{ STATIC_URL }} and RequestContext()

2011-04-25 Thread Joakim Hove
Hello,

I have just started using the {{ STATIC_URL }} template tag to insert
proper url's to static resources in my templates. To use this tag I
need to create the context for rendering as RequestContext() instance,
which takes the request as a parameter for the initialisation.

In my code I have several methods attached to models which create a
suitable context for rendering that model instance in a specfied way:

class MyModel( models.Model ):



def create_xxx_context( self , **kwargs):
 

def create_yyy_context( self, ,**kwargs):
 

(Maybe that is a horrific design in the first place ???).


Anyway - the methods create_???_context() do not have natural access
to the request object (and I am reluctant to pass that argument on) -
so I was wondering if I could achieve exactly the same by just
"manually" adding the context variable STATIC_URL like:

from django.conf import settings


def view(request, args):
context = .
context["STATIC_URL"] = settings.STATIC_URL
return render_to_response( template , context )

Or is there more magic to the {{ STATIC_URL }} tag when it comes as a
RequestContext()?


Joakim

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



Re: class-based generic views and forms

2011-04-25 Thread lingrlongr
A lifesaver you are!  Thx DR!

On Apr 25, 4:37 pm, Daniel Roseman  wrote:
> On Monday, April 25, 2011 9:16:18 PM UTC+1, lingrlongr wrote:
>
> > I have a view that subclasses uses django.views.generic UpdateView.
> > In my template, I'm trying to access a form field's required
> > property.  For example:
>
> > {% for field in form %}
> >    {{ field.required }}
> > {% endfor %}
>
> > Nothing outputs when the template is rendered.  Does the "required"
> > attribute not get populated when using the class-based UpdateView
> > generic view?  I'm assuming that is correct, just looking for
> > confirmation as to yes, it's supposed to work like that.  Any reason
> > why this would not be an included attribute?
>
> > These documentation for the new class-based views seems very vague
> > ATM.
>
> > Keith
>
> Forms work exactly the same in class-based views as they do in any other
> views. However you're using the form, the `required` attribute is not on the
> `field` object you get when doing `for field in forms`. It is, perhaps
> confusingly, on the field's `field` property, so you need to do {{
> field.field.required }}.
> --
> DR.

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



Re: django and fastcgi losing some info in request data

2011-04-25 Thread xiao_haozi
I could just manually check and add it before working with the model
like:
stump_split = list(this_stump.partition(":"))
if stump_split[1] and not stump_split[2].startswith("//"):
stump_split[2] = "/"+stump_split[2]
this_stump = ''.join(stump_split)

but that's kinda meh and still doesn't get to why it's happening.

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



Re: class-based generic views and forms

2011-04-25 Thread Daniel Roseman
On Monday, April 25, 2011 9:16:18 PM UTC+1, lingrlongr wrote:
>
> I have a view that subclasses uses django.views.generic UpdateView. 
> In my template, I'm trying to access a form field's required 
> property.  For example: 
>
> {% for field in form %} 
>{{ field.required }} 
> {% endfor %} 
>
> Nothing outputs when the template is rendered.  Does the "required" 
> attribute not get populated when using the class-based UpdateView 
> generic view?  I'm assuming that is correct, just looking for 
> confirmation as to yes, it's supposed to work like that.  Any reason 
> why this would not be an included attribute? 
>
> These documentation for the new class-based views seems very vague 
> ATM. 
>
> Keith


Forms work exactly the same in class-based views as they do in any other 
views. However you're using the form, the `required` attribute is not on the 
`field` object you get when doing `for field in forms`. It is, perhaps 
confusingly, on the field's `field` property, so you need to do {{ 
field.field.required }}.
--
DR.

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



class-based generic views and forms

2011-04-25 Thread lingrlongr
I have a view that subclasses uses django.views.generic UpdateView.
In my template, I'm trying to access a form field's required
property.  For example:

{% for field in form %}
   {{ field.required }}
{% endfor %}

Nothing outputs when the template is rendered.  Does the "required"
attribute not get populated when using the class-based UpdateView
generic view?  I'm assuming that is correct, just looking for
confirmation as to yes, it's supposed to work like that.  Any reason
why this would not be an included attribute?

These documentation for the new class-based views seems very vague
ATM.

Keith

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



django and fastcgi losing some info in request data

2011-04-25 Thread xiao_haozi
Hi all-

I have a problem that is driving me to the brink of insanity.

I'll preface this with the fact that running the built-in server
everything works fine. I encounter this issue running it via fastcgi
and lighttpd.
I will paste in all relevant info at the bottom.

In short, the workflow scheme is like this:

-take a url and encode it say like this: http%3A%2F%2Fgoogle.com/
-send it to django via url/http%3A%2F%2Fgoogle.com/
-urls.py reads in that and sends anything after url/ to a view
-this view handles the url and does some things with it for the
database model

running with the built-in server i can return and httpresponse with my
request data and get the proper:
http://google.com
but running with fastcgi i get:
http:/google.com

this breaks lots of code for me.

I can't figure out what is going on that it's getting stripped of one
of the / (or %2F).

Here is all the relevant information I could think of.

=
=> the attempted url:
http://__myDOMAIN/url/http%3A%2F%2Fgoogle.com/

=
=> expect (and receive when running built-in)
http://google.com

=
=> get when running via fastcgi
http:/google.com

=
=> urls.py part:
url(r'^url/(?P\S+)/$', 'shortener.views.submit'),

=
=> lighttpd accesslog info:
"GET /url/http%3A%2F%2F%2Fgoogle.com/ HTTP/1.1" 200 120 "-"

=
=> view part:
def submit(request,stump):
stump_clean = bleach.clean(stump)
this_stump = smart_str(stump_clean)
return HttpResponse("%s %s %s " % (stump,stump_clean,this_stump))

=
=> view httpresponse:
 http:/google.com http:/google.com http:/google.com

=
=> lighty stanza:
$HTTP["host"] =~ "__myDOMAIN__" {
  server.document-root = "/home/blahblah/Stumpy/"
  fastcgi.server = ( ".fcgi" =>
 ( "localhost" => (
 "socket" => "/var/lib/lighttpd/stumpy-fastcgi.socket",
 "bin-path" => "/home/blahblah/Stumpy/
stumpy.fcgi",
 "check-local" => "disable",
 "min-procs" => 2,
 "max-procs" => 4,
   )
 ),
   )
  alias.url = ( "/static/admin"  => "/home/blahblah/django/contrib/
admin/media/" )
  url.rewrite-once = ( "^(/static/.*)$" => "$1",
   "^/favicon\.ico$" => "/static/favicon.ico",
   "^(/.*)$" => "/stumpy.fcgi$1" )
}

=
=> fcgi script:
#!/usr/bin/env python
import sys, os

sys.path.insert(0, "..")

os.environ['PYTHON_EGG_CACHE'] = "/tmp/"

os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])



Again, I don't have any problems if i run via "python manage.py
runserver" and use the built-in.
I only have this stripping problem via the fastcgi method.

Any help would be miraculous. I've been yanking hair out over this for
a while!
Thanks so much in advance for any input!

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



Re: How do I decode a string that it is received by a filter ???

2011-04-25 Thread Rafael Durán Castañeda

On 25/04/11 20:40, Ariel wrote:

The site is deploy in an apache server, that does not help.
Do you have any other idea ???
I thought this would be very easy to solve.

I'd thanks any help.
Regards
Ariel


On Mon, Apr 25, 2011 at 6:21 PM, Oleg Lomaka > wrote:


Not sure if it helps in your case, but try to start django in
UTF-8 locale. For example,

LANG=en_US.UTF-8 ./manage.py runserver


On Mon, Apr 25, 2011 at 6:23 PM, Ariel > wrote:

I have the following problem, I have made a template filter
that process a string, but when the string that is passed to
the filter has a non-ascii character then I received that
string in the filter codified, how can I decode the string ???

For instance: in the template html I have the following code:

{{object.name |tag_process}}

But the name = "español" , the character ñ'' it is pass to the
tag_process filter as C3%B1, then the string I received in the
tag_process function is espaC3%B1ol instead of 'español', How
can I solved that ???

-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.
I'm quite new on django, but I think you could tray to escape that 
string, of course you shouldn't do it if you can trust that string.


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



Re: django 1.1 performance versus django 1.2 performance

2011-04-25 Thread ydjango
Is there a way to identify which queries use cloning?

Is there a way rewrite those queries to avoid cloning overhead?

(If many of the queries use cloning then  migrating one of my django
apps to 1.2.x may not be right for me.)

On Apr 25, 9:39 am, djeff  wrote:
> Russ,
>
> Thanks for the response.  You have confirmed what I'm seeing in the profile
> dump.  The cloning of a queryset is expensive and it is more expensive in
> 1.2 than with 1.1.  I really appreciate the feedback.  
>
> Jeff Fischer

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



Work around restarting server on image uploads?

2011-04-25 Thread neridaj
Hello,

Is there a way to get uploaded images to render without having to
restart the server? Whenever I add a new image via the admin interface
I have to restart apache in order for the images to render.

Thanks,

Jason

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



Re: How do I decode a string that it is received by a filter ???

2011-04-25 Thread Ariel
The site is deploy in an apache server, that does not help.
Do you have any other idea ???
I thought this would be very easy to solve.

I'd thanks any help.
Regards
Ariel


On Mon, Apr 25, 2011 at 6:21 PM, Oleg Lomaka  wrote:

> Not sure if it helps in your case, but try to start django in UTF-8 locale.
> For example,
>
> LANG=en_US.UTF-8 ./manage.py runserver
>
>
> On Mon, Apr 25, 2011 at 6:23 PM, Ariel  wrote:
>
>> I have the following problem, I have made a template filter that process a
>> string, but when the string that is passed to the filter has a non-ascii
>> character then I received that string in the filter codified, how can I
>> decode the string ???
>>
>> For instance: in the template html I have the following code:
>>
>> {{object.name|tag_process}}
>>
>> But the name = "español" , the character ñ'' it is pass to the tag_process
>> filter as C3%B1, then the string I received in the tag_process function is
>> espaC3%B1ol instead of 'español', How can I solved that ???
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Interesting race condition in Django views with decorators (fix included)

2011-04-25 Thread Cal Leeming [Simplicity Media Ltd]
So, here's an interesting race condition, which causes request bleeding to
happen.

If you use a decorator on a view method, where the decorator is a class, the
class isn't created per request, it seems to stay the same throughout. So,
if you define any logic within this class, which depends on 'instance'
attributes or methods (i.e. self.*), then you will experience this problem.

The way we got around this, was to seperate our own logic into a different
class, and create a new instance of this class (per request) within the
__call__() method.

It's *very* difficult to spot this problem happening, and it's only because
our logic contained so many access control routines and safety checks, that
we received a debug email telling us something wasn't right.

*Works: *

class MembersAreaLogic:
def init():
return HttpResponse("Hit init()")

class MembersArea:
def __init__(self, orig_func):
self.orig_func = orig_func

def __call__(self, request, *args, **kwargs):
# Create new members area logic instance
ma = MembersAreaLogic(request)

# Perform the logic initialisation
_r = ma.init(*args, **kwargs)

# The logic init() will only ever return a response if it wishes to
# stop you from continuing to the actual view.
if _r:
return _r

# Execute the original view
return self.orig_func(request, ma, *args, **kwargs)

@MembersArea
def upgrade(request, ma, doorway, *args, **kwargs):
return HttpResponse("Hit View")

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



Re: Dynamically form modification - Is this possible?

2011-04-25 Thread Shawn Milochik
If your __init__ method of the form reads the contents of the data
kwarg and adds to self.fields then you can validate the additional
fields.

If your form has a prefix you have to ensure that the dynamic fields
that get passed in the POST also have the same prefix.

However, this allows an attacker to arbitrarily add anything they want
to their POST to see what happens. You probably know this, but be
mindful of that when writing your validation and save() code.

Shawn

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



Dynamically form modification - Is this possible?

2011-04-25 Thread BrendanC
Is there away to dynamically modify and validate a Django form AFTER it's 
been created and displayed. I have a form where I want to display and 
validate additional input fields based on the selection from a dropdown on 
the initial form.

(I have found a few snippets that show dynamic form creation, but these 
require that the dynamic fields are known/defined prior to creating the 
form.) 

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



Re: Checking for user type in view

2011-04-25 Thread Shawn Milochik
You can use a user profile for a lot more, and there's no reason the
two roles have to be mutually exclusive when you're creating your own
class.

I just wanted to make that point. I have never used the built-in
groups myself, but from your explanation it seems like a good solution
for the original problem.

Shawn

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



Outputting plain/text with class-based views

2011-04-25 Thread Federico Maggi
Hello,
I need a view to return plain/text and I came up with the following code:

from django import http
from django.views.generic.base import TemplateResponseMixin
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView

from django.conf import settings

class PlainTextResponseMixin(TemplateResponseMixin):
def render_to_response(self, context):
return super(PlainTextResponseMixin, self).render_to_response(
context,
content_type='plain/text; charset=%s' % settings.DEFAULT_CHARSET)

class PlainTextListView(PlainTextResponseMixin, ListView):
pass

class PlainTextDetailView(PlainTextResponseMixin, DetailView):
pass

meant to be used as follows (for example):

url(r'^v/(?P[-\w]+)\.bib$',
cache_page(PlainTextDetailView.as_view(
model=Publication,
template_name='academic/publication_detail.bib')),
name='academic_publishing_publication_detail_bibtex'),

Questions:
1) If I don't add `charset=%s' % settings.DEFAULT_CHARSET` the default
charset is not honored. Why?
2) could I do better or with less code? For instance, with
function-based views, all I had to do is pass a `{'mimetype':
'text/plain'}` kwarg to `object_list`

Thanks.
-F

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



Re: django 1.1 performance versus django 1.2 performance

2011-04-25 Thread djeff
Russ,

Thanks for the response.  You have confirmed what I'm seeing in the profile 
dump.  The cloning of a queryset is expensive and it is more expensive in 
1.2 than with 1.1.  I really appreciate the feedback.  

Jeff Fischer

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



sorl thumbnails

2011-04-25 Thread xeed
hi,

i used sorl thumbnails to implement thumbnail in my projects, i follow
the instructions but my image doest appear,

i open my source web page and the link doesnt exist

like this
u:\python27\lib\site-packages\django\contrib\admin\media\cache
\53\2a\532a8f7367b735d8f4b20064e9c2525d.jpg does not exist

what my error

thks for your help

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



Re: How do I decode a string that it is received by a filter ???

2011-04-25 Thread Oleg Lomaka
Not sure if it helps in your case, but try to start django in UTF-8 locale.
For example,

LANG=en_US.UTF-8 ./manage.py runserver

On Mon, Apr 25, 2011 at 6:23 PM, Ariel  wrote:

> I have the following problem, I have made a template filter that process a
> string, but when the string that is passed to the filter has a non-ascii
> character then I received that string in the filter codified, how can I
> decode the string ???
>
> For instance: in the template html I have the following code:
>
> {{object.name|tag_process}}
>
> But the name = "español" , the character ñ'' it is pass to the tag_process
> filter as C3%B1, then the string I received in the tag_process function is
> espaC3%B1ol instead of 'español', How can I solved that ???
>
>

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



Re: URLs in error messages from form validation

2011-04-25 Thread Jason Culverhouse

On Apr 25, 2011, at 5:39 AM, Kane Dou wrote:

> * Daniel Gerzo  [2011-04-25 13:07:46 +0200]:
> 
>> On 25.4.2011 12:40, Kane Dou wrote:
>>> * Daniel Gerzo  [2011-04-24 17:52:13 +0200]:
>>> 
 Hello all,
 
 say I have a following form:
 
 class MyForm(forms.Form):
id = forms.IntegerField(max_length=9)
language = forms.CharField(max_length=10)
file = forms.FileField()
 
 And a following pseudo clean method:
 
def clean(self):
for file in self.files.values():
if file_exists(file):
raise forms.ValidationError('We already have this
 filehere')
return self.cleaned_data

 
 So I want to display a URL in the error message. The text is
 displayed fine, but the URL is being escaped by Django and thus is
 not clickable. Is there some way to disable it for this specific
 case?

You only need to mark the string as safe as in:

http://docs.djangoproject.com/en/1.3/ref/utils/#module-django.utils.safestring

from django.utils.safestring import mark_safe

raise forms.ValidationError(mark_safe('We already have this
filehere'))

Jason

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



How do I decode a string that it is received by a filter ???

2011-04-25 Thread Ariel
I have the following problem, I have made a template filter that process a
string, but when the string that is passed to the filter has a non-ascii
character then I received that string in the filter codified, how can I
decode the string ???

For instance: in the template html I have the following code:

{{object.name|tag_process}}

But the name = "español" , the character ñ'' it is pass to the tag_process
filter as C3%B1, then the string I received in the tag_process function is
espaC3%B1ol instead of 'español', How can I solved that ???

Please I need you help.
Regards
Ariel

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



Re: Problems with running Hello world app, urls.py probably ignored

2011-04-25 Thread Jacob
> ROOT_URLCONF = 'emil.urls'

What's "emil"? It needs to be projectname.urls. So probably
"john.urls".

--Jacob

On Apr 23, 2:57 pm, Honza Javorek  wrote:
> Hello guys,
>
> I have searched to solve this for a whole evening without any results.
> I have read all known "my first app in django" tutorials, but my test
> app just isn't working.
>
> I have project called "john". In it's directory I have app package
> "dashboard" containing init, models, tests and views. Moreover, in
> project directory "john" are init, manage, settings and urls files. My
> urls.py:
>
> from django.conf.urls.defaults import patterns, include, url
> urlpatterns = patterns('john',
>     (r'^$', 'dashboard.views.hello'),
>     (r'^hello/$', 'dashboard.views.hello'),
> )
>
> My dashboard/views.py:
>
> from datetime import datetime
> from django.http import HttpResponse
> def hello(request):
>     return HttpResponse(datetime.now().strftime('%H:%M:%S'))
>
> My settings.py (not complete, I copied only apparently important
> parts):
>
> ROOT_URLCONF = 'emil.urls'
> INSTALLED_APPS = (
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     'django.contrib.sessions',
>     'django.contrib.sites',
>     'django.contrib.messages',
>     'django.contrib.staticfiles',
> )
>
> Now what is the problem. If I go to my "john" directory and I launch
> server, it looks like this:
>
> .../john$ python manage.py runserver
> Validating models...
> 0 errors found
> Django version 1.3, using settings 'john.settings'
> Development server is running athttp://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> [23/Apr/2011 14:40:31] "GET / HTTP/1.1" 200 2047
> [23/Apr/2011 14:40:38] "GET / HTTP/1.1" 200 2047
>
> but if I go to the browser and I 
> typehttp://127.0.0.1:8000/orhttp://127.0.0.1:8000/hello, it shows me Django 
> welcome screen (It
> worked! ... you haven't configured any URLs.). According to it's text
> I assume it completely ignores what I have configured in urls.py. I
> can't get over this screen, I haven't seen any 404 yet or anything
> else. Welcome screen is the most far place I managed to get in half of
> a day spent with Django :(
>
> Thanks for any help,
>
> Honza Javorek

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



Re: Ajax headers not work in all browsers?

2011-04-25 Thread Carl Nobile
>From your header it looks like HTML and XML are the only things that
will get parsed correctly. You haven't mentioned what type of
container your data is in. If it's XML then it should be working if
it's JSON it will not work on Firefox and other browsers. the Accept
header should have in it application/json to be industry compliant,
but then IE will break because no version of IE so far is industry
compliant. IFRAMEs will be your only solution to be cross browser
compliant.

The client will also need to send the proper mimetype for the server
to get it right.

~Carl

On Apr 24, 9:25 pm, Daniel França  wrote:
> Here's the header in request as seen from Firebug:
> Request Headers
> Hostlocalhost:8000User-Agent Mozilla/5.0 (X11; Linux i686 on x86_64; rv:2.0)
> Gecko/20100101 Firefox/4.0Accept
> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
> Accept-Language en-us,en;q=0.5Accept-Encodinggzip, deflate Accept-Charset
> ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive115Connection 
> keep-aliveRefererhttp://localhost:8000/home2
> Cookie__utma=111872281.1574255346.1303689518.1303691822.1303693660.3;
> __utmc=111872281;
> __utmz=111872281.1303689518.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
> sessionid=498174cb74222f0570fead661c787935; __utmb=111872281.5.10.1303693660
> 2011/4/24 Daniel França 
>
> > There are some django middleware classes to test the browser compatibility,
> > can it be a problem?
>
> > There's no cross domain call, it's all about my domain =/
> > It's necessary to set the mimetype in a get/load method?
> > What else information can I post here to help?
>
> > On Sun, Apr 24, 2011 at 2:44 AM, Masklinn  wrote:
>
> >> On 24 avr. 2011, at 04:38, Daniel França  wrote:
>
> >> Hi all,
> >> I was using JQuery to retrieve some data using AJAX and Django...
> >> at my django view code I wrote a verification to check if it's an ajax
> >> request:
> >> *if request.is_ajax():*
> >> *   #Ajax handler*
> >> *else:*
> >> *  #Not Ajax handler*
>
> >> and do the properly handler, and here's my Jquery script:
> >> $('#id_show_updates').load("/profiles/get_updates/"+
> >> document.getElementById('last_update').innerHTML);
>
> >> It's working like a charm in Chrome and Opera... but at Firefox django
> >> thinks it's not Ajax and  =/ Anyone know someway to solve that?
>
> >> Best Regards,
> >> Daniel França
>
> >> Would you per chance have some kind of redirection (any redirection) per
> >> chance?
>
> >> Firefox will not forward any explicitly set header (including Ajax ones)
> >> across redirections.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.
>
>

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



Django 1.2 Dropped Sessions when single view contains registration and login authentication

2011-04-25 Thread benp
Hi,

This issue has been raised on Stack Overflow many times without any
resolution.  The gist is that all of the views in my site are
protected by the @login_required decorator except for a splash page
and  a registration page (which is only accessible by going through
the splash page and passing a test which sets session data).

At my registration page, I register a user based on my custom
UserCreationForm and then authenticate and login this user.  For some
users, this works as it should.  For others though, there is a nasty
bug.  After they register/login, they are redirected to my homepage as
an authenticated User.  However, the next request that they send to my
site is interpreted as an Anonymous User.  They are redirected to my
splash page where they have to login in again.  Once they login, they
are fine to move around the site.

I've seen other Django developers have the same exact issue with
registering and logging in a user in the same view.  There hasn't been
a satisfactory answer yet, though I've seen it suggested that it could
be related to MySQL timeouts or threading issues.

Any thoughts on what could be the cause of this?  I can't reproduce
the error on my computer, so it's really hard to debug/log.  POSSIBLE
SOLUTION: I'm thinking about registering the user and setting session
variables in the register view and then redirecting to the login view,
where I'll read the session variables.  That seems somewhat insecure,
except for the fact that both register and login are handled through
Https. I'm not sure that that strategy will even work.

Thanks for any help!

Ben

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



Block of the previous fields inline

2011-04-25 Thread jonas peters
hi,

I have a question, have an administration that uses the User will
inlines where adding elements as needed, but when it records the edit
inlines earlier blocked a kind "readolnly" and he just can not add new
and edit earlier.

Sorry for my english.

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



Re: Extremely Frustrated

2011-04-25 Thread Gandeida
Hi Ogi,

It turned out that I had some tab characters in my code that I
inadvertently added when I copied and pasted.  I've changed my editor
settings to use spaces instead of tabs, and all is working now.  Thank
you for offering to help!

Regards,
Gandeida

On Apr 22, 6:04 am, Ogi Vranesic  wrote:
> Could You also send us the definition of Book class?
> Ogi
>
> On Donnerstag 21 April 2011 10:00:17 pm you wrote:
>
>
>
> > Hello,
>
> > I have been working through the Django Book, and I keep getting syntax
> > errors in the examples in Chapter 6.
>
> > The following example works:
>
> > class BookAdmin(admin.ModelAdmin):
> >     list_display = ('title', 'publisher', 'publication_date')
> >     list_filter = ('publication_date',)
> >     date_hierarchy = 'publication_date'
> >     ordering = ('-publication_date',)
> >     fields = ('title', 'authors', 'publisher', 'publication_date')
>
> > The next one, however, does not - it throws a syntax error:
>
> > class BookAdmin(admin.ModelAdmin):
> >     list_display = ('title', 'publisher', 'publication_date')
> >     list_filter = ('publication_date',)
> >     date_hierarchy = 'publication_date'
> >     ordering = ('-publication_date',)
> >     fields = ('title', 'authors', 'publisher')
>
> > Nor can I add fields back in to this example or I get a syntax error:
>
> > class BookAdmin(admin.ModelAdmin):
> >     list_display = ('title', 'publisher', 'publication_date')
> >     list_filter = ('publication_date',)
> >     date_hierarchy = 'publication_date'
> >     ordering = ('-publication_date',)
> >     filter_horizontal = ('authors',)
> >     (would like to still define fields, but throws a syntax error)
>
> > Same with this one:
>
> > class BookAdmin(admin.ModelAdmin):
> >     list_display = ('title', 'publisher', 'publication_date')
> >     list_filter = ('publication_date',)
> >     date_hierarchy = 'publication_date'
> >     ordering = ('-publication_date',)
> >     filter_horizontal = ('authors',)
> >     raw_id_fields = ('publisher',)
> >     (would like to still define fields, but throws a syntax error)
>
> > Could someone please show me how to include "fields = ('title',
> > 'authors', 'publisher')" without getting an error?
>
> > Thanks,
> >Gandeida- Hide quoted text -
>
> - Show quoted text -

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



Re: Extremely Frustrated

2011-04-25 Thread Gandeida
Hello,

I am running version 1.3.

After copying and pasting about 20 more times, but getting the error
sporadically, I have found that the issue was the tab characters that
were being automatically generated to keep my indentation level.  I've
changed it to use spaces instead.  Thank you for offering to help,
though!  I just figured it out by accident :-)

Regards,
Gandeida

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



Re: URLs in error messages from form validation

2011-04-25 Thread Kane Dou
* Daniel Gerzo  [2011-04-25 13:07:46 +0200]:

> On 25.4.2011 12:40, Kane Dou wrote:
> >* Daniel Gerzo  [2011-04-24 17:52:13 +0200]:
> >
> >>Hello all,
> >>
> >>say I have a following form:
> >>
> >>class MyForm(forms.Form):
> >> id = forms.IntegerField(max_length=9)
> >> language = forms.CharField(max_length=10)
> >> file = forms.FileField()
> >>
> >>And a following pseudo clean method:
> >>
> >> def clean(self):
> >> for file in self.files.values():
> >> if file_exists(file):
> >> raise forms.ValidationError('We already have this
> >>filehere')
> >> return self.cleaned_data
> >>
> >>So I want to display a URL in the error message. The text is
> >>displayed fine, but the URL is being escaped by Django and thus is
> >>not clickable. Is there some way to disable it for this specific
> >>case?
> >>
> >>The form is being rendered like:
> >>
> >>  >>id="upload">{% csrf_token %}
> >> 
> >> {{ form.as_table }}
> >>  >>/>
> >> 
> >> 
>
> >
> >You may check the 'safe'[1] filter
> >
> >
> >[1]  http://docs.djangoproject.com/en/1.3/ref/templates/builtins/#safe
>
> Hello Kane,
>
> thanks for your reply. I already tried |safe previously, as
>
> {{ form.as_table|safe }}
>
> but that doesn't work, the hyperlink is still being escaped. Maybe I
> need to do something else in this case?
>
> I even tried:
>
> {% autoescape off %}
> {{ form.as_table }}
> {% endautoescape %}
>
> Doesn't work either. Maybe the validation errors are being escaped
> prior they being passed to the template itself? How can I turn that
> off?
>
> Thanks.
>

Try to render the form in separate parts:

{{ form..label }}
{{ form..errors|safe }}
{{ form. }}

This works, but I'm not sure if this is a good or right practice.

--
Kane

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



Re: [Share] Protected web APIs (short and simple)

2011-04-25 Thread Subhranath Chunder
Updated this with a django helper (decorator) to make it work without any
view code changes at the receiving end.


On Fri, Apr 22, 2011 at 4:52 PM, Subhranath Chunder wrote:

> Hi,
>
> I've created a small and simple Python helper module to have protected web
> APIs in Django or other python projects, using a secret key string.
> It's using HMAC MD5.
>
> The main concept is of Facebook 'signed_request'.
>
> For details: https://github.com/subhranath/python-web-api-auth-helper
>
> Thanks,
> Subhranath Chunder.
>

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



Re: URLs in error messages from form validation

2011-04-25 Thread Daniel Gerzo

On 25.4.2011 12:40, Kane Dou wrote:

* Daniel Gerzo  [2011-04-24 17:52:13 +0200]:


Hello all,

say I have a following form:

class MyForm(forms.Form):
 id = forms.IntegerField(max_length=9)
 language = forms.CharField(max_length=10)
 file = forms.FileField()

And a following pseudo clean method:

 def clean(self):
 for file in self.files.values():
 if file_exists(file):
 raise forms.ValidationError('We already have this
filehere')
 return self.cleaned_data

So I want to display a URL in the error message. The text is
displayed fine, but the URL is being escaped by Django and thus is
not clickable. Is there some way to disable it for this specific
case?

The form is being rendered like:

 {% csrf_token %}
 
 {{ form.as_table }}
 
 
 




You may check the 'safe'[1] filter


[1]  http://docs.djangoproject.com/en/1.3/ref/templates/builtins/#safe


Hello Kane,

thanks for your reply. I already tried |safe previously, as

{{ form.as_table|safe }}

but that doesn't work, the hyperlink is still being escaped. Maybe I 
need to do something else in this case?


I even tried:

{% autoescape off %}
{{ form.as_table }}
{% endautoescape %}

Doesn't work either. Maybe the validation errors are being escaped prior 
they being passed to the template itself? How can I turn that off?


Thanks.

--
Kind regards
  Daniel Gerzo

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



Re: URLs in error messages from form validation

2011-04-25 Thread Kane Dou
* Daniel Gerzo  [2011-04-24 17:52:13 +0200]:

> Hello all,
>
> say I have a following form:
>
> class MyForm(forms.Form):
> id = forms.IntegerField(max_length=9)
> language = forms.CharField(max_length=10)
> file = forms.FileField()
>
> And a following pseudo clean method:
>
> def clean(self):
> for file in self.files.values():
> if file_exists(file):
> raise forms.ValidationError('We already have this
> file  here')
> return self.cleaned_data
>
> So I want to display a URL in the error message. The text is
> displayed fine, but the URL is being escaped by Django and thus is
> not clickable. Is there some way to disable it for this specific
> case?
>
> The form is being rendered like:
>
>  id="upload">{% csrf_token %}
> 
> {{ form.as_table }}
>  />
> 
> 
>
> Thanks.
>
> --
> Kind regards
>   Daniel Gerzo
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>

You may check the 'safe'[1] filter


[1]  http://docs.djangoproject.com/en/1.3/ref/templates/builtins/#safe

--
Kane

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