models.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Gestor de nodos para LaOtraRed La Paz - El Alto
  4. Copyright (C) 2017 Rodrigo Garcia
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU Affero General Public License as
  7. published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Affero General Public License for more details.
  13. You should have received a copy of the GNU Affero General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. '''
  16. from sqlalchemy import Column, Integer, String, Float, Boolean
  17. from sqlalchemy import ForeignKey
  18. from database.database import Base
  19. class Ubicacion(Base):
  20. __tablename__ = 'ubicacion'
  21. sqlite_autoincrement=True
  22. id = Column(Integer, primary_key=True)
  23. localidad = Column(String(200))
  24. zona = Column(String(250))
  25. direccion = Column(String(200))
  26. url_mapa = Column(String(1000))
  27. iframe_mapa = Column(String(2000))
  28. elevacion_aproximada = Column(Integer)
  29. latitud = Column(Float())
  30. longitud = Column(Float())
  31. is_public = Column(Boolean(create_constraint=True))
  32. def __init__(self, localidad='', zona='',
  33. direccion='', url_mapa='',
  34. iframe_mapa='', elevacion_aproximada='',
  35. latitud=16.0, longitud=16.0,
  36. is_public=True):
  37. self.localidad= localidad
  38. self.zona = zona
  39. self.direccion = direccion
  40. self.url_mapa = url_mapa
  41. self.iframe_mapa = iframe_mapa
  42. self.elevacion_aproximada = elevacion_aproximada
  43. self.latitud = latitud
  44. self.longitud = longitud
  45. self.is_public = is_public
  46. def __repr__(self):
  47. return '<Ubicacion(%s) %s, %s, %s publica:%s> '\
  48. %(str(self.id), self.localidad, self.zona, self.direccion,\
  49. str(self.is_public))
  50. class Nodo(Base):
  51. __tablename__ = 'nodo'
  52. sqlite_autoincrement=True
  53. id = Column(Integer, primary_key=True)
  54. ubicacion_id = Column(Integer, ForeignKey('ubicacion.id'))
  55. nombre = Column(String(200), unique=True)
  56. bloque_ipv4 = Column(String(19), unique=True)
  57. bloque_ipv4_privado = Column(String(19), unique=True)
  58. ipv4_network_addr = Column(String(16), unique=True)
  59. ipv4_cidr = Column(Integer)
  60. ipv4_cidr_privado = Column(Integer)
  61. bloque_ipv6 = Column(String(164), unique=True)
  62. ipv6_network_addr = Column(String(164), unique=True)
  63. ipv6_cidr = Column(Integer)
  64. is_active = Column(Boolean(create_constraint=False))
  65. is_confirmed = Column(Boolean(create_constraint=False))
  66. url_descarga = Column(String(500), unique=True)
  67. fecha_creacion = Column(String(20)) # se guardan en formato YYYY-MM-DD hh:mm:ss
  68. descripcion = Column(String(2599))
  69. clave_edicion = Column(String(500))
  70. nombres_responsable = Column(String(200))
  71. apellidos_responsable = Column(String(200))
  72. email = Column(String(254))
  73. telf = Column(String(30))
  74. def __init__(self, responsable_id=1, ubicacion_id=1,\
  75. nombre = "-",
  76. bloque_ipv4="-", ipv4_network_addr="-",\
  77. bloque_ipv4_privado = "-", ipv4_cidr_privado=27,
  78. ipv4_cidr=29, bloque_ipv6="-", \
  79. ipv6_network_addr="-",\
  80. ipv6_cidr=128,\
  81. is_active=False, is_confirmed=False,\
  82. url_descarga="sin ulr",\
  83. fecha_creacion = "no valida",\
  84. descripcion="-", clave_edicion="Sin Clave",\
  85. nombres_responsable="-",\
  86. apellidos_responsable="-",\
  87. email="-",\
  88. telf="-",\
  89. ):
  90. self.responsable_id = responsable_id
  91. self.ubicacion_id = ubicacion_id
  92. self.nombre = nombre
  93. self.bloque_ipv4 = bloque_ipv4
  94. self.bloque_ipv4_privado = bloque_ipv4_privado
  95. self.ipv4_network_addr = ipv4_network_addr
  96. self.ipv4_cidr = ipv4_cidr
  97. self.ipv4_cidr_privado = ipv4_cidr_privado
  98. self.bloque_ipv6 = bloque_ipv6
  99. self.ipv6_network_addr = ipv6_network_addr
  100. self.ipv6_cidr = ipv6_cidr
  101. self.is_active = is_active
  102. self.is_confirmed = is_confirmed
  103. self.descripcion = descripcion
  104. self.clave_edicion = clave_edicion
  105. self.url_descarga = url_descarga
  106. self.fecha_creacion = fecha_creacion
  107. self.nombres_responsable = nombres_responsable.lower()
  108. self.apellidos_responsable = apellidos_responsable.lower()
  109. self.email = email.lower()
  110. self.telf = telf
  111. def __repr__(self):
  112. return '<Nodo(%s) %s, %s, activ: %s, confir: %s <%s>'\
  113. % (str(self.id), self.nombre, self.bloque_ipv4, str(self.is_active),\
  114. str(self.is_confirmed), self.email)