コード例 #1
0
ファイル: views.py プロジェクト: n8carrier/sharingcommons
def item_due_reminders():
	count = 0
	"""find all the items due tomorrow and send reminder emails"""
	items = ItemCopy.query(ItemCopy.due_date==date.today() + timedelta(days=1)).fetch()
	for item in items:
		count += 1
		owner = UserAccount.query(UserAccount.key==item.owner).get()
		mail.send_mail(sender=owner.email,
			to=UserAccount.query(UserAccount.key==item.borrower).get().email,
			subject="Item Due Soon",
			body="""The following item is due to be returned tomorrow: '%s'.
			
Please return it to %s"""%(Item.query(Item.key==item.item).get().title,owner.name))
	return "%s reminders were sent out" %count
コード例 #2
0
ファイル: views.py プロジェクト: byu-osl/bookout
def book_due_reminders():
	count = 0
	"""find all the books due tomorrow and send reminder emails"""
	books = BookCopy.query(BookCopy.due_date==date.today() + timedelta(days=1)).fetch()
	for book in books:
		count += 1
		owner = UserAccount.query(UserAccount.key==book.owner).get()
		mail.send_mail(sender=owner.email,
			to=UserAccount.query(UserAccount.key==book.borrower).get().email,
			subject="Book Due Soon",
			body="""Hey, remember that book you borrowed on Bookout from me, '%s'? Please get it back to me by tomorrow.
			
Thanks!
%s"""%(Book.query(Book.key==book.book).get().title,owner.name))
	return "%s reminders were sent out" %count
コード例 #3
0
ファイル: views.py プロジェクト: n8carrier/sharingcommons
def profile(userID):
	try:
		int(userID)
		profile_user = UserAccount.get_by_id(int(userID))
		# Check if profile user has a custom url and forward if so
		if profile_user.custom_url:
			try:
				long(profile_user.custom_url) # Custom URLs MUST include at least one letter, so this will always fail with a custom URL
			except:
				return redirect('/user/' + profile_user.custom_url)
			
	except:
		# Query custom URLs
		custom_url_user = UserAccount.query(UserAccount.custom_url==userID).get()
		if custom_url_user:
			profile_user = custom_url_user
		else:
			return redirect(url_for("invalid_profile"))
	
	user = current_user()
	if user.is_authenticated():
		inNetwork = user.is_connected(profile_user)
	else:
		inNetwork = False
	if inNetwork or profile_user.profile_privacy == 1:
		if user == profile_user:
			inNetwork = True
		booklist = []
		for copy in profile_user.get_library():
			item = Item.query(Item.key == copy.item).get().to_dict()
			if item["item_type"] == "book":
				item["item_subtype"] = copy.item_subtype
				item["star_rating"] = copy.star_rating
				item["escapedtitle"] = re.escape(item["title"])
				if copy.borrower is None:
					item["available"] = True
				else:
					item["available"] = False
				item["copyID"] = copy.key.id()
				booklist.append(item)
			
		# Sort library alphabetically, with title as the primary sort key,
		# author as secondary, and item_subtype as tertiary
		booklist.sort(key=lambda item: item["item_subtype"])
		booklist.sort(key=lambda item: item["title"].lower())

		movielist = []
		for copy in profile_user.get_library():
			item = Item.query(Item.key == copy.item).get().to_dict()
			if item["item_type"] == "movie":
				item["item_subtype"] = copy.item_subtype
				item["star_rating"] = copy.star_rating
				item["escapedtitle"] = re.escape(item["title"])
				if copy.borrower is None:
					item["available"] = True
				else:
					item["available"] = False
				item["copyID"] = copy.key.id()
				movielist.append(item)
			
		# Sort library alphabetically, with title as the primary sort key,
		# author as secondary, and item_subtype as tertiary
		movielist.sort(key=lambda item: item["item_subtype"])
		movielist.sort(key=lambda item: item["title"].lower())
		import hashlib
		import urllib
		gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(profile_user.email).hexdigest() + "?s=150&d=" + urllib.quote(request.host_url,'') + "static%2Fimg%2Fnoimage.png"
		return render_response('profile.html',inNetwork=inNetwork,profile_user=profile_user,booklist=booklist,movielist=movielist,gravatar_url=gravatar_url)
	return redirect(url_for("invalid_profile"))
