Login

Snippets by semente

Snippet List

BRPhoneNumberWidget

A widget created for BRPhoneNumberField that splits the input into a <input> for the area code and another for the phone number. Usage example: class MyForm(forms.Form): mobile_phone = BRPhoneNumberField( label='Telefone Celular', widget=BRPhoneNumberWidget() ) ...

  • phone
  • br
  • localflavor
  • BRPhoneNumberField
Read More

truncatechars filter

Truncates a string after a certain number of chars. Question: > *Why don't you use the built-in filter slice?* I need the "three points" (...) only when it really truncates.

  • template
  • filter
  • truncatewords
Read More

TinyMCE Widget

Widget for TinyMCE 3.2.6, a WYSIWYG HTML editor for `textarea`. **Note:** > This snippet uses the TinyMCE package thats contains special jQuery build of TinyMCE and a jQuery integration plugin. Anyway, is easily to adapt to standard package. Usage example: from django.contrib.flatpages.admin import FlatpageForm class MyFlatPageForm(FlatpageForm): content = forms.CharField(widget=TinyMCEEditor()) [TinyMCE download page](http://tinymce.moxiecode.com/download.php)

  • forms
  • wysiwyg
  • form
  • widget
  • modelform
  • tinymce
Read More

ImageField for admin with thumbnail

AdminImageWidget is a ImageField Widget for admin that shows a thumbnail. Usage example on a form: class IconForm(forms.ModelForm): icon = forms.ImageField(label='icon', widget=AdminImageWidget)

  • image
  • admin
  • thumbnail
  • imagefield
  • widget
  • imagewidget
Read More

Alphabetic filter for admin

This snippet is based on [#748](http://www.djangosnippets.org/snippets/748/). Adds filtering by first char (alphabetic style) of values in the admin filter sidebar. The example below results in this filter: By name that starts with All A B G M X urls.py example (only for register the filter): import <your project>.admin.filterspecs models.py example: from django.db import models class Person(models.Model): name = models.CharField(max_length=40) name.alphabetic_filter = True admin.py example: class Admin: list_filter = ['name']

  • filter
  • admin
  • filterspec
Read More

Dynamic thumbnail generator

This snippet creates thumbnails on-demand from a ImageField with any size using dynamics methods, like ``get_photo_80x80_url`` or ``get_photo_640x480_filename``, etc. It assumes you have an `ImageField` in your Model called `photo` and have this in your models.py: import re from os import path from PIL import Image GET_THUMB_PATTERN = re.compile(r'^get_photo_(\d+)x(\d+)_(url|filename)$') `models.py` example: import re from os import path from PIL import Image from django.db import models GET_THUMB_PATTERN = re.compile(r'^get_photo_(\d+)x(\d+)_(url|filename)$') class Photo(models.Model): photo = models.ImageField(upload_to='photos/%Y/%m/%d') <snippet here> Example usage: >>> photo = Photo(photo="/tmp/test.jpg") >>> photo.save() >>> photo.get_photo_80x80_url() u"http://media.example.net/photos/2008/02/26/test_80x80.jpg" >>> photo.get_photo_80x80_filename() u"/srv/media/photos/2008/02/26/test_80x80.jpg" >>> photo.get_photo_64x64_url() u"http://media.example.net/photos/2008/02/26/test_64x64.jpg" >>> photo.get_photo_64x64_filename() u"/srv/media/photos/2008/02/26/test_64x64.jpg"

  • image
  • thumbnail
  • model
  • imagefield
Read More

semente has posted 6 snippets.