Re: template: writing "\u20ac 20.000" fails

2009-01-29 Thread SanPy

Well, I thought it didn't escape the input string. I was wrong. I
tried `escape_js` again and now it works just fine. It probably did
before, but I don't remember why I thought it didn't.

Regards,
Sander

On 28 jan, 04:28, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:
> On Tue, 2009-01-27 at 00:37 -0800, SanPy wrote:
> > Thanks a lot, Malcolm,
>
> > You got me on the right track, I just needed to escape the string,
> > like this:
>
> > var prices=[{% for price in prices %}[{{ price.0 }}, '{{ price.1|
> > escape }}']{% if not forloop.last %},{% endif %}{% endfor %}];
>
> > I tried the `escapejs` filter. That didn't work.
>
> What does "didn't work" mean? It raised an error? Your computer caught
> on fire?
>
> The "escapejs" filter isn't broken and works quite well. The "escape"
> filter does HTML-aware escaping, not Javascript-aware escaping. They are
> different, so using the "escape" (of "force_escape") filter for data
> intended for Javascript will lead to incorrect results.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template: writing "\u20ac 20.000" fails

2009-01-27 Thread SanPy

Thanks a lot, Malcolm,

You got me on the right track, I just needed to escape the string,
like this:

var prices=[{% for price in prices %}[{{ price.0 }}, '{{ price.1|
escape }}']{% if not forloop.last %},{% endif %}{% endfor %}];

I tried the `escapejs` filter. That didn't work. Then I tried the
`escape` filter, that worked.

Cheers, Sander.

On 27 jan, 05:05, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:
> On Mon, 2009-01-26 at 14:40 -0800, SanPy wrote:
> > For my website, I need to write this in one of my generated html's
> > (dynamically, of course):
>
> > 
> > var prices=[[0, '\u20ac 0'],[100, '\u20ac 100'],[150, '\u20ac 150'],
> > [200, '\u20ac 200'],[250, '\u20ac 250'],[300, '\u20ac 300']];
> > 
>
> > BTW, \u20ac represents the € symbol.
>
> > Whatever I try, I can't write '\u20ac 0' dynamically. It shows up like
> > u'\u20ac 0' or '\\u20ac 0', but never the required '\u20ac 0'. Can
> > somebody please help me with this?
>
> How are you trying to do this? Do the values come from a string that
> you're substituting into a template?
>
> If that's the case, have you looked at the "escapejs" filter ([1])? That
> will allow you to use the € character in your raw data and the template
> rendering will take care of suitably encoding it for Javascript
> purposes.
>
> [1]http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



template: writing "\u20ac 20.000" fails

2009-01-26 Thread SanPy

For my website, I need to write this in one of my generated html's
(dynamically, of course):


var prices=[[0, '\u20ac 0'],[100, '\u20ac 100'],[150, '\u20ac 150'],
[200, '\u20ac 200'],[250, '\u20ac 250'],[300, '\u20ac 300']];


BTW, \u20ac represents the € symbol.

Whatever I try, I can't write '\u20ac 0' dynamically. It shows up like
u'\u20ac 0' or '\\u20ac 0', but never the required '\u20ac 0'. Can
somebody please help me with this?

Thanks,
Sander.



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



custom AdminSite access for non-staff user (newforms-admin)

2008-07-20 Thread SanPy

Is it possible to allow a non-staff member access to a custom
AdminSite? When I try to login as a non-staff user, I get the error
message: "Please enter a correct username and password. Note that both
fields are case-sensitive."

Regards, Sander.
--~--~-~--~~~---~--~~
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: newforms and File (image) upload

2007-06-20 Thread SanPy

Dirk,

