Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing perm link

  • Loading branch information...
commit d51a3e71413f8414b01e75dce2d4b042563e86dd 1 parent 876d6a6
@peterbe authored
View
39 handlers.py
@@ -375,6 +375,14 @@ def get(self):
@route('/following/(\w+)', name='following')
class FollowingHandler(BaseHandler, tornado.auth.TwitterMixin):
+ def get_following_perm_url(self, username, compared_to):
+ base_url = self.request.host
+ perm_url = self.reverse_url('following_compared',
+ username,
+ compared_to)
+ return 'http://%s%s' % (base_url, perm_url)
+
+
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, username):
@@ -468,6 +476,8 @@ def _render(self, options):
self._set_ratio(options, 'username')
self._set_ratio(options, 'this_username')
options['page_title'] = page_title % options['username']
+ options['perm_url'] = self.get_following_perm_url(
+ options['username'], options['this_username'])
self.render('following.html', **options)
else:
options['page_title'] = 'Error :('
@@ -502,10 +512,14 @@ class SuggestTweetHandler(BaseHandler):
def get(self):
username = self.get_argument('username')
- current_user = self.get_current_user()
- if not current_user:
- raise HTTPError(403, "Not logged in")
- compared_to = current_user['username']
+
+ if self.get_argument('compared_to', None):
+ compared_to = self.get_argument('compared_to')
+ else:
+ current_user = self.get_current_user()
+ if not current_user:
+ raise HTTPError(403, "Not logged in")
+ compared_to = current_user['username']
tweeter = self.db.Tweeter.find_one({'username': username})
if not tweeter:
@@ -514,6 +528,11 @@ def get(self):
if not tweeter:
raise HTTPError(400, "Unknown tweeter %r" % compared_to)
+ if self.get_current_user() and self.get_current_user()['username'] == compared_to:
+ different_user = False
+ else:
+ different_user = True
+
def make_message(include_hashtag=False, include_fullname=False):
if include_fullname:
name = '@%s (%s)' % (username, fullname)
@@ -522,13 +541,16 @@ def make_message(include_hashtag=False, include_fullname=False):
tweet = "Apparently "
if abs(a - b) < 1.0:
tweet += "%s is " % name
- tweet += "as cool as me"
+ tweet += "as cool as %s" % (compared_to if different_user else 'me')
elif b > a:
- tweet += "I am "
+ tweet += "%s am " % (compared_to if different_user else 'I')
tweet += "%s times cooler than %s" % (get_times(a, b), name)
elif a > b:
tweet += "%s is " % name
- tweet += "%s times cooler than me" % get_times(a, b)
+ tweet += "%s times cooler than %s" % (
+ get_times(a, b),
+ compared_to if different_user else 'me'
+ )
hashtag = "#toocool"
if include_hashtag:
@@ -642,6 +664,9 @@ def get(self, username, compared_to):
self._set_ratio(options, 'username')
self._set_ratio(options, 'this_username')
options['compared_to'] = compared_to
+ options['perm_url'] = self.get_following_perm_url(
+ options['username'], options['this_username'])
+
self.render('following.html', **options)
View
BIN  static/images/link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
50 templates/following.html
@@ -9,11 +9,31 @@
td.label { border-right:1px solid #999; }
th.label { border-bottom:1px solid #999; }
.footnut { font-size:0.8em; }
+#perm-link {
+ font-size:0.8em;
+ background-position:0 50%;
+ padding-left:18px;
+ background-image: url({{ static_url('images/link.png') }});
+ background-repeat: no-repeat;
+}
+#perm-link input {
+ width:300px;
+}
</style>
{% end %}
+{% block extra_header %}
+{% if compared_to is None %}
+<p id="perm-link"><a href="{{ perm_url }}">permanent link</a>
+<input type="url" name="_perm" value="{{ perm_url }}" size="30" style="display:none">
+</p>
+{% end %}
+{% end %}
+
+
{% block content %}
+
<p style="font-size:2em">
<a href="https://twitter.com/#!{{ username }}"
><img src="http://api.twitter.com/1/users/profile_image/{{ username }}.png?size=bigger"></a>
@@ -34,10 +54,14 @@
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
+var USERNAME = '{{ username }}';
+var COMPARED_TO = {% if compared_to %}'{{ compared_to }}'{% else %}null{% end %};
+
google.load("visualization", "1", {packages:["corechart"]});
google.load("jquery", "1.6.4");
google.setOnLoadCallback(function() {
drawChart();
+ addPermHover();
addTweetButton();
});
function drawChart() {
@@ -46,10 +70,10 @@
data.addColumn('number', 'followers');
data.addColumn('number', 'following');
data.addRows(2);
- data.setValue(0, 0, '{{ username }}');
+ data.setValue(0, 0, USERNAME);
data.setValue(0, 1, {{ info[username]['followers_count'] }});
data.setValue(0, 2, {{ info[username]['friends_count'] }});
- data.setValue(1, 0, {% if compared_to %}'{{ compared_to }}'{% else %}'you'{% end %});
+ data.setValue(1, 0, COMPARED_TO ? COMPARED_TO : 'you');
data.setValue(1, 1, {{ info[this_username]['followers_count'] }});
data.setValue(1, 2, {{ info[this_username]['friends_count'] }});
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
@@ -60,9 +84,26 @@
});
}
- function addTweetButton() {
+ function addPermHover() {
+ if ($('#perm-link').size()) {
+ $('#perm-link a').bind('mouseover', function() {
+ $('#perm-link input:hidden').show();
+ }).bind('mouseout', function() {
+ setTimeout(function() {
+ $('#perm-link input:visible').hide();
+ }, 10*1000);
+ $('#perm-link input').bind('focus', function() {
+ this.select();
+ $(this).unbind('focus');
+ });
+ });
+ }
+ }
- $.getJSON('/following/suggest_tweet.json', {username: '{{ username }}'}, function(response) {
+ function addTweetButton() {
+ var data = {username: USERNAME};
+ if (COMPARED_TO) data.compared_to = COMPARED_TO;
+ $.getJSON('/following/suggest_tweet.json', data, function(response) {
$('<a href="https://twitter.com/share" class="twitter-share-button">')
.attr('data-url', response.url)
.attr('data-text', response.text)
@@ -70,6 +111,7 @@
.text('Tweet')
.appendTo($('<div>').prependTo('#content'));
$('#content').prepend($('<script>').attr('src', '//platform.twitter.com/widgets.js'));
+
});
}
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.