Browse Source

Tag search no longer goes to iframe :)

Forms and iframes go together like a horse and marriage
master
The Dod 11 years ago
parent
commit
ec238a0150
  1. 21
      swizzler.py
  2. 21
      templates/sidebar.html
  3. 30
      templates/standard.html

21
swizzler.py

@ -46,18 +46,15 @@ def format_trending(twister,num_messages=8): @@ -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): @@ -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)

21
templates/sidebar.html

@ -33,18 +33,25 @@ @@ -33,18 +33,25 @@
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<form target="searchresult" tag="searchresult" method=get action="{{site_root}}/search" class="inline-form" role="search">
<form method=get action="{{site_root}}/tag" class="form-horizontal" role="search">
<div class="form-group">
<label for="#search"><span class="glyphicon glyphicon-search"></span> Search for tag or partial username</label>
<input id="q" name="q" type="text" class="form-control" placeholder="#twister or @twi"{{#user_prefix}} value="{{.}}"{{/user_prefix}}>
<label class="col-xs-4 text-right" for="#tag">Tag <span class="glyphicon glyphicon-tag"></span></label>
<div class="col-xs-8">
<input id="tag" name="tag" type="text" class="form-control input-sm" placeholder="#twister"{{#user_prefix}} value="{{.}}"{{/user_prefix}}>
</div>
</div>
</form>
<form target="searchresult" tag="searchresult" method=get action="{{site_root}}/search_embed" class="form-horizontal" role="search">
<div class="form-group">
<label class="col-xs-4 text-right" for="#userprefix">Usernam... <span class="glyphicon glyphicon-user"></span></label>
<div class="col-xs-8">
<input id="userprefix" name="userprefix" type="text" class="form-control input-sm" placeholder="@twi"{{#user_prefix}} value="{{.}}"{{/user_prefix}}>
</div>
</div>
</div>
</form>
<iframe name="searchresult" class="thumbnail media-object {{#fromMe}}pull-right{{/fromMe}}{{^fromMe}}pull-left{{/fromMe}}"
style="width:100%; border:none; padding:0; background:none; overflow:hidden"
width=100 height=2645 seamless=seamless
src="{{site_root}}/search"></iframe>
src="{{site_root}}/search_embed"></iframe>
</div>

30
templates/standard.html

@ -15,16 +15,11 @@ @@ -15,16 +15,11 @@
<div class="row">
<div id="main" class="col-md-8">
<div class="row">
<div id="header" class="col-md-12 well">
{{#subject}}
<div class="media">
<a class="pull-left thumbnail" href="{{#username}}/user/{{.}}{{/username}}{{^username}}#{{/username}}">
<img class="media-object avatar" src="{{#avatar}}{{.}}{{/avatar}}{{^avatar}}/assets/img/twister-64.jpg{{/avatar}}" alt="{{fullname}}">
</a>
<div class="media-body">
{{#is_home}}
<div class="panel panel-primary">
<div class="panel-heading">
{{#username}}
<h3 class="media-heading">
<h3 class="panel-title">
{{#is_feed}}
<a class="label label-primary" href="{{site_root}}/home/{{username}}" title="@{{username}}'s home"><span class="glyphicon glyphicon-home"></span>
{{fullname}}'s home</a>
@ -38,6 +33,11 @@ @@ -38,6 +33,11 @@
{{fullname}}</a>
{{/is_messages}}
</h3>
{{/username}}
{{^username}}
{{/username}}
</div>
<div class="panel-body">
<h4>
{{^is_feed}}
<a class="label label-primary" href="{{site_root}}/home/{{username}}" title="@{{username}}'s home"><span class="glyphicon glyphicon-home"></span>Home</a>
@ -50,8 +50,17 @@ @@ -50,8 +50,17 @@
{{/is_messages}}
<a class="label label-info" href="{{site_root}}{{#username}}/user/{{.}}{{/username}}" title="@{{username}}'s profile"><span class="glyphicon glyphicon-user"></span>Profile</a>
</h4>
{{/username}}
</div>
</div>
{{/is_home}}
{{^is_home}}
<div id="header" class="col-md-12 well">
{{#subject}}
<div class="media">
<a class="pull-left thumbnail" href="{{#username}}/user/{{.}}{{/username}}{{^username}}#{{/username}}">
<img class="media-object avatar" src="{{#avatar}}{{.}}{{/avatar}}{{^avatar}}/assets/img/twister-64.jpg{{/avatar}}" alt="{{fullname}}">
</a>
<div class="media-body">
{{#is_user}}
<h4 class="media-heading">
{{#location}}<span class="pull-right small">{{.}}</span>{{/location}}
@ -70,7 +79,8 @@ @@ -70,7 +79,8 @@
</div>
{{/subject}}
</div>
</div>
{{/is_home}}
</div><!-- /.row -->
<div class="row">
<div id="messages" class="col-md-12">
{{#any_messages}}<ul class="list-group media-list">{{#messages}}{{> message}}{{/messages}}</ul>{{/any_messages}}

Loading…
Cancel
Save