Skip to content

Instantly share code, notes, and snippets.

View gtsalles's full-sized avatar

Gustavo Carvalho gtsalles

View GitHub Profile
@gtsalles
gtsalles / keybase.md
Created January 30, 2020 12:55
keybase.md

Keybase proof

I hereby claim:

  • I am gtsalles on github.
  • I am gtcarvalho (https://keybase.io/gtcarvalho) on keybase.
  • I have a public key ASAEqSRvP0zECfNlvIqJmbNBkl25rAoApzDF1PCMShxt8Ao

To claim this, I am signing this object:

@gtsalles
gtsalles / admin.py
Created January 22, 2016 20:40
Exemplo de readonly_fields dinâmico no admin do django
def get_form(self, request, obj=None, **kwargs):
if obj:
self.readonly_fields = ('employer',)
else:
self.readonly_fields = ()
return super(ScoreAdmin, self).get_form(request, obj, **kwargs)
@gtsalles
gtsalles / onename_verification.txt
Created January 15, 2016 11:39
Verifying that +gtcarvalho is my blockchain ID. https://onename.com/gtcarvalho
Verifying that +gtcarvalho is my blockchain ID. https://onename.com/gtcarvalho
@gtsalles
gtsalles / diamantes.py
Created October 14, 2015 11:28
Solução do problema dos diamantes feita no primeiro encontro do Grupo de Usuários de Python do Piauí. http://dojopuzzles.com/problemas/exibe/diamantes/
#alfabeto = range(97,(97+26))
letra = raw_input("Insira o caractere: ")
i = ord(letra) - 65
aux = 0
for j in range(i, -1, -1):
if aux == 0:
print "%s%c"%(' '*j, chr(65))
else:
print "%s%c%s%c"%(' '*j, chr(65+aux),' '*((aux-1)*2+1),chr(65+aux))
aux += 1
@gtsalles
gtsalles / changelist.py
Created March 24, 2014 13:50
Busca Avançada no Admin
def get_changelist(self, request, **kwargs):
cl = super(CurriculoAdmin, self).get_changelist(request, **kwargs)
class CustomCL(cl):
def get_queryset(self, *args, **kwargs):
qs = super(CustomCL, self).get_queryset(*args, **kwargs)
# deveria montar a query baseadas nos parametros get que passei e
# retornar o novo queryset mas não consigo pegar os parâmetros do get
return qs.filter(query)
@gtsalles
gtsalles / models.py
Created December 2, 2013 00:23
Example of use of signals in Django
from django.db.models.signals import pre_save, post_save, post_delete
from django.dispatch import receiver
class RandomModel(models.Model):
"""fields, etc, etc"""
# Esse método vai ser executado antes de salvar o model RandomModel (model que tá no sender aqui abaixo)
@receiver(pre_save, sender=RandomModel)
def random_pre_save(instance, **kwargs):
@gtsalles
gtsalles / dojo_pug-24-08.py
Last active December 21, 2015 16:39
Solution of PUG-PI for the 'Quebra Linha' [1] problem. [1] http://dojopuzzles.com/problemas/exibe/quebra-de-linha/
# -*- coding: utf-8 -*-
texto = 'Um pequeno jabuti xereta viu dez cegonhas felizes.'
limite = 20
cont_espacos = 0
while len(texto) >20:
print "Tamanho String: ", len(texto)
if texto[19] != ' ':
@gtsalles
gtsalles / admin.py
Created August 20, 2013 18:04
Demonstration of formfield_for_foreignkey method on Django.
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "usuario":
usuario_id = request.GET.get('usuario_id', None)
if usuario_id:
kwargs['initial'] = usuario_id
if db_field.name == "psicologo":
kwargs["queryset"] = User.objects.filter(is_superuser=True)
return super(EntrevistaAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)