Esempio n. 1
0
def partner_book_match(request,username):
	user_login = get_user_login_object(request)
	new_notify = get_new_notify(request)
	partner = get_object_or_404(User,username=username)
	user_login_transaction_book = BookTransaction.objects.filter(seller=user_login)
	partner_transaction_book = BookTransaction.objects.filter(seller=partner)

	books_sell_trade = []
	books_buy = []

	# Get all the book the user_login want to buy and the partner want to sell/trade
	for book_transaction in partner_transaction_book:
		for book_buying in user_login.get_profile().buy_book.all():
			if book_transaction.book == book_buying.book: 
				books_sell_trade.append(book_transaction)

	# Get all the book the user_login want to sell/trade and the partner want to buy
	for book_transaction in user_login_transaction_book:
		for book_buying in partner.get_profile().buy_book.all():
			if book_transaction.book == book_buying.book: 
				books_buy.append(book_transaction) 

	return render_to_response(
							"app/partner/page/partner_match.html",
							{
								'user_login': user_login,
								'new_notify': new_notify,
								'partner': partner,
								"books_buy": remove_duplicate_object(books_buy),
								'books_sell_trade': remove_duplicate_object(books_sell_trade)
							}
							,context_instance=RequestContext(request)
						)
Esempio n. 2
0
def partner_of_partner_match(request,username):
	user_login = get_user_login_object(request)
	new_notify = get_new_notify(request)
	partner = get_object_or_404(User,username=username)

	partner_match_data = []

	partners = user_login.get_profile().partners.all()
	for user1 in partners:
		for user2 in partners:
			if user1 != user2:
				partner_match_data += get_partner_match_value(user1,user2)

	return render_to_response(
							"app/partner/page/partner_of_partner_match.html",
							{
								'user_login': user_login,
								'new_notify': new_notify,
								'partner': partner,
								'partner_match_data': remove_duplicate_object(partner_match_data)
							}
							,context_instance=RequestContext(request)
						)

	
Esempio n. 3
0
def buy_book_search_course_listed(request):
	user_login = get_user_login_object(request)
	new_notify = get_new_notify(request)
	course_number = None
	school = None
	if "course_number" in request.GET:
		course_number = request.GET['course_number']
	if 'school_id' in request.GET:
		school_id = request.GET['school_id']
	books =  get_book_by_course(request,course_number,school_id)
	if len(books) == 0:
		return HttpResponseRedirect("/book/buy/search/not_found")
	else:
		listed_books = []
		for book in books:
			listed = convert_queryset_to_list(BookTransaction.objects.filter(book=book).exclude(seller=user_login))
			listed_books = listed_books + listed
		return render_to_response(
				"app/book/page/buy/buy_book_listed.html",
				{
					'user_login': user_login,
					'new_notify': new_notify,
					'listed_books': remove_duplicate_object(listed_books)
				}
				,context_instance=RequestContext(request))
Esempio n. 4
0
def main_view(request):
	message = handle_request_get_message(request)
	autocomplete_data = get_autocomplete_data(request)
	user_login = get_user_login_object(request)
	new_notify = get_new_notify(request)
	books = []
	people = []
	if request.method == "GET":
		if "q" in request.GET:
			query = request.GET['q']
			if len(query) != 0:
				book_by_isbn = get_book_by_isbn(query)
				book_by_title = get_book_by_title(query)
				book_by_author = get_book_by_author(query)
				books = remove_duplicate_object(book_by_isbn + book_by_title + book_by_author)
				people = get_people_by_name(request,query)
				for person in people:
					person.get_profile().partner_status = check_partnership(request,person.username)
					person.get_profile().save()
	return render_to_response(
			"app/search/page/main_view.html",
			{
				'message': message,
				'autocomplete_data': autocomplete_data,
				'user_login': user_login,
				'books': books,
				'people': people,
				'new_notify': new_notify,
			},
			context_instance=RequestContext(request)
		)
