Example #1
0
def get_notification_previous(request,max_id=0,count = 5):	
	#Get the data streams for the user
	import user_streams
	items = user_streams.get_stream_items(request.user).filter(id__lt = max_id)[:count]
	list = []
	for item in items:
		#Split the string for info about the user.
		object = item.content.split(":")
		#Get the username from the id
		username = User.objects.get(id=object[0])
		profile = User_Info.objects.get(user_id = object[0])
		data = {}
		data['id'] = item.id
		try:
			data['image'] = profile.profile_pic.image
		except:
			image = None
			data['image'] = image
			
		data['username'] = username
		data['topic'] = object[1]
		data['time'] = timesince(item.created_at).split(', ')[0]
		if len(object) == 3:
			story = Story.objects.get(storyid = object[2])
			image = Image.objects.filter(storyid = story.id).first()
			data['story_image'] = image.source
			data['story'] = object[2]
		list.append(data)
	return list
Example #2
0
    def test_unicode_handled_properly(self):
        user = User.objects.create()
        message = u'☃'

        add_stream_item(user, message)

        items = get_stream_items(user)
        self.assertEqual(items[0].content, message)
Example #3
0
def get_notification_count(request):
	#Get user last seen
	from last_seen.models import LastSeen
	seen = LastSeen.objects.when(user=request.user)
	#Get the data streams for the user
	import user_streams
	count = user_streams.get_stream_items(request.user).filter(created_at__gte = seen).count()
	return count
Example #4
0
def project_index(request):
    newsfeed = user_streams.get_stream_items(request.user)
    newsfeed_new = list(newsfeed.filter(seen=False))
    newsfeed_old = list(newsfeed.filter(seen=True)[:10])
    newsfeed.update(seen=True)
    context = {'newsfeed_old': newsfeed_old,
               'newsfeed_new': newsfeed_new}
    return render(request, 'project/index.html', context)
Example #5
0
    def test_unicode_handled_properly(self):
        user = User.objects.create()
        message = u'☃'

        add_stream_item(user, message)

        items = get_stream_items(user)
        self.assertEqual(items[0].content, message)
Example #6
0
    def test_multiple_users(self):
        user_1 = User.objects.create(username='******')
        user_2 = User.objects.create(username='******')
        user_3 = User.objects.create(username='******')
        content = 'Broadcast message'

        add_stream_item(User.objects.all(), content)

        for user in user_1, user_2, user_3:
            self.assertEqual(get_stream_items(user)[0].content, content)
Example #7
0
    def test_single_user(self):
        user = User.objects.create()
        content = 'Test message'

        add_stream_item(user, content)

        items = get_stream_items(user)
        self.assertEqual(len(items), 1)
        item = items[0]
        self.assertEqual(item.content, content)
Example #8
0
    def test_single_user(self):
        user = User.objects.create()
        content = 'Test message'

        add_stream_item(user, content)

        items = get_stream_items(user)
        self.assertEqual(len(items), 1)
        item = items[0]
        self.assertEqual(item.content, content)
Example #9
0
    def test_multiple_users(self):
        user_1 = User.objects.create(username='******')
        user_2 = User.objects.create(username='******')
        user_3 = User.objects.create(username='******')
        content = 'Broadcast message'

        add_stream_item(User.objects.all(), content)

        for user in user_1, user_2, user_3:
            self.assertEqual(get_stream_items(user)[0].content, content)
Example #10
0
    def test_identical_messages(self):
        """Check that identical messages are handled properly. Mostly
        an issue for the Redis backend (which uses sets to store messages)"""
        user = User.objects.create()
        message = 'Test message'

        add_stream_item(user, message)
        add_stream_item(user, message)

        items = get_stream_items(user)
        self.assertEqual(len(items), 2)
Example #11
0
    def test_identical_messages(self):
        """Check that identical messages are handled properly. Mostly
        an issue for the Redis backend (which uses sets to store messages)"""
        user = User.objects.create()
        message = 'Test message'

        add_stream_item(user, message)
        add_stream_item(user, message)

        items = get_stream_items(user)
        self.assertEqual(len(items), 2)
