Esempio n. 1
0
    def test_url_sort_options(self):
        feed = 'http://www.my.jobs/jobs/feed/rss?date_sort=False'

        # Test to make sure sort by "Relevance" has '&date_sort=False' added
        # a single time
        feed_url = url_sort_options(feed, "Relevance")
        parsed = urlparse(feed_url)
        query = parse_qs(parsed.query)
        self.assertEquals(parsed.path, "/jobs/feed/rss")
        self.assertEquals(query['date_sort'], [u'False'])
        # If a frequency isn't specified, days_ago should be missing from
        # the url.
        self.assertNotIn('days_ago', query)

        # Test to make sure sort by "Date" doesn't have anything added
        feed_url = url_sort_options(feed, "Date")
        self.assertEquals(feed_url, "http://www.my.jobs/jobs/feed/rss")

        # Test to make sure that passing in a frequency does in fact
        # add the frequency to the feed url.
        feed_url = url_sort_options(feed, "Relevance", frequency='D')
        query = parse_qs(urlparse(feed_url).query)
        self.assertEquals(query['days_ago'][0], '1')
        feed_url = url_sort_options(feed, "Relevance", frequency='W')
        query = parse_qs(urlparse(feed_url).query)
        self.assertEquals(query['days_ago'][0], '7')
        feed_url = url_sort_options(feed, "Relevance", frequency='M')
        query = parse_qs(urlparse(feed_url).query)
        self.assertEqual(query['days_ago'][0], '30')
Esempio n. 2
0
    def test_url_sort_options(self):
        feed = 'http://www.my.jobs/jobs/feed/rss?date_sort=False'

        # Test to make sure sort by "Relevance" has '&date_sort=False' added
        # a single time
        feed_url = url_sort_options(feed, "Relevance")
        parsed = urlparse(feed_url)
        query = parse_qs(parsed.query)
        self.assertEquals(parsed.path, "/jobs/feed/rss")
        self.assertEquals(query['date_sort'], [u'False'])
        # If a frequency isn't specified, days_ago should be missing from
        # the url.
        self.assertNotIn('days_ago', query)

        # Test to make sure sort by "Date" doesn't have anything added
        feed_url = url_sort_options(feed, "Date")
        self.assertEquals(feed_url, "http://www.my.jobs/jobs/feed/rss")

        # Test to make sure that passing in a frequency does in fact
        # add the frequency to the feed url.
        feed_url = url_sort_options(feed, "Relevance", frequency='D')
        query = parse_qs(urlparse(feed_url).query)
        self.assertEquals(query['days_ago'][0], '1')
        feed_url = url_sort_options(feed, "Relevance", frequency='W')
        query = parse_qs(urlparse(feed_url).query)
        self.assertEquals(query['days_ago'][0], '7')
        feed_url = url_sort_options(feed, "Relevance", frequency='M')
        query = parse_qs(urlparse(feed_url).query)
        self.assertEqual(query['days_ago'][0], '30')
Esempio n. 3
0
def view_full_feed(request):
    search_id = request.REQUEST.get('id')
    saved_search = SavedSearch.objects.get(id=search_id)
    if hasattr(saved_search, 'partnersavedsearch'):
        is_pss = True
    else:
        is_pss = False
    if request.user == saved_search.user:
        url_of_feed = url_sort_options(saved_search.feed,
                                       saved_search.sort_by,
                                       frequency=saved_search.frequency)
        try:
            items, count = parse_feed(url_of_feed, saved_search.frequency,
                                      saved_search.jobs_per_email)
        except HTTPError:
            items = None
            count = 0
        start_date = date.today() + timedelta(get_interval_from_frequency(
            saved_search.frequency))
        return render_to_response('mysearches/view_full_feed.html',
                                  {'search': saved_search,
                                   'items': items,
                                   'view_name': 'Saved Searches',
                                   'is_pss': is_pss,
                                   'start_date': start_date,
                                   'count': count},
                                  RequestContext(request))
    else:
        return HttpResponseRedirect(reverse('saved_search_main'))
Esempio n. 4
0
def view_full_feed(request):
    search_id = request.REQUEST.get('id')
    saved_search = SavedSearch.objects.get(id=search_id)
    if hasattr(saved_search, 'partnersavedsearch'):
        is_pss = True
    else:
        is_pss = False
    if request.user == saved_search.user:
        url_of_feed = url_sort_options(saved_search.feed,
                                       saved_search.sort_by,
                                       frequency=saved_search.frequency)
        try:
            items, count = parse_feed(url_of_feed, saved_search.frequency,
                                      saved_search.jobs_per_email)
        except HTTPError:
            items = None
            count = 0
        start_date = date.today() + timedelta(
            get_interval_from_frequency(saved_search.frequency))
        return render_to_response(
            'mysearches/view_full_feed.html', {
                'search': saved_search,
                'items': items,
                'view_name': 'Saved Searches',
                'is_pss': is_pss,
                'start_date': start_date,
                'count': count
            }, RequestContext(request))
    else:
        return HttpResponseRedirect(reverse('saved_search_main'))
