On Mon, Jun 1, 2009 at 2:26 PM, bfrederi <brfrederi...@gmail.com> wrote:

>
> I am having problems using the
> django.contrib.markup.templatetags.markup.markdown function with
> special characters (diacritics and such).
>
> I am using markdown in my model and creating a function that returns
> markdown from a model field. I even went as far as to override the
> save method for my model, and encode the field data as "utf-8" prior
> to the field data being saved, like so:
>
>    def save(self):
>        """Overrides the Model's save method """
>        self.collection_description_short =
> self.collection_description_short.encode("utf-8")
>        self.collection_description_long =
> self.collection_description_long.encode("utf-8")
>        super(MyModel, self).save()
>
> When I try to retrieve it and return the field data in a function, I
> do this:
>
> from django.contrib.markup.templatetags.markup import markdown
>
>    def collection_description_short_markdown(self):
>        """ Generate markdown out of the short description text """
>        if self.collection_description_short:
>            try:
>                markdown_html = markdown
> (self.collection_description_short)
>            except:
>                return "Fail"
>            return markdown_html
>        else:
>            return None
>
> And the markdown function always fails if there is a special character
> in the field data.
>
> Any suggestions?


Get rid of the try/except/return "Fail" so that you get feedback on what,
exactly, the problem is.  What you've done there is hide whatever specific
error/exception message markdown may have provided and replaced it with a
generic "Fail" that doesn't convey any information as to what might be
wrong.  I'd hope markdown is a bit more specific about what it is having
trouble with, and that should give a clue how to fix it.

Karen

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

Reply via email to