I think I have found a workaround but it will probably blow up in my face due to encoding/decoding things I don't fully understand.

Can anyone comment on the robustness of calling the following method in a model's save() ...

"""
def subscript(self):
    formula = u''
    if self.formula:
        for char in self.formula:
            if char == '2':
                char = u'\u2082'
            elif char == '3':
                char = u'\u2083'
            elif char == '4':
                char = u'\u2084'
            elif char == '5':
                char = u'\u2085'
            elif char == '6':
                char = u'\u2086'
            elif char == '7':
                char = u'\u2087'
            elif char == '8':
                char = u'\u2088'
            elif char == '9':
                char = u'\u2089'
            elif char == '0':
                char = u'\u2080'
            elif char == '1':
                char = u'\u2081'
            else:
                char = char.upper()
            formula += char
    return formula

"""

... which seems to work even when re-saving. The subscripts seem to be interpreted as numbers too.

Thanks

Mike


On 6/01/2012 3:08pm, Mike Dewhirst wrote:
Does anyone know of a Django widget for representing molecula formulae?

For example, entering h2o would display with the 2 subscripted and the h
and o both uppercased.

Thanks

Mike


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

Reply via email to