Re: Django-admin-tools unicode problem

2013-06-28 Thread Roberto López López

Hi,

I can perfectly understand Portuguese, but it's not the case for many
users of this mailing list. Please, stick to English...

Cheers,

Roberto



On 06/28/2013 01:35 PM, Sandro Dutra wrote:
> Como o Gilberto postou, pode haver um problema quando o teu editor de
> textos salva o arquivo do template, tente abrir este template pelo
> bloco de notas e ao 'salvar como' deve haver um campo lá embaixo para
> selecionar a 'Codificação', selecione UTF-8 e salve ou tente a
> configuração relativa no editor de textos que está a utilizar, talvez
> isto resolva o problema.
>
> Eu já tive esses problemas quando usava Notepad++, mas tenho utilizado
> PyCharm e não tive mais este tipo de problema, há opções gratuitas que
> devem lidar com isto também, tais como Sublime e Aptana.
>
>
> 2013/6/27 Jaimerson Leandro Amaro de Araújo  >
>
> Cara, o problema é que a exceção tá sendo no template do
> aplicativo, que lê as informações do banco de dados. Alterar os
> arquivos do admin-tools é inviável em termos de portabilidade na
> hora do deploy. O que eu quero saber é se é possível mudar o
> encoding padrão desse app.
>
> Em quarta-feira, 26 de junho de 2013 11h22min18s UTC-3, Odin
> escreveu:
>
> Jaimerson, ainda assim creio que você deva tentar adicionar ao
> topo de suas views e/ou dos módulos usados do admin-tools a
> linha:
>
> # -*- coding: utf-8 -*- ou # -*- coding: iso-8859-1 -*-
>
> Isso permitirá ao Python ler o arquivo no encoding definido.
>
>
> 2013/6/26 Jaimerson Leandro Amaro de Araújo
> 
>
> Uh, I know it`s an encoding problem, I was hoping there
> was a way of changing default charset for that app.
>
> Em quarta-feira, 26 de junho de 2013 10h16min02s UTC-3,
> Odin escreveu:
>
> Think it's an encode problem. I never use this app but
> try to add this line o top of your views file:
>
> # -*- coding: utf-8 -*-
>
>
> 2013/6/26 Jaimerson Leandro Amaro de Araújo
> 
>
> (I posted this on django-admin-tools mail list,
> but apparently there's no one alive there)
>
>
> Hello, I'm stuck in a encoding issue, on the
> dashboard template. Some of my models have fields
> with non-ascii characters (like "à" or "á"), and
> when I try to load the page, I get the following
> error:
>
>
>   DjangoUnicodeDecodeError at /
>
> 'ascii' codec can't decode byte 0xc3 in position 5: 
> ordinal not in range(128).
> You passed in  at 0xb581d98c> ()
>
> [...]
>
>
> Unicode error hint
>
> The string that could not be encoded/decoded was:
> *Conte��do*
>
> Please, advise. --
> You received this message because you are
> subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving
> emails from it, send an email to
> django-users...@googlegroups.com.
> To post to this group, send email to
> django...@googlegroups.com.
>
> Visit this group at
> http://groups.google.com/group/django-users.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>  
>  
>
>
> -- 
> You received this message because you are subscribed to
> the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails
> from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to
> django...@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/django-users.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>  
>  
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscr...@googlegroups.com
> .
> To post to this group, send email to django-users@googlegroups.com
> .
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
>
> -- 
> You received this message because you are subsc

Re: Django-admin-tools unicode problem

2013-06-28 Thread Sandro Dutra
Como o Gilberto postou, pode haver um problema quando o teu editor de
textos salva o arquivo do template, tente abrir este template pelo bloco de
notas e ao 'salvar como' deve haver um campo lá embaixo para selecionar a
'Codificação', selecione UTF-8 e salve ou tente a configuração relativa no
editor de textos que está a utilizar, talvez isto resolva o problema.

Eu já tive esses problemas quando usava Notepad++, mas tenho utilizado
PyCharm e não tive mais este tipo de problema, há opções gratuitas que
devem lidar com isto também, tais como Sublime e Aptana.


2013/6/27 Jaimerson Leandro Amaro de Araújo 

> Cara, o problema é que a exceção tá sendo no template do aplicativo, que
> lê as informações do banco de dados. Alterar os arquivos do admin-tools é
> inviável em termos de portabilidade na hora do deploy. O que eu quero saber
> é se é possível mudar o encoding padrão desse app.
>
> Em quarta-feira, 26 de junho de 2013 11h22min18s UTC-3, Odin escreveu:
>>
>> Jaimerson, ainda assim creio que você deva tentar adicionar ao topo de
>> suas views e/ou dos módulos usados do admin-tools a linha:
>>
>> # -*- coding: utf-8 -*- ou # -*- coding: iso-8859-1 -*-
>>
>> Isso permitirá ao Python ler o arquivo no encoding definido.
>>
>>
>> 2013/6/26 Jaimerson Leandro Amaro de Araújo 
>>
>> Uh, I know it`s an encoding problem, I was hoping there was a way of
>>> changing default charset for that app.
>>>
>>> Em quarta-feira, 26 de junho de 2013 10h16min02s UTC-3, Odin escreveu:

 Think it's an encode problem. I never use this app but try to add this
 line o top of your views file:

 # -*- coding: utf-8 -*-


 2013/6/26 Jaimerson Leandro Amaro de Araújo 

