From 9e04f5d80bc5f7be95920727e4e5646c4ae99cfd Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Fri, 4 Mar 2011 15:01:22 -0800
Subject: [PATCH] make it easy to contact election creators (when admin only,
 of course)

---
 auth/auth_systems/google.py           |  2 +-
 auth/auth_systems/twitter.py          |  3 +++
 auth/auth_systems/yahoo.py            |  2 +-
 auth/models.py                        | 17 ++++++++++++++++-
 helios/templates/stats_elections.html |  2 +-
 helios/views.py                       |  2 +-
 6 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/auth/auth_systems/google.py b/auth/auth_systems/google.py
index 02953a3..0666498 100644
--- a/auth/auth_systems/google.py
+++ b/auth/auth_systems/google.py
@@ -40,7 +40,7 @@ def get_user_info_after_auth(request):
   else:
     name = email
 
-  return {'type' : 'google', 'user_id': email, 'name': name , 'info': {}, 'token':{}}
+  return {'type' : 'google', 'user_id': email, 'name': name , 'info': {'email': email}, 'token':{}}
     
 def do_logout(user):
   """
diff --git a/auth/auth_systems/twitter.py b/auth/auth_systems/twitter.py
index 56ea1ab..a0ae9a0 100644
--- a/auth/auth_systems/twitter.py
+++ b/auth/auth_systems/twitter.py
@@ -86,6 +86,9 @@ def update_status(user_id, user_info, token, message):
 def send_message(user_id, user_name, user_info, subject, body):
   pass
 
+def public_url(user_id):
+  return "http://twitter.com/%s" % user_id
+
 def send_notification(user_id, user_info, message):
   twitter_client = _get_client_by_token(DM_TOKEN)
   result = twitter_client.oauth_request('http://api.twitter.com/1/direct_messages/new.json', args={'screen_name': user_id, 'text': message}, method='POST')
diff --git a/auth/auth_systems/yahoo.py b/auth/auth_systems/yahoo.py
index 48dd246..dc29ab7 100644
--- a/auth/auth_systems/yahoo.py
+++ b/auth/auth_systems/yahoo.py
@@ -27,7 +27,7 @@ def get_auth_url(request, redirect_url):
 def get_user_info_after_auth(request):
   data = view_helpers.finish_openid(request.session, request.GET, request.session['yahoo_redirect_url'])
 
-  return {'type' : 'yahoo', 'user_id': data['ax']['email'][0], 'name': data['ax']['fullname'][0], 'info': {}, 'token':{}}
+  return {'type' : 'yahoo', 'user_id': data['ax']['email'][0], 'name': data['ax']['fullname'][0], 'info': {'email': data['ax']['email'][0]}, 'token':{}}
     
 def do_logout(user):
   """
diff --git a/auth/models.py b/auth/models.py
index 5b39a03..b09e873 100644
--- a/auth/models.py
+++ b/auth/models.py
@@ -134,9 +134,24 @@ class User(models.Model):
 
     return self.user_id
   
+  @property
+  def public_url(self):
+    if AUTH_SYSTEMS.has_key(self.user_type):
+      if hasattr(AUTH_SYSTEMS[self.user_type], 'public_url'):
+        return AUTH_SYSTEMS[self.user_type].public_url(self.user_id)
+
+    return None
+    
   def _display_html(self, size):
+    public_url = self.public_url
+    
+    if public_url:
+      name_display = '<a href="%s">%s</a>' % (public_url, self.pretty_name)
+    else:
+      name_display = self.pretty_name
+
     return """<img border="0" height="%s" src="/static/auth/login-icons/%s.png" alt="%s" /> %s""" % (
-      str(int(size)), self.user_type, self.user_type, self.pretty_name)
+      str(int(size)), self.user_type, self.user_type, name_display)
 
   @property
   def display_html_small(self):
diff --git a/helios/templates/stats_elections.html b/helios/templates/stats_elections.html
index 55a5252..7fe4133 100644
--- a/helios/templates/stats_elections.html
+++ b/helios/templates/stats_elections.html
@@ -18,7 +18,7 @@ Elections {{elections_page.start_index}} - {{elections_page.end_index}}&nbsp;&nb
 
 {% for election in elections %}
 <p>
-<b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> -- {{election.num_voters}} voters / {{election.num_cast_votes}} cast votes
+<b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> by <a href="mailto:{{election.admin.info.email}}">{{election.admin.pretty_name}}</a> -- {{election.num_voters}} voters / {{election.num_cast_votes}} cast votes
 </p>
 {% endfor %}
 
diff --git a/helios/views.py b/helios/views.py
index 286e7c8..38d533a 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -100,7 +100,7 @@ def get_voter(request, user, election):
 ## simple admin for development
 ##
 def admin_autologin(request):
-  if "localhost" not in settings.URL_HOST:
+  if "localhost" not in settings.URL_HOST and "127.0.0.1" not in settings.URL_HOST:
     raise Http404
   
   users = User.objects.filter(admin_p=True)
-- 
GitLab