Exemplo n.º 1
0
def searchSaved(handler):
	handler.title('Saved Searches')
	requirePriv(handler, 'User')
	print tabs.where('yours')
	undelay(handler)

	searches = SavedSearch.loadAll(userid = handler.session['user'].id)
	if searches != []:
		print "<table border=0 cellspacing=4>"
		print "<tr><th>Name</th><th>Query</th><th>Shared</th><th>&nbsp;</th></tr>"
		for search in searches:
			print "<form method=\"post\" action=\"/search/saved/%d/update\">" % search.id
			print "<tr>"
			print "<td><input type=\"text\" name=\"name\" value=\"%s\"></td>" % search.name.replace('"', '&quot;')
			print "<td style=\"width: 100%%\"><input type=\"text\" name=\"query\" value=\"%s\" style=\"width: 100%%\"></td>" % search.query.replace('"', '&quot;')
			print "<td style=\"text-align: center\"><input type=\"checkbox\" name=\"share\"%s></td>" % (' checked' if search.public else '')
			print "<td nowrap>"
			print "<button onClick=\"document.location = '/search/saved/%d/run'; return false;\" class=\"fancy\">run</button>" % search.id
			print "<button type=\"submit\" class=\"fancy\" name=\"action\" value=\"update\">update</button>"
			print "<button type=\"submit\" class=\"fancy danger\" name=\"action\" value=\"delete\">delete</button>"
			print "</td>"
			print "</tr>"
			print "</form>"
		print "</table>"

	print "<h3>New Search</h3>"
	newSearchForm()
Exemplo n.º 2
0
def searchSavedMenubox(handler):
	handler.wrappers = False
	handler.log = False
	if not handler.session['user']: return

	yours = [{'name': search.name, 'id': search.id, 'query': search.query} for search in SavedSearch.loadAll(userid = handler.session['user'].id)]
	others = [{'name': search.name, 'id': search.id, 'query': search.query, 'username': search.user.username, 'gravatar': search.user.getAvatar(16)} for search in SavedSearch.loadAll(public = True) if handler.session['user'] in search.followers]
	otherTotal = len(filter(lambda search: search.user != handler.session['user'], SavedSearch.loadAll(public = True)))

	print toJS({'yours': yours, 'others': others, 'otherTotal': otherTotal})
Exemplo n.º 3
0
def searchSavedOthers(handler):
	handler.title('Saved Searches')
	requirePriv(handler, 'User')
	print tabs.where('others')
	undelay(handler)

	print "<style type=\"text/css\">"
	print ".other-search {padding-bottom: 4px; border-bottom: 1px dashed #000;}"
	print ".other-search h2 {margin-bottom: 4px;}"
	print ".other-search small {float: right; font-weight: normal; font-size: 12pt;}"
	print ".other-search code {font-size: 14pt;}"
	print "</style>"

	searches = filter(lambda search: search.user != handler.session['user'] and search.public, SavedSearch.loadAll(orderby = 'name'))
	if searches == []:
		print "No shared searches available"
	else:
		for search in searches:
			print "<div class=\"other-search\">"
			print "<h2>%s<small><img class=\"bumpdown\" src=\"%s\">&nbsp;%s</small></h2>" % (search.safe.name, search.user.getAvatar(16), search.user.username)
			print "<code>%s</code><br><br>" % search.safe.query

			following = handler.session['user'] in search.followers
			print "<form method=\"post\" action=\"/search/saved/%d/%s\">" % (search.id, 'unfollow' if following else 'follow')
			print Button('Run', url = "/search/saved/%d/run" % search.id)
			btn = Button('Unfollow' if following else 'Follow', type = 'submit')
			if following:
				btn.negative()
			else:
				btn.positive()
			print btn
			print "</form>"
			print "</div>"