Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Função para transformar CaixaCamelo em Caixa Camelo
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Luciano Ramalho  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 8:12 am
From: Luciano Ramalho <luci...@ramalho.org>
Date: Fri, 5 Feb 2010 11:12:25 -0200
Local: Fri, Feb 5 2010 8:12 am
Subject: Função para transformar CaixaCamelo em Caixa Camelo
Deve ter uma função no Django que transforma "UmaStringAssim" em "Uma
String Assim", porque ele faz isso no Admin. Mas eu passei meia hora
vasculhando o código-fonte do Django 1.1 e não achei.

Em menos de meia hora eu poderia ter feito a minha própria função, mas
quando se usa um framework não é uma boa idéia duplicar a
funcionalidade que ele oferece nas nossas aplicações.

Então, alguém sabe onde fica a bendita função?

[ ]s
Luciano

--
"""
Many were increasingly of the opinion that they'd all made a big
mistake in coming down from the trees in the first place. And some
said that even the trees had been a bad move, and that no one should
ever have left the oceans. (DA/HHGTTG)
"""


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luciano Ramalho  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 8:26 am
From: Luciano Ramalho <luci...@ramalho.org>
Date: Fri, 5 Feb 2010 11:26:17 -0200
Local: Fri, Feb 5 2010 8:26 am
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo
2010/2/5 Luciano Ramalho <luci...@ramalho.org>:

> Deve ter uma função no Django que transforma "UmaStringAssim" em "Uma
> String Assim", porque ele faz isso no Admin. Mas eu passei meia hora
> vasculhando o código-fonte do Django 1.1 e não achei.

> Em menos de meia hora eu poderia ter feito a minha própria função, mas
> quando se usa um framework não é uma boa idéia duplicar a
> funcionalidade que ele oferece nas nossas aplicações.

Pronto, resolvi assim:

>>> import re
>>> s = 'UmTextoCaixaCamelo'
>>> re.sub('(\w)([A-Z])', lambda m: m.group(1)+' '+m.group(2), s)

'Um Texto Caixa Camelo'

Mas eu ainda gostaria de saber onde uma coisa assim está implementada
no Django, se alguém souber.

Valeu!

[ ]s
Luciano

--
"""
Many were increasingly of the opinion that they'd all made a big
mistake in coming down from the trees in the first place. And some
said that even the trees had been a bad move, and that no one should
ever have left the oceans. (DA/HHGTTG)
"""


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vanderson Mota dos Santos  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 8:28 am
From: Vanderson Mota dos Santos <vanderson.m...@gmail.com>
Date: Fri, 5 Feb 2010 11:28:36 -0200
Local: Fri, Feb 5 2010 8:28 am
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo

Eu também procurei, sem sucesso. Agora estou curioso também.

Em 5 de fevereiro de 2010 11:26, Luciano Ramalho <luci...@ramalho.org>escreveu:

--
Vanderson Mota dos Santos

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rafael Sierra  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 8:48 am
From: Rafael Sierra <rafaeljs...@gmail.com>
Date: Fri, 5 Feb 2010 11:48:49 -0200
Local: Fri, Feb 5 2010 8:48 am
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo
2010/2/5 Luciano Ramalho <luci...@ramalho.org>:

O mais perto que eu cheguei até agora foi isso aqui (não testei):

django/db/models/options.py:get_verbose_name = lambda class_name:
re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1',
class_name).lower().strip()

--
Rafael Sierra
http://blog.stiod.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luciano Ramalho  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 11:41 am
From: Luciano Ramalho <rama...@gmail.com>
Date: Fri, 5 Feb 2010 14:41:35 -0200
Local: Fri, Feb 5 2010 11:41 am
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo
2010/2/5 Rafael Sierra <rafaeljs...@gmail.com>:

Valeu, Rafael, você achou o código!

É curioso que a minha solução e a do Django usam lambda, mas em minha
opinião a solução do Django usa o lambda sem motivo.

A utilidade do lambda é criar funções anônimas, para uso apenas em um
contexto bem restrito. Se vocẽ usa o lambda para definir uma função e
na mesma linha você atribui a uma variável para poder usá-la depois,
deveria usar o def, que serve exatamente para criar uma função e
associá-la a um nome!

Ou seja, em vez disso:

get_verbose_name = lambda class_name:
re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1',
class_name).lower().strip()

O código do Django ficaria mais fácil de ler assim:

def get_verbose_name(class_name):
    return re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1',
class_name).lower().strip()

[ ]s
Luciano

--
"""
Many were increasingly of the opinion that they'd all made a big
mistake in coming down from the trees in the first place. And some
said that even the trees had been a bad move, and that no one should
ever have left the oceans. (DA/HHGTTG)
"""


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rafael Sierra  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 7:08 pm
From: Rafael Sierra <rafaeljs...@gmail.com>
Date: Fri, 5 Feb 2010 22:08:25 -0200
Local: Fri, Feb 5 2010 7:08 pm
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo
2010/2/5 Luciano Ramalho <rama...@gmail.com>:

Pois é...eu achei tão estranho que postei como "cheguei perto",
prefiri não arriscar um "achei!"

Sem duvida nenhuma a melhor opção do ponto de vista da leitura a
melhor opção é a definição da função. Me sobram 2 sugestões e uma
duvida:

1. Não seria interessante subir isso pra django-dev?
2. Por questões de performance, não valeria a pena fazer o cacheamento
do verbose_name com base no class_name (acredito que não devido a essa
função ser chamado poucas vezes e praticamente apenas no admin)
3. (Duvida) Existe algum ganho de performance -significante- em manter
o lambda ou em utilizar o def? Acredito que não mas não tenho nenhum
embasamento, é puro "achometro"

> [ ]s
> Luciano

> --
> """
> Many were increasingly of the opinion that they'd all made a big
> mistake in coming down from the trees in the first place. And some
> said that even the trees had been a bad move, and that no one should
> ever have left the oceans. (DA/HHGTTG)
> """

> --
> Django Brasil em Google Groups <http://groups.google.com.br/group/django-brasil>
> Associe-se à Python Brasil e suporte nossa comunidade! <http://associacao.python.org.br/>

--
Rafael Sierra
http://blog.stiod.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vanderson Mota dos Santos  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 7:12 pm
From: Vanderson Mota dos Santos <vanderson.m...@gmail.com>
Date: Fri, 5 Feb 2010 22:12:20 -0200
Local: Fri, Feb 5 2010 7:12 pm
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo

1. Não seria interessante subir isso pra django-dev?
 +1. Esse lambda complicou a leitura desnecessariamente, como o Luciano
falou.

Em 5 de fevereiro de 2010 22:08, Rafael Sierra <rafaeljs...@gmail.com>escreveu:

--
Vanderson Mota dos Santos

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rafael Sierra  
View profile   Translate to Translated (View Original)
 More options Feb 5 2010, 7:22 pm
From: Rafael Sierra <rafaeljs...@gmail.com>
Date: Fri, 5 Feb 2010 22:22:59 -0200
Local: Fri, Feb 5 2010 7:22 pm
Subject: Re: Função para transformar CaixaCamelo em Caixa Camelo
2010/2/5 Vanderson Mota dos Santos <vanderson.m...@gmail.com>:

> 1. Não seria interessante subir isso pra django-dev?
>  +1. Esse lambda complicou a leitura desnecessariamente, como o Luciano
> falou.

Tomei a liberdade de criar um ticket sobre isso:

http://code.djangoproject.com/ticket/12796

--
Rafael Sierra
http://blog.stiod.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »