Commits

Scott Nixon committed b06f148

Partially working need to finish the Save view.

  • Participants
  • Parent commits 03d92ef

Comments (0)

Files changed (4)

File inbounding/dispatch/api/handlers.py

                                      refer__name=request.GET.get('ref'))
             if not result:
                 result = "No valid Refer & Action combination was found."
-            return result
+            return result[0]
         except Action:
             return "An exception occured when checking the Referrer."
 

File inbounding/dispatch/forms.py

 from models import Action, Refer
 
 class ActionForm(ModelForm):
+    id = forms.CharField(widget=forms.HiddenInput())
     label = forms.CharField(widget=forms.TextInput(attrs={'class':'input-text url'}))
     url = forms.CharField(widget=forms.TextInput(attrs={'class':'input-text url'}))
     code = forms.CharField(widget=forms.Textarea(attrs={'class':'input-text url'}))

File inbounding/dispatch/static/in.js

 INBOUND.getCookie = function(name) {
     var nameEQ = name + "=";
     var ca = document.cookie.split(';');
-    for(var i=0;i < ca.length;i++) {
+    for(var i=0; i < ca.length; i += 1) {
 	var c = ca[i];
 	while (c.charAt(0) === ' ') { 
 	    c = c.substring(1,c.length);
 		    /* This is the default event that will show the template in 
 		     * an unchanged state.
 		    */
-
+		    console.log(results.type);
 		    if (results.type === '1') {
 			$('#ckembed_' + results.id).html(ck_embed);		
 		    }

File inbounding/dispatch/views.py

 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 from django.utils.decorators import method_decorator
+from django.views.generic.create_update import create_object, update_object
 
 from models import Refer, Action
 from forms import ActionForm
     def dispatch(self, *args, **kwargs):
         return super(Dashboard, self).dispatch(*args, **kwargs)
 
+@login_required
+def edit_breweries(request, id):
+        if request.method == 'POST':
+                return update_object(request, form_class=BreweriesForm, object_id=id, template_name='hops/edit_breweries.html', post_save_redirect=(reverse('hops.views.breweries')))
+        else:
+                brew_instance = get_object_or_404(Breweries, pk=id)
+                form = BreweriesForm(instance=brew_instance)
+                
+        return render_to_response('hops/edit_breweries.html', locals(),context_instance=RequestContext(request))
+
 
 @login_required
 def action_page(request, id=None):
-        if request.method == 'POST':
-                form = ActionForm(data=request.POST)
-                if form.is_valid():
-                        profile_obj = form.save(commit=False)
-                        profile_obj.user = request.user
-                        profile_obj.save()
-                        if hasattr(form, 'save_m2m'):
-                            form.save_m2m()
-                        return HttpResponseRedirect(reverse('dashboard-url'))
+    // MUST FIX LOGIC.
+    if request.method == 'POST' and request.POST.get('id'):
+        return update_object(request, form_class=ActionForm, 
+                             object_id=id, 
+                             post_save_redirect=(reverse('dashboard-url')))
+    elif request.method == 'POST' and not request.POST.get('id'):
+        form = ActionForm(data=request.POST)
+        if form.is_valid():
+            profile_obj = form.save(commit=False)
+            profile_obj.user = request.user
+            profile_obj.save()
+            if hasattr(form, 'save_m2m'):
+                form.save_m2m()
+            return HttpResponseRedirect(reverse('dashboard-url'))
+    else:
+        if id:
+            action_instance = get_object_or_404(Action, pk=id)
+            form = ActionForm(instance=action_instance)
         else:
-            if id:
-                action_instance = get_object_or_404(Action, pk=id)
-                form = ActionForm(instance=action_instance)
-            else:
-                form = ActionForm()
+            form = ActionForm()
 
-        return render_to_response('action.html', locals(),context_instance=RequestContext(request))   
+    return render_to_response('action.html', locals(),context_instance=RequestContext(request))  
 
 def ref_log(request):
     try: