import db
import logging

from ckan.plugins.toolkit import get_validator, ValidationError
import ckan.lib.navl.dictization_functions as df

log = logging.getLogger(__name__)

schema = {
    'id': [get_validator('ignore_empty'), unicode],
    'address': [get_validator('not_empty'), unicode],
    'topic': [get_validator('not_empty'), unicode],
    'user_id': [get_validator('ignore_missing'), unicode],
    'created_at': [get_validator('ignore_missing'), get_validator('isodate')]
}

def webhook_create(context, data_dict):
    log.info(data_dict)

    data, errors = df.validate(data_dict, schema, context)

    if errors:
        raise ValidationError(errors)

    webhook = db.webhook_table

def webhook_delete(context, data_dict):
    pass

@@ -677,21 +677,188 @@
  db.
-webhook_table
+Webhook()%0A    webhook.address = data%5B'address'%5D%0A    webhook.topic = data%5B'topic'%5D%0A    webhook.save()%0A%0A    session = context%5B'session'%5D%0A    session.add(webhook)%0A    session.commit()
 %0A%0Ade

create action