From ec238a01502e67997e9c43d911288815b5736b1f Mon Sep 17 00:00:00 2001 From: The Dod Date: Mon, 7 Apr 2014 21:10:43 +0700 Subject: [PATCH] Tag search no longer goes to iframe :) Forms and iframes go together like a horse and marriage --- swizzler.py | 21 +++---- templates/sidebar.html | 23 +++++--- templates/standard.html | 120 ++++++++++++++++++++++------------------ 3 files changed, 91 insertions(+), 73 deletions(-) diff --git a/swizzler.py b/swizzler.py index 3e19f61..9bcd0b5 100644 --- a/swizzler.py +++ b/swizzler.py @@ -46,18 +46,15 @@ def format_trending(twister,num_messages=8): ### The Swizzler app class SwizzlerApp(object): @cherrypy.expose - def search(self,q=''): + def search_embed(self,userprefix=''): conf = cherrypy.request.app.config['swizzler'] twister = Twister(conf['rpc_url'],format_twist) result = {'site_root':cherrypy.request.base+cherrypy.request.script_name} - q = q.strip().split(' ')[0] # ignore anything after the first space if any - if q.startswith('#'): # user said "#sometag", change to "sometag" - q=q[1:] - if q and not q.startswith('@'): # Tag. redirect. - raise cherrypy.HTTPRedirect(result['site_root']+'/tag/{0}'.format(q)) - if q: - result['user_prefix'] = q - result['users'] = twister.get_users_by_partial_name(q[1:],conf['num_messages']) + userprefix = userprefix.strip().split(' ')[0] + if not userprefix.startswith('@'): userprefix = '@'+userprefix + if len(userprefix)>1: + result['user_prefix'] = userprefix + result['users'] = twister.get_users_by_partial_name(userprefix[1:],conf['num_messages']) else: result['trending'] = format_trending(twister,conf['num_messages']) return stache.render(stache.load_template('search'),result) @@ -112,7 +109,11 @@ class SwizzlerApp(object): result['style_{0}'.format(style)] = True return stache.render(stache.load_template('user-iframe'),result) @cherrypy.expose - def tag(self,tag): + def tag(self,tag=''): + tag = tag.strip().split(' ')[0] + if tag.startswith('#'): tag = tag[1:] + if not tag: + raise cherrypy.HTTPRedirect('/') # go home to sponsored posts conf = cherrypy.request.app.config['swizzler'] twister = Twister(conf['rpc_url'],format_twist) messages = twister.get_tag_posts(tag) diff --git a/templates/sidebar.html b/templates/sidebar.html index 5f7860d..8603ee3 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -33,18 +33,25 @@ -
-
- -
-
+ + + src="{{site_root}}/search_embed"> diff --git a/templates/standard.html b/templates/standard.html index 3fc9efd..2e71cf9 100644 --- a/templates/standard.html +++ b/templates/standard.html @@ -15,62 +15,72 @@
- + {{/is_home}} + {{^is_home}} + + {{/is_home}} +
{{#any_messages}}
    {{#messages}}{{> message}}{{/messages}}
{{/any_messages}}