This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.safestring import SafeData, mark_safe | |
from django.template import TemplateSyntaxError | |
@register.filter | |
def truncate(value, arg): | |
""" | |
Truncates a string after a given number of chars | |
Argument: Number of chars to truncate after | |
""" | |
mark_safe_if_safe = lambda v: mark_safe(v) if isinstance(value, SafeData) else v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from query import QuerySet | |
class CustomQuerySet(QuerySet): | |
def published(self): | |
return self.filter(published=True) | |
class Content(models.Model): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
""" | |
Template tag to stop template rendering to debug. | |
It's useful to know what is in the context. | |
Just put this file in a templatetags module inside your app and | |
insert this code in your templates where you want to debug: | |
{% load pdbdebug %}{% pdbdebug %} | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ====================================================================== | |
# | |
# Function: lnsp | |
# Creates a symbolic link to a folder inside current site-packages. If | |
# the file already exists, ask for override. | |
# Works ok with virtualenv. | |
# | |
# Parameters: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source /usr/local/Cellar/git/1.7.5.4/etc/bash_completion.d/git-completion.bash # path to git completion | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export GIT_PS1_SHOWSTASHSTATE=1 | |
export GIT_PS1_SHOWUNTRACKEDFILES=1 | |
export GIT_PS1_SHOWUPSTREAM="verbose" | |
PS1='\[$(tput setf 3)\]\u\[$(tput sgr0)\]: \[$(tput setf 6)\]\w \[$(tput setf 2)\]$(__git_ps1 "(%s)")\n\[$(tput bold)$(tput setf 6)\]$ \[$(tput sgr0)\]' | |
source ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from models import Pais | |
class MyForm(forms.Form): | |
pais = forms.ModelChoiceField(queryset = Pais.objects.all()) | |
def __init__(self, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.template import Node, TemplateSyntaxError | |
from django.template import resolve_variable | |
from django.utils.encoding import smart_str | |
class BaseNode(Node): | |
def __init__(self, **kwargs): | |
self.parsed = kwargs | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class HTTPRequest(object): | |
""" | |
Class to generate plain HTTP Requests | |
usage: | |
>>> req = HTTPRequest('meiocodigo.com', path='/') | |
>>> req.add_header('Content-Type', 'application/x-www-form-urlencoded') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
""" | |
Você pode criar a mensagem no próprio form. | |
""" | |
from django import forms | |
from django.forms.util import ErrorList | |
from models import UserDoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModelAdmin(ModelAdmin): | |
... | |
def __getattr__(self, name): | |
""" | |
Permite o uso de um atributo no admin com o nome | |
do atributo mais '_or_blank'. Exemplo: name_or_blank | |
""" | |
if name.endswith('_or_blank'): | |
try: | |
return getattr(self, name[:-9]) or u'' |