Login

Tag "output"

Snippet List

ExcelResponse2

A function extends of Tarken's django-excel-response django-excel-response 1、djangosnippets - http://djangosnippets.org/snippets/1151/ 2、pypi - https://pypi.python.org/pypi/django-excel-response/1.0 When using Tarken's django-excel-response. We find that Chinese is messed code when we open .xls in Mac OS. As discussed in http://segmentfault.com/q/1010000000095546. We realize django-excel-response2 Based on Tarken's django-excel-response to solve this problem By adding a Param named font to set font.

  • output
  • httpresponse
  • excel
  • cvs
Read More

Prettify HTML body contents in HTTP response

This is an enhancement of snippet [#172](http://djangosnippets.org/snippets/172/). Here I use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) — far more easier to install through pip in a virtualenv, and possibly a bit more maintained — to format and properly indent the rendered HTML from templates. I also added a check to only tidy contents in a `DEBUG=True` environment, regarding high impact on performance while doing so in production. Last, it's compatible with Django 1.2.x.

  • templates
  • format
  • html
  • tidy
  • syntax
  • output
  • prettify
  • formatting
  • indentation
  • readability
Read More

Limit the output of a field

This is a really simple snippet , but is not documented well ... Whit this , you can limit the output of one field in 25 characters before you test that is equal or over 30 characters! Note that the snippet cut the text and add three points at the end (...) Enjoy!

  • form
  • field
  • output
  • limit
Read More

format output as table

Ever wished you could have pretty SQL-like output for a python object (e.g., a list of dicts) while you're debugging your code? This function will do just that. Simply pass it an object that is an iterable of dictionaries and it returns it in an easy-to-read table, similar to the output of commandline SQL. Example: from tablelize import tableize from django.contrib.auth.models import User print(tableize(User.objects.values('email', 'first_name', 'last_name'))) +------------+-----------+-------------------+ | first_name | last_name | email | +------------+-----------+-------------------+ | Test | User | [email protected] | | Another | User | [email protected] | +------------+-----------+-------------------+

  • format
  • table
  • output
  • tablize
  • tableize
Read More

ExcelResponse

A subclass of `HttpResponse` which will transform a `QuerySet`, or sequence of sequences, into either an Excel spreadsheet or CSV file formatted for Excel, depending on the amount of data. All of this is done in-memory and on-the-fly, with no disk writes, thanks to the StringIO library. **Requires:** [xlwt](http://pypi.python.org/pypi/xlwt/) **Example:** def excelview(request): objs = SomeModel.objects.all() return ExcelResponse(objs)

  • csv
  • output
  • httpresponse
  • excel
Read More

Remove self links middleware

This simple middleware replaces all 'a href' links to the current page to the 'span' elements. This very usefule from the usability point of view. For example, user open in bowser page http://svetlyak.ru/blog/, and this middleware will replace all 'a' elements on this page, which refer to the '/blog/'. Because of this, link 'Blog' in the main menu, become a simple 'span'. Next, when user goes to the next page, a post with full comments list ('/blog/123/'), for example, the item 'Blog' in the main menu become a link again! To use this middleware, just add it to the list of middleware classes: MIDDLEWARE_CLASSES = ('utils.middleware.RemoveSelfLinks',)

  • middleware
  • html
  • output
  • usability
  • utils
Read More

self-related objects list with links

The problem was to output self-related objects (like category objects which may be a sub-category in any category and so on) in unordered list with links to certain view (providing some object.id arg). Its somewhat like unordered_list tag but takes plain list of objects and provides links. For example: category_list = Category.objects.all() In your template: {% related_linked_list category_list view_category %} This tag, however, have some limits: 1. Model shoud have self-related "parent" and id that may be passed into view. 2. In model parent = ForeignKey('self', ...) *related_name* is "child_set". But its simple enough that you may easily rewrite it for your own needs. :)

  • template-tags
  • output
Read More

7 snippets posted so far.