> (I posted this on django-admin-tools mail list, but apparently there's
> no one alive there)
>
>
> Hello, I'm stuck in a encoding issue, on the dashboard template. Some
> of my models have fields with non-ascii characters (like "à" or "á"), and
> when I try to load the page, I get the following error:
> DjangoUnicodeDecodeError at /
>
> 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in 
> range(128).
> You passed in  0xb581d98c> ()
>
> [...]
> Unicode error hint
>
> The string that could not be encoded/decoded was: *Conte��do*
> Please, advise.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@**googlegroups.**com.
> To post to this group, send email to django...@googlegroups.com.
>
> Visit this group at 
> http://groups.google.com/**group**/django-users
> .
> For more options, visit 
> https://groups.google.com/**grou**ps/opt_out
> .
>
>
>

  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>>
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-admin-tools unicode problem

2013-06-27 Thread Jaimerson Leandro Amaro de Araújo
Cara, o problema é que a exceção tá sendo no template do aplicativo, que lê 
as informações do banco de dados. Alterar os arquivos do admin-tools é 
inviável em termos de portabilidade na hora do deploy. O que eu quero saber 
é se é possível mudar o encoding padrão desse app.

Em quarta-feira, 26 de junho de 2013 11h22min18s UTC-3, Odin escreveu:
>
> Jaimerson, ainda assim creio que você deva tentar adicionar ao topo de 
> suas views e/ou dos módulos usados do admin-tools a linha:
>
> # -*- coding: utf-8 -*- ou # -*- coding: iso-8859-1 -*-
>
> Isso permitirá ao Python ler o arquivo no encoding definido.
>
>
> 2013/6/26 Jaimerson Leandro Amaro de Araújo 
> >
>
>> Uh, I know it`s an encoding problem, I was hoping there was a way of 
>> changing default charset for that app.
>>
>> Em quarta-feira, 26 de junho de 2013 10h16min02s UTC-3, Odin escreveu:
>>>
>>> Think it's an encode problem. I never use this app but try to add this 
>>> line o top of your views file:
>>>
>>> # -*- coding: utf-8 -*-
>>>
>>>
>>> 2013/6/26 Jaimerson Leandro Amaro de Araújo 
>>>
 (I posted this on django-admin-tools mail list, but apparently there's 
 no one alive there)


 Hello, I'm stuck in a encoding issue, on the dashboard template. Some 
 of my models have fields with non-ascii characters (like "à" or "á"), and 
 when I try to load the page, I get the following error:
 DjangoUnicodeDecodeError at / 

 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in 
 range(128).
 You passed in  
 ()

 [...]
 Unicode error hint 

 The string that could not be encoded/decoded was: *Conte��do*
 Please, advise. 

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@**googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.

 Visit this group at 
 http://groups.google.com/**group/django-users
 .
 For more options, visit 
 https://groups.google.com/**groups/opt_out
 .
  
  

>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-admin-tools unicode problem

2013-06-26 Thread gilberto dos santos alves
tudo depende do seu editor de texto. por exemplo no windows em português do 
brasil normalmente é usado o cp1250 como padrão. mas na hora de salvar o 
seu arquivo você pode escolher salvá-lo como utf-8 (aí no início do código 
vai a correspondente diretiva) se preferir salvar em outro codepage deve 
declarar esse codepage na diretiva  -*- coding: x -*-.
quando você define os nomes dos códigos de página unicode é possivel nomear 
os "elementos" do seu modelo usando acentuação e os caracteres da nossa 
língua. Estou nos finalmente das "modificações"  sugestões para que o 
tutorial da versão 1.6 contemple algumas explicações adicionais para nós 
que não usamos só a língua inglesa.

# -*- coding: utf-8 -*-


from django.db import models
class Poll(models.Model):
questão = models.CharField(max_length=200)
pub_date = models.DateTimeField('data da publicação')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)



Em quarta-feira, 26 de junho de 2013 11h11min20s UTC-3, Jaimerson Leandro 
Amaro de Araújo escreveu:
>
> Uh, I know it`s an encoding problem, I was hoping there was a way of 
> changing default charset for that app.
>
> Em quarta-feira, 26 de junho de 2013 10h16min02s UTC-3, Odin escreveu:
>>
>> Think it's an encode problem. I never use this app but try to add this 
>> line o top of your views file:
>>
>> # -*- coding: utf-8 -*-
>>
>>
>> 2013/6/26 Jaimerson Leandro Amaro de Araújo 
>>
>>> (I posted this on django-admin-tools mail list, but apparently there's 
>>> no one alive there)
>>>
>>>
>>> Hello, I'm stuck in a encoding issue, on the dashboard template. Some of 
>>> my models have fields with non-ascii characters (like "à" or "á"), and when 
>>> I try to load the page, I get the following error:
>>> DjangoUnicodeDecodeError at / 
>>>
>>> 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in 
>>> range(128).
>>> You passed in  
>>> ()
>>>
>>> [...]
>>> Unicode error hint 
>>>
>>> The string that could not be encoded/decoded was: *Conte��do*
>>> Please, advise. 
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-admin-tools unicode problem

