-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpyTo
63 lines (48 loc) · 1.56 KB
/
pyTo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#-*- coding: utf-8 -*-
"""Un simple Backend para una aplicación TODO, usando Elixir"""
import os
from elixir import *
dbdir=os.path.join(os.path.expanduser("~"), ".pyqtodo")
dbfile=os.path.join(dbdir, "tasks.sqlite")
class Task(Entity):
"""Una Tarea para la Lista TODO"""
using_options(tablename='tasks')
text = Field(Unicode, required=True)
date = Field(DateTime, default=None, required=False)
done = Field(Boolean,default=False, required=True)
tags = ManyToMany("Tag")
def __repr__(self):
return "Tarea:"+self.text
class Tag(Entity):
"""Una Etiqueta (tag) que podemos aplicar a la tarea"""
using_options(tablename='tags')
name = Field(Unicode, required= True)
tasks = ManyToMany("Task")
def __repr__(self):
return "Tag:"+self.name
def initDB():
if not os.path.isdir(dbdir):
os.mkdir(dbdir)
metadata.bind = "sqlite:///%s"%dbfile
setup_all()
if not os.path.exists(dbfile):
create_all()
def main():
initDB()
verde=Tag(name=u"verde")
rojo=Tag(name=u"rojo")
tarea1=Task(text=u"Comprar Tomate", tags=[rojo])
tarea2=Task(text=u"Comprar Morron",tags=[rojo])
tarea3=Task(text=u"Comprar Lechuga", tags=[verde])
tarea4=Task(text=u"Comprar Frutillas", tags=[rojo, verde])
session.commit()
print "Tareas Verdes:"
print verde.tasks
print
print "Tareas Rojas:"
print rojo.tasks
print
print "Tareas con l"
print [(t.id, t.text, t.done) for t in Task.query.filter(Task.text.like(ur'%l%')).all()]
if __name__ =="__main__":
main()