Last active
August 29, 2015 14:03
-
-
Save renzon/bd4bde74e05fbba0839e to your computer and use it in GitHub Desktop.
This file contains 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
# Categoria | |
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
from google.appengine.ext import ndb | |
class Categoria(ndb.Model): | |
descricao=ndb.StringProperty() | |
tipo=ndb.StringProperty() | |
# Transacao | |
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
from google.appengine.ext import ndb | |
from web.model.Categoria import Categoria | |
from web.model.Conta import Conta | |
from web.model.Pessoa import Pessoa | |
class Transacao(ndb.Model): | |
data=ndb.DateProperty(auto_now_add=True) | |
categoria = ndb.KeyProperty(Categoria, required=True) | |
# valor=ndb.FloatProperty(required=True) | |
# favorecido=ndb.KeyProperty(Pessoa, required=True) | |
# conta=ndb.KeyProperty(Conta, required=True) | |
# contaDestino=ndb.KeyProperty(Conta) | |
dct['categoria_id']=self.categoria.id() | |
complemento=ndb.StringProperty() | |
def to_dict(self): | |
dct=super(Transacao, self).to_dict() | |
# dct['data']=self.data.strftime('%d/%m/%Y') | |
# dct['data_informada']=self.data_informada.strftime('%d/%m/%Y') | |
dct['id']=self.key.id() | |
return dct | |
# transacao_serv | |
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, unicode_literals | |
import json | |
import datetime | |
from web.model.Transacao import Transacao | |
from google.appengine.ext import ndb | |
def listar(_json): | |
query = Transacao.query().order(Transacao.data) | |
lista = query.fetch() | |
lista_dct=[objeto.to_dict() for objeto in lista] | |
_json(lista_dct) | |
def salvar(_json, complemento, categoria_id): | |
print complemento | |
categoria_key=ndb.Key(Categoria, int(categoria_id)) | |
objeto = Transacao(complemento=complemento, categoria=categoria_key) | |
objeto.put() | |
_json(objeto.to_dict()) | |
# data=ndb.DateProperty(auto_now_add=True) | |
# categoria = ndb.KeyProperty(Categoria, required=True) | |
# valor=ndb.FloatProperty(required=True) | |
# favorecido=ndb.KeyProperty(Pessoa, required=True) | |
# conta=ndb.KeyProperty(Conta, required=True) | |
# contaDestino=ndb.KeyProperty(Conta) | |
# complemento=ndb.StringProperty() | |
def apagar(objeto_id): | |
chave = ndb.Key(Transacao, int(objeto_id)) | |
chave.delete() | |
def atualizar(objeto_id, nome): | |
objeto_id = int(objeto_id) | |
transacao = Transacao.get_by_id(objeto_id) | |
transacao.nome = nome | |
transacao.put() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment