예제 #1
0
파일: dbapi.py 프로젝트: 3ll34ndr0/10cur4
 def loadReg(self):
   """Method that creates an Horario object from current activity and database data"""
   areg = getActivityRegister(self.database,self.activity)
   horarios = json.loads(getActivityRegister(self.database,self.activity)[1])
   h = horarios['horarios']
   # Get all keys from 'horarios'
   keys = list(h.keys())
   # Get the first key and create the object
   key = keys.pop()
   objetoHorario = Horario(self.activity, key, h[key][0], h[key][1], h[key][2])
   # Next, get all other keys and populate the object with data from ddbb
   while len(keys)>0:
      key = keys.pop()
      objetoHorario.addAppointment(key,h[key][0], h[key][1], h[key][2])
   return objetoHorario
예제 #2
0
파일: dbapi.py 프로젝트: 3ll34ndr0/10cur4
 def loadReg(self):
     """Method that creates an Horario object from current activity and database data"""
     areg = getActivityRegister(self.database, self.activity)
     horarios = json.loads(
         getActivityRegister(self.database, self.activity)[1])
     h = horarios['horarios']
     # Get all keys from 'horarios'
     keys = list(h.keys())
     # Get the first key and create the object
     key = keys.pop()
     objetoHorario = Horario(self.activity, key, h[key][0], h[key][1],
                             h[key][2])
     # Next, get all other keys and populate the object with data from ddbb
     while len(keys) > 0:
         key = keys.pop()
         objetoHorario.addAppointment(key, h[key][0], h[key][1], h[key][2])
     return objetoHorario
예제 #3
0
파일: dbapi.py 프로젝트: 3ll34ndr0/10cur4
def modifyActivityRegister(
		database,
		activity,
		initHour,
		endHour=None,
		quota='1',
		participants=None,
		description=None,
		vCalendar=None):
    """
	Modifico algun valor de la tabla
	Horarios, cantidad maxima de participantes (quota)
	TODO: Chequear la integridad (formato) de los datos antes de guardar.
	horarios: "{'Dia':'(HoraComienzo,HoraFin,participants,quota),(HoraComienzo2,HoraFin2,participants,quota2),...)'}"
	horarios incluye la cantidad maxima de participantes  y lista de inscriptos (telefonos)
	Dia, HoraComienzo, horaFin, quota: Are UTF-8 strings
	participants is a set, including telephoneNumber's participants
	Dia: lunes|martes|... en minusculas.
	Hora: HH:MM
    """
    # Primero tengo que obtener de la base de datos, lo que haya
    activityRegister = getActivityRegister(database, activity)
    if activityRegister[0] == activity:
        # Luego transformalo en un objeto clase Horario
        horarios = json.loads(activityRegister[1])
        h = horarios['horarios']
        for key in h.keys():
            objetoHorario = Horario(activity, key, h[key][0], h[key][1], h[key][2])
            #print("dentro el for")
            #print(h[key][2])
            #print(objetoHorario.horarios[key][2])
            # Recupero los valores para no pisarlos despues (solo el que modifica)
            if initHour == key:
                participantsReg = objetoHorario.horarios[key][2]
                #print("aca")
                #print objetoHorario.horarios
                #print(participantsReg)
                if participants is not None:
                    #print("New participants, but recovering old ones: {}".format(participantsReg))
                    ##print(participantsReg)
                    participantsReg.update(participants)
            if endHour     == None:
                endHour = objetoHorario.horarios[key][0]
            if quota       == '1':
                quota = objetoHorario.horarios[key][1]
        else:
            print("Appointment {key} is not going to be modified".format(key))
        #print("{}, {}, {}, {}".format(key, h[key][0],h[key][1],participantsReg))

        # Ya tengo el objeto, ahora puedo actualizarlo:
        objetoHorario.addAppointment(initHour,endHour,quota, participantsReg)
        horariosJSON  = json.dumps(objetoHorario, default=jdefault)
        #print(horariosJSON)
    else:
        return "Message: Not such activity defined"
    try:
        db = sqlite3.connect(database)
        cursor = db.cursor()
        # Aca va un update only horario column.
        cursor.execute(
        '''UPDATE activityCalendar SET horarios = ? WHERE act = ? ''', (horariosJSON, activity))
        message = "Message: {}, ".format(horariosJSON)
        if description is not None:
            cursor.execute(
            '''UPDATE activityCalendar SET description = ? WHERE act = ? ''', (description, activity))
            message += "{}, ".format(description)
        if vCalendar is not None:
            cursor.execute(
            '''UPDATE activityCalendar SET vCalendar = ? WHERE act = ? ''', (vCalendar, activity))
            message += "{}, ".format(vCalendar) 
        message += "added to {}".format(activity) 
        db.commit()
    except sqlite3.IntegrityError as e:
        db.rollback()
        raise e
    except sqlite3.OperationalError as e:
        db.rollback()
        raise e
    finally:
        cursor.close()
    return message
