Example #1
0
File: views.py Project: slok/dwarf
def forward(request, token):

    # get the forwarding Forward
    sl = ShortLink.find(token=token)

    if sl.disabled:
        raise Http404

    # Click :)
    click_link(token, request.META)

    if not re.search("^https?://.+", sl.url):
        forward_url = "http://{0}".format(sl.url)
    else:
        forward_url = sl.url

    # Add the points to the user
    user_link = UserLink.objects.get(token=token)
    # If returns something then level upload then notification
    new_level = utils.incr_points(user_link.user, settings.POINTS_PER_CLICK)
    if new_level:
        # Send notifications
        notif = LevelNotification(level=new_level,
                                  user_id=user_link.user.id)
        #notif.send_push()  # Push realtime notification
        notif.save()  # save the notification for the dashboard

    return redirect(forward_url)
Example #2
0
File: tests.py Project: slok/dwarf
    def test_level_notification_store(self):
        #with three we have enought to test
        levels = Level.objects.all()[:3]
        user = User.objects.get(id=1)

        a_len = len(levels)

        for i in levels:
            notif = LevelNotification(level=i, user=user)
            time.sleep(1)  # We need notification order
            notif.save()

        r = get_redis_connection()
        res = r.zrange(
            Notification.STORE_KEY_UNREAD_FORMAT.format(user.id), 0, -1)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = levels[i]
            after = json.loads(res[i])

            self.assertEquals(before.level_number, after['level'])