File and image uploading for newforms, AFAIK, is not implemented in
0.96. There is a ticket for this (#3297). If you look in the django-
developers newsgroup and search for #3297, you will find more
information. It is possible to have it working with the latest trunk
from SVN and a patch from #3297. It works fine on my machine with the
latest trunk and patch.

Als je er niet uitkomt, laat het hier dan even weten, dan geef ik je
wat code voorbeelden.

Groet, Sander.

On 20 jun, 18:15, "Dirk van Oosterbosch, IR labs" <[EMAIL PROTECTED]>
wrote:
> Hello,
>
> I'm starting with Django, so I was adviced to use the newforms. But I
> can't just figure out how to correctly upload images (or other files
> for that matter). I heard that there was already much discussion on
> this list, but on groups.google.com I couldn't find any pointers.
>
> I tried out two code examples from blogs, but get stuck with both.
>
> First I tried this 
> one:http://www.oluyede.org/blog/2007/03/18/django-image-uploading-
> validation-and-newforms/
> The strange thing about this example is that part of the validation
> happens in the view (not in the clean_photo method of the Form).
> I got stuck with this, because this (line 6 , in views):
>  img = Image.open(StringIO(request.FILES['photo']
> ['content']))
> kept failing. I would like to test this behavior of Image in the
> django shell, but wouldn't know how.
>
> Then I triedhttp://batiste.dosimple.ch/blog/2007-05-13-1/
> which claims to be based on the former example, but seems quite
> different to me. Probably the reason why I can't get this to work is
> my lack of understanding the monkey-patching business.
> The strange thing here (i.e. the part where I get lost), is that the
> clean_avatar method takes two arguments clean_avatar(self, value),
> but I have no idea where this other argument should be coming from.
> (Django has the same problem: TypeError at /upload/  clean_photo()
> takes exactly 2 arguments (1 given))
>
> I'm using 0.96
>
> I was hoping you guys could lead me towards working image upload. ;-)
>
> best
> dirk
>
> -
> Dirk van Oosterbosch
> de Wittenstraat 225
> 1052 AT Amsterdam
> the Netherlands
>
> http://labs.ixopusada.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?hl=en
-~--~~~~--~~--~--~---



Re: Moving Images to Amazon S3

2007-05-31 Thread SanPy

One addition:

On 31 mei, 21:35, SanPy <[EMAIL PROTECTED]> wrote:
> Try this:
> # in your view
> raw_image_data = form.cleaned_data['photo']['content']
> thumbnail_content = resize_image(raw_image_data)
> filename = form.cleaned_data['photo']['filename']

Change the filename's extension to jpg, because it gets converted to
JPEG in resize_image:
filename = os.path.splitext(filename)[0] + ".jpg"

> upload_to_s3(filename, thumbnail_content)
>
> def resize_image(buf, size=(100, 100)):
> f = cStringIO.StringIO(buf)
> image = PILImage.open(f)
> if image.mode not in ('L', 'RGB'):
> image = image.convert('RGB')
> image.thumbnail(size, PILImage.ANTIALIAS)
> o = cStringIO.StringIO()
> image.save(o, "JPEG")
> return o.getvalue()
>
> def upload_to_s3(filename, filedata):
> conn = S3.AWSAuthConnection(AWS_ACCESS_KEY_ID,
> AWS_SECRET_ACCESS_KEY)
> content_type = mimetypes.guess_type(filename)[0]
> response = conn.put(BUCKET_NAME, '%s' % filename,
> S3.S3Object(filedata), {'x-amz-acl': 'public-read', 'Content-Type':
> content_type})
>
> Regards, Sander.
>
> On 31 mei, 17:38, Kyle Fox <[EMAIL PROTECTED]> wrote:
>
> > I think my question wasn't clear:  we're having NO problem putting
> > files on S3, that's dead simple (ie what Holovaty blogged about).
>
> > What we need to do is take an *in-memory Image* and put it directly
> > onto S3.  We need a way to convert a PIL Image instance into a format
> > S3 can accept WITHOUT having to first save the Image to the file-
> > system.  S3 accepts the kind of string that gets returned from
> > open(afile).read()
>
> > I was trying to wrap the result of img.tostring() in the StringIO
> > class, and then put that on S3, but that doesn't work either...


--~--~-~--~~~---~--~~
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: Moving Images to Amazon S3

2007-05-31 Thread SanPy

Try this:
# in your view
raw_image_data = form.cleaned_data['photo']['content']
thumbnail_content = resize_image(raw_image_data)
filename = form.cleaned_data['photo']['filename']
upload_to_s3(filename, thumbnail_content)

def resize_image(buf, size=(100, 100)):
f = cStringIO.StringIO(buf)
image = PILImage.open(f)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.thumbnail(size, PILImage.ANTIALIAS)
o = cStringIO.StringIO()
image.save(o, "JPEG")
return o.getvalue()

