예제 #1
0
파일: views.py 프로젝트: qoelet/buzzfire
def search(request):
	auth_status = check_auth(request)
	if auth_status:
		query_string = request.GET.get('q')
		user_id = request.session['buzz_user_id']
		
		conn = get_redis_conn()
		user_dao = UserDao(conn)
		
		user = user_dao.get_user(user_id)
		oauth_token = user.oauth_token

		oauth_token_secret = user.oauth_token_secret
		authorized_token = oauth.Token(oauth_token, oauth_token_secret)
		user_client =oauth.Client(consumer, authorized_token)
		q = urllib.urlencode({"q":query_string})
		search_url = SEARCH_URL+"&"+q
		resp, content = user_client.request(search_url)
		try:
				if resp['status'] != '200':
						error_message = "Invalid response received: %s" % resp['status']
						return HttpResponseRedirect(settings.BUZZFIRE_ERROR)
		except KeyError:
				return HttpResponseRedirect(settings.BUZZFIRE_ERROR)
		return HttpResponse(content, content_type = "application/json")
	else:
		return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #2
0
파일: views.py 프로젝트: qoelet/buzzfire
def add(request):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method == 'POST':
            owner_id = request.session['buzz_user_id']
            tweet_id = request.POST['tweet_id']
            tweet_txt = request.POST['tweet_txt']
            tweeter_screenname = request.POST['tweeter_screenname']
            if request.POST.has_key('latitude'):
                latitude = request.POST['latitude']
            else:
                latitude = None
            if request.POST.has_key('longitude'):
                longitude = request.POST['longitude']
            else:
                longitude =None
            
            bookmark = Bookmark(owner_id, tweet_id, tweet_txt, tweeter_screenname, location=(latitude, longitude))
            id = bookmark_dao.save(bookmark)
            
            if id:
                bookmark = bookmark_dao.get_bookmark(id)
                result = json.dumps([bookmark], default=Bookmark.json_encode)
                return HttpResponse(result, content_type = "application/json")
            else:
                result ='{"status":"error"}'
                return HttpResponse(result)
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #3
0
파일: views.py 프로젝트: qoelet/buzzfire
def get_timeline(request):
	auth_status = check_auth(request)
	
	if auth_status:
		user_id = request.session['buzz_user_id']

		conn = get_redis_conn()
		user_dao = UserDao(conn)

		user = user_dao.get_user(user_id)
		oauth_token = user.oauth_token

		oauth_token_secret = user.oauth_token_secret
		authorized_token = oauth.Token(oauth_token, oauth_token_secret)
		user_client =oauth.Client(consumer, authorized_token)
		resp, content = user_client.request(USER_TIMELINE_URL)
		try:
				if resp['status'] != '200':
						error_message = "Invalid response received: %s" % resp['status']
						return HttpResponseRedirect(settings.BUZZFIRE_ERROR)
		except KeyError:
				return HttpResponseRedirect(settings.BUZZFIRE_ERROR)
				
		return HttpResponse(content, content_type = "application/json")
	else:
		return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #4
