Esempio n. 1
0
 def updateRegistered(self, **kw):
     print(kw)
     current_student = DBSession.query(Student).filter_by(student_id=kw["student_id"]).first()
     current_course = DBSession.query(Course).filter_by(code=kw["course_name"]).first()
     current_student.courses.append(current_course)
     DBSession.flush()
     return dict(total=200, page=1, records=500, rows=kw)
Esempio n. 2
0
 def DeleteRegistered(self, **kw):
     print(kw)
     student_id = kw["student_id"]
     course_id = kw["course_id"]
     print(student_id)
     print(course_id)
     current_student = DBSession.query(Student).filter_by(student_id=student_id).first()
     current_course = DBSession.query(Course).filter_by(course_id=course_id).first()
     current_student.courses.remove(current_course)
     DBSession.flush()
     return dict()
Esempio n. 3
0
    def saveFile(self, **kw):
        print(kw)
        name = kw["name"]
        age = kw["age"]
        phone = kw["phone"]
        email_address = kw["email_address"]

        if name == "" or age == "" or phone == "" or email_address == "":
            return dict(error="Campos obligatorios")

        if kw["usuario_id"] == "0":
            if kw["image"] == "undefined":
                return dict(error="Archivo obligatorio")
            handler = Usuario()
            i = 0
        else:
            handler = DBSession.query(Usuario).filter_by(
                usuario_id=kw['usuario_id']).first()
            i = 1

        if kw["image"] != "undefined":
            image = kw["image"]
            if image.file:
                fileName = image.filename
                if fileName.find(".png") > 0 or fileName.find(
                        ".jpeg") > 0 or fileName.find(
                            ".jpg") > 0 or fileName.find(
                                ".doc") > 0 or fileName.find(
                                    ".PDF") > 0 or fileName.find(".pdf") > 0:
                    ftyoe = ""
                    if fileName.find(".png") > 0 or fileName.find(
                            ".jpeg") > 0 or fileName.find(".jpg") > 0:
                        ftyoe = "image"
                    if fileName.find(".doc") > 0:
                        ftyoe = "doc"
                    if fileName.find(".pdf") > 0:
                        ftyoe = "pdf"
                    if fileName.find(".PDF") > 0:
                        ftyoe = "pdf"
                    handler.image = image.file.read()
                else:
                    return dict(
                        error="Archivo obligatorio de tipo PNG, JPEG, DOC, PDF"
                    )

        handler.name = name
        handler.age = age
        handler.phone = phone
        handler.email_address = email_address

        if i == 0:
            DBSession.add(handler)
        DBSession.flush()
        return dict(error="ok", usuario_id=handler.usuario_id)
Esempio n. 4
0
 def DeletePrestamo(self, **kw):
     print(kw)
     usuario_id = kw["usuario_id"]
     book_id = kw["book_id"]
     print(usuario_id)
     print(book_id)
     current_usuario = DBSession.query(Usuario).filter_by(
         usuario_id=usuario_id).first()
     current_book = DBSession.query(Book).filter_by(book_id=book_id).first()
     current_usuario.books.remove(current_book)
     DBSession.flush()
     return dict()
Esempio n. 5
0
 def setUp(self):
     """Setup test fixture for each model test method."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Esempio n. 6
0
 def addLoan(self, **kw):
     phone_id = kw["phone_id"]
     amount = kw["amount"]
     due_date = kw["due_date"]
     query = DBSession.query(PhoneBook).filter_by(id=phone_id).first()
     if query is not None:
         newLoan = Loans()
         newLoan.phone_id = phone_id
         newLoan.amount = amount
         newLoan.due_date = due_date
         query.loans.append(newLoan)
         DBSession.add(newLoan)
         DBSession.flush()
     return dict(ok="ok")
Esempio n. 7
0
    def updateGrid(self):
        if "oper" in self.kw:
            if self.kw['oper'] == "edit":
                print("edit")
                # print("id:{}".format(self.kw['id']))
                # for key, value in self.kw.iteritems():
                #     print "%s = %s" % (key, value)

                my_filters = {self.indexkey: self.kw['id']}
                query = DBSession.query(self.model)

                for attr, value in my_filters.items():
                    query = query.filter(getattr(self.model, attr) == value)
                item = query.first()
                if item is not None:
                    #print("None Edit")
                    for column in item.__table__.columns:
                        if column.name != self.indexkey:
                            if column.name in self.kw:
                                if str(column.type) == "BOOLEAN":
                                    newvalue = True if self.kw[
                                        column.name] == "True" else False
                                else:
                                    newvalue = self.kw[column.name]
                                #print("updating: {} to {} type:{}".format(column.name, self.kw[column.name],str(column.type)))
                                setattr(item, column.name, newvalue)
                    DBSession.flush()
            if self.kw['oper'] == "add":
                item = self.model()
                #print("add")
                for column in item.__table__.columns:
                    if column.name in self.kw:
                        #print("{}={}".format(str(column.name),str(self.kw[column.name])))
                        if (self.indexkey == column.name):
                            pass
                        else:
                            setattr(item, column.name, self.kw[column.name])

                DBSession.add(item)
                DBSession.flush()

            if self.kw['oper'] == "del":
                my_filters = {self.indexkey: self.kw['id']}
                query = DBSession.query(self.model)
                for attr, value in my_filters.items():
                    query = query.filter(getattr(self.model, attr) == value)
                item = query.first()
                if item is not None:
                    DBSession.delete(item)
                    DBSession.flush()
            return dict(error="")