Esempio n. 5
0
def more_feed_results(request):
    # Ajax request comes from the view_full_feed view when user scrolls to
    # bottom of the page
    if request.is_ajax():
        url_of_feed = url_sort_options(request.GET['feed'],
                                       request.GET['sort_by'],
                                       frequency=request.GET['frequency'])
        items = parse_feed(url_of_feed, request.GET['frequency'],
                           offset=request.GET['offset'])[0]
        return render_to_response('mysearches/feed_page.html',
                                  {'items': items}, RequestContext(request))
Esempio n. 6
0
def more_feed_results(request):
    # Ajax request comes from the view_full_feed view when user scrolls to
    # bottom of the page
    if request.is_ajax():
        url_of_feed = url_sort_options(request.GET['feed'],
                                       request.GET['sort_by'],
                                       frequency=request.GET['frequency'])
        items = parse_feed(url_of_feed,
                           request.GET['frequency'],
                           offset=request.GET['offset'])[0]
        return render_to_response('mysearches/feed_page.html',
                                  {'items': items}, RequestContext(request))
Esempio n. 7
0
 def get_feed_items(self, num_items=None):
     num_items = num_items or self.jobs_per_email
     url_of_feed = url_sort_options(self.feed, self.sort_by, self.frequency,
                                    hasattr(self, 'partnersavedsearch'))
     url_of_feed = update_url_if_protected(url_of_feed, self.user)
     parse_feed_args = {
         'feed_url': url_of_feed,
         'frequency': self.frequency,
         'num_items': num_items,
         'return_items': num_items,
         'last_sent': self.last_sent
     }
     if hasattr(self, 'partnersavedsearch'):
         parse_feed_args['ignore_dates'] = True
     items = parse_feed(**parse_feed_args)
     return items
Esempio n. 8
0
 def get_feed_items(self, num_items=None):
     num_items = num_items or self.jobs_per_email
     url_of_feed = url_sort_options(self.feed, self.sort_by, self.frequency,
                                    hasattr(self, 'partnersavedsearch'))
     url_of_feed = update_url_if_protected(url_of_feed, self.user)
     parse_feed_args = {
         'feed_url': url_of_feed,
         'frequency': self.frequency,
         'num_items': num_items,
         'return_items': num_items,
         'last_sent': self.last_sent
     }
     if hasattr(self, 'partnersavedsearch'):
         parse_feed_args['ignore_dates'] = True
     items = parse_feed(**parse_feed_args)
     return items
Esempio n. 9
0
    def test_unicode_in_search(self):
        search = SavedSearch(url=u"http://www.my.jobs/search?q=%E2%80%93",
                             user=self.user,
                             feed=u"http://www.my.jobs/search/feed/rss?q=%E2%80%93",
                             sort_by=u'Relevance')
        search.save()

        feed_url = url_sort_options(search.feed, search.sort_by)

        old = parse_qs(urlparse(search.feed).query)
        new = parse_qs(urlparse(feed_url).query)

        self.assertFalse(old.get('date_sort'))
        self.assertTrue(new['date_sort'][0])

        del new['date_sort']
        self.assertEqual(new, old)
Esempio n. 10
0
    def test_unicode_in_search(self):
        search = SavedSearch(
            url=u"http://www.my.jobs/search?q=%E2%80%93",
            user=self.user,
            feed=u"http://www.my.jobs/search/feed/rss?q=%E2%80%93",
            sort_by=u'Relevance')
        search.save()

        feed_url = url_sort_options(search.feed, search.sort_by)

        old = parse_qs(urlparse(search.feed).query)
        new = parse_qs(urlparse(feed_url).query)

        self.assertFalse(old.get('date_sort'))
        self.assertTrue(new['date_sort'][0])

        del new['date_sort']
        self.assertEqual(new, old)
Esempio n. 11
0
 def get_feed_items(self, num_items=5):
     url_of_feed = url_sort_options(self.feed, self.sort_by, self.frequency)
     return parse_rss(url_of_feed, self.frequency, num_items=num_items)
Esempio n. 12
0
 def get_feed_items(self, num_items=5):
     url_of_feed = url_sort_options(self.feed, self.sort_by, self.frequency)
     return parse_rss(url_of_feed, self.frequency, num_items=num_items)