Skip to content

Instantly share code, notes, and snippets.

View patrys's full-sized avatar

Patryk Zawadzki patrys

View GitHub Profile
@patrys
patrys / forms.py
Created August 3, 2011 22:11 — forked from octaflop/forms.py
satchless model example
from django import forms
from satchless.forms.widgets import DecimalInput
from satchless.product.forms import BaseVariantForm
from . import models
class ProductPriceForm(forms.ModelForm):
class Meta:
widgets = {
'price': DecimalInput(min_decimal_places=2),
@patrys
patrys / base.py
Created July 20, 2011 11:59
A custom sqlite3 database backend for Django that turns synchronous mode off
"""
sqlite3 database backend with non-synchronous mode.
It gives you a huge performance boost by turning off the overzealous
synchronous operation mode. The tradeoff is less data protection in case of
power outages but come on, you were not going to use it in production, were you?
"""
from django.db.backends.sqlite3.base import (
DatabaseWrapper as Sqlite3Wrapper,
DatabaseError,
@patrys
patrys / stinson.py
Created June 22, 2011 09:33
Implements the awesome pattern
class Barney(object):
def __enter__(self):
print 'legen...'
def __exit__(self, exc_type, exc_value, traceback):
print '...dary'
with Barney():
print 'wait for it'
@patrys
patrys / gist:784810
Created January 18, 2011 17:38
Proper translation for gender-related messages
{% load i18n %}
{% if u.sex == 'm' %}
{% blocktrans with u.get_full_name as male %}
{{ male }} set up us a bomb.
{% endblocktrans %}
{% else %}
{% blocktrans with u.get_full_name as female %}
{{ female }} set up us a bomb.
{% endblocktrans %}
{% load liczba_mnoga %}
<p>{% liczba_mnoga user_count "jedna osoba" "%(n)s osoby" "%(n)s osób" %}</p>
@patrys
patrys / abstract.py
Created September 17, 2010 11:59
Parametrized apps for Django
class AbstractMixin(object):
_classcache = {}
@classmethod
def contribute(cls):
return {}
@classmethod
def construct(cls, *args, **kwargs):
attrs = cls.contribute(*args, **kwargs)
@patrys
patrys / jquery.placeholder.js
Created August 3, 2010 14:43
Fallback code for the HTML5 "placeholder" attribute
$(function() {
if (!('placeholder' in document.createElement('input'))) {
$('input[placeholder], textarea[placeholder]').each(function() {
var text = this.getAttribute('placeholder');
var fld = $(this);
function setPlaceholder() {
if (fld.val() == text || fld.val() == '') {
fld.addClass('jqPlaceholder');
fld.val(text);