2013-06-26 Thread Sandro Dutra
Jaimerson, ainda assim creio que você deva tentar adicionar ao topo de suas
views e/ou dos módulos usados do admin-tools a linha:

# -*- coding: utf-8 -*- ou # -*- coding: iso-8859-1 -*-

Isso permitirá ao Python ler o arquivo no encoding definido.


2013/6/26 Jaimerson Leandro Amaro de Araújo 

> Uh, I know it`s an encoding problem, I was hoping there was a way of
> changing default charset for that app.
>
> Em quarta-feira, 26 de junho de 2013 10h16min02s UTC-3, Odin escreveu:
>>
>> Think it's an encode problem. I never use this app but try to add this
>> line o top of your views file:
>>
>> # -*- coding: utf-8 -*-
>>
>>
>> 2013/6/26 Jaimerson Leandro Amaro de Araújo 
>>
>>> (I posted this on django-admin-tools mail list, but apparently there's
>>> no one alive there)
>>>
>>>
>>> Hello, I'm stuck in a encoding issue, on the dashboard template. Some of
>>> my models have fields with non-ascii characters (like "à" or "á"), and when
>>> I try to load the page, I get the following error:
>>> DjangoUnicodeDecodeError at /
>>>
>>> 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in 
>>> range(128).
>>> You passed in  
>>> ()
>>>
>>> [...]
>>> Unicode error hint
>>>
>>> The string that could not be encoded/decoded was: *Conte��do*
>>> Please, advise.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>>
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-admin-tools unicode problem

2013-06-26 Thread Jaimerson Leandro Amaro de Araújo
Uh, I know it`s an encoding problem, I was hoping there was a way of 
changing default charset for that app.

Em quarta-feira, 26 de junho de 2013 10h16min02s UTC-3, Odin escreveu:
>
> Think it's an encode problem. I never use this app but try to add this 
> line o top of your views file:
>
> # -*- coding: utf-8 -*-
>
>
> 2013/6/26 Jaimerson Leandro Amaro de Araújo 
> >
>
>> (I posted this on django-admin-tools mail list, but apparently there's no 
>> one alive there)
>>
>>
>> Hello, I'm stuck in a encoding issue, on the dashboard template. Some of 
>> my models have fields with non-ascii characters (like "à" or "á"), and when 
>> I try to load the page, I get the following error:
>> DjangoUnicodeDecodeError at / 
>>
>> 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in 
>> range(128).
>> You passed in  
>> ()
>>
>> [...]
>> Unicode error hint 
>>
>> The string that could not be encoded/decoded was: *Conte��do*
>> Please, advise. 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-admin-tools unicode problem