Esempio n. 5
0
def get_book_by_title_and_author(title_query,author_query):
	title_words = title_query.split()
	author_words = author_query.split()
	result = []
	for title_word in title_words:
		for author_word in author_words:
			if title_word.lower() not in IGNORE_WORDS and author_word.lower() not in IGNORE_WORDS:
				books = convert_queryset_to_list(Book.objects.filter(title__icontains=title_word,author__icontains=author_word))
				result = result + books
	return remove_duplicate_object(result)
Esempio n. 6
0
def get_people_by_name(request,query):
	user_login = get_user_login_object(request)
	author_words = query.split()
	result = []
	for word in author_words:
		if word.lower() not in IGNORE_WORDS:
			users1 = convert_queryset_to_list(User.objects.filter(first_name__icontains=word).exclude(pk=1).exclude(pk=user_login.pk))
			users2 = convert_queryset_to_list(User.objects.filter(last_name__icontains=word).exclude(pk=1).exclude(pk=user_login.pk))
			users = users1 + users2
			result = result + users
	return remove_duplicate_object(result)
Esempio n. 7
0
def get_book_by_title(query):
	title_words = query.split()
	books = Book.objects.filter(title=query)
	if len(books) != 0:
		return convert_queryset_to_list(books)
	else:
		result = []
		for title_word in title_words:
			if title_word.lower() not in IGNORE_WORDS:
				books = convert_queryset_to_list(Book.objects.filter(title__icontains=title_word))
				result = result + books
		return remove_duplicate_object(result)
Esempio n. 8
0
def get_book_by_author(query):
	author_words = query.split()
	books = Book.objects.filter(author=query)
	if len(books) != 0:
		return convert_queryset_to_list(books)
	else:
		result = []
		for author_word in author_words:
			if author_word.lower() not in IGNORE_WORDS:
				print author_word
				books = convert_queryset_to_list(Book.objects.filter(author__icontains=author_word))
				result = result + books
		return remove_duplicate_object(result)
Esempio n. 9
0
def get_book_by_course(request,course_number,school_id):
	user_login = get_user_login_object(request)
	courses = Course.objects.filter(course_number__iexact=course_number,institution=Institution.objects.get(id=school_id))
	if len(courses) == 0:
		return []
	else:
		course = courses[0]
		books = convert_queryset_to_list(course.course_book.all())
		result = []
		for book in books:
			b = BookTransaction.objects.filter(seller=user_login,book=book)
			if len(b) == 0:
				result.append(book)
		return remove_duplicate_object(result)
Esempio n. 10
0
def get_book_by_isbn(query):
	if query == None:
		return []
	isbn_str = query.split()[0].replace(" ","")
	books = []
	if len(isbn_str) == 10:
		books = convert_queryset_to_list(Book.objects.filter(isbn10__iexact=isbn_str))
		if len(books) == 0:
			new_book = search_book_online_by_isbn(isbn_str)
			if new_book != None:
				books.append(new_book)
	elif len(isbn_str) == 13:
		books = convert_queryset_to_list(Book.objects.filter(isbn13__iexact=isbn_str))
		if len(books) == 0:
			new_book = search_book_online_by_isbn(isbn_str)
			if new_book != None:
				books.append(new_book)
	return remove_duplicate_object(books)
Esempio n. 11
0
def get_authors(query):
	lst = [word[0].upper() + word[1:] for word in query.split()]
	author_name = " ".join(lst).replace(" ","+")
	author_link = "http://openlibrary.org/query.json?type=/type/author&name=" + author_name
	author_request = urllib2.urlopen(author_link)
	author_data = author_request.read()
	author_json = json.loads(author_data)
	result = []
	if len(author_json) != 0:
		for item in author_json:
			author_id = item['key']
			author_item_link = "http://openlibrary.org" + author_id + ".json"
			print author_item_link
			author_item_request = urllib2.urlopen(author_item_link)
			author_item_data = author_item_request.read()
			author_item_json = json.loads(author_item_data)
			if 'name' in author_item_json:
				author_item_name = author_item_json['name']
				result.append(author_item_name)
	return remove_duplicate_object(result)