def save_search_form(request): search_id = request.POST.get('search_id') try: search_id = int(search_id) original = SavedSearch.objects.get(id=search_id, user=request.user) except (ValueError, TypeError): original = None if hasattr(original, 'partnersavedsearch'): form = PartnerSubSavedSearchForm(data=request.POST, instance=original.partnersavedsearch, request=request) else: form = SavedSearchForm(user=request.user, data=request.POST, instance=original) if form.is_valid(): form.save() if request.is_ajax(): return HttpResponse(status=200) else: return HttpResponseRedirect(reverse('saved_search_main')) else: if request.is_ajax(): return HttpResponse(json.dumps(form.errors)) else: return render_to_response('mysearches/saved_search_edit.html', {'form': form, 'search_id': search_id}, RequestContext(request))
def save_search_form(request): search_id = request.POST.get('search_id') try: search_id = int(search_id) original = SavedSearch.objects.get(id=search_id, user=request.user) except (ValueError, TypeError): original = None if hasattr(original, 'partnersavedsearch'): form = PartnerSubSavedSearchForm(data=request.POST, instance=original.partnersavedsearch, request=request) else: form = SavedSearchForm(user=request.user, data=request.POST, instance=original) if form.is_valid(): form.save() if request.is_ajax(): return HttpResponse(status=200) else: return HttpResponseRedirect(reverse('saved_search_main')) else: if request.is_ajax(): return HttpResponse(json.dumps(form.errors)) else: return render_to_response('mysearches/saved_search_edit.html', { 'form': form, 'search_id': search_id }, RequestContext(request))
def pss_sub_form_last_action_time_updated_on_edit(self): """ Verify saving partner saved search sub form causes last_action_time to update """ original_time = self.instance.last_action_time new_form = PartnerSubSavedSearchForm(instance=self.instance, request=self.request, data=self.partner_search_data) self.assertTrue(new_form.is_valid()) new_instance = new_form.save() self.assertEqual(self.instance.pk, new_instance.pk) self.assertNotEqual(new_instance.last_action_time, original_time)