2013-06-26 Thread Sandro Dutra
Think it's an encode problem. I never use this app but try to add this line
o top of your views file:

# -*- coding: utf-8 -*-


2013/6/26 Jaimerson Leandro Amaro de Araújo 

> (I posted this on django-admin-tools mail list, but apparently there's no
> one alive there)
>
>
> Hello, I'm stuck in a encoding issue, on the dashboard template. Some of
> my models have fields with non-ascii characters (like "à" or "á"), and when
> I try to load the page, I get the following error:
> DjangoUnicodeDecodeError at /
>
> 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128).
> You passed in  
> ()
>
> [...]
> Unicode error hint
>
> The string that could not be encoded/decoded was: *Conte��do*
> Please, advise.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Django-admin-tools unicode problem

2013-06-26 Thread Jaimerson Leandro Amaro de Araújo
(I posted this on django-admin-tools mail list, but apparently there's no 
one alive there)

Hello, I'm stuck in a encoding issue, on the dashboard template. Some of my 
models have fields with non-ascii characters (like "à" or "á"), and when I 
try to load the page, I get the following error:
DjangoUnicodeDecodeError at / 

'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128).
You passed in  ()

[...]
Unicode error hint 

The string that could not be encoded/decoded was: *Conte��do*
Please, advise.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Django-admin-tools unicode problem