Example #12
0
    def test_message_ordering(self):
        user = User.objects.create()
        now = datetime_now()

        add_stream_item(user, 'Message 1', created_at=now)
        add_stream_item(user, 'Message 2', created_at=now + timedelta(minutes=1))
        add_stream_item(user, 'Message 3', created_at=now + timedelta(minutes=2))

        stream_items = get_stream_items(user)

        self.assertEqual(stream_items[0].content, 'Message 3')
        self.assertEqual(stream_items[1].content, 'Message 2')
        self.assertEqual(stream_items[2].content, 'Message 1')
Example #13
0
    def test_message_ordering(self):
        user = User.objects.create()
        now = datetime_now()

        add_stream_item(user, 'Message 1', created_at=now)
        add_stream_item(user,
                        'Message 2',
                        created_at=now + timedelta(minutes=1))
        add_stream_item(user,
                        'Message 3',
                        created_at=now + timedelta(minutes=2))

        stream_items = get_stream_items(user)

        self.assertEqual(stream_items[0].content, 'Message 3')
        self.assertEqual(stream_items[1].content, 'Message 2')
        self.assertEqual(stream_items[2].content, 'Message 1')
Example #14
0
def get_friend_activity_stream(request,content_type):
	if SESSION_KEY in request.session:
		user = User.objects.get(pk=request.session[SESSION_KEY])
		member = Member.objects.get(user=user)
		friends = member.get_friends()
		print "friend: "
		print friends
		obj_list = []
		for friend in friends:
			items = user_streams.get_stream_items(friend.user)
			for item in items:
				if member.user.username not in item.user_exclude:
					data = {}
					data['user'] = friend
					if content_type == 'friend_content':
						data['friend_content'] = item.friend_content
					elif content_type == "page_content":
						data['page_content'] = item.page_content
					data['time'] = item.created_at
					obj_list.append(data)
		obj_list.sort(key=lambda r: r['time'],reverse=True)
		return obj_list
	return []
Example #15
0
def get_friend_activity_stream(request, content_type):
    if SESSION_KEY in request.session:
        user = User.objects.get(pk=request.session[SESSION_KEY])
        member = Member.objects.get(user=user)
        friends = member.get_friends()
        print "friend: "
        print friends
        obj_list = []
        for friend in friends:
            items = user_streams.get_stream_items(friend.user)
            for item in items:
                if member.user.username not in item.user_exclude:
                    data = {}
                    data['user'] = friend
                    if content_type == 'friend_content':
                        data['friend_content'] = item.friend_content
                    elif content_type == "page_content":
                        data['page_content'] = item.page_content
                    data['time'] = item.created_at
                    obj_list.append(data)
        obj_list.sort(key=lambda r: r['time'], reverse=True)
        return obj_list
    return []
Example #16
0
    def test_pagination(self):
        user = User.objects.create()
        now = datetime_now()

        for count in range(100):
            created_at = now + timedelta(minutes=count)
            add_stream_item(user, 'Message %s' % count, created_at=created_at)

        paginator = Paginator(get_stream_items(user), 10)
        self.assertEqual(paginator.num_pages, 10)

        page_1 = paginator.page(1)
        objects = page_1.object_list
        self.assertEqual(len(objects), 10)
        self.assertEqual(objects[0].content, 'Message 99')
        self.assertEqual(objects[9].content, 'Message 90')
        self.assertEqual(page_1.next_page_number(), 2)

        page_10 = paginator.page(10)
        objects = page_10.object_list
        self.assertEqual(len(objects), 10)
        self.assertEqual(objects[0].content, 'Message 9')
        self.assertEqual(objects[9].content, 'Message 0')
        self.assertFalse(page_10.has_next())
