Skip to content

Instantly share code, notes, and snippets.

View maxwellamaral's full-sized avatar
😀

Maxwell Anderson maxwellamaral

😀
View GitHub Profile
@maxwellamaral
maxwellamaral / README.md
Last active October 6, 2022 12:46 — forked from crissilvaeng/README.md
Padrão e mensagens de commit.

Styleguides

Mensagens de commit styleguide

  • Usar modo imperativo ("Adiciona feature" não "Adicionando feature" ou "Adicionada feature")
  • Primeira linha deve ter no máximo 72 caracteres
  • Considere descrever com detalhes no corpo do commit
  • Considere usar um emoji no início da mensagem de commit

Emoji | Code | Commit Type

@maxwellamaral
maxwellamaral / admin.py
Created September 6, 2022 12:41 — forked from maxwellcc/admin.py
Para retirar o botão 'Novo' do Django Admin
@admin.register(NotificationType)
class NotificationTypeAdmin(admin.ModelAdmin):
model = NotificationType
(...)
def has_add_permission(self, request, obj=None):
return False
@maxwellamaral
maxwellamaral / ex01.py
Created September 6, 2022 12:41 — forked from maxwellcc/ex01.py
Exemplos de decoradores
def timethis(func):
@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(func.__name__, end - start)
return result
return wrapper
@maxwellamaral
maxwellamaral / model.py
Created September 6, 2022 12:41 — forked from maxwellcc/model.py
Django: detectando mudanças nos campos do model
def save(self, *args, **kwargs):
# Detectando mudanças em alguns campos
old = Notification.objects.filter(pk=getattr(self, 'pk', None)).first()
if old:
# Se o campo number tiver sido modificado, limpar os campos
if old.number != self.number:
self.file = None
self.download_success = False
self.download_date_time = None
@maxwellamaral
maxwellamaral / model.py
Created September 6, 2022 12:40 — forked from maxwellcc/model.py
Campo requerido condicionado no Django
class ArticleForm(forms.ModelForm):
brief_summary = forms.CharField(
widget=TinyMCE(
attrs={
'cols': 80,
'rows': 50
}
)
)
@maxwellamaral
maxwellamaral / model.py
Created September 6, 2022 12:40 — forked from maxwellcc/model.py
Campo requerido condicionado
class ArticleForm(forms.ModelForm):
brief_summary = forms.CharField(
widget=TinyMCE(
attrs={
'cols': 80,
'rows': 50
}
)
)
@maxwellamaral
maxwellamaral / ex02.py
Created September 6, 2022 12:40 — forked from maxwellcc/ex02.py
Exemplos de decoradores com argumentos
def logged(level, name=None, message=None):
def decorate(func):
logname = name if name else func.__name__
log = logging.getLogger(logname)
logmsg = message if message else func.__name__
@wraps(func)
def wrapper(*args, **kwargs):
log.log(level, logmsg)
return func(*args, **kwargs)
@maxwellamaral
maxwellamaral / model.py
Created September 6, 2022 12:39 — forked from maxwellcc/model.py
Django: definindo valor default para campos Foreign Key
def get_symbol_default():
"""
Busca pelo ícone padrão do sistema
:return: retorna o valor default do
"""
try:
default_icon = Default.objects.first().get('default_icon')
except BaseException as error:
raise BaseException(_('Register a default icon.')) from error
return default_icon
@maxwellamaral
maxwellamaral / insert_mdi_icons.sql
Created September 6, 2022 12:39 — forked from maxwellcc/insert_mdi_icons.sql
SQL: Inserindo dados relacionados aos ícones do Material Design Icons (https://materialdesignicons.com/)
INSERT INTO config_icon(name, image_mdb)
VALUES ('axis arrow info', 'mdi-axis-arrow-info'),
('baby buggy', 'mdi-baby-buggy'),
('beehive off outline', 'mdi-beehive-off-outline'),
('bell cancel', 'mdi-bell-cancel'),
('bell cancel outline', 'mdi-bell-cancel-outline'),
('bell minus', 'mdi-bell-minus'),
('bell minus outline', 'mdi-bell-minus-outline'),
('bell remove', 'mdi-bell-remove'),
('bell remove outline', 'mdi-bell-remove-outline'),
@maxwellamaral
maxwellamaral / util1.py
Created September 6, 2022 12:38 — forked from maxwellcc/util1.py
XML: Processa a RPI de patentes, marcas e registros de programa de computador do INPI
# Processa patentes
def get_despachos_patentes_INPI(ip_type, Patent):
if ip_type == 'Patente':
ip_id = Patent.objects.values_list('patent_id', flat=True).filter(active=True)
if ip_id:
for despatch in doc.iterfind('despacho'):
for process in despatch.iterfind('processo-patente'):
number = process.findtext('numero')
if number in ip_id:
qtd_finded += 1