Commits

Scott Nixon committed f65a5d1

Updated tests and MailChimp form on the client side.

Comments (0)

Files changed (13)

inbounding/dispatch/api/handlers.py

 import re
+import json
 
 from django.views.decorators.csrf import csrf_exempt
 from django.shortcuts import get_object_or_404
 
 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 templates.py 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>
+                  </div>
+                  <div class="clear">
+                      <input type="submit" value="Subscribe" name="subscribe" id="submit" class="btn button">
+                  </div>
+                 </form>
+            </div>
+            ''' % customer_uuid
+
+        result.code = mailchimp
+    elif template_id == 2:
+        '''
+        Facebook Template
+        '''
+
+        '''j = json.loads(result.tpl_values)
+        j.get('url')'''
+
+
 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.
+        '''
         try:
             result = Action.objects.select_related().\
                               filter(url=request.GET.get('u'), \
                                      refer__name=request.GET.get('ref'))
             if not result:
                 result = "No valid Refer & Action combination was found."
+            else:
+                template_engine(result[0])
+                
             return result[0]
         except Action:
             return "An exception occured when checking the Referrer."
     
     def delete(self, request, recipe_id=None):
         pass
+
+

inbounding/dispatch/forms.py

 from django.forms import ModelForm
 from django.forms.formsets import formset_factory
 
+from userena.models import UserenaBaseProfile
+from userena.forms import EditProfileForm
+
 from models import Action, Refer, Template
 
 class ActionForm(ModelForm):
         model = Action
         exclude = ('created', 'user', 'lastmod', 'tpl_values', 'template')
         
-        #    def __init__(self, user, *args, **kwargs):
-        #        self.user = user
-        #        super(ActionForm, self).__init__(*args, **kwargs)
-
 
 class MailChimpForm(ModelForm):
     class Meta:
         model = Action
         
     
+''' Does not currently overwrite the form. NOT IMPLEMENTED '''
+class CustomUserEnaForm(EditProfileForm):
+    class Meta:
+        model = UserenaBaseProfile
+        exclude = ('uuid', 'privacy')
+        

inbounding/dispatch/models.py

+import uuid 
+
 from django.db import models
 from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
                                 verbose_name=('user'),
                                 related_name='my_profile')
     site = models.ForeignKey(Site, default=1)
+    uuid = models.CharField(max_length=36, blank=True, null=True)
     
+"""
+Save signal for creating a UUID for every user.
+"""
+def create_uuid(sender, **kwargs):
+    obj = kwargs['instance']
+    if not obj.uuid:
+        obj.uuid = str(uuid.uuid4())
+
+pre_save.connect(create_uuid, sender=CustomerProfile)

inbounding/dispatch/static/css/love.css

     text-align: center;
     line-height: 1.1;
 }
