Re: Strange encoding behavior

2007-08-31 Thread Anderson Santos

Ahhh, finally!

Thank you very much, it worked now  =D
I didn't know about the __unicode__ trick

And I am not sure if it is it that you want to know, but I still not
using the encoding header on the top of the files. I thought it was
more to the enconding chars of the file and not an advanced settings
for the application. Should I put it on the top of all my files?

Cheers,

Anderson

On 31 ago, 08:37, Michael Radziej <[EMAIL PROTECTED]> wrote:
> On Fri, Aug 31, Anderson Santos wrote:
>
> > Here the code:
>
> > class Download(models.Model):
> > """ Disponibilização de arquivos para download """
>
> > descricao =
> > models.CharField(verbose_name='Descrição',maxlength=250)
> > data_do_arquivo = models.DateField()
> > caminho_do_arquivo = models.CharField(maxlength=400)
> > atualizar_versao_com_grupo =
> > models.BooleanField(verbose_name='Controlar a versão pelo sistema
> > principal')
> > versao = models.CharField(verbose_name='Versão do
> > Arquivo',blank=True,null=True,maxlength=20)
> > usuarios_permitidos =
> > models.ManyToManyField(User,blank=True,null=True,filter_interface=models.HORIZONTAL)
> > restringir_por_usuario = models.BooleanField(default=False)
> > ordem = models.IntegerField(blank=True,null=True,default=0)
>
> > def __str__(self):
> > return self.descricao
>
> Can you rename __str__(self) to __unicode__(self) and try again? And, BTW,
> what is the line with '# -*- encoding'?
>
> Michael
>
> --
> noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
> Tel +49-911-9352-0 - Fax +49-911-9352-100http://www.noris.de- The 
> IT-Outsourcing Company
>
> Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk -
> Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689


--~--~-~--~~~---~--~~
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: Strange encoding behavior

2007-08-31 Thread Michael Radziej

On Fri, Aug 31, Anderson Santos wrote:

> 
> Here the code:
> 
> 
> class Download(models.Model):
> """ Disponibilização de arquivos para download """
> 
> descricao =
> models.CharField(verbose_name='Descrição',maxlength=250)
> data_do_arquivo = models.DateField()
> caminho_do_arquivo = models.CharField(maxlength=400)
> atualizar_versao_com_grupo =
> models.BooleanField(verbose_name='Controlar a versão pelo sistema
> principal')
> versao = models.CharField(verbose_name='Versão do
> Arquivo',blank=True,null=True,maxlength=20)
> usuarios_permitidos =
> models.ManyToManyField(User,blank=True,null=True,filter_interface=models.HORIZONTAL)
> restringir_por_usuario = models.BooleanField(default=False)
> ordem = models.IntegerField(blank=True,null=True,default=0)
> 
> def __str__(self):
> return self.descricao

Can you rename __str__(self) to __unicode__(self) and try again? And, BTW,
what is the line with '# -*- encoding'?

Michael

-- 
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
 
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - 
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689

--~--~-~--~~~---~--~~
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: Strange encoding behavior

2007-08-31 Thread Anderson Santos

Here the code:


class Download(models.Model):
""" Disponibilização de arquivos para download """

descricao =
models.CharField(verbose_name='Descrição',maxlength=250)
data_do_arquivo = models.DateField()
caminho_do_arquivo = models.CharField(maxlength=400)
atualizar_versao_com_grupo =
models.BooleanField(verbose_name='Controlar a versão pelo sistema
principal')
versao = models.CharField(verbose_name='Versão do
Arquivo',blank=True,null=True,maxlength=20)
usuarios_permitidos =
models.ManyToManyField(User,blank=True,null=True,filter_interface=models.HORIZONTAL)
restringir_por_usuario = models.BooleanField(default=False)
ordem = models.IntegerField(blank=True,null=True,default=0)

def __str__(self):
return self.descricao

def download_restrito(self,usuario):
try:
usuario = self.usuarios_permitidos.get(username=usuario)
except:
usuario = None
return (not self.restringir_por_usuario or usuario)


class Admin:
list_display = ('descricao','versao','caminho_do_arquivo')
list_filter = ('versao',)
search_fields = ('descricao',)
ordering = ('ordem','descricao',)
list_per_page = 20

class Meta:
ordering = ('ordem','descricao',)


There's more issues about Unicode error on another application that
never occured with Lighttpd. I am afraid that's something about
mod_python.


Regards,


Anderson

On 30 ago, 19:06, Michael Radziej <[EMAIL PROTECTED]> wrote:
> On Thu, Aug 30, Anderson Santos wrote:
>
> > I am still having this issue.
> > I have in my settings DEFAULT_CHARSET = "utf-8", and I created a new
> > database with UTF-8 encoding (using PGAdmin).
> > So I go to admin page, click on my model and then the "add" button, I
> > include a special char (á, ç, etc) and I get a Unicode error on both,
> > Linux and Windows.
>
> > The error message on Linux is:
>
> > 'utf8' codec can't decode bytes in position 1-2: unexpected end of
> > data
>
> > The error message on Windows is:
>
> > 'utf8' codec can't decode bytes in position 1-3: invalid data
>
> > The problem is, it DOES saves the data and displays correctly on the
> > listing admin page for the model. The error only occurs when I try to
> > edit, on display. If the record don't have any special char, it works
> > correctly.
>
> > Both occurs on force_unicode procedure
>
> > When I try to add from manage.py shell onlinux (with or without
> > special chars), it raises an error "SET client_encoding to 'UNICODE'"
> > in  django/db/backends/postgresql/base.py
>
> > I really have no clue why it's happening. I just updated from svn so I
> > have the latest django.
>
> > Any help will be really appreciate
>
> Can you please post the model class, including (if present) __unicode__()
> and __str__() functions?
>
> Michael
>
> --
> noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
> Tel +49-911-9352-0 - Fax +49-911-9352-100http://www.noris.de- The 
> IT-Outsourcing Company
>
> Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk -
> Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689


--~--~-~--~~~---~--~~
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: Strange encoding behavior

2007-08-30 Thread Michael Radziej

On Thu, Aug 30, Anderson Santos wrote:

> 
> I am still having this issue.
> I have in my settings DEFAULT_CHARSET = "utf-8", and I created a new
> database with UTF-8 encoding (using PGAdmin).
> So I go to admin page, click on my model and then the "add" button, I
> include a special char (á, ç, etc) and I get a Unicode error on both,
> Linux and Windows.
> 
> The error message on Linux is:
> 
> 'utf8' codec can't decode bytes in position 1-2: unexpected end of
> data
> 
> 
> The error message on Windows is:
> 
> 'utf8' codec can't decode bytes in position 1-3: invalid data
> 
> 
> The problem is, it DOES saves the data and displays correctly on the
> listing admin page for the model. The error only occurs when I try to
> edit, on display. If the record don't have any special char, it works
> correctly.
> 
> 
> Both occurs on force_unicode procedure
> 
> 
> When I try to add from manage.py shell onlinux (with or without
> special chars), it raises an error "SET client_encoding to 'UNICODE'"
> in  django/db/backends/postgresql/base.py
> 
> I really have no clue why it's happening. I just updated from svn so I
> have the latest django.
> 
> Any help will be really appreciate

Can you please post the model class, including (if present) __unicode__()
and __str__() functions?

Michael

-- 
noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The IT-Outsourcing Company
 
Vorstand: Ingo Kraupa (Vorsitzender), Joachim Astel, Hansjochen Klenk - 
Vorsitzender des Aufsichtsrats: Stefan Schnabel - AG Nürnberg HRB 17689

--~--~-~--~~~---~--~~
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: Strange encoding behavior

2007-08-30 Thread Anderson Santos

I am still having this issue.
I have in my settings DEFAULT_CHARSET = "utf-8", and I created a new
database with UTF-8 encoding (using PGAdmin).
So I go to admin page, click on my model and then the "add" button, I
include a special char (á, ç, etc) and I get a Unicode error on both,
Linux and Windows.

The error message on Linux is:

'utf8' codec can't decode bytes in position 1-2: unexpected end of
data


The error message on Windows is:

'utf8' codec can't decode bytes in position 1-3: invalid data


The problem is, it DOES saves the data and displays correctly on the
listing admin page for the model. The error only occurs when I try to
edit, on display. If the record don't have any special char, it works
correctly.


Both occurs on force_unicode procedure


When I try to add from manage.py shell onlinux (with or without
special chars), it raises an error "SET client_encoding to 'UNICODE'"
in  django/db/backends/postgresql/base.py

I really have no clue why it's happening. I just updated from svn so I
have the latest django.

Any help will be really appreciate


cheers


Anderson




On 29 ago, 18:30, Anderson Santos <[EMAIL PROTECTED]>
wrote:
> Hello,
>
> I am migrating a stable lighttpd+fcgi django app to apache+mod_python
> and I am dealing with a strange encoding behavior. Here what I did:
>
> With a plain migration from the working app to the new mod_python one
> I got a lot of LATIN1 codec errors that never occured on the last
> architecture.  So, I decided to migrate everything to UTF-8.
>
> - I had a Latin1 encoded Postgresql database. I backed it up, created
> a new one with utf-8 encoding and restored the data
> - I changed the settings to DEFAULT_CHARSET = UTF-8
>
> Now everything is fine: flatpages, admin in general, etc, except when
> I click to edit a record on admin interface it raises the error:
>
> UnicodeDecodeError at /admin/suporte/download/95/
> 'utf8' codec can't decode bytes in position 8-10: invalid data
>
> Unicode error hint
>
> The string that could not be encoded/decoded was: aliza??o de B
>
> Template error
>
> In template /srv/djprojects/django_src_trunk/django/contrib/admin/
> templates/admin/change_form.html, error at line 15
>
> Traceback (innermost last)
> Switch back to interactive view
>
> * /srv/djprojects/django_src_trunk/django/template/__init__.py in
> render_node
>747.
>748. def render_node(self, node, context):
>749. return node.render(context)
>750.
>751. class DebugNodeList(NodeList):
>752. def render_node(self, node, context):
>753. try:
>754. result = node.render(context) ...
>755. except TemplateSyntaxError, e:
>756. if not hasattr(e, 'source'):
>757. e.source = node.source
>758. raise
>759. except Exception, e:
>760. from sys import exc_info
>
> Traceback (most recent call last):
> File "/srv/djprojects/django_src_trunk/django/template/__init__.py" in
> render_node
>   754. result = node.render(context)
> File "/srv/djprojects/django_src_trunk/django/template/__init__.py" in
> render
>   790. return self.filter_expression.resolve(context)
> File "/srv/djprojects/django_src_trunk/django/template/__init__.py" in
> resolve
>   603. obj = func(obj, *arg_vals)
> File "/srv/djprojects/django_src_trunk/django/template/
> defaultfilters.py" in _dec
>   25. args[0] = force_unicode(args[0])
> File "/srv/djprojects/django_src_trunk/django/utils/encoding.py" in
> force_unicode
>   39. s = unicode(str(s), encoding, errors)
>
>   UnicodeDecodeError at /admin/suporte/download/95/
>   'utf8' codec can't decode bytes in position 8-10: invalid data
>
> """
>
> But when displayed on admin list for the model, it displays the
> encoding correctly, even the special chars. The line in template is
> the following:
>
> 
> #...
> {% if add %}{% trans "Add" %} {{ opts.verbose_name|escape }}{% else %}
> {{ original|truncatewords:"18"|escape }}{% endif %}
> #...
>
> When I click on a record that don't have special char, it works fine
> for editing, the error just occur with records with special chars.
> Again, the listing displays without problem, it seems to be a problem
> to force unicode procedure on template system.
>
> I appreciate any help.
>
> Cheers,
>
> Anderson


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