inbounding / inbounding / dispatch / api /

import re
import json

from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import get_object_or_404

from piston.handler import BaseHandler
from piston.utils import rc

from dispatch.models import Refer, Action

def template_engine(result):
       This is used to select the templates based on the Action.template value.
       We override the exising database Action.code value. The html templates 
       are stored in the file.
    template_id = result.template
    if template_id == 1:
        #Use MailChimp html template
        profile = result.user.get_profile()
        customer_uuid = profile.uuid
        mailchimp = '''
            <!-- ContextKick custom form --> 
            <div id="embed_signup">
                <h3>Subscribe to our Newsletter</h3>
                <form src="#" id="subscribe-form" name="mc-embedded-subscribe-form" 
                     class="mailchimp-submit validate form-stacked">
                  <input type="hidden" value="%s">
                  <div class="mc-field-group clearfix">
                    <label for="mce-EMAIL">Email Address </label>
                    <div class="input">
                        <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
                  <div class="clear">
                      <input type="submit" value="Subscribe" name="subscribe" id="submit" class="btn button">
            ''' % customer_uuid

        result.code = mailchimp
    elif template_id == 2:
        Facebook Template

        '''j = json.loads(result.tpl_values)

class ReferHandler(BaseHandler):
    allowed_methods = ('GET')
    model = Refer
    def read(self, request):
           Search for an Action by the source (customer) domain and the
           referral domain.
            result = Action.objects.select_related().\
                              filter(url=request.GET.get('u'), \
            if not result:
                result = "No valid Refer & Action combination was found."
            return result[0]
        except Action:
            return "An exception occured when checking the Referrer."

class ActionHandler(BaseHandler):

    allowed_methods = ('GET')
    model = Action
    fields = ("id", "url", "code", "type")
    def read(self, request):
        mylist = []
        return mylist

    def create(self, request, recipe_id=None):

    def update(self, request):
    def delete(self, request, recipe_id=None):