Example #17
0
    def test_pagination(self):
        user = User.objects.create()
        now = datetime_now()

        for count in range(100):
            created_at = now + timedelta(minutes=count)
            add_stream_item(user, 'Message %s' % count, created_at=created_at)

        paginator = Paginator(get_stream_items(user), 10)
        self.assertEqual(paginator.num_pages, 10)

        page_1 = paginator.page(1)
        objects = page_1.object_list
        self.assertEqual(len(objects), 10)
        self.assertEqual(objects[0].content, 'Message 99')
        self.assertEqual(objects[9].content, 'Message 90')
        self.assertEqual(page_1.next_page_number(), 2)

        page_10 = paginator.page(10)
        objects = page_10.object_list
        self.assertEqual(len(objects), 10)
        self.assertEqual(objects[0].content, 'Message 9')
        self.assertEqual(objects[9].content, 'Message 0')
        self.assertFalse(page_10.has_next())
Example #18
0
    def test_slicing(self):
        user = User.objects.create()
        now = datetime_now()

        for count in range(10):
            created_at = now + timedelta(minutes=count)
            add_stream_item(user, 'Message %s' % count, created_at=created_at)

        stream_items = get_stream_items(user)

        first_five = stream_items[:5]
        self.assertEqual(len(first_five), 5)
        self.assertEqual(first_five[0].content, 'Message 9')
        self.assertEqual(first_five[4].content, 'Message 5')

        middle = stream_items[3:7]
        self.assertEqual(len(middle), 4)
        self.assertEqual(middle[0].content, 'Message 6')
        self.assertEqual(middle[3].content, 'Message 3')

        end = stream_items[6:]
        self.assertEqual(len(end), 4)
        self.assertEqual(end[0].content, 'Message 3')
        self.assertEqual(end[3].content, 'Message 0')
Example #19
0
    def test_slicing(self):
        user = User.objects.create()
        now = datetime_now()

        for count in range(10):
            created_at = now + timedelta(minutes=count)
            add_stream_item(user, 'Message %s' % count, created_at=created_at)

        stream_items = get_stream_items(user)

        first_five = stream_items[:5]
        self.assertEqual(len(first_five), 5)
        self.assertEqual(first_five[0].content, 'Message 9')
        self.assertEqual(first_five[4].content, 'Message 5')

        middle = stream_items[3:7]
        self.assertEqual(len(middle), 4)
        self.assertEqual(middle[0].content, 'Message 6')
        self.assertEqual(middle[3].content, 'Message 3')

        end = stream_items[6:]
        self.assertEqual(len(end), 4)
        self.assertEqual(end[0].content, 'Message 3')
        self.assertEqual(end[3].content, 'Message 0')
