Ejemplo n.º 1
0
    def get_queryset(self):
        self.page_base_url = reverse_channel(self.channel, 'log_all')
        msg_id = self.kwargs['message_id']
        half_page_count = self.paginate_by / 2
        queryset = super(MessageLogViewer, self).get_queryset()
        try:
            message = queryset.get(pk=msg_id)
            timestamp = message.timestamp
        except models.Log.DoesNotExist:
            raise Http404
        # This is pretty inefficient, but it gets us the queryset we want
        messages_before = (queryset.filter(timestamp__lt=timestamp)
                                   .order_by('-timestamp'))
        messages_after = (queryset.filter(timestamp__gt=timestamp)
                                  .order_by('timestamp'))

        try:
            first = list(messages_before[:half_page_count])[-1]
        except IndexError:
            first = message
        try:
            last = list(messages_after[:half_page_count - 1])[-1]
        except IndexError:
            last = message
        return queryset.filter(timestamp__range=(first.timestamp,
                                                 last.timestamp))
Ejemplo n.º 2
0
 def channel_date_url(self, date=None):
     if not date:
         date = self.date
     viewname = self.format == 'text' and 'log_day_text' or 'log_day'
     return reverse_channel(self.channel,
                            viewname,
                            kwargs=self._kwargs_with_date(date))
Ejemplo n.º 3
0
 def setUp(self):
     super(KudosTests, self).setUp()
     kudos = []
     for i, letter in enumerate('abcdefghijklmnopqrstuvwxyz'):
         kudos.append(Kudos(
             nick=letter*3, count=1+i+(i % 5), channel=self.public_channel,
             first=now()-datetime.timedelta(days=100), recent=now()))
     Kudos.objects.bulk_create(kudos)
     self.url = reverse_channel(self.public_channel, "kudos")
