Exemple #1
0
    def test_day_of_month(self):
        self.data['frequency'] = 'M'
        form = SavedSearchForm(user=self.user, data=self.data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['day_of_month'][0],
                         'This field is required.')

        self.data['day_of_month'] = '1'
        form = SavedSearchForm(user=self.user, data=self.data)
        self.assertTrue(form.is_valid())
Exemple #2
0
def saved_search_main(request):
    # instantiate the form if the digest object exists
    try:
        digest_obj = SavedSearchDigest.objects.get(user=request.user)
    except (SavedSearchDigest.DoesNotExist,
            SavedSearchDigest.MultipleObjectsReturned):
        digest_obj = None
    updated = request.REQUEST.get('d')
    saved_searches = SavedSearch.objects.filter(
        user=request.user, partnersavedsearch__isnull=True)
    partner_saved_searches = PartnerSavedSearch.objects.filter(
        user=request.user)

    if request.user.is_verified:
        form = DigestForm(user=request.user, instance=digest_obj)
        add_form = SavedSearchForm(user=request.user)
    else:
        form = None
        add_form = None
    return render_to_response(
        'mysearches/saved_search_main.html', {
            'saved_searches': saved_searches,
            'partner_saved_searches': partner_saved_searches,
            'form': form,
            'add_form': add_form,
            'updated': updated,
            'view_name': 'Saved Searches'
        }, RequestContext(request))
Exemple #3
0
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))
Exemple #4
0
def save_edit_form(request):
    if request.is_ajax():
        search_id = request.POST.get('search_id')
        saved_search = SavedSearch.objects.get(id=search_id)
        if request.user == saved_search.user:
            form = SavedSearchForm(user=request.user,
                                   data=request.POST,
                                   instance=saved_search)
            if form.is_valid():
                form.save()
                return HttpResponse('success')
            else:
                return HttpResponse(json.dumps(form.errors))
Exemple #5
0
def edit_search(request):
    search_id = request.REQUEST.get('id')
    partner_saved_search = request.REQUEST.get('pss')
    if not partner_saved_search:
        if search_id:
            saved_search = get_object_or_404(SavedSearch,
                                             id=search_id,
                                             user=request.user)
            if hasattr(saved_search, 'partnersavedsearch'):
                raise Http404("mysearches.views.edit_search: trying to edit a "
                              "PartnerSavedSearch as a SavedSearch")
        else:
            saved_search = None

        is_pss = False
        form = SavedSearchForm(user=request.user,
                               instance=saved_search,
                               auto_id='id_edit_%s')
    else:
        if search_id:
            saved_search = get_object_or_404(SavedSearch,
                                             id=search_id,
                                             user=request.user)
            if hasattr(saved_search, 'partnersavedsearch'):
                is_pss = True
                form = PartnerSubSavedSearchForm(
                    instance=saved_search.partnersavedsearch,
                    auto_id=False,
                    request=request)
        else:
            raise Http404("mysearches.views.edit_search: no id provided")

    return render_to_response(
        'mysearches/saved_search_edit.html', {
            'form': form,
            'search_id': search_id,
            'view_name': 'Saved Searches',
            'search': saved_search,
            'is_pss': is_pss,
            'label': form.instance.label
        }, RequestContext(request))
Exemple #6
0
    def test_duplicate_url(self):
        original = SavedSearchFactory(user=self.user)
        form = SavedSearchForm(user=self.user, data=self.data)

        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['url'][0], 'URL must be unique.')
Exemple #7
0
 def test_invalid_url(self):
     self.data['url'] = 'http://google.com'
     form = SavedSearchForm(user=self.user, data=self.data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['url'][0], 'This URL is not valid.')
Exemple #8
0
 def test_successful_form(self):
     form = SavedSearchForm(user=self.user, data=self.data)
     self.assertTrue(form.is_valid())