示例#1
0
文件: meal.py 项目: mariajbp/LI4
 def delete(id_meal_type):
     mt = MealType.query.filter(Meal.id_meal_type==id_meal_type)
     
     if mt.delete() == 1:
         db.session.commit()
     else:
         raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS)
示例#2
0
文件: meal.py 项目: mariajbp/LI4
 def delete(date,id_location,id_meal_type):
     m = Meal.query.filter(Meal.date==date,Meal.id_location==id_location,Meal.id_meal_type==id_meal_type)
     
     if m.delete() == 1:
         db.session.commit()
     else:
         raise ErrorCodeException(ErrorCode.MEAL_DOESNT_EXISTS)
示例#3
0
    def delete(id_user):
        u = User.query.filter(User.id_user == id_user)

        if u.delete() == 1:
            db.session.commit()
        else:
            raise ErrorCodeException(ErrorCode.USER_DOESNT_EXISTS)
示例#4
0
    def delete(id_ticket):
        t = TicketType.query.filter(TicketType.id_ticket == id_ticket)

        if t.delete() == 1:
            db.session.commit()
        else:
            raise ErrorCodeException(ErrorCode.TICKETTYPE_DOESNT_EXISTS)
示例#5
0
文件: meal.py 项目: mariajbp/LI4
 def delete(id_location):
     l = Location.query.filter(Location.id_location==id_location)
     
     if l.delete() == 1:
         db.session.commit()
     else:
         raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS)
示例#6
0
 def add_transaction(transaction):
     e = Transaction.query.filter_by(id_transaction=transaction.id_transaction, id_ticket=transaction.id_ticket).first()
     if e != None:
         raise ErrorCodeException(ErrorCode.TRANSACTION_EXISTS)
     
     db.session.add(transaction)
     db.session.commit()
示例#7
0
文件: meal.py 项目: mariajbp/LI4
 def add_meal_type(meal_type):
     try:
         MealType.get_meal_type(meal_type.id_meal_type)
     except ErrorCodeException:
         db.session.add(meal_type)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.MEALTYPE_EXISTS)
示例#8
0
 def add_user(user):
     try:
         User.get_user(user.id_user)
     except ErrorCodeException:
         db.session.add(user)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.USER_EXISTS)
示例#9
0
def set_as_used(id_ticket, id_user):

    t = Ticket.get_ticket(id_ticket)
    if t == None:
        raise ErrorCodeException(ErrorCode.TICKET_DOESNT_EXISTS)

    if t.id_user != id_user:
        raise ErrorCodeException(ErrorCode.TICKET_DOESNT_BELONG_TO_USER)

    if User.get_user(id_user) == None:
        raise ErrorCodeException(ErrorCode.USER_DOESNT_EXISTS)

    if t.used == True:
        raise ErrorCodeException(ErrorCode.TICKET_ALREADY_USED)
    t.set_used()

    History.add_entry(History(id_ticket=unhexlify(id_ticket), id_user=id_user))
示例#10
0
    def delete(id_ticket):

        t = Ticket.query.filter(Ticket.id_ticket == unhexlify(id_ticket))

        if t.delete() == 1:
            db.session.commit()
        else:
            raise ErrorCodeException(ErrorCode.TICKET_DOESNT_EXISTS)
示例#11
0
 def add_ticket(ticket):
     try:
         Ticket.get_ticket(hexlify(ticket.id_ticket).decode('ascii'))
     except ErrorCodeException:
         db.session.add(ticket)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.TICKET_EXISTS)
示例#12
0
文件: meal.py 项目: mariajbp/LI4
 def add_location(location):
     try:
         Location.get_location(location.id_location)
     except ErrorCodeException:
         db.session.add(location)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.LOCATION_EXISTS)
示例#13
0
文件: meal.py 项目: mariajbp/LI4
 def add_meal(meal):
     try:
         Meal.get_meal(meal.date,meal.id_location,meal.id_meal_type)
     except ErrorCodeException:
         db.session.add(meal)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.MEAL_EXISTS)
示例#14
0
 def add_type(type):
     try:
         TicketType.get_type(type.type)
     except ErrorCodeException as ec:
         db.session.add(type)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.TICKETTYPE_EXISTS)
示例#15
0
def params_validation(rgxs, params):
    for param, rgx in zip(params, rgxs):
        if re.match(rgx, param) == None:
            raise ErrorCodeException(ErrorCode.INVALID_PARAMETER)
示例#16
0
 def get_transaction(id_transaction,id_ticket):
     e = Transaction.query.filter_by(id_transaction=id_transaction,id_ticket=unhexlify(id_ticket)).first()
     if e == None:
         raise ErrorCodeException(ErrorCode.TRANSACTION_DOESNT_EXISTS)
     return e
示例#17
0
 def get_user(id_user):
     u = User.query.filter_by(id_user=id_user).first()
     if u == None:
         raise ErrorCodeException(ErrorCode.USER_DOESNT_EXISTS)
     return u
示例#18
0
 def get_type(type):
     tt = TicketType.query.filter_by(type=type).first()
     if tt == None:
         raise ErrorCodeException(ErrorCode.TICKETTYPE_DOESNT_EXISTS)
     return tt
示例#19
0
文件: meal.py 项目: mariajbp/LI4
 def get_by_name(name):
     mt = MealType.query.filter_by(name=name).first()
     if mt == None:
         raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS)
     return mt
示例#20
0
文件: meal.py 项目: mariajbp/LI4
 def get_meal_type(id_meal_type):
     mt = MealType.query.filter_by(id_meal_type=id_meal_type).first()
     if mt == None:
         raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS)
     return mt
示例#21
0
文件: meal.py 项目: mariajbp/LI4
 def get_location(id_location):
     l = Location.query.filter_by(id_location=id_location).first()
     if l == None:
         raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS)
     return l
示例#22
0
文件: meal.py 项目: mariajbp/LI4
 def get_meal(date,id_location,id_meal_type):
     m = Meal.query.filter_by(date=date,id_location=id_location,id_meal_type=id_meal_type).first()
     if m == None:
         raise ErrorCodeException(ErrorCode.MEAL_DOESNT_EXISTS)
     return m
示例#23
0
文件: meal.py 项目: mariajbp/LI4
 def get_by_name(name):
     l = Location.query.filter_by(name=name).first()
     if l == None:
         raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS)
     return l
示例#24
0
 def get_ticket(id_ticket):
     t = Ticket.query.filter_by(id_ticket=unhexlify(id_ticket)).first()
     if t == None:
         raise ErrorCodeException(ErrorCode.TICKET_DOESNT_EXISTS)
     return t