-
+.morevisitors h3 a, .morevisitors h3 a:visited {
+    color: white;
+}
 /* Dashboard Styling */
 .selection-options li {
     padding: 2.5em 4.5em;
 .nohover:hover {
     border: 5px solid #eee !important;
 }
+
+
+/* LIST #4 */
+#list4 { width:320px; font-family:Georgia, Times, serif; font-size:15px; }
+#list4 ul { margin: 0; list-style: none; }
+#list4 ul li { margin: 0;}
+#list4 ul li a { display:block; text-decoration:none; color:#000000; background-color:#FFFFFF; line-height:30px;
+  border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#CCCCCC; padding-left:10px; cursor:pointer; }
+#list4 ul li a:hover { 
+    color:#FFFFFF;
+    background: #258dc8; /* Old browsers */
+    background: -moz-linear-gradient(top,  #258dc8 0%, #258dc8 100%); /* FF3.6+ */
+    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#258dc8), color-stop(100%,#258dc8)); /* Chrome,Safari4+ */
+    background: -webkit-linear-gradient(top,  #258dc8 0%,#258dc8 100%); /* Chrome10+,Safari5.1+ */
+    background: -o-linear-gradient(top,  #258dc8 0%,#258dc8 100%); /* Opera 11.10+ */
+    background: -ms-linear-gradient(top,  #258dc8 0%,#258dc8 100%); /* IE10+ */
+    background: linear-gradient(top,  #258dc8 0%,#258dc8 100%); /* W3C */
+    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#258dc8', endColorstr='#258dc8',GradientType=0 ); /* IE6-9 */
+}
+#list4 ul li a strong { margin-right:10px; }
+
+
 /* MailChimp Page styling */
 .modal-footer .close { 
     margin-top: 0 !important;

inbounding/dispatch/static/in.js

     var INBOUND = {};
 }
 
+/* INIT referrer and host domain values */
+var referrer = document.referrer;
+var dom = document.URL;
+referrer = 'digg.com';
+
 INBOUND.unimplementedMethod_ = function() {
   throw new Error("unimplemented method");
 };
 
-INBOUND.host_p = 'dev.contextkick.com';
+/* host_d is the url of the ContextKick Server. */
+var host_d = 'localhost:8100';
+
+INBOUND.host_p = host_d; //'dev.contextkick.com';
 
 INBOUND.setCookie = function(name,value,maxage,path,domain) {
     /*
 };
 
 INBOUND.queryAction = function(ref_url, host_url, callback) {
-    var host_d = 'localhost:8100';
     
     $.ajax({
 	url: 'http://'+ INBOUND.host_p + '/api/refer/?ref=' + ref_url + '&u=' + host_url,
 	type: 'GET',
 	dataType: 'jsonp',
 	success: function(results) {
-	    /* We pass the id of the action to that we can check a 
+	    /* We pass the id of the action so that we can check a 
 	     * cookie to see if it has been closed or completed.
 	     */
 
     /* This is used to close the overlay action box. 
      * Cookie expires in 30 days.
      */
+    // This push is static and should be re-designed.
     _gaq.push(['_trackEvent', 'ContextKick', 'Close', 'Facebook Static Overlay']);
     $('#ck_container').hide();
     // Value = 101 for Closed
     else {
 	var styles = "@import url('" + css_uri  +"');";
 	var newSS=document.createElement('link');
+        newSS.rev="ck";
 	newSS.rel='stylesheet';
 	newSS.href='data:text/css,'+escape(styles);
 	document.getElementsByTagName("head")[0].appendChild(newSS);
 
 /* end Tool Library */
 
+/* 
+   Main Function
+   When the Customer loads the script on their site this function is excuted.
 
+*/
 (function () {
 
-    /* INIT referrer and host domain values */
-    var referrer = document.referrer; //'digg.com';
-    var dom = document.URL;
+
 
     /* 
        Example of returned value when executing parse_url.

inbounding/dispatch/static/in_cl.js

         var s = document.createElement('script');
         s.type = 'text/javascript';
         s.async = true;
-        s.src = 'http://localhost:8000/static/in.js?v=8';
+        s.src = 'http://localhost:8100/static/in.js?v=10';
         var x = document.getElementsByTagName('script')[0];
         x.parentNode.insertBefore(s, x);
     }

inbounding/dispatch/static/tests/in-tests.js

 describe("Cookies", function() {
 
+    it('Validate INBOUND namespace is defined', function () {
+	expect(INBOUND).toBeDefined();
+    });
+
     it('makeUUID should make a unique id', function () {
 	var uid = INBOUND.makeUUID(); // uid should be 36 in length
 	expect(uid.length).toEqual(36); 
 
     it('create a uid cookie', function () {
 	var newuser = INBOUND.makeUUID();
-	expect(INBOUND.setCookie('uid', newuser, (60*60*24*365), '')).toBeTruthy(); 
+	expect(INBOUND.setCookie('uid', newuser, (60*60*24*365), '')).toBeUndefined(); 
     });
 
     it('should read the uid cookie', function () {
 	expect(checkSession.length).toEqual(36); 
     });
 
+    it('should update the cookie to the closed state', function () {
+	INBOUND.action_id = '1001';
+	_gaq = []; // Mock so that test can complete
+	INBOUND.close();
+	var checkValue = INBOUND.getCookie("ck_status-" + INBOUND.action_id);
+        /* checkValue should return the '1001=101'
+	  Completed should always value 101 */
+	expect(checkValue).toEqual(INBOUND.action_id + '=101'); 
+    });
+
+    it('should update the cookie to the completed state', function () {
+	INBOUND.action_id = '1001';
+	INBOUND.completed();
+	var checkValue = INBOUND.getCookie("ck_status-" + INBOUND.action_id);	
+        /* checkValue should return the '1001=100'
+	   Completed should always value 100 */
+	expect(checkValue).toEqual(INBOUND.action_id + '=100'); 
+    });
 
 });
 
 describe("Referral", function() {
     
     it('check the document.referrer', function() {
-
-	var referrer = document.referrer;
-	
-	expect(referrer).toEqual('digg.com');
+	var get_referrer = referrer;
+	expect(get_referrer).toEqual('digg.com');
     });
 });
+
+
+describe("Query Server", function() {
+    
+/*
+  Was not able to get this to work because the href field
+  contains several data elements and not just the uri.
+    it('does the css load', function() {
+	INBOUND.loadcss();
+	expect($("link[rev='ck']").attr("href")).toEqual(INBOUND.css);
+    });
+
+*/
+});

inbounding/dispatch/static/tests/spec-runner.html

   <script type="text/javascript" src="jasmine-1.1.0/jasmine.js"></script>
   <script type="text/javascript" src="jasmine-1.1.0/jasmine-html.js"></script>
 
+  <script type="text/javascript" src="../js/jquery-1.6.4.min.js"></script>
+  <script type="text/javascript" src="jasmine-1.1.0/plugins/jasmine-jquery.js"></script>
+
   <!-- include source files here... -->
   <script type="text/javascript" src="../in.js"></script>
   <script type="text/javascript" src="../in_cl.js"></script>

inbounding/dispatch/templates/dashboard.html

     </div>
 
     <div class="span4">
-      <h2 class="">Your Actions</h2>
-      <h3 class=""><a href="{% url dispatch.views.action_page %}">+ Add an Action</a></h3>
+      <h2 class="">Existing Actions</h2>
+      
+      <div id="list4">
+	<ul>
+	  {% for action in object_list %}
+	  <li><a href="/action/{{ action.id }}/">{{ action.label }}</a></li>
+	  {% endfor %}
+	</ul>
 
-      <ul class="ul">
-	{% for action in object_list %}
-	<li><a href="/action/{{ action.id }}/">{{ action.label }}</a></li>
-	{% endfor %}
-      </ul>
+	<h2 style="margin-top:2em;"><a href="{% url dispatch.views.action_page %}">+ Add an Action</a></h2>
+      </div>
+
     </div>
   </div>
 
 &lt;/script&gt;
       </pre>
     </p>
-
+    <a href="http://contextkickdemo.wordpress.com/">Our Demo Site</a>
   </section>
 </div>
 

inbounding/dispatch/templates/index2.html

       <h1 id="title" class="tk-ff-meta-web-pro">
 	Retain More Visitors on the Web
       </h1>
-      <h3>Read Our Story</h3>
+      <h3><a href="#ourstory">Read Our Story</a></h3>
   </div>
 
 <div class="container" style="margin-top: 40px;">
 	  <ol>
 	    <li>Configure Google Analytics Events.</li>
 	    <li>Measure the Engagement.</li>
+	    <li>Retain more Visitors</li>
 	  </ol>
-	  <ul>
-	    <li></li>
-	  </ul>
 	</p>
       </div>
 
     </div>
     
-    <blockquote>***We are a very new product and we are working to automated many of these steps.</blockquote>
+    <blockquote style="margin-top:2em;">***We are a very new product and we are working to automated many of these steps.</blockquote>
 
 
-    <h1>Our Story</h1>
+    <h1 id="ourstory">Our Story</h1>
 
     <p>Last year 300,000 New Visitors, approxiately a city the size of Cincinnati, visited HappyHerbivore.com, and nothing was done to make sure they returned.</p>
 
     </p>
     
 
-    <p>Rather than continue to lose half of our traffic, I decided I wanted to built tools 
+    <p>Rather than continue to loose half of our traffic, I decided I wanted to built tools 
       that help you keep more of the traffic you've earned.
     </p>
 

inbounding/dispatch/templates/mailchimp.html

 	      </div>
 	    </div>
 	    <div class="span5 helpboxes">
-	      <a href="#" rel="popover" data-content="A Floated box will is fixed in the bottom right corner of your website. Othewise, you chose the location with Embedded boxes." data-original-title="Floated vs. Embedded." data-placement="right">What is a Action Box?</a>
+	      <a href="#" rel="popover" data-content="A Floated box is fixed in the bottom right corner of your website. Othewise, you chose the location in your HTML for the Embedded box." data-original-title="Floated vs. Embedded." data-placement="right">What is a Action Box?</a>
 	    </div>
 	  </div>
 	</fieldset>
       </div>
 -->
       <div id="preview" class="preview">
-	<iframe src="http://127.0.0.1:8100/subscribe/" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:350px; height:200px;" allowTransparency="true"></iframe>
+	<iframe src="/subscribe/" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:350px; height:200px;" allowTransparency="true"></iframe>
       </div>
       </div>
 

inbounding/dispatch/views.py

                                                     defaults={
                                                     'label': request.POST['label'], 
                                                     'url': request.POST['url'],
-                                                    'code': 'code here',
+                                                    'code': 'This code is overridden by the Template.',
                                                     'type': request.POST['action-box'],
                                                     'template': '1',
                                                     'tpl_values': data,
 
     if request.method == 'POST':
         post = request.POST
+
+        # Post the mc_list_id and then we can do a lookup on 
         ck_list_id = mc_list_id = '0a66cc769c'
         ck_api_key = mc_api_key ='30060673b5472f3674d20c65782422ca-us2'
 
             pass
         #schedule task to subscribe
 
-        return HttpResponse("Done with Banannas")
+        return HttpResponse("Success. Check email to confirm your subscription.")
     else:
         return render_to_response('client/mc_form.html', locals(),context_instance=RequestContext(request))

inbounding/settings_default.py

 )
 
 USERENA_ACTIVATION_DAYS = 14
+USERENA_DISABLE_PROFILE_LIST = True
 
 # A sample logging configuration. The only tangible logging
 # performed by this configuration is to send an email to