Esempio n. 1
0
def display_bookmarks(request):
	''' Display existing bookmarks '''

	username , data = get_bookmarks(request)	
	bookmark_form = BookmarkForm(initial={'visibility':'public'})	
	category_form = CategoryForm()
	tag_form = TagForm()
	redis_obj = Redis()

	if request.is_ajax():
		
		data = simplejson.dumps(data)
		return HttpResponse(data, mimetype='application/json')

	user_info = get_user_info(redis_obj, get_unique_id(redis_obj, username), get_userId(request))
	user_info['following'] = get_following_count(redis_obj, get_unique_id(redis_obj, username))
	user_info['followers'] = get_followers_count(redis_obj, get_unique_id(redis_obj, username))
	
	return render_to_response(HOME_TEMPLATE_PATH, 
		{
			'username' : username,
			'bookmark_form':bookmark_form,
			'category_form':category_form,
			'tag_form':tag_form,
			'user_info':user_info,
		},
		context_instance=RequestContext(request))	
Esempio n. 2
0
def get_users(redis_obj, current_user_id):
	''' Returns the users excluding the current user '''
	
	key = "global:users:userId"
	user_ids = redis_obj.members_in_set(key)

	users_list = []
	for i, user_id in enumerate(user_ids):
		
		if int(user_id) != current_user_id:
			
			user_id = int(user_id)
			user_info = {}
			user_info['others_id'] = user_id
			user_info['email'] = get_email(redis_obj, user_id)
			user_info['username'] = get_username(redis_obj, user_id)
			user_info['first_name'] = get_first_name(redis_obj, user_id)
			user_info['last_name'] = get_last_name(redis_obj, user_id)
			user_info['description'] = get_summary(redis_obj,user_id)
			user_info['image_url'] = get_image_url(redis_obj, user_id)
			user_info['timestamp'] = get_timestamp(redis_obj, user_id)
			user_info['follow'] = is_following(redis_obj, current_user_id, user_id)
			user_info['followers'] = get_followers_count(redis_obj, user_id)
			user_info['following'] = get_following_count(redis_obj, user_id)

			users_list.append(user_info)
	
	return users_list
Esempio n. 3
0
def get_following(redis_obj, current_user_id):
	''' Returns the users whom the user is following '''
	
	key = "userId:%d:following" %(current_user_id)
	
	following_ids = redis_obj.members_in_set(key)
	following_list = [{} for i in xrange(len(following_ids))]

	for i, following_id in enumerate(following_ids):

		following_info = {}
		following_id = int(following_id)
		following_info['others_id'] = following_id
		following_info['email'] = get_email(redis_obj, following_id)
		following_info['username'] = get_username(redis_obj, following_id)
		following_info['first_name'] = get_first_name(redis_obj, following_id)
		following_info['last_name'] = get_last_name(redis_obj, following_id)
		following_info['image_url'] = get_image_url(redis_obj, following_id)
		following_info['summary'] = get_summary(redis_obj,following_id)
		following_info['timestamp'] = get_timestamp(redis_obj, following_id)	
		following_info['relationship_status'] = True
		following_info['following_count'] = get_following_count(redis_obj,following_id)
		following_info['followers_count'] = get_followers_count(redis_obj,following_id)

		following_list[i] = following_info

	return following_list
Esempio n. 4
0
def toggle_relationship(request):
	''' Follow/unfollow a user '''

	current_user_id = get_userId(request)
	redis_obj = Redis()
	username = get_username(redis_obj, current_user_id)

	if request.method == "POST":

		if request.is_ajax():
			data = simplejson.loads(request.POST.keys()[0])
		else:
			data = request.POST

		others_id = data.get("others_id", "")
		relationship_request = data.get("relationship_request", "")
	
		if others_id != "" and relationship_request != "":

			if relationship_request == "follow":
				follow_user(redis_obj, current_user_id, int(others_id))
				toggle_status = "unfollow" 
			else:
				unfollow_user(redis_obj, current_user_id, int(others_id))
				toggle_status = "follow"

		data = {}
		try:
			
			data['status'] = 'success'
			data['toggle_status'] = toggle_status
			data['followers'] = get_followers_count(redis_obj,int(others_id))
			data['following'] = get_following_count(redis_obj,int(others_id))
		except:
			pass
		return HttpResponse(simplejson.dumps(data),mimetype='application/json')

	users_list = get_users(redis_obj, current_user_id)
	return render_to_response(USERS_LIST_TEMPLATE_PATH,
		{
			'users_list':users_list,
			'username':username,
		},
		context_instance=RequestContext(request))