2013-06-26 Thread Jaimerson Leandro Amaro de Araújo
(I have posted this on django-admin-tools specific mailing list, but 
apparently there's no one alive there)
Hello, I'm stuck in a encoding issue, on the dashboard template. Some of my 
models have fields with non-ascii characters (like "à" or "á"), and when I 
try to load the page, I get the following error:
DjangoUnicodeDecodeError at / 

'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128).
You passed in  ()

[...]
Unicode error hint 

The string that could not be encoded/decoded was: *Conte��do*
Please, advise.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Apache unicode problem!why it is OK in "manage.py runserver 8000" ? but it is not OK when "apach + mod_python" !

2009-11-28 Thread hao he
hi all:
 I write a tag "model_as_table_with", used like this  in template :

{{model_instance | *model_as_table_with*:"real_name,gender,birthdate,}}


problem was raise in my  "*model_as_table_with*" function.
this following code is ok when I runserver with "manage.py runserver 8000"
*col = "%s:%s" % (field.name and field.verbose_name,
getattr(model_instance, **field**.name)) *
but, when I run my project with " apache + mod_python ".
it raise this Exception :
"Exception=,e='ascii' codec can't decode byte
0xe7 in position 4: ordinal not in range(128)"
I have to modify the code like this :
*col = "%s:%s" % (field.name and field.verbose_name,
getattr(**model_instance**, **field**.name).encode('utf-8')  **)*

all of my code files are set to utf-8, why it is still need to *encode('utf-8')
?*
why it is OK in "manage.py runserver 8000" ? but it is not OK when "apach +
mod_python"

thanks .

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: unicode problem?

2009-08-26 Thread andreas schmid

take a look at that discussion:
http://groups.google.com/group/django-users/browse_thread/thread/1de89cdee99b1086

lerner wrote:
> def output(request):
> response = HttpResponse(mimetype='text/csv')
> response['Content-Disposition'] = 'attachment; filename=%s' %
> 'address.csv'
> t = loader.get_template('csv.html')
> #objs = Address.objects.get_list()
> objs = Address.objects.all()
> d = []
> for o in objs:
> d.append((o.name, o.gender, o.telphone, o.mobile, o.room))
> c = Context({
> 'data': d,
> })
> response.write(t.render(c))
> return response
> -
> I define a funtion to write some chinese into a csv type file,
> but i I get this file and open it  in windows, it will appear messy
> code.
> I know this file is encoded in utf-8 default,  but I find the
> response.write module
> have no encoding method, because django just has utf-8 encoding.
> how to write it encoding "Gb2312" or "GBK" or some others chinese
> encoding.
>
> >
>
>   


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



unicode problem?

2009-08-26 Thread lerner

def output(request):
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=%s' %
'address.csv'
t = loader.get_template('csv.html')
#objs = Address.objects.get_list()
objs = Address.objects.all()
d = []
for o in objs:
d.append((o.name, o.gender, o.telphone, o.mobile, o.room))
c = Context({
'data': d,
})
response.write(t.render(c))
return response
-
I define a funtion to write some chinese into a csv type file,
but i I get this file and open it  in windows, it will appear messy
code.
I know this file is encoded in utf-8 default,  but I find the
response.write module
have no encoding method, because django just has utf-8 encoding.
how to write it encoding "Gb2312" or "GBK" or some others chinese
encoding.

--~--~-~--~~~---~--~~
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: Unicode problem when rendering a template

2007-09-07 Thread Tipan



On Sep 5, 9:28 pm, wolfds <[EMAIL PROTECTED]> wrote:
> Can we see the model definition for Reward?

Just got back to this and realised I was being a dummy. Whilst I had
changed all the def's to unicode, I'd still left some str() functions
on the return. Changed these to smart_unicode() and the problem was
solved.

Lesson learnt - read the notes carefully first!


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



Re: Unicode problem when rendering a template

2007-09-05 Thread wolfds

Can we see the model definition for Reward?


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



Unicode problem when rendering a template

2007-09-05 Thread Tipan

I've recently updated our Django source to the latest version which
meant implementing the Unicode handling. In the main all went well,
although I'm getting a few decode errors such as:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
28: ordinal not in range(128)

I have changed the __str__ to __unicode__ methods in my models and
checked to _str_ methods on model fields. But I can't seem to resolve
one of two of the errors.

In particular I'm getting the error above when I loop through a
queryset in a template. The queryset is called as:

qs=Reward.objects.all().select_related().order_by(add_sort)

This is passed to the template in a render_to_response and then called
in the template as:

 {% for i in qs %}

Which causes the error.

The database is MySQL which was encoded as Latin-1 with
latin1_general_ci as the collation. Although I've changed the Table
settings to utf-8, I suspect, all of the data is still held as
Latin1.

I've checked through/removed a lot of the dto ata in the table in an
attempt to troubleshoot but I have not been able to  get rid of the
error.

I've changed the FILE_CHARSET setting to 'latin-1' -  again without
success.

I'm also getting the error on several tables in the Admin interface.

Questions...
Do I need to recreate the databse and re-load all of the data into the
database to ensure it gets converted to utf-8?
When defining the queryset, can I ensure that the object returned is
forced to be unicode compatible?

I seem to be going round in circles on this one, so I'd be grateful
for any advice in trouble shooting the problem.

Cheers ... Tim


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



Re: Template: unicode problem

2007-07-31 Thread Malcolm Tredinnick

On Tue, 2007-07-31 at 15:40 +, Mario Gonzalez wrote:
> Hello, I'm getting some problems with unicode in templates: 'ascii'
> codec can't encode character u'\xf1' in position 1: ordinal not in
> range(128)  However, templates, database are in UTF8. I changed
> __str__ by __unicode__ in my models files.
> 
>   Django (I think) is trying to encode an ascii string. I modified
> django/template/__init__.py line 704 and just for testing purposes I
> deleted raise and I changed it by print e

It's going to be almost impossible for anybody other than you to debug
this based on the information you have given: we have no way to
replicate the problem.

The easiest way to get help here is to reduce your template to the
smallest possible example required to reproduce the problem. Start
removing lines (in particular static text) until the problem goes away.
Then go back one step. I would guess that the error is being triggered
by some dynamic content you are putting in (a variable substitution or
filter output). Once you have reduce the situation to a minimum, that
should be easy enough to spot. Then work out what the content is that is
being substituted in.

There may well be a problem, but from the current information there is a
0% chance of anybody being able to guess the solution. There are just
too many things it could be from bad strings in your code to bad
handling on some uncommon code path in Django to some inadvertent
encoding mismatch somewhere else. So if you can come up with a small
reproducible test case, that will help greatly.

Regards,
Malcolm


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



Re: Template: unicode problem

2007-07-31 Thread Mario Gonzalez

On 31 jul, 12:28, Mario Gonzalez <[EMAIL PROTECTED]> wrote:
>
>   I understand it and please forgive my pour words :-) I'll do what
> you said and I'll try to fix it by my self today. If not, I'll write
> to this list for any comments.
>

 The problem:  I had a non-ascii character (ñ) in my template as a
variable

{% for item in publicacion %}
  {{ item.tema|escape }}, {{ item.año }}, {{ item.autores }}
{% endfor %}

  So, I had to change my model file and my form. AS a tip: forms names
cannot have got non-ascii character(s). In my country the translation
of "year" is año. So, what about if you want to display a field with
that name?

class test(forms.Form):
  año = forms.DateField() <= this doesn't work

you've got to change the field name and add a label like:

class test(forms.Form):
  anio = forms.DateField(label="Año") <=  And the label can contain
non-ascii chars.

Inside your view, to get the POST data you've got to do something
like:
 request.POST.get('anio', None)  not request.POST.get('año', None)

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



Re: Template: unicode problem

2007-07-31 Thread Malcolm Tredinnick

Mario,

On Tue, 2007-07-31 at 15:40 +, Mario Gonzalez wrote:
[...]
>   Django (I think) is trying to encode an ascii string. I modified
> django/template/__init__.py line 704 and just for testing purposes I
> deleted raise and I changed it by print e
> 
> Index: __init__.py
> ===
> --- __init__.py (revision 5779)
> +++ __init__.py (working copy)
> @@ -700,7 +700,8 @@
>  if getattr(e, 'silent_variable_failure', False):
>  current = settings.TEMPLATE_STRING_IF_INVALID
>  else:
> -raise
> +print e
> +#raise
>  del bits[0]
>  if isinstance(current, (basestring, Promise)):
>  try:

I was thinking about this a bit more and the place the exception is
coming from is a clue. It's being raised from the current=current() call
on line 680. So you might be able to get further by print out what
"current" is just before that line (current.__name__, since it should be
a function by that point). It is somewhere inside current() that the
exception is being created.

You might also get some more clues by printing out the current stack
trace when the exception is raised (import traceback and
traceback.print_stack()). That *might* tell you which function is the
real problem.

Regards,
Malcolm


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



Re: Template: unicode problem

2007-07-31 Thread Mario Gonzalez

On 31 jul, 12:18, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> There may well be a problem, but from the current information there is a
> 0% chance of anybody being able to guess the solution. There are just
> too many things it could be from bad strings in your code to bad
> handling on some uncommon code path in Django to some inadvertent
> encoding mismatch somewhere else. So if you can come up with a small
> reproducible test case, that will help greatly.
>

  I understand it and please forgive my pour words :-) I'll do what
you said and I'll try to fix it by my self today. If not, I'll write
to this list for any comments.

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



Template: unicode problem

2007-07-31 Thread Mario Gonzalez

 Hello, I'm getting some problems with unicode in templates: 'ascii'
codec can't encode character u'\xf1' in position 1: ordinal not in
range(128)  However, templates, database are in UTF8. I changed
__str__ by __unicode__ in my models files.

  Django (I think) is trying to encode an ascii string. I modified
django/template/__init__.py line 704 and just for testing purposes I
deleted raise and I changed it by print e

Index: __init__.py
===
--- __init__.py (revision 5779)
+++ __init__.py (working copy)
@@ -700,7 +700,8 @@
 if getattr(e, 'silent_variable_failure', False):
 current = settings.TEMPLATE_STRING_IF_INVALID
 else:
-raise
+print e
+#raise
 del bits[0]
 if isinstance(current, (basestring, Promise)):
 try:

 After that, the template content is showed in the browser. Maybe a
bug, I'm checking the __init__.py file but maybe you will find it
faster than me.


--~--~-~--~~~---~--~~
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: Unicode problem while changing from 0.95 to latest developer version

2007-07-19 Thread Jeremy Dunck

On 7/19/07, piotr <[EMAIL PROTECTED]> wrote:
...
> TemplateSyntaxError: Caught an exception while rendering: 'utf8' codec
> can't decode bytes in position 833-834: invalid data
>
...
> Any idea what can be wrong?


I'm betting a string it's trying to decode isn't in utf-8.  ;-)

Go through this checklist:
http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsTheQuickChecklist

If still problems, check to see what string it's working with there,
and adjust the unicode-related settings and/or file encoding
declarations as needed.

(DEFAULT_CHARSET, FILE_CHARSET, etc.)

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



Unicode problem while changing from 0.95 to latest developer version

2007-07-19 Thread piotr

Hello,
I have done upgrade from 0.95 to svn developer version.

One of my django apps using unicode characters does not start anymore,
I get the following:

--

Traceback (most recent call last):

  File "C:\Python24\lib\site-packages\django\core\servers
\basehttp.py", line 278, in run
self.result = application(self.environ, self.start_response)

  File "C:\Python24\lib\site-packages\django\core\servers
\basehttp.py", line 620, in __call__
return self.application(environ, start_response)

  File "C:\Python24\lib\site-packages\django\core\handlers\wsgi.py",
line 190, in __call__
response = self.get_response(request)

  File "C:\Python24\lib\site-packages\django\core\handlers\base.py",
line 111, in get_response
return debug.technical_500_response(request, *sys.exc_info())

  File "C:\Python24\lib\site-packages\django\views\debug.py", line
141, in technical_500_response
return HttpResponseServerError(t.render(c), mimetype='text/html')

  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 181, in render
return self.nodelist.render(context)

  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 736, in render
bits.append(self.render_node(node, context))

  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 754, in render_node
result = node.render(context)

  File "C:\Python24\lib\site-packages\django\template\defaulttags.py",
line 134, in render
nodelist.append(node.render(context))

  File "C:\Python24\lib\site-packages\django\template\defaulttags.py",
line 228, in render
return self.nodelist_true.render(context)

  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 736, in render
bits.append(self.render_node(node, context))

  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 764, in render_node
raise wrapped

TemplateSyntaxError: Caught an exception while rendering: 'utf8' codec
can't decode bytes in position 833-834: invalid data

Original Traceback (most recent call last):
  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 754, in render_node
result = node.render(context)
  File "C:\Python24\lib\site-packages\django\template\defaulttags.py",
line 134, in render
nodelist.append(node.render(context))
  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 790, in render
return self.filter_expression.resolve(context)
  File "C:\Python24\lib\site-packages\django\template\__init__.py",
line 603, in resolve
obj = func(obj, *arg_vals)
  File "C:\Python24\lib\site-packages\django\template
\defaultfilters.py", line 25, in _dec
args[0] = force_unicode(args[0])
  File "C:\Python24\lib\site-packages\django\utils\encoding.py", line
42, in force_unicode
s = unicode(s, encoding, errors)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position
833-834: invalid data

--

The admin site works, I can browse and update the data base without
any problems.

My development PC runs Windows.

Any idea what can be wrong?
Regards,
Piotr


--~--~-~--~~~---~--~~
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 unit tests and unicode problem

2007-04-29 Thread Eugene Morozov

Hmm, I've figured how to inspect context in the test by reading django
sources.
But that didn't help greatly, because context['translation'].content
(translation is a model for translated pages content) still returns
doubly encoded utf-8 data. By the way, the page in browser is rendered
correctly. Does anyone has suggestions how to test i18n features in
Django apps?
Eugene

On 29 апр, 17:07, Eugene Morozov <[EMAIL PROTECTED]> wrote:
> Hello,
> I'm new to django (using it only for two weeks and I was reading
> django tutorial, documentation and book for the first week).
>
> I'm writing unit tests for my CMS similar to built-in flatpages CMS,
> but with builtin i18n features and other things required for full-
> fledged CMS.
>
> I cannot use standard django test client because it doesn't work with
> middleware intercepting 404 errors (I didn't investigate why, because
> I've thought that testing view manually would be easier).
> Unfortunately, I was wrong. When I'm trying to test i18n features,
> response.content returns non-ascii text *doubly* encoded in utf-8.
> First invocation of response.content.decode('utf-8') returns unicode
> object that contains utf-8 encoded original string. I can find some
> tricky way to decode unicode object again using struct module or
> something, but I don't understand why django encodes content twice.
> And how test client gains access to template context.
>
> Will look at the sources meanwhile, but would be very grateful if
> someone will explain.
> Eugene


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



Django unit tests and unicode problem

2007-04-29 Thread Eugene Morozov

Hello,
I'm new to django (using it only for two weeks and I was reading
django tutorial, documentation and book for the first week).

