>>> import os >>> from django.conf import settings >>> from django.core.files.images import ImageFile
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: utf-8 | |
from django.core.files.images import ImageFile | |
from django.core.management.base import BaseCommand, CommandError | |
from icon_manager.models import Icone, Cor | |
import os, re | |
from settings import STATIC_ROOT | |
try: | |
from PIL import Image | |
except ImportError: |
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 random import shuffle | |
class Tombola(object): | |
'''Sorteia itens sem repetir''' | |
def carregar(self, seq): | |
self.itens = list(seq) | |
def misturar(self, misturadora=None): | |
if misturadora is None: |
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 core.validators import format_locality, validate_locality | |
class ClientForm(forms.ModelForm): | |
... | |
... | |
locality = forms.CharField( | |
help_text=u'Local da sede principal do cliente. Ex: São Paulo - SP', | |
validators=[validate_locality], | |
) | |
... |
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: utf-8 | |
from core.forms import ClientForm | |
from core.models import Client | |
from django.test import TestCase | |
from django.contrib.auth.models import User | |
class ClientFormTestCase(TestCase): | |
fixtures = ['client_forms_testdata.json'] | |
def setUp(self): |
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
# forms.py | |
class UserProfileForm(forms.ModelForm): | |
class Meta: | |
model = UserProfile | |
exclude = ('user',) | |
class UserForm(UserCreationForm): | |
def __init__(self, *args, **kwargs): | |
super(UserForm, self).__init__(*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
# coding: utf-8 | |
import os, re, zipfile, argparse | |
try: | |
from PIL import Image | |
except ImportError: | |
import Image | |
def normalizar(valor): | |
""" |
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
import timeit | |
t = timeit.Timer("v=sorted(d.items(), key=lambda x: x[1])[-1]", | |
"d = {'a': 1000, 'b': 3000, 'c':100}") | |
print t.timeit() | |
# 1.648s | |
t = timeit.Timer("v=max(d.iteritems(), key = operator.itemgetter(1))[0]", | |
"import operator; d = {'a': 1000, 'b': 3000, 'c':100}") | |
print t.timeit() |
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 tkinter import * | |
def salvar_dados(): | |
valor_nome = nome.get() | |
valor_categoria = categoria.get() | |
valor_endereco = endereco.get('1.0', END) | |
with open('dados.txt', mode='a', encoding='utf8') as dados: | |
dados.write(""" | |
Nome: {} |
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
import sys | |
try: | |
from PIL import Image | |
except ImportError: | |
import Image | |
try: | |
largura_desejada = int(sys.argv[2]) | |
imagem = Image.open(str(sys.argv[1])) |