def notification_create(context, data_dict):
    '''Create new notification data.

    :param package_id: The id of the package the data belongs to.
    :type package_id: string

    :returns: the newly created notification data
    :rtype: dictionary

    '''
    not_seen = False
    notifications = []
    maintainers = data_dict['users']
    for m in maintainers:
        data = {'package_maintainer_id': m['id'], 'seen': not_seen}
        user_notification = ckanextUserNotification(**data)
        user_exist = ckanextUserNotification.get(package_maintainer_id=m['id'])
        if user_exist is None:
            user_notification.save()
            notifications.append(user_notification)
        else:
            user_exist.seen = not_seen
            user_exist.commit()
            notifications.append(user_exist)
    return notifications
def notification_for_current_user(context, data_dict):
    '''Returns a notification for logged in user

    :rtype: boolean

    '''

    model = context['model']
    user_id = model.User.get(context['user']).id
    notification = ckanextUserNotification.get(package_maintainer_id=user_id)
    if notification is None:
        # do not display notification
        return True
    else:
        is_notified = notification.seen
        return is_notified
def notification_change(context, data_dict):
    '''
        Change the notification status to seen
    :param context:

    :param user_id: The id of logged in user
    :type String

    :return:
    '''

    data, errors = df.validate(data_dict, schema.notification_change_schema(),
                               context)
    if errors:
        raise toolkit.ValidationError(errors)

    user_id = data.get('user_id')
    notification = ckanextUserNotification.get(package_maintainer_id=user_id)
    if notification is not None:
        notification.seen = True
        notification.commit()
        return notification