Example #1
0
def message_map(request):
    messages = TalkMessage.getMessages()
    return render_to_response('geocamTalk/map.html',
                              dict(gc_msg=messages,
                                   first_geolocation=get_first_geolocation(messages),
                                   timestamp=TalkMessage.getLargestMessageId()),
                              context_instance=RequestContext(request))
Example #2
0
def feed_messages(request, recipient_username=None, author_username=None):
    if not request.user.is_authenticated():
        return HttpResponseForbidden()
    else:
        timestamp = TalkMessage.getLargestMessageId()
        if recipient_username is not None:
            recipient = get_object_or_404(User, username=recipient_username)
        else:
            recipient = None

        if author_username is not None:
            author = get_object_or_404(User, username=author_username)
        else:
            author = None
        since = request.GET.get("since", None)

        if since is not None:
            since_dt = since
            messages = TalkMessage.getMessages(recipient, author).filter(pk__gt=since_dt)
            message_count = TalkMessage.getMessages(request.user).filter(pk__gt=since_dt).count()
        else:
            messages = TalkMessage.getMessages(recipient, author)
            message_count = TalkMessage.getMessages(request.user).count()
        return HttpResponse(
            json.dumps({"ts": timestamp, "msgCnt": message_count, "ms": [msg.getJson() for msg in messages]})
        )
Example #3
0
def feed_messages(request, recipient_username=None, author_username=None):
    if not request.user.is_authenticated():
        return HttpResponseForbidden()
    else:
        timestamp = TalkMessage.getLargestMessageId()
        if recipient_username is not None:
            recipient = get_object_or_404(User, username=recipient_username)
        else:
            recipient = None

        if author_username is not None:
            author = get_object_or_404(User, username=author_username)
        else:
            author = None
        since = request.GET.get('since', None)

        if since is not None:
            since_dt = since
            messages = TalkMessage.getMessages(recipient,
                                               author).filter(pk__gt=since_dt)
            message_count = TalkMessage.getMessages(
                request.user).filter(pk__gt=since_dt).count()
        else:
            messages = TalkMessage.getMessages(recipient, author)
            message_count = TalkMessage.getMessages(request.user).count()
        return HttpResponse(
            json.dumps({
                'ts': timestamp,
                'msgCnt': message_count,
                'ms': [msg.getJson() for msg in messages]
            }))
Example #4
0
    def testEnsureLastViewedMyMessages(self):
        # arrange
        user = User.objects.all()[0]
        latestmsgId = TalkMessage.getLargestMessageId()
        profile = user.profile

        # act
        profile.last_viewed_mymessages = latestmsgId
        profile.save()

        # assert
        self.assertEquals(latestmsgId, user.profile.last_viewed_mymessages)
Example #5
0
    def testEnsureLastViewedMyMessages(self):
        # arrange
        user = User.objects.all()[0]
        latestmsgId = TalkMessage.getLargestMessageId()
        profile = user.profile

        # act
        profile.last_viewed_mymessages = latestmsgId
        profile.save()

        # assert
        self.assertEquals(latestmsgId, user.profile.last_viewed_mymessages)
Example #6
0
 def test_NewMessageCountJsonFeed(self):
     author = User.objects.get(username="******")
     self.client.login(username=author.username, password='******')
     # need to cast the query set to a list here to avoid the dynamic update 
     # when we create the new msg
     #old_messages = list(TalkMessage.getMessages())
     before_new_message = TalkMessage.getLargestMessageId()
     recipient = User.objects.get(username="******")
     msg = TalkMessage.objects.create(content='This is a new message', content_timestamp=datetime.now(), author=author)
     msg.recipients.add(recipient)
     msg.recipients.add(User.objects.all()[2])
     msg.save()
     response = self.client.get(reverse("talk_message_list_author_json", args=[author.username])+
                                '?since=%s' % before_new_message)
     self.assertContains(response, '"msgCnt": 1')
Example #7
0
 def test_NewMessageCountJsonFeed(self):
     author = User.objects.get(username="******")
     self.client.login(username=author.username, password='******')
     # need to cast the query set to a list here to avoid the dynamic update
     # when we create the new msg
     #old_messages = list(TalkMessage.getMessages())
     before_new_message = TalkMessage.getLargestMessageId()
     recipient = User.objects.get(username="******")
     msg = TalkMessage.objects.create(content='This is a new message', content_timestamp=datetime.now(), author=author)
     msg.recipients.add(recipient)
     msg.recipients.add(User.objects.all()[2])
     msg.save()
     response = self.client.get(reverse("geocamTalk_message_list_author_json", args=[author.username])
                                + '?since=%s' % before_new_message)
     self.assertContains(response, '"msgCnt": 1')
Example #8
0
def get_messages(request, recipient_username=None, author_username=None):
    timestamp = TalkMessage.getLargestMessageId()
    if recipient_username is not None:
        recipient = get_object_or_404(User, username=recipient_username)
    else:
        recipient = None

    if author_username is not None:
        author = get_object_or_404(User, username=author_username)
    else:
        author = None
    since = request.GET.get('since', None)

    if since is not None:
        since_dt = since
        messages = TalkMessage.getMessages(recipient, author).filter(pk__gt=since_dt)
        message_count = TalkMessage.getMessages(recipient).filter(pk__gt=since_dt).count()
    else:
        messages = TalkMessage.getMessages(recipient, author)
        message_count = TalkMessage.getMessages(recipient).count()
    return timestamp, messages, message_count
Example #9
0
def message_list(request, recipient_username=None, author_username=None):
    timestamp = TalkMessage.getLargestMessageId()
    if recipient_username is not None:
        recipient = get_object_or_404(User, username=recipient_username)
    else:
        recipient = None

    if author_username is not None:
        author = get_object_or_404(User, username=author_username)
    else:
        author = None

    if recipient is not None and recipient.pk == request.user.pk and author is None:
        profile = recipient.profile
        profile.last_viewed_mymessages = timestamp
        profile.save()

    return render_to_response('geocamTalk/message_list.html',
                               dict(gc_msg=TalkMessage.getMessages(recipient, author),
                                   recipient=recipient,
                                   author=author,
                                   timestamp=timestamp),
                               context_instance=RequestContext(request))
Example #10
0
def clear_messages(request):
    profile = request.user.profile
    profile.last_viewed_mymessages = TalkMessage.getLargestMessageId()
    profile.save()

    return HttpResponse(json.dumps({"ts": TalkMessage.getLargestMessageId()}))
Example #11
0
def clear_messages(request):
    profile = request.user.profile
    profile.last_viewed_mymessages = TalkMessage.getLargestMessageId()
    profile.save()

    return HttpResponse(json.dumps({'ts': TalkMessage.getLargestMessageId()}))