Example #20
0
def member_main_page(request, username):
    autocomplete_data = get_autocomplete_data(request)

    request.session["current_user"] = username

    member_login = get_member_login_object(request)
    if request.method == "POST":
        # Handle multiple POST request. The one below is for create activity
        if "activity_name" in request.POST:
            new_activity = Activity()
            try:
                new_activity.name = request.POST["activity_name"]
                new_activity.description = request.POST["activity_description"]
                starttime_tmp = request.POST["activity_starttime"].split()
                new_activity.start_time = convert_time(starttime_tmp[0], starttime_tmp[1], starttime_tmp[2])
                endtime_tmp = request.POST["activity_endtime"].split()
                new_activity.end_time = convert_time(endtime_tmp[0], endtime_tmp[1], endtime_tmp[2])
                new_activity.member_create = member_login
                new_activity.location = Location.objects.get(pk=int(request.POST["location"]))
                new_activity.activity_type = request.POST["activity_type"]

                if new_activity.activity_type == "blind_date":
                    new_activity.limit = 1
                    new_activity.age_range_start = int(request.POST["activity_age_range_from"])
                    new_activity.age_range_end = int(request.POST["activity_age_range_to"])
                else:
                    if "activity_unlimited" not in request.POST:
                        new_activity.limit = request.POST["activity_limit"]
                new_activity.save()
            except:
                return render_to_response(
                    "activity_template/admin_page/create_error.html",
                    {
                        "member_login": member_login,
                        "autocomplete_data": autocomplete_data,
                        "location_id": int(request.POST["location"]),
                    },
                    context_instance=RequestContext(request),
                )
            return HttpResponseRedirect("/activity/" + str(new_activity.pk) + "/manage/")

        if "location_name" in request.POST:
            new_location = Location()
            try:
                new_location.name = request.POST["location_name"]
                new_location.description = request.POST["location_description"]
                new_location.category = request.POST["location_category"]
                new_location.address1 = request.POST["location_address1"]
                new_location.address2 = request.POST["location_address2"]
                new_location.city = request.POST["location_city"]
                new_location.state = request.POST["location_state"]
                new_location.zip_code = int(request.POST["location_zipcode"])
                new_location.preference = request.POST["location_preference"]
                new_location.create_by = member_login
                if "location_avatar" in request.FILES:
                    new_location.avatar = request.FILES["location_avatar"]
                new_location.save()
            except:
                return render_to_response(
                    "location_template/page/create_error.html",
                    {"member_login": member_login, "autocomplete_data": autocomplete_data},
                    context_instance=RequestContext(request),
                )
            return HttpResponseRedirect("/location/" + str(new_location.pk))

    if member_login != None:
        if check_confirm_email(request) == False:
            notice = "resend_email"

    member_view = get_object_or_404(Member, user=get_object_or_404(User, username=username))
    template = ""
    section = None
    notice = None
    if "section" in request.GET:
        section = request.GET["section"]
    else:
        section = "activity"

        # Define whether this is user login page or not. If yes, return
        # his/her admin page. If not return the view page of this user
    if check_user_login_page(request, username):
        if "act" in request.GET:
            notice = request.GET["act"]
        template = "member_template/admin_page/main_page.html"
        is_friend = None
    else:
        if member_login != None:
            if check_user_block(member_login.user, member_view.user):
                raise Http404
        template = "member_template/normal_page/main_page.html"
        is_friend = check_friendship(request, username)

        # Necessary data here
    new_buzzes = get_new_buzzes(request)
    new_mail = get_new_mail(request)
    new_notify = len(new_buzzes) + len(new_mail)
    location_create = Location.objects.filter(create_by=member_view)
    location_follow = Location.objects.filter(follow_by=member_view)
    location_categories = LocationCategory.objects.all()
    activity_create = Activity.objects.filter(member_create=member_view)
    activity_join = Activity.objects.filter(member_join=member_view)
    friends = member_view.get_friends()
    recent_activity_stream = user_streams.get_stream_items(User.objects.get(username=username))[:NORMAL_STREAM_LIMIT]
    friends_activity_stream = get_friend_activity_stream(request, "friend_content")[:NORMAL_STREAM_LIMIT]

    # Return the response and render the template view
    return render_to_response(
        template,
        {
            "autocomplete_data": autocomplete_data,
            "is_friend": is_friend,
            "notice": notice,
            "section": section,
            "new_buzzes": new_buzzes,
            "new_mail": new_mail,
            "new_notify": new_notify,
            "member_login": member_login,
            "member_view": member_view,
            "location_create": location_create,
            "location_follow": location_follow,
            "location_categories": location_categories,
            "activity_create": activity_create,
            "activity_join": activity_join,
            "friends": friends,
            "recent_activity_stream": recent_activity_stream,
            "friends_activity_stream": friends_activity_stream,
        },
        context_instance=RequestContext(request),
    )
