示例#1
0
def deleteNotification(nid):
    notification_object = getNotification(nid)
    if notification_object is None:
        return errorhelper.generateError("Notification doesn't exist", 400)
    models.db.session.delete(notification_object)

    return helpers.commitResponse(models.db.session, {})
示例#2
0
def createUser(obj):
    if userExists(obj['username'], obj['email']):
        return errorhelper.generateError('username or password already exist',
                                         400)
    user_object = models.User(
        email=obj['email'],
        username=obj['username'],
        admin=obj['admin'],
    )
    security.hashPassword(user_object, obj['password'])
    models.db.session.add(user_object)
    return helpers.commitResponse(models.db.session, {}, user_object)
示例#3
0
def deleteImages(images_idx):
    """images_idx is array of ids of images to delete"""
    res = []
    for imgId in images_idx:
        image_object = getImage(imgId)
        if image_object is None:
            return errorhelper.generateError("Image doesn't exist", 400)
        try:
            os.remove(image_object.path)  # Delete file on system
        except:
            print("Couldn't find file on system")
        models.db.session.delete(image_object)  # Delete file entry in database
    return helpers.commitResponse(models.db.session, {})
示例#4
0
def createNotification(obj):
    notification_object = models.Notification(checked=False,
                                              name=obj['name'],
                                              email=obj['email'],
                                              comment=obj['comment'],
                                              created=helpers.currentTime(),
                                              telephone=obj['telephone'],
                                              when=obj['when'])
    notification_object.address = models.Address(
        city=obj['address']['city'],
        road=obj['address']['road'],
        number=obj['address']['number'])
    models.db.session.add(notification_object)

    return helpers.commitResponse(models.db.session, {}, notification_object)
示例#5
0
def changeUnread(nid, checked):
    notification = getNotification(nid)
    res = {"prev_checked": notification.checked}
    notification.checked = checked
    return helpers.commitResponse(models.db.session, res, notification)
示例#6
0
def changeEmail(obj):
    user_object = getUser(obj['uid'])
    user_object.email = obj['email']
    return helpers.commitResponse(models.db.session, {}, user_object)
示例#7
0
def blacklistToken(_jti):
    revoked_token = models.RevokedToken(jti=_jti)
    models.db.session.add(revoked_token)
    return helpers.commitResponse(models.db.session, {})
示例#8
0
def createImage(_name, _path):
    image_object = models.Image(name=_name, path=_path)
    models.db.session.add(image_object)
    return helpers.commitResponse(models.db.session, {}, image_object)