Skip to content

Commit

Permalink
add on CI flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiusstrauss committed Aug 29, 2021
1 parent 5776816 commit 7806c56
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 210 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ staticfiles/
/media/
mediafiles/

/flake-report/


*.pyc
__pycache__/
*.py[cod]
Expand Down
18 changes: 1 addition & 17 deletions dessafio/urls.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
"""dessafio URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from pytransfer import urls as ApiUrl
from django.views.generic import TemplateView
from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='pyTransfer')


urlpatterns = [
path('', schema_view, name='swagger-ui' ),
path('', schema_view, name='swagger-ui'),
path('admin/', admin.site.urls),
path('api/', include(ApiUrl)),

Expand Down
100 changes: 47 additions & 53 deletions pytransfer/models.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
import uuid
from decimal import Decimal
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.db.models import Sum, Q
from decimal import Decimal
from django.db import models
from django.db.models import Sum


class PessoaManager(models.Manager):

# retorna apenas as pessoas ativas
def get_queryset(self):
return super().get_queryset().filter(ativo=True)


class Pessoa(models.Model):
nome = models.CharField(max_length=50)
sobrenome = models.CharField(max_length=50)
nomecompleto = models.CharField(max_length=110)
email = models.EmailField()
telefone = models.CharField(max_length=20)
cpf = models.CharField(max_length=20)
ativo = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
objects = PessoaManager() # Manager de Pessoas
nome = models.CharField(max_length=50)
sobrenome = models.CharField(max_length=50)
nomecompleto = models.CharField(max_length=110)
email = models.EmailField()
telefone = models.CharField(max_length=20)
cpf = models.CharField(max_length=20)
ativo = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
objects = PessoaManager() # Manager de Pessoas

class Meta:
verbose_name = ('Pessoa')
verbose_name_plural = ('Pessoas')

def __str__(self):
return '%s | Saldo: R$ %s' % (self.nomecompleto, self.balance)

return '%s | Saldo: R$ %s' % (self.nomecompleto, self.balance)

@property
def token(self):
def token(self):
result = Token.objects.get(Pessoa=self)
return result.codigo

@property
def balance(self):
result = Decimal('0.00000')
def balance(self):
result = Decimal('0.00000')

# Soma valores bloqueados em transações
bloqueado = History.objects.filter(remetente=self).filter(
Expand All @@ -58,19 +56,17 @@ def balance(self):
result = carteira - bloqueado
return result


def setInicialToken(self, token):
loToken = Token()
loToken.codigo = token
loToken.pessoa = self
loToken = Token()
loToken.codigo = token
loToken.pessoa = self
loToken.save()
return True


def setInicialBalance(self, value):
loBalance = Balance()
loBalance.valor = value
loBalance.pessoa = self
loBalance = Balance()
loBalance.valor = value
loBalance.pessoa = self
loBalance.save()
return True

Expand All @@ -81,24 +77,25 @@ class Token(models.Model):

def __str__(self):
return '%s : %s' % (
self.pessoa.nome,
self.pessoa.nome,
self.codigo
)


class Balance(models.Model):
valor = models.DecimalField(null=True, max_digits=12, decimal_places=5, default=0)
pessoa = models.ForeignKey("Pessoa", on_delete=models.CASCADE)
tx_token = models.CharField(max_length=100, blank=True, default='')
cancelado = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
valor = models.DecimalField(
null=True, max_digits=12, decimal_places=5, default=0)
pessoa = models.ForeignKey("Pessoa", on_delete=models.CASCADE)
tx_token = models.CharField(max_length=100, blank=True, default='')
cancelado = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return '%s | R$ %s' % (
self.pessoa.nome,
self.pessoa.nome,
self.valor
)


class History(models.Model):

F = 'Finalizado'
Expand All @@ -113,31 +110,28 @@ class History(models.Model):
(C, 'Cancelado')
)

remetente = models.ForeignKey("Pessoa", on_delete=models.CASCADE)
destino = models.ForeignKey("Pessoa", related_name="Pessoa", on_delete=models.CASCADE)
token_destino = models.CharField(max_length=100)
valor = models.DecimalField(null=True, max_digits=12, decimal_places=5, default=0)
created_at = models.DateField(auto_now_add=True)
update_at = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=P)
auth_token = models.CharField(max_length=100, blank=True)
remetente = models.ForeignKey("Pessoa", on_delete=models.CASCADE)
destino = models.ForeignKey(
"Pessoa", related_name="Pessoa", on_delete=models.CASCADE)
token_destino = models.CharField(max_length=100)
valor = models.DecimalField(
null=True, max_digits=12, decimal_places=5, default=0)
created_at = models.DateField(auto_now_add=True)
update_at = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=P)
auth_token = models.CharField(max_length=100, blank=True)

def __str__(self):
return '%s -> R$ %s -> %s -> cpf %s | %s' % (
self.remetente.nome,
self.remetente.nome,
self.valor,
self.destino.nome,
self.destino.cpf,
self.destino.nome,
self.destino.cpf,
self.status
)

)

def save(self, *args, **kwargs):
# Gera o token da transacao
if not self.auth_token:
self.auth_token = uuid.uuid4()
self.auth_token = uuid.uuid4()
super(History, self).save(*args, **kwargs)




Loading

0 comments on commit 7806c56

Please sign in to comment.