0
def homepage(request):
	auth_status = check_auth(request)
	
	if auth_status:
		buzz_auth = True
		buzz_id = request.session['buzz_user_id']
	else:
		buzz_auth = None
		buzz_id = None
		
	return render_to_response('common_pages/homepage.html', {'buzz_auth':buzz_auth, 'buzz_id':buzz_id}, context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: qoelet/buzzfire
def untag_bookmark(request, bookmark_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method == 'POST':
            tag = request.POST['tag']
            bookmark_dao.untag_bookmark(tag, bookmark_id)
            return HttpResponse(tag, content_type = "application/json")
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #6
0
파일: views.py 프로젝트: qoelet/buzzfire
def get_user_who_like_bookmark(request, bookmark_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method =='GET':
             users = bookmark_dao.get_users_who_like_bookmark(bookmark_id)
             result = json.dumps(users)
             return HttpResponse(result, content_type="application/json")
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #7
0
파일: views.py 프로젝트: qoelet/buzzfire
def like_bookmark(request, bookmark_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method == 'POST':
            user_id = request.session['buzz_user_id']
            bookmark_dao.like_bookmark(user_id, bookmark_id)
            return HttpResponse(bookmark_id, content_type="application/json")
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #8
0
파일: views.py 프로젝트: qoelet/buzzfire
def get_bookmark_comment(request, bookmark_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        comment_dao = CommentDao(conn)
        if request.method =='GET':
            comments = comment_dao.get_bookmark_comment(bookmark_id)
            result  = json.dumps(comments, default=Comment.json_encode)
            return HttpResponse(result)
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #9
0
파일: views.py 프로젝트: qoelet/buzzfire
def delete_bookmark(request, bookmark_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method == 'POST':
            status = bookmark_dao.delete(bookmark_id)
            if status:
                  return HttpResponse('{"status":"Success"}', content_type = "application/json")
            else:
                return HttpResponse('{"status":"Error"}', content_type = "application/json")
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #10
0
파일: views.py 프로젝트: qoelet/buzzfire
def delete(request, comment_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        comment_dao = CommentDao(conn)
        if request.method =='POST':
            status = comment_dao.delete(id)
            if status:
                return HttpResponse('{"status":"Success"}')
            else:
                return HttpResponse('{"status":"Error"}')
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #11
0
파일: views.py 프로젝트: qoelet/buzzfire
def get_user_bookmark_rank(request, bookmark_id):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method =='GET':
            user_id =request.session['buzz_user_id']
            rank = bookmark_dao.get_bookmark_user_rank(user_id, bookmark_id)
            
            if rank!=None:
                return HttpResponse(rank, content_type = "application/json")
            else:
                return HttpResponse("{'status':'error'}", content_type="application/json")
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #12
0
파일: views.py 프로젝트: qoelet/buzzfire
def get_user_bookmark(request, user_id):
    oauth_status = check_auth(request)
    if oauth_status:
        
        conn = get_redis_conn()
        bookmark_dao = BookmarkDao(conn)
        if request.method =='GET':
            if request.GET.has_key("offset"):
                offset = request.GET['offset']
            else:
                offset = 0
            if request.GET.has_key("length"):
                length = str(int(request.GET['length'])-1)
            else:
                length ='-1'
            bookmarks = bookmark_dao.get_bookmark_of_user(user_id, offset, length)
            result  = json.dumps(bookmarks, default=Bookmark.json_encode)
            return HttpResponse(result, content_type = "application/json")
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #13
0
파일: views.py 프로젝트: qoelet/buzzfire
def add(request):
    oauth_status = check_auth(request)
    if oauth_status:
        conn = get_redis_conn()
        comment_dao = CommentDao(conn)
        if request.method  == 'POST':
            owner_id = request.POST["owner_id"]
            bookmark_id = request.POST["bookmark_id"]
            text = request.POST["text"]
            comment = Comment(owner_id, bookmark_id, text)
            id = comment_dao.save(comment)
            if id:
                comment = comment_dao.get_comment(id)
                result  = json.dumps(comment, default=Comment.json_encode)
                return HttpResponse(result)
            else:
                result = '{"status":"error"}'
                return HttpResponse(result)
        else:
            return HttpResponse()
    else:
        return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
예제 #14
0
파일: views.py 프로젝트: qoelet/buzzfire
def update_status(request):
	auth_status = check_auth(request)
	if auth_status:
		user_id = request.session['buzz_user_id']

		if request.method == 'POST':
				status = request.POST['status']
		if request.POST.has_key('tweet_id'):
			tweet_id = request.POST['tweet_id']
		else:
			tweet_id =None
					
			conn = get_redis_conn()
			user_dao = UserDao(conn)
	
			user = user_dao.get_user(user_id)
			oauth_token = user.oauth_token
			
			oauth_token_secret = user.oauth_token_secret
			authorized_token = oauth.Token(oauth_token, oauth_token_secret)
			user_client =oauth.Client(consumer, authorized_token)
		if tweet_id:
			q = urllib.urlencode({"status":status, "in_reply_to_status_id":tweet_id})
		else:
			q =urllib.urlencode({"status":status})
		
		resp, content = user_client.request(STATUS_UPDATE_URL, method="POST", body=q)	 
		try:
			if resp['status'] != '200':
				error_message = "Invalid response received: %s" % resp['status']
			else:
				return HttpResponse()
		except KeyError:
				raise Exception('Did not get a proper response')
				return HttpResponse('{"status":"Success"}')
	else:
			return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)