def upload_to_s3(filename, filedata):
conn = S3.AWSAuthConnection(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
content_type = mimetypes.guess_type(filename)[0]
response = conn.put(BUCKET_NAME, '%s' % filename,
S3.S3Object(filedata), {'x-amz-acl': 'public-read', 'Content-Type':
content_type})

Regards, Sander.

On 31 mei, 17:38, Kyle Fox <[EMAIL PROTECTED]> wrote:
> I think my question wasn't clear:  we're having NO problem putting
> files on S3, that's dead simple (ie what Holovaty blogged about).
>
> What we need to do is take an *in-memory Image* and put it directly
> onto S3.  We need a way to convert a PIL Image instance into a format
> S3 can accept WITHOUT having to first save the Image to the file-
> system.  S3 accepts the kind of string that gets returned from
> open(afile).read()
>
> I was trying to wrap the result of img.tostring() in the StringIO
> class, and then put that on S3, but that doesn't work either...


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



tests in separate project directory

2007-05-02 Thread SanPy

I have some unit tests that are not directly app / model related. I
want to put those tests in a separate directory in my svn trunk (e.g.
myprojects/project1/trunk/project, myprojects/project1/trunk/tests).
How can I make these tests run through the django test runner (i.e.
when executing 'python manage.py test')?


--~--~-~--~~~---~--~~
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: Django Gebruikers Groep

2006-11-11 Thread SanPy

Count me in!

Ik ben wel geinteresseerd in een nederlandtalige Django Gebruikers
Groep.

Groet, Sander.

baasbartels schreef:

> To non-dutch speaking: this is not spam, it's just a message in dutch,
> for dutch django users about the possibility of forming a dutch Django
> user group. Having localized user groups could in my opinion
> potentially benefit Django development (both in the technical sense as
> in the "growing the community" sense). So far I've not found signs of
> active user groups being in existence. Therefor I'm interested to see
> if there're enough active dutch Django users who are interested in
> starting such a user group. I've no precise ideas as for what such a
> group should do, how often they would meet etc. - that's up for
> discussion once we've established that there's enough interest.
> 
>
> Naar mijn mening zou Django gebaat kunnen zijn bij het bestaan van
> lokaal georganiseerde gebruikers groepen. Het versterkt de Django
> community en als groep kun je in kortere tijd bepaalde problemen
> tackelen dan als individuele ontwikkelaar. Door het lokale karakter
> kunnen de leden elkaar met enige regelmaat ontmoeten, hetgeen de groep
> versterkt.
>
> Mijn concrete vraag is: zijn er Nederlandse (of eventueel Vlaamse)
> Django gebruikers die geinteresseerd zouden zijn om eens te kijken of
> we een Nederlandse/nederlands-talige Django Gebruikers Groep van de
> grond kunnen krijgen?
> 
> Groeten,
> Jeroen


--~--~-~--~~~---~--~~
 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: automatically login after email confirmation

2006-10-09 Thread SanPy

Joseph Kocherhans wrote:
> > Does anyone know of a way to login a user without having to
> > authenticate first? Or authenticating with an encrypted password?
>
> The problem is probably that the user.backend attribute does not
> exist. As a hack, you could just set it.
>
> user.backend = 'django.contrib.auth.backends.ModelBackend'
> login(request, user)

Thanks Joseph, now it's working!

Sander


--~--~-~--~~~---~--~~
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: automatically login after email confirmation

2006-10-09 Thread SanPy

Chris Moffitt wrote:
> >
> I've was tripped up by this too.  Can you try something like this:
>
>   user = authenticate(username=data[*'user_name'*], 
> password=data[*'password'*])
>   login(request, user)
>
> This seems to work for me.  If you want to see the full code, it's here -
> http://satchmo.python-hosting.com/file/trunk/satchmo/shop/views/account.py
>
> -Chris

Thanks Chris, I tried this. The problem is that a that particular line
I don't have access to the 'real ' password. In my app, the user
registers by choosing a username and password and email, the password
gets encrypted, and all values are stored. Then, the user press an
activation link in the received confirmation email. In the confirm
view, the user status gets updated to active, and then I want to
perform a login. Maybe, I have to authenticate just before the login
method call, but I don't have access to an unencrypted password there.
Does anyone know of a way to login a user without having to
authenticate first? Or authenticating with an encrypted password?


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



automatically login after email confirmation

2006-10-08 Thread SanPy

I've been trying to implement the user registration process from
http://www.b-list.org/weblog/2006/09/02/django-tips-user-registration .
It's basically a registration process where the user has to be
activated by clicking on a link in an email. Everything went fine and
it worked. Then I wanted to login automatically after the user clicks
on the link in the email.

I use this view for that:
def confirm(request, activation_key):
if request.user.is_authenticated():
return render_to_response('login/confirm.html', {'has_account':
True})
user_profile = get_object_or_404(UserProfile,
 activation_key=activation_key)
if user_profile.key_expires < datetime.datetime.today():
return render_to_response('login/confirm.html', {'expired':
True})
user_account = user_profile.user
user_account.is_active = True
user_account.save()
user = User.objects.get(pk=user_account.id)
if user is not None:
login(request, user)
return render_to_response('login/confirm.html', {'success': True})

I get the following error:
Request Method: GET
Request URL:
http://localhost:8000/accounts/confirm/080784d003e4cc87d63e0dad2fdcf5ffac3b9de8/
Exception Type: AttributeError
Exception Value: 'User' object has no attribute 'backend'
Exception Location:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/contrib/auth/__init__.py
in login, line 53

The exception is thrown from login(request, user). Can somebody help me
out on this issue?


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