Example #21
0
def member_main_page(request, username):
    autocomplete_data = get_autocomplete_data(request)

    request.session['current_user'] = username

    member_login = get_member_login_object(request)
    if request.method == 'POST':
        # Handle multiple POST request. The one below is for create activity
        if 'activity_name' in request.POST:
            new_activity = Activity()
            try:
                new_activity.name = request.POST['activity_name']
                new_activity.description = request.POST['activity_description']
                starttime_tmp = request.POST['activity_starttime'].split()
                new_activity.start_time = convert_time(starttime_tmp[0],
                                                       starttime_tmp[1],
                                                       starttime_tmp[2])
                endtime_tmp = request.POST['activity_endtime'].split()
                new_activity.end_time = convert_time(endtime_tmp[0],
                                                     endtime_tmp[1],
                                                     endtime_tmp[2])
                new_activity.member_create = member_login
                new_activity.location = Location.objects.get(
                    pk=int(request.POST['location']))
                new_activity.activity_type = request.POST['activity_type']

                if new_activity.activity_type == 'blind_date':
                    new_activity.limit = 1
                    new_activity.age_range_start = int(
                        request.POST['activity_age_range_from'])
                    new_activity.age_range_end = int(
                        request.POST['activity_age_range_to'])
                else:
                    if 'activity_unlimited' not in request.POST:
                        new_activity.limit = request.POST['activity_limit']
                new_activity.save()
            except:
                return render_to_response(
                    "activity_template/admin_page/create_error.html", {
                        "member_login": member_login,
                        "autocomplete_data": autocomplete_data,
                        'location_id': int(request.POST['location'])
                    },
                    context_instance=RequestContext(request))
            return HttpResponseRedirect("/activity/" + str(new_activity.pk) +
                                        "/manage/")

        if 'location_name' in request.POST:
            new_location = Location()
            try:
                new_location.name = request.POST['location_name']
                new_location.description = request.POST['location_description']
                new_location.category = request.POST['location_category']
                new_location.address1 = request.POST['location_address1']
                new_location.address2 = request.POST['location_address2']
                new_location.city = request.POST['location_city']
                new_location.state = request.POST['location_state']
                new_location.zip_code = int(request.POST['location_zipcode'])
                new_location.preference = request.POST['location_preference']
                new_location.create_by = member_login
                if "location_avatar" in request.FILES:
                    new_location.avatar = request.FILES['location_avatar']
                new_location.save()
            except:
                return render_to_response(
                    "location_template/page/create_error.html", {
                        "member_login": member_login,
                        "autocomplete_data": autocomplete_data,
                    },
                    context_instance=RequestContext(request))
            return HttpResponseRedirect("/location/" + str(new_location.pk))

    if member_login != None:
        if check_confirm_email(request) == False:
            notice = "resend_email"

    member_view = get_object_or_404(Member,
                                    user=get_object_or_404(User,
                                                           username=username))
    template = ""
    section = None
    notice = None
    if 'section' in request.GET:
        section = request.GET['section']
    else:
        section = 'activity'

    # Define whether this is user login page or not. If yes, return
    # his/her admin page. If not return the view page of this user
    if check_user_login_page(request, username):
        if "act" in request.GET:
            notice = request.GET['act']
        template = "member_template/admin_page/main_page.html"
        is_friend = None
    else:
        if member_login != None:
            if check_user_block(member_login.user, member_view.user):
                raise Http404
        template = "member_template/normal_page/main_page.html"
        is_friend = check_friendship(request, username)

    # Necessary data here
    new_buzzes = get_new_buzzes(request)
    new_mail = get_new_mail(request)
    new_notify = len(new_buzzes) + len(new_mail)
    location_create = Location.objects.filter(create_by=member_view)
    location_follow = Location.objects.filter(follow_by=member_view)
    location_categories = LocationCategory.objects.all()
    activity_create = Activity.objects.filter(member_create=member_view)
    activity_join = Activity.objects.filter(member_join=member_view)
    friends = member_view.get_friends()
    recent_activity_stream = user_streams.get_stream_items(
        User.objects.get(username=username))[:NORMAL_STREAM_LIMIT]
    friends_activity_stream = get_friend_activity_stream(
        request, 'friend_content')[:NORMAL_STREAM_LIMIT]

    # Return the response and render the template view
    return render_to_response(
        template, {
            'autocomplete_data': autocomplete_data,
            'is_friend': is_friend,
            "notice": notice,
            'section': section,
            "new_buzzes": new_buzzes,
            'new_mail': new_mail,
            'new_notify': new_notify,
            "member_login": member_login,
            'member_view': member_view,
            'location_create': location_create,
            'location_follow': location_follow,
            'location_categories': location_categories,
            'activity_create': activity_create,
            'activity_join': activity_join,
            'friends': friends,
            'recent_activity_stream': recent_activity_stream,
            'friends_activity_stream': friends_activity_stream,
        },
        context_instance=RequestContext(request))