コード例 #4
0
ファイル: views.py プロジェクト: n8carrier/sharingcommons
def search():
	itemlist = {}
	item_type = request.args.get('item_type')
	subtype_book = request.args.get('subtype_book')
	subtype_ebook = request.args.get('subtype_ebook')
	subtype_audiobook = request.args.get('subtype_audiobook')
	subtype_dvd = request.args.get('subtype_dvd')
	subtype_bluray = request.args.get('subtype_bluray')
	user_email = request.args.get('user_email')
	searchterm = request.args.get('query')
	attr = request.args.get('refineSearch')
	src = request.args.get('src')
	
	# If searching for a user, redirect to profile
	if user_email:
		profile_user = UserAccount.query(UserAccount.email==searchterm).get()
		if not profile_user:
			return redirect(url_for("invalid_profile"))
		else:
			if profile_user.custom_url:
				return redirect('/user/' + profile_user.custom_url)
			else:
				return redirect('/user/' + str(profile_user.get_id()))
	
	subtype_specified = "true" # Used in javascript to determine whether out-of-network cookie should be respected or not
	
	if item_type is None and subtype_book is None and subtype_ebook is None and subtype_audiobook is None and subtype_dvd is None and subtype_bluray is None:
		#Nothing was specified, so act as if they searched books
		item_type = "book"
	
	if subtype_book or subtype_ebook or subtype_audiobook or subtype_dvd or subtype_bluray:
		# If subtype is included, item_type may not be, so it must be added
		if subtype_book or subtype_ebook or subtype_audiobook:
			item_type = "book"
		if subtype_dvd or subtype_bluray:
			item_type = "movie"
	else:
		# None are included, so only item_type is being pass; set all subtypes to true
		if item_type == "book":
			subtype_specified = "false"
			subtype_book = "true"
			subtype_ebook = "true"
			subtype_audiobook = "true"
		elif item_type == "movie":
			subtype_specified = "false"
			subtype_dvd = "true"
			subtype_bluray = "true"
			
	if attr == "all":
		attr = None
	
	if searchterm is None:
		searchterm = ""
	else:
		searchterm = searchterm.lstrip()
		
	if searchterm is None or searchterm == "":
		pass
	else:
		cur_user = current_user()
		logging.info(cur_user)
		if not cur_user.is_authenticated():
			#Assume no books in library or network, return results only
			itemlist = Item.search_by_attribute(item_type,searchterm,attr)
			for item in itemlist:
				item["inLibrary"] = []
				item["inNetwork"] = []
		
		else:
			user = current_user()
			
			#Create a dictionary of the user's items
			librarylist = {}
			for copy in user.get_library():
				copyItemKey = Item.query(Item.key == copy.item).get().item_key
				copyItemSubtype = copy.item_subtype
				librarylist[(copyItemKey,copyItemSubtype)] = copy.to_dict()
				
			#Create a dictionary of the items in the user's network
			#The dict, networkitemlist, includes each ItemCopy object, with it's associated item_key.
			networkitemlist = {}
			for connection in user.get_connections():
				u = UserAccount.getuser(connection.id())
				for copy in u.get_library():
					copyItemKey = Item.query(Item.key == copy.item).get().item_key
					copyItemSubtype = copy.item_subtype
					networkitemlist[(copyItemKey,copyItemSubtype)] = copy.to_dict()

			itemlist = Item.search_by_attribute(item_type,searchterm,attr)
			for item in itemlist:
				item["escapedtitle"] = re.escape(item["title"])
				
				# Check for copies in library and in network, 
				# return "inLibrary" list with all item types in Library
				# return "inNetwork" list with all item types in Library
				item["inLibrary"] = []
				item["inNetwork"] = []
				for item_subtype in ['book', 'ebook', 'audiobook', 'dvd', 'bluray']:
					if (item["item_key"],item_subtype) in librarylist:
						item["inLibrary"].append(item_subtype)
					if (item["item_key"],item_subtype) in networkitemlist:
						item["inNetwork"].append(item_subtype)
				
	return render_response('search.html', itemlist=itemlist, search=searchterm, attribute=attr, include_type=item_type, subtype_book=subtype_book, subtype_ebook=subtype_ebook, subtype_audiobook=subtype_audiobook, subtype_specified=subtype_specified, src=src)