djangosnippets.org: Latest snippets tagged with 'unicode'https://djangosnippets.org/tags/unicode/2016-01-22T12:12:52.311295-06:00Generic Outputting CSV with Django
2016-01-22T12:12:52.311295-06:00PatrickPortohttps://djangosnippets.org/snippets/10550/<p>Save the snippet as actions.py within your core app, and then add an action on any model you want in it's ModelAdmin definition.</p>
<p>Example usage:</p>
<p><code>from actions import export_as_csv_action</code></p>
<p><code>class YourModelAdmin(admin.ModelAdmin):</code><br />
<code>list_display = ('field', 'get_field2')</code><br />
<code>actions = [export_to_csv(filename='your-model')]</code><br />
<code>def get_field2(self, obj):</code><br />
<code>return obj.field2</code></p>
Freely redistributableBetter slugify
2011-10-30T06:03:39.736479-05:00mmajcherhttps://djangosnippets.org/snippets/2585/<p>Better slugify function for national characters. Source of original script: http://trac.django-fr.org/browser/site/trunk/project/links/slughifi.py?rev=47</p>
Freely redistributablePossessive-aware unicode for models
2010-02-15T16:30:12.662462-06:00shackerhttps://djangosnippets.org/snippets/1928/<p>For a model FK'd to a user or profile, you might want every instance of that thing to appear in your site and in the admin as say "Joe's bucketlist." But if Joe's name is Ross, you want "Ross' bucketlist", not "Ross's bucketlist." </p>
Freely redistributableUnicodeFixer
2009-12-16T10:54:33.761089-06:00jeanmachucahttps://djangosnippets.org/snippets/1837/<p>This snippet is for resolve the Django-PyAMF unicode problems, through the django force_unicode function called recursively, with a tuple of different charsets.</p>
Freely redistributableUnicodeReprMixIn
2009-01-04T18:23:30.810675-06:00ashcrowhttps://djangosnippets.org/snippets/1275/<p>Add's updated and created fields to a model if mixed in.</p>
<p>Example that uses the name as the representation:</p>
<pre><code>class Company(models.Model, UnicodeReprMixIn):
"""
A representation of a comic book company.
"""
name = models.CharField(max_length=255)
slug = models.SlugField()
logo = models.ImageField(upload_to=os.path.join('upload', 'company_logos'))
url = models.URLField(verify_exists=True)
_unicode = "name"
</code></pre>
Freely redistributableUnicodeWriter and UnicodeDictWriter - write unicode strings out to Excel compatible CSV files
2008-08-20T05:40:10.097551-05:00simonhttps://djangosnippets.org/snippets/993/<p>Exporting unicode data to Excel in a CSV file is surprisingly difficult. After much experimentation, it turns out the magic combination is UTF-16, a byte order mark and tab-delimiters. This snippet provides two classes - UnicodeWriter and UnicodeDictWriter - which can be used to output Excel-compatible CSV.</p>
Freely redistributableCharacter encoding fix
2008-04-25T10:38:16.216227-05:00mrtronhttps://djangosnippets.org/snippets/724/<p>There is a commonly encountered problem with Django and character sets. Windows applications such as Word/Outlook add characters that are not valid ISO-8859-1 and this results in problems saving a Django model to a database with a Latin 1 encoding. These characters should also be converted to avoid any display …</p>
Freely redistributableConvert Unicode to ASCII
2008-02-06T18:14:06.699953-06:00coordthttps://djangosnippets.org/snippets/588/<p>Unicode is great, but there are places where the conversion ends up with unintelligible characters. I first noticed this with curly quotes entered in forms on our site.</p>
<p><code>unicode_to_ascii</code> converts compound characters to close approximations in ASCII: such as umlaut-u to u, 1/2 (fraction glyph) to 1/2. You can add …</p>
Freely redistributablegettext parachut for python 2.3 with unicode and utf-8
2007-03-07T02:48:49.787573-06:00angermanhttps://djangosnippets.org/snippets/88/<p>I ran into this because my development system is django on python 2.4 and I deploy to 2.3. It's a corner case where you use gettext, the </p>
<p># -*- coding: utf-8 -*-</p>
<p>header and want to have a consistant style in your file.</p>
<p>It is encouraged to use the unicode …</p>
Freely redistributable