# Path: dockci/api/util.py
# def clean_attrs(values):
#     """
#     Return only dict items from ``values`` whose keys exist in the request
#     values, or json
#     """
#     return {
#         attr_name: attr_value
#         for attr_name, attr_value in values.items()
#         if (
#             (request.values is not None and attr_name in request.values) or
#             (request.json is not None and attr_name in request.json)
#         )
#     }
# 
# def set_attrs(obj, values):
#     """ Set attrs in values, on obj """
#     for attr_name, attr_value in values.items():
#         setattr(obj, attr_name, attr_value)
# 
# Path: dockci/server.py
# DB = WrappedSQLAlchemy()
# 
# Path: dockci/util.py
# def unique_model_conflicts(klass, ignored_id=None, **fields):
#     """ Find any models that have values in fields """
#     queries = {
#         field_name: klass.query.filter_by(**{field_name: field_value})
#         for field_name, field_value in fields.items()
#     }
# 
#     if ignored_id is not None:
#         queries = {
#             field_name: query.filter(klass.id != ignored_id)
#             for field_name, query in queries.items()
#         }
# 
#     return {
#         field_name: query
#         for field_name, query in queries.items()
#         if query.count() > 0
#     }


from flask_restful import abort, reqparse, Resource
from .util import clean_attrs, set_attrs
from dockci.server import DB
from dockci.util import unique_model_conflicts
        if data is None:
            args = parser.parse_args(strict=True)
            args = clean_attrs(args)
        else:
            args = data

        unique_columns = {name
                          for name, column in model.__mapper__.c.items()
                          if column.unique}
        conflict_checks = {
            name: value
            for name, value in args.items()
            if name in unique_columns
        }

        conflicts = {
            field_name: "Duplicate value '%s'" % getattr(
                query.first(), field_name,
            )
            for field_name, query in unique_model_conflicts(
                model.__class__,
                ignored_id=model.id,
                **conflict_checks
            ).items()
        }
        if conflicts:
            abort(400, message=conflicts)

        set_attrs(model, args)
        DB.session.add(model)

# Path: dockci/api/util.py
# def clean_attrs(values):
#     """
#     Return only dict items from ``values`` whose keys exist in the request
#     values, or json
#     """
#     return {
#         attr_name: attr_value
#         for attr_name, attr_value in values.items()
#         if (
#             (request.values is not None and attr_name in request.values) or
#             (request.json is not None and attr_name in request.json)
#         )
#     }
# 
# def set_attrs(obj, values):
#     """ Set attrs in values, on obj """
#     for attr_name, attr_value in values.items():
#         setattr(obj, attr_name, attr_value)
# 
# Path: dockci/server.py
# DB = WrappedSQLAlchemy()
# 
# Path: dockci/util.py
# def unique_model_conflicts(klass, ignored_id=None, **fields):
#     """ Find any models that have values in fields """
#     queries = {
#         field_name: klass.query.filter_by(**{field_name: field_value})
#         for field_name, field_value in fields.items()
#     }
# 
#     if ignored_id is not None:
#         queries = {
#             field_name: query.filter(klass.id != ignored_id)
#             for field_name, query in queries.items()
#         }
# 
#     return {
#         field_name: query
#         for field_name, query in queries.items()
#         if query.count() > 0
#     }


# Path: dockci/api/base.py
from flask_restful import abort, reqparse, Resource
from .util import clean_attrs, set_attrs
from dockci.server import DB
from dockci.util import unique_model_conflicts

        if data is None:
            args = parser.parse_args(strict=True)
            args = clean_attrs(args)
        else:
            args = data

        unique_columns = {name
                          for name, column in model.__mapper__.c.items()
                          if column.unique}
        conflict_checks = {
            name: value
            for name, value in args.items()
            if name in unique_columns
        }

        conflicts = {
            field_name: "Duplicate value '%s'" % getattr(
                query.first(), field_name,
            )
            for field_name, query in unique_model_conflicts(
                model.__class__,
                ignored_id=model.id,
                **conflict_checks
            ).items()
        }
        if conflicts:
            abort(400, message=conflicts)

        set_attrs(model, args)
        DB.session.add(model)

        DB.session.commit()