I'm writing unit tests for my CMS similar to built-in flatpages CMS,
but with builtin i18n features and other things required for full-
fledged CMS.

I cannot use standard django test client because it doesn't work with
middleware intercepting 404 errors (I didn't investigate why, because
I've thought that testing view manually would be easier).
Unfortunately, I was wrong. When I'm trying to test i18n features,
response.content returns non-ascii text *doubly* encoded in utf-8.
First invocation of response.content.decode('utf-8') returns unicode
object that contains utf-8 encoded original string. I can find some
tricky way to decode unicode object again using struct module or
something, but I don't understand why django encodes content twice.
And how test client gains access to template context.

Will look at the sources meanwhile, but would be very grateful if
someone will explain.
Eugene


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



Django unit tests and unicode problem

2007-04-29 Thread Eugene Morozov

Hello,
I'm new to django (using it only for two weeks and I was reading
django tutorial, documentation and book for the first week).

I'm writing unit tests for my CMS similar to built-in flatpages CMS,
but with builtin i18n features and other things required for full-
fledged CMS.

I cannot use standard django test client because it doesn't work with
middleware intercepting 404 errors (I didn't investigate why, because
I've thought that testing view manually would be easier).
Unfortunately, I was wrong. When I'm trying to test i18n features,
response.content returns non-ascii text *doubly* encoded in utf-8.
First invocation of response.content.decode('utf-8') returns unicode
object that contains utf-8 encoded original string. I can find some
tricky way to decode unicode object again using struct module or
something, but I don't understand why django encodes content twice.
And how test client gains access to template context.

Will look at the sources meanwhile, but would be very grateful if
someone will explain.
Eugene


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



Re: SelectDateWidget unicode problem

2007-04-12 Thread Christian Schmidt

Got the same Problem here. On my Laptop all is fine but on the Server
I got an Unicode Error. Seems to me, that the german month "März"
isn't correctly encoded.

Can someone help? On both PCs is  DEFAULT_CHARSET = 'utf-8' in the
settings and a postgres database running.

Christian.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [EMAIL PROTECTED]
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
-~--~~~~--~~--~--~---



SelectDateWidget unicode problem

2007-04-11 Thread Robert

When trying to use a SelectDateWidget from forms.extras.widgets.py I'm
getting the
following error:


Traceback (most recent call last):
File "c:\Python24\Lib\site-packages\django\template\__init__.py" in
render_node
  723. result = node.render(context)
File "c:\Python24\Lib\site-packages\django\template\__init__.py" in
render
  778. return self.encode_output(output)
File "c:\Python24\Lib\site-packages\django\template\__init__.py" in
encode_output
  757. return str(output)
File "c:\Python24\Lib\site-packages\django\utils\encoding.py" in
__str__
  31. return self.__unicode__().encode(settings.DEFAULT_CHARSET)
File "c:\Python24\Lib\site-packages\django\newforms\forms.py" in
__unicode__
  74. return self.as_table()
File "c:\Python24\Lib\site-packages\django\newforms\forms.py" in
as_table
  145. return self._html_output(u'%(label)s%(errors)s%
(field)s%(help_text)s', u'%s',
'', u'%s', False)
File "c:\Python24\Lib\site-packages\django\newforms\forms.py" in
_html_output
  130. output.append(normal_row % {'errors': bf_errors, 'label':
label, 'field': unicode(bf), 'help_text': help_text})
File "c:\Python24\Lib\site-packages\django\newforms\forms.py" in
__unicode__
  228. value = self.as_widget(self.field.widget)
File "c:\Python24\Lib\site-packages\django\newforms\forms.py" in
as_widget
  253. return widget.render(self.html_name, data, attrs=attrs)
File "c:\Python24\Lib\site-packages\django\newforms\extras\widgets.py"
in render
  42. select_html =
Select(choices=month_choices).render(self.month_field % name,
month_val)
File "c:\Python24\Lib\site-packages\django\newforms\widgets.py" in
render
  171. output.append(u'%s' %
(escape(option_value), selected_html,
escape(smart_unicode(option_label

  UnicodeDecodeError at /prod/add/
  'ascii' codec can't decode byte 0xc5 in position 6: ordinal not in
range(128)

Tried with both Django 0.96 & SVN (as of today April 11th).
DEFAULT_CHARSET='utf-8'

Thanks,

Robert


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