예제 #4
0
파일: dbapi.py 프로젝트: 3ll34ndr0/10cur4
def modifyActivityRegister(database,
                           activity,
                           initHour,
                           endHour=None,
                           quota='1',
                           participants=None,
                           description=None,
                           vCalendar=None):
    """
	Modifico algun valor de la tabla
	Horarios, cantidad maxima de participantes (quota)
	TODO: Chequear la integridad (formato) de los datos antes de guardar.
	horarios: "{'Dia':'(HoraComienzo,HoraFin,participants,quota),(HoraComienzo2,HoraFin2,participants,quota2),...)'}"
	horarios incluye la cantidad maxima de participantes  y lista de inscriptos (telefonos)
	Dia, HoraComienzo, horaFin, quota: Are UTF-8 strings
	participants is a set, including telephoneNumber's participants
	Dia: lunes|martes|... en minusculas.
	Hora: HH:MM
    """
    # Primero tengo que obtener de la base de datos, lo que haya
    activityRegister = getActivityRegister(database, activity)
    if activityRegister[0] == activity:
        # Luego transformalo en un objeto clase Horario
        horarios = json.loads(activityRegister[1])
        h = horarios['horarios']
        for key in h.keys():
            objetoHorario = Horario(activity, key, h[key][0], h[key][1],
                                    h[key][2])
            #print("dentro el for")
            #print(h[key][2])
            #print(objetoHorario.horarios[key][2])
            # Recupero los valores para no pisarlos despues (solo el que modifica)
            if initHour == key:
                participantsReg = objetoHorario.horarios[key][2]
                #print("aca")
                #print objetoHorario.horarios
                #print(participantsReg)
                if participants is not None:
                    #print("New participants, but recovering old ones: {}".format(participantsReg))
                    ##print(participantsReg)
                    participantsReg.update(participants)
            if endHour == None:
                endHour = objetoHorario.horarios[key][0]
            if quota == '1':
                quota = objetoHorario.horarios[key][1]
        else:
            print("Appointment {key} is not going to be modified".format(key))
        #print("{}, {}, {}, {}".format(key, h[key][0],h[key][1],participantsReg))

        # Ya tengo el objeto, ahora puedo actualizarlo:
        objetoHorario.addAppointment(initHour, endHour, quota, participantsReg)
        horariosJSON = json.dumps(objetoHorario, default=jdefault)
        #print(horariosJSON)
    else:
        return "Message: Not such activity defined"
    try:
        db = sqlite3.connect(database)
        cursor = db.cursor()
        # Aca va un update only horario column.
        cursor.execute(
            '''UPDATE activityCalendar SET horarios = ? WHERE act = ? ''',
            (horariosJSON, activity))
        message = "Message: {}, ".format(horariosJSON)
        if description is not None:
            cursor.execute(
                '''UPDATE activityCalendar SET description = ? WHERE act = ? ''',
                (description, activity))
            message += "{}, ".format(description)
        if vCalendar is not None:
            cursor.execute(
                '''UPDATE activityCalendar SET vCalendar = ? WHERE act = ? ''',
                (vCalendar, activity))
            message += "{}, ".format(vCalendar)
        message += "added to {}".format(activity)
        db.commit()
    except sqlite3.IntegrityError as e:
        db.rollback()
        raise e
    except sqlite3.OperationalError as e:
        db.rollback()
        raise e
    finally:
        cursor.close()
    return message