Exemple #1
0
 def __call__(self, args):
     for eid in args.task_id:
         record = db.get(eid=eid)
         if args.uncheck:
             print("Unchecked task T{} - {}".format(eid, record['name']))
             db.update({'completed': False}, eids=[eid])
         else:
             print("Completed task T{} - {}".format(eid, record['name']))
             db.update({'completed': True}, eids=[eid])
Exemple #2
0
    def __call__(self, args):
        props = {}

        if args.name:
            props['name'] = args.name

        if args.category:
            props['category'] = args.category

        db.update(props, eids=args.task_id)
Exemple #3
0
def update_user(username, body):
    fields = [
        'email', 'username', 'full_name', 'password', 'device_token',
        'show_notifications'
    ]

    result, code = db.get_one(User, username)

    if code == 404:
        return result, code

    user = get_row_dict(result)

    params = get_params_by_body(fields, body)

    errors = validate_update_user(body, params)
    if errors:
        return errors, 400

    if 'password' in params:
        params['password'] = BCRYPT.generate_password_hash(
            params['password']).decode('utf-8')

    result, code = db.update(User, username, params)

    if code == 200:  # if successful, returns the data
        if 'device_token' in body:
            send_notification_on_signin(user, username, body)
        user = get_row_dict(result)  # converts row to dict
        return user, code
    return result, code  # else, returns database error and error code
Exemple #4
0
def update_rating(rating_id, body, username=None):

    result, status = db.get_one(Rating, rating_id)
    rating_before_update = result.to_dict(del_null_attr=False)

    if status == 404:
        return 'Erro ao achar avaliação', 404

    errors = validate_update_rating(body, rating_before_update)
    if errors:
        return errors, 400

    details = []
    for attr, value in rating_before_update['details'].items():
        if attr in body:
            details.append(body[attr])
        else:
            details.append(value)
    body = dict(filter(lambda x: x[0] == 'rating_neighborhood', body.items()))
    body['details'] = details

    result, code = db.update(Rating, rating_id, body, username)

    if code == 200:
        rating = result.to_dict()
        return rating, code

    return result, code
def update_task(id_task):

    if request.method == "POST":

        # query for check id task
        query_db = db.read("tasks", "id", id_task)
        task = query_db[0] if len(query_db) == 1 else None
        if task == None:
            return jsonify(error(404, "Task not exists"))

        else:
            json = request.get_json()

            id = task["id"]
            title = json["title"]
            description = json["description"]
            date = task["date"]
            id_list = task["id_list"]
            status = json["status"]

            task = Task(
                id=id,
                id_list=id_list,
                title=title,
                description=description,
                date=date,
                status=status,
            )

            if db.update("tasks", id_task, task.to_dict()):
                return jsonify(task.to_dict())

            else:
                return jsonify(error(203, "Not Allowed"))
def update_occurrence(id_occurrence, body, username=None):

    current_occurrence, code = db.get_one(Occurrence, id_occurrence)
    if code != 200:
        return current_occurrence, code

    fields = [
        'occurrence_date_time', 'physical_aggression', 'victim',
        'police_report', 'gun', 'location', 'occurrence_type'
    ]

    params = get_params_by_body(fields, body)

    errors = validate_update_occurrence(body, params, current_occurrence)
    if errors:
        return errors, 400

    result, code = db.update(Occurrence, id_occurrence, params, username)

    if code == 200:  # if successful, returns the data
        occurrence = result.to_dict()  # converts row to dict
        return occurrence, code
    return result, code  # else, returns database error and error code
def update_list(id_list):
    if request.method == "POST":
        # query for check username
        query_db = db.read("lists", "id", id_list)
        list_user = query_db[0] if len(query_db) == 1 else None
        if list_user == None:
            return jsonify(error(404, "List not exists"))

        else:
            json = request.get_json()

            id = list_user["id"]
            title = json["title"]
            date = list_user["date"]
            id_user = list_user["id_user"]
            link = list_user["link"]

            list_user = List(id, id_user, title, date)

            if db.update("lists", id_list, list_user.to_dict()):
                return jsonify(list_user.to_dict())

            else:
                return jsonify(error(203, "Not Allowed"))