This file contains hidden or 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 json | |
class customdict(dict): | |
def __getattr__(self, name): | |
if name not in self: | |
raise AttributeError | |
return self[name] | |
This file contains hidden or 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 os | |
from django.core.files.storage import default_storage | |
# obj seria uma instância de algum modelo com um FileField ou ImageField | |
# chamado img. | |
with obj.img.open("r") as img: | |
_, ext = os.path.splitext(img.file) |
This file contains hidden or 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.contrib import admin | |
from auditlog.admin import LogEntryAdmin | |
from auditlog.models import LogEntry | |
from .models import CustomLogEntry | |
@admin.register(CustomLogEntry) | |
class CustomLogEntryAdmin(LogEntryAdmin): |
This file contains hidden or 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 datetime import datetime | |
def make_datetime(date, time): | |
return datetime( | |
year=date.year, | |
month=date.month, | |
day=date.day, | |
hour=time.hour, | |
minute=time.minute, |
This file contains hidden or 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 django.contrib.staticfiles.storage import staticfiles_storage | |
DEFAULT_IMAGE = 'img/default.svg' | |
class Place(models.Model): | |
name = models.CharField(max_length=50, unique=True) | |
image = models.ImageField(upload_to="places/", blank=True, null=True) |
This file contains hidden or 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 ItemSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Item | |
fields = "__all__" | |
class CreatePointSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Point | |
fields = "__all__" |
This file contains hidden or 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 functools import wraps | |
from django.shortcuts import redirect | |
def verificar_funcionario(redirect_to='set_password'): | |
def decorator(view_func): | |
@wraps(view_func) | |
def _wrapped_view(request, *args, **kwargs): | |
if request.user.funcionario.mudou_senha_padrao: |
This file contains hidden or 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
<?php | |
function choices($start, $operation, $max = 999) | |
{ | |
$down = $operation < 0; | |
$start = $down ? $start : $start + 1; | |
$end = $start + ($down ? $operation : $operation - 1); | |
$choices = []; |
This file contains hidden or 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.models import Q | |
from django_rest import filters | |
class DateRangeFilterBackend(filters.BaseFilterBackend): | |
field_name = None | |
base_query_param = None | |
suffix_lookups = { | |
'inicio': 'date__gte', | |
'fim': 'date__lte' |