Skip to content

Instantly share code, notes, and snippets.

View rg3915's full-sized avatar
🏠
Working from home

Regis Santos rg3915

🏠
Working from home
View GitHub Profile
@rg3915
rg3915 / Makefile
Created April 8, 2023 20:42
Makefile
indenter:
find backend -name "*.html" | xargs djhtml -t 2
autopep8:
find backend -name "*.py" | xargs autopep8 --max-line-length 120 --in-place
isort:
isort -m 3 * --skip migrations --skip .venv
lint: autopep8 isort indenter
@rg3915
rg3915 / group_by.js
Last active April 6, 2023 04:41
desafio 4 - agrupar dados de um JSON - agrupar pela data
function group_by_date(transactions) {
/*
Agrupa os dados por data.
*/
// Dicionário vazio
const result = {}
for (const transaction of transactions) {
// Adiciona uma chave no dicionário
const date = transaction['date']
@rg3915
rg3915 / dj_scaffold.sh
Last active March 31, 2023 07:01
Create templates to Django app dj_scaffold
#!/bin/bash
# Run this code with manager.py folder.
# Usage: $ ~/.dj_scaffold.sh crm person
<<comment
Create templates
* _list.html
* _detail.html
@rg3915
rg3915 / models.py
Created March 31, 2023 03:43
get_fields_verbose_names return field names of models field name model
def get_fields_verbose_names(self):
return [{'name': field.verbose_name, 'value': getattr(self, field.name)} for field in self._meta.fields]
@rg3915
rg3915 / README.md
Created March 24, 2023 19:06
delete backward and forward word on terminal linux - delete word

delete backward - Ctrl + W

delete forward - Alt + D

@rg3915
rg3915 / views.py
Last active March 22, 2023 05:09
form add select add form validation
def save_data(data, form_class, model, field) -> bool:
'''
Adiciona um novo valor no FK vindo do select do form.
Usando select2 com tags:true no select.
field_name: Nome do campo no form.
field_name_fk: Nome do campo na tabela ForeignKey.
field_value: Valor do campo field_name.
'''
field_name, field_name_fk, field_value = field
@rg3915
rg3915 / README.md
Created March 22, 2023 03:22
form add select add form validation Como inserir um novo valor no select do form e contornar o erro de formulário

Como inserir um novo valor no select do form e contornar o erro de formulário?

Eu tenho um formulário com um campo FK, no meu exemplo, Setor.

# models.py
class Produto(models.Model):
    titulo = models.CharField('Título', max_length=255)
    setor = models.ForeignKey(
 Setor,
@rg3915
rg3915 / alpine.js.gif
Last active March 15, 2023 05:23
Select all checkbox with AlpineJS - select all alpinejs
alpine.js.gif
@rg3915
rg3915 / README.md
Last active March 15, 2023 05:10
AlpineJS start project
@rg3915
rg3915 / report.py
Last active March 10, 2023 05:26
report creator
import uuid
from datetime import datetime
from pprint import pprint
import click
import yaml
from utils import datetime_to_string
FILENAME = 'report_test.yml'
# limit the task_type enum add just add an valid one