'Shorten range for display and add next/prev buttons.'

def check_dates(self, thing):

    (start, end) = promote.get_traffic_dates(thing)
    history = list(get_promo_traffic(thing, start, end))
    if history:
        end = max((date for (date, data) in history))
        end = end.replace(tzinfo=g.tz)
    if self.period:
        display_start = self.after
        display_end = self.before
        if ((not display_start) and (not display_end)):
            display_end = end
            display_start = (end - self.period)
        elif (not display_end):
            display_end = (display_start + self.period)
        elif (not display_start):
            display_start = (display_end - self.period)
        if (display_start > start):
            p = request.GET.copy()
            p.update({'after': None, 'before': display_start.strftime('%Y%m%d%H')})
            self.prev = ('%s?%s' % (request.path, urllib.urlencode(p)))
        else:
            display_start = start
        if (display_end < end):
            p = request.GET.copy()
            p.update({'after': display_end.strftime('%Y%m%d%H'), 'before': None})
            self.next = ('%s?%s' % (request.path, urllib.urlencode(p)))
        else:
            display_end = end
    else:
        (display_start, display_end) = (start, end)
    return (display_start, display_end)
