Browse Source

Tag unicode bug fix + dht peer count indicator

Don't get your hopes too high. It's not like swizzler now showing
unicode tags [yet]. It's just that it doesn't crash if there are
unicode errors (i.e. some weird pre-unicode codepage).
How does such a thing become a trending hashtag? I wonder :)
master
The Dod 11 years ago
parent
commit
b7231df882
  1. 7
      swizzler.py
  2. 7
      templates/sidebar.html
  3. 2
      twister.py

7
swizzler.py

@ -13,7 +13,7 @@ class TwistParser(ttp.Parser): @@ -13,7 +13,7 @@ class TwistParser(ttp.Parser):
def format_tag(self, tag, text):
'''Return formatted HTML for a hashtag.'''
return '<a href="/tag/{0}">{1}{2}</a>'.format(
ttp.urllib.quote(text.lower().encode('utf-8')), tag, text)
ttp.urllib.quote(text.lower().encode('utf-8'),'xmlcharrefreplace'), tag, text)
def format_username(self, at_char, user):
'''Return formatted HTML for a username.'''
@ -58,6 +58,7 @@ class SwizzlerApp(object): @@ -58,6 +58,7 @@ class SwizzlerApp(object):
'rts':rts,
'any_rts':not not rts,
'local_users':twister.local_user_menu()['users'],
'info':twister.get_info(),
'trending':format_trending(twister,conf['num_messages'])
}
return stache.render(stache.load_template('twist'),result)
@ -72,6 +73,7 @@ class SwizzlerApp(object): @@ -72,6 +73,7 @@ class SwizzlerApp(object):
'subject':user,
'messages':twister.get_user_posts(username,conf['num_messages']),
'local_users':twister.local_user_menu()['users'],
'info':twister.get_info(),
#the filter avoids some utf etc. that ttf can't handle (TODO: fix or replace format_twist)
'trending':format_trending(twister,conf['num_messages'])
}
@ -86,6 +88,7 @@ class SwizzlerApp(object): @@ -86,6 +88,7 @@ class SwizzlerApp(object):
'subject':{"fullname":tag},
'messages':twister.get_tag_posts(tag),
'local_users':twister.local_user_menu()['users'],
'info':twister.get_info(),
#the filter avoids some utf etc. that ttf can't handle (TODO: fix or replace format_twist)
'trending':format_trending(twister,conf['num_messages'])
}
@ -105,6 +108,7 @@ class SwizzlerApp(object): @@ -105,6 +108,7 @@ class SwizzlerApp(object):
'is_feed':mode!='mentions',
'title':u"{0} (@{1}): Home - Swizzler".format(menu['active']['fullname'],menu['active']['username']),
'local_users':menu['users'],
'info':twister.get_info(),
'subject':menu['active'],
'messages':messages,
#the filter avoids some utf etc. that ttf can't handle (TODO: fix or replace format_twist)
@ -119,6 +123,7 @@ class SwizzlerApp(object): @@ -119,6 +123,7 @@ class SwizzlerApp(object):
'is_user':True, # i.e. we want to display "bio" and not mentions/DMs/profile buttons
'title':"Welcome to Swizzler",
'local_users':twister.local_user_menu('')['users'], # '' means: "Nobody" is active
'info':twister.get_info(),
'subject':{ # pseudo-user describing sponsored posts
'fullname':'Sponsored posts',
'bio':format_twist("""

7
templates/sidebar.html

@ -1,5 +1,10 @@ @@ -1,5 +1,10 @@
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title"><span class="glyphicon glyphicon-home"></span> Local users</h3></div>
<div class="panel-heading">
{{#info}}
<div class="pull-right badge">Peers: {{dht_nodes}}/{{dht_global_nodes}}</div>
{{/info}}
<h3 class="panel-title"><span class="glyphicon glyphicon-home"></span> Local users</h3>
</div>
<ul class="panel-body list-group media-list">
{{#local_users}}
<li class="media list-group-item avatars32{{#active}} active{{/active}}">

2
twister.py

@ -129,3 +129,5 @@ class Twister: @@ -129,3 +129,5 @@ class Twister:
@functioncache(60,ignore_instance=True)
def get_trending_tags(self,num=8):
return self.twister.gettrendinghashtags(num)
def get_info(self): # not cached
return self.twister.getinfo()

Loading…
Cancel
Save