# Path: data/get_row.py
# def get_row(model, row_id, **kwargs):
#     """Get a database row by its id.
# 
#     Parameters
#     ----------
#     model : BaseModel
#     row_id : int or None
# 
#     Returns
#     -------
#     row
#     """
#     try:
#         if row_id:
#             try:
#                 row = model.get(model.id == row_id)
#             except DoesNotExist:
#                 raise
#         else:
#             row = model()
#     except ImportError:
#         raise
# 
#     return row
# 
# def get_row_by_name(model, row_name, FK_name=None, FK_id=None, **kwargs):
#     """Get a unique row by its name or by name plus FK if a FK is needed.
# 
#     Parameters
#     ----------
#     FK_id : int
#     FK_name : str
#     model : BaseModel
#     row_name : str
# 
#     Returns
#     -------
#     row
#     """
#     try:
#         if FK_name:
#             row = model.get(model.name == row_name,
#                             getattr(model, FK_name) == FK_id)
#         else:
#             row = model.get(model.name == row_name)
#     except DoesNotExist:
#         raise
#     else:
#         return row
# 
# Path: logic/reserved/reserved.py
# class Reserved(BaseModel):
#     """ORM for a reserved name."""
#     import datetime
#     id = pwe.PrimaryKeyField()
#     name = pwe.CharField(default=u'', index=True, unique=True)
#     primary_package = pwe.CharField(default=u'')
#     created_timestamp = pwe.DateTimeField(default=datetime.datetime.now)
# 
#     class Meta:
#         db_table = 'reserved'
# 
#     @validate('Reserved', 'name')
#     def validate_name(self):
#         if not self.name:
#             raise AssertionError('Name must be given.')


from data.get_row import get_row, get_row_by_name
from logic.reserved.reserved import Reserved

def get_reserved(reserved_id, **kwargs):
    """Get an reserved row from an id.

    Parameters
    ----------
    reserved_id : int or None

    Returns
    -------
    reserved_row
    """
    try:
        reserved_row = get_row(Reserved, reserved_id)
    except:
        raise
    return reserved_row


def get_reserved_by_name(reserved_name, **kwargs):
    """Get reserved by its name.

    Parameters
    ----------
    reserved_name : str

    Returns
    -------
    reserved_row
    """

# Path: data/get_row.py
# def get_row(model, row_id, **kwargs):
#     """Get a database row by its id.
# 
#     Parameters
#     ----------
#     model : BaseModel
#     row_id : int or None
# 
#     Returns
#     -------
#     row
#     """
#     try:
#         if row_id:
#             try:
#                 row = model.get(model.id == row_id)
#             except DoesNotExist:
#                 raise
#         else:
#             row = model()
#     except ImportError:
#         raise
# 
#     return row
# 
# def get_row_by_name(model, row_name, FK_name=None, FK_id=None, **kwargs):
#     """Get a unique row by its name or by name plus FK if a FK is needed.
# 
#     Parameters
#     ----------
#     FK_id : int
#     FK_name : str
#     model : BaseModel
#     row_name : str
# 
#     Returns
#     -------
#     row
#     """
#     try:
#         if FK_name:
#             row = model.get(model.name == row_name,
#                             getattr(model, FK_name) == FK_id)
#         else:
#             row = model.get(model.name == row_name)
#     except DoesNotExist:
#         raise
#     else:
#         return row
# 
# Path: logic/reserved/reserved.py
# class Reserved(BaseModel):
#     """ORM for a reserved name."""
#     import datetime
#     id = pwe.PrimaryKeyField()
#     name = pwe.CharField(default=u'', index=True, unique=True)
#     primary_package = pwe.CharField(default=u'')
#     created_timestamp = pwe.DateTimeField(default=datetime.datetime.now)
# 
#     class Meta:
#         db_table = 'reserved'
# 
#     @validate('Reserved', 'name')
#     def validate_name(self):
#         if not self.name:
#             raise AssertionError('Name must be given.')


# Path: logic/reserved/get_row.py
from data.get_row import get_row, get_row_by_name
from logic.reserved.reserved import Reserved


def get_reserved(reserved_id, **kwargs):
    """Get an reserved row from an id.

    Parameters
    ----------
    reserved_id : int or None

    Returns
    -------
    reserved_row
    """
    try:
        reserved_row = get_row(Reserved, reserved_id)
    except:
        raise
    return reserved_row


def get_reserved_by_name(reserved_name, **kwargs):
    """Get reserved by its name.

    Parameters
    ----------
    reserved_name : str

    Returns
    -------
    reserved_row
    """

    reserved_row = get_row_by_name(Reserved, reserved_name)