Ejemplo n.º 4
0
 def test_searched_log(self):
     log_models.Log.objects.create(
         channel=self.public_channel,
         nick="test",
         text="This is a test",
         timestamp=pytz.utc.localize(datetime.datetime.now() + datetime.timedelta(seconds=1)))
     url = "%ssearch/?q=test" % reverse_channel(self.public_channel, "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 5
0
 def test_day_log_text_viewer(self):
     url = reverse_channel(self.public_channel,
                           "log_day_text",
                           kwargs=dict(year=self.log.timestamp.year,
                                       month="%02d" %
                                       self.log.timestamp.month,
                                       day="%02d" % self.log.timestamp.day))
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 6
0
 def setUp(self):
     super(KudosJSONTest, self).setUp()
     member = account_models.User.objects.create_user(
         username="******",
         password="******",
         email="*****@*****.**")
     admin = account_models.User.objects.create_user(
         username="******", password="******", email="*****@*****.**")
     self.url = reverse_channel(self.public_channel, "kudos_json")
Ejemplo n.º 7
0
 def test_searched_log(self):
     log_models.Log.objects.create(channel=self.public_channel,
                                   nick="test",
                                   text="This is a test",
                                   timestamp=timezone.now() +
                                   datetime.timedelta(seconds=1))
     url = "%ssearch/?q=test" % reverse_channel(self.public_channel,
                                                "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 8
0
 def test_day_log_text_viewer(self):
     url = reverse_channel(
         self.public_channel,
         "log_day_text",
         kwargs=dict(
         year=self.log.timestamp.year,
         month="%02d" % self.log.timestamp.month,
         day="%02d" % self.log.timestamp.day))
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 9
0
 def setUp(self):
     super(KudosJSONTest, self).setUp()
     member = account_models.User.objects.create_user(
         username="******",
         password="******",
         email="*****@*****.**")
     admin = account_models.User.objects.create_user(
         username="******",
         password="******",
         email="*****@*****.**")
     self.url = reverse_channel(self.public_channel, "kudos_json")
Ejemplo n.º 10
0
 def setUp(self):
     super(KudosTests, self).setUp()
     kudos = []
     for i, letter in enumerate('abcdefghijklmnopqrstuvwxyz'):
         kudos.append(
             Kudos(nick=letter * 3,
                   count=1 + i + (i % 5),
                   channel=self.public_channel,
                   first=timezone.now() - datetime.timedelta(days=100),
                   recent=timezone.now()))
     Kudos.objects.bulk_create(kudos)
     self.url = reverse_channel(self.public_channel, "kudos")
Ejemplo n.º 11
0
 def test_missed_log(self):
     log_models.Log.objects.create(channel=self.public_channel,
                                   command='QUIT',
                                   nick="test",
                                   timestamp=timezone.now())
     log_models.Log.objects.create(channel=self.public_channel,
                                   nick="test",
                                   timestamp=timezone.now() +
                                   datetime.timedelta(seconds=1))
     url = "%smissed/test/" % reverse_channel(self.public_channel,
                                              "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 12
0
 def test_missed_log(self):
     log_models.Log.objects.create(
         channel=self.public_channel,
         command='QUIT',
         nick="test",
         timestamp=pytz.utc.localize(datetime.datetime.now()))
     log_models.Log.objects.create(
         channel=self.public_channel,
         nick="test",
         timestamp=pytz.utc.localize(datetime.datetime.now() + datetime.timedelta(seconds=1)))
     url = "%smissed/test/" % reverse_channel(self.public_channel, "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 13
0
 def get_queryset(self):
     # individual page URLs will already be passed a date
     # they don't need to use the date in the URL
     self.page_base_url = reverse_channel(self.channel, 'log_all')
     try:
         year = int(self.kwargs['year'])
         month = int(self.kwargs['month'])
         day = int(self.kwargs['day'])
     except ValueError:
         raise Http404
     try:
         tz = pytz.timezone(self.request.GET.get('tz', 'UTC'))
     except (KeyError, pytz.UnknownTimeZoneError):
         tz = pytz.utc
     self.fetch_after = tz.localize(datetime.datetime(year, month,
                                                      day, 0, 0, 0))
     return super(DayLogViewer, self).get_queryset()
Ejemplo n.º 14
0
 def channel_date_url(self, date=None):
     if not date:
         date = self.date
     viewname = self.format == 'text' and 'log_day_text' or 'log_day'
     return reverse_channel(
         self.channel, viewname, kwargs=self._kwargs_with_date(date))
Ejemplo n.º 15
0
 def get_absolute_url(self):
     from botbot.apps.bots.utils import reverse_channel
     return reverse_channel(self, 'log_current')
Ejemplo n.º 16
0
def get_help_url(channel):
    return SITE + reverse_channel(channel, "help_bot")
Ejemplo n.º 17
0
 def get_eventsource_url(self):
     from botbot.apps.bots.utils import reverse_channel
     return reverse_channel(self, 'log_stream')
Ejemplo n.º 18
0
 def test_day_log_viewer(self):
     url = reverse_channel(self.public_channel, "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 19
0
 def get_absolute_url(self):
     from botbot.apps.bots.utils import reverse_channel
     return reverse_channel(self, 'log_current')
Ejemplo n.º 20
0
 def test_current_redirects_to_today(self):
     url = reverse_channel(self.public_channel, "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)
Ejemplo n.º 21
0
 def channel_date_url(self, date=None):
     if not date:
         date = self.date
     return reverse_channel(
         self.channel, 'log_day', kwargs=self._kwargs_with_date(date))
Ejemplo n.º 22
0
 def channel_date_url(self, date=None):
     if not date:
         date = self.date
     return reverse_channel(self.channel,
                            'log_day',
                            kwargs=self._kwargs_with_date(date))
Ejemplo n.º 23
0
 def get_eventsource_url(self):
     from botbot.apps.bots.utils import reverse_channel
     return reverse_channel(self, 'log_stream')
Ejemplo n.º 24
0
def get_help_url(channel):
    return SITE + reverse_channel(channel, "help_bot")
Ejemplo n.º 25
0
 def test_current_viewer(self):
     url = reverse_channel(self.public_channel, "log_current")
     res = self.client.get(url)
     self.assertEqual(res.status_code, 200)