Commits

Matthew Turk  committed fc0f363

Adding gravatar as well as refining the user page.

  • Participants
  • Parent commits d6a91b6

Comments (0)

Files changed (6)

File ythub/__init__.py

 from flask import Flask, g, session
+from flaskext.gravatar import Gravatar
 from ythub.local_config import secret_key
 import os
 
 app.secret_key = secret_key
 app.config['MAX_CONTENT_LENGTH'] = 1024*1024*1024
 
+gravatar = Gravatar(app,
+                    size=80,
+                    rating='g',
+                    default='MysteryMan',
+                    force_default=False,
+                    force_lower=False)
+
 import ythub.views, ythub.hub_api
 from ythub.models import User
 from ythub.database import db_session

File ythub/templates/index.html

 {% extends "layout.html" %}
 {% block subpage %} Welcome {% endblock %}
 
-{% block toolbar %}
-<div class="navbar navbar-fixed-top">
-  <div class="navbar-inner">
-    <div class="container">
-      <a class="brand" href="#">yt Data Hub</a>
-      <ul class="nav">
-        <li class="active"><a href="http://yt-project.org/">Home</a></li>
-        <li><a href="http://hg.yt-project.org/">yt dev</a></li>
-        <li><a href="http://paste.yt-project.org/">PasteBin</a></li>
-        <li><a href="http://hub.yt-project.org/">Projects</a></li>
-      </ul>
-      {% with username = session['username'] %}
-      {% if username %}
-        <p class="navbar-text pull-right">Logged in as <a href="/user">{{username}}</a> (<a href="/logout">logout</a>)</p>
-      {% else %}
-        <p class="navbar-text pull-right"><a href="/login">Login</a> / 
-                                          <a href="/create_user">Register</a></p>
-      {% endif %}
-      {% endwith %}
-    </div>
-  </div>
-</div>
-{% endblock %}
-
 {% block mainbody %}
       <!-- Main hero unit for a primary marketing message or call to action -->
       <section id="home">
               <div class="span8">
                 <div class="row">
                   <div class="span8">
-                    <h2><a style="text-decoration:none; color:#000000;" href="{{d.project_url}}">{{d.title}}</a></h2>
+                    <h3><a style="text-decoration:none; color:#000000;" href="{{d.project_url}}">{{d.title}}</a></h3>
                   </div>
                   <div class="span8">
                     <p>By <a href="/users/{{u.username}}">{{ u.name }}</a>

File ythub/templates/layout.html

     <div class="navbar navbar-fixed-top">
       <div class="navbar-inner">
         <div class="container">
-          <a class="brand" href="/">yt Hub</a>
+          <a class="brand" href="http://data.yt-project.org/">yt Data Hub</a>
+          <ul class="nav">
+            <li><a href="http://yt-project.org/">yt Home</a></li>
+            <li><a href="http://data.yt-project.org/projects/">Projects</a></li>
+            <li><a href="http://data.yt-project.org/users">Users</a></li>
+          </ul>
           {% with username = session['username'] %}
           {% if username %}
             <p class="navbar-text pull-right">Logged in as <a href="/user">{{username}}</a> (<a href="/logout">logout</a>)</p>

File ythub/templates/user_data.html

 {% extends "layout.html" %}
-{% block subpage %} Data Listing for {{name}} {% endblock %}
-{% block title %} Data Listing for {{name}} {% endblock %}
+{% block subpage %} Data Listing for {{user.name}} {% endblock %}
+{% block title %} Data Listing for {{user.name}} {% endblock %}
 
 {% block mainbody %}
 <section style="padding-top:5.0em;">
   <div class="row">
     <div class="span12">
       <div class="row">
+        <div class="span4">
+          <img style="text-align:center;" src="{{user.email | gravatar(size=200)}}">
+        </div>
+        <div class="span8">
+          <p><h2>{{user.name}}</h2></p>
+          <p><a href="{{ user.url }}"><tt>{{ user.url }}</tt></a></p>
+        </div>
+      </div>
+      <div class="row">
         <div class="span12">
-          <h1>Data Listing for {{name}}</h1>
-          <p>&nbsp;</p>
           <table class="table table-bordered table-striped">
             <thead>
               <tr>
                 <th>Type</th>
-                <th>Descr</th>
-                <th>Short URL</th>
+                <th>Description</th>
                 <th>Context</th>
                 <th>View</th>
               </tr>
             </thead>
             <tbody>
               {% for d in data %}
-              <tr><td>{{ d.obj_type }}</td>
+              <tr><td>{{ d.display_name }}</td>
                   <td>{{ d.descr() }}</td>
                   <td>{{ d.opt() | safe }}</td>
                   <td>{{ d.url() | safe }}</td>

File ythub/templates/users.html

           <table class="table table-bordered table-striped">
             <thead>
               <tr>
+                <th width=80></th>
                 <th>Username</th>
                 <th>Name</th>
                 <th>URL</th>
             </thead>
             <tbody>
               {% for u in users %}
-              <tr><td><a href="/users/{{u.username}}">{{ u.username }}</a></td>
+              <tr><td><a href="/users/{{u.username}}"><img src="{{ u.email | gravatar }}" width=80></a>
+                  <td><a href="/users/{{u.username}}"><tt>{{ u.username }}</tt></a></td>
                   <td>{{ u.name }}</td>
-                  <td>{{ u.url }}</td>
+                  <td><a href="{{ u.url }}"><tt>{{ u.url }}</tt></a></td>
               </tr>
               {% endfor %}
             </tbody>

File ythub/views.py

     projects.sort(key = lambda a: -getattr(a[1], "created", 0))
     return render_template("index.html", data = data, projects = projects)
 
-@app.route("/create_user", methods=["GET", "POST"])
+@app.route("/create_user/", methods=["GET", "POST"])
 def create_user():
     error = None
     if request.method == 'POST':
             flash('Failed to register user. Try another username.')
     return render_template("create_user.html")
 
-@app.route('/login', methods=['GET', 'POST'])
+@app.route('/login/', methods=['GET', 'POST'])
 def login():
     error = None
     if request.method == 'POST':
             flash('Invalid login.')
     return render_template('login.html', error=error)
 
-@app.route('/reset_pw', methods=['POST'])
+@app.route('/reset_pw/', methods=['POST'])
 def pw_recovery():
     email = request.form.get('email')
     user = User.query.filter(User.email == email).first()
     flash("Password reset and sent by email.")
     return redirect("/")
 
-@app.route('/user', methods=['POST'])
+@app.route('/user/', methods=['POST'])
 @login_required
 def update_user(user):
     user.email = request.form.get("email")
     flash("Updated!")
     return redirect("/user")
 
-@app.route('/reset_api_key')
+@app.route('/user/')
+@login_required
+def user_profile(user):
+    return render_template('user.html', user = user)
+
+@app.route('/reset_api_key/')
 @login_required
 def reset_api_key(user):
     user.api_key = uuid.uuid4().hex
     flash("Your API key has been reset")
     return redirect("/user")
 
-@app.route('/user')
-@login_required
-def user_profile(user):
-    return render_template('user.html', user = user)
-
-@app.route("/users")
+@app.route("/users/")
 def user_listing():
     users = User.query.all()
     users.sort(key = lambda u: u.username)
     return render_template('users.html', users = users)
 
-@app.route("/users/<user_name>")
+@app.route("/users/<user_name>/")
 def user_data(user_name):
     show_delete = (session.get(SESSION_USERNAME) == user_name)
     print "SHOW_DELETE", show_delete, session.get(SESSION_USERNAME), user_name
         print ds, getattr(ds, 'created', 0)
         if u.username != user_name: continue
         data.append(ds)
-    return render_template("user_data.html", name = user.name, data = data,
+    return render_template("user_data.html", user = user, data = data,
                            show_delete = show_delete)
 
-@app.route('/logout')
+@app.route('/logout/')
 def logout():
     flash("Logged out.")
     logout_user()
     return redirect('/')
 
-@app.route("/map_server/<map_id>")
+@app.route("/map_server/<map_id>/")
 def mapserver(map_id = None):
     map = obj_query(map_id, "proj") + obj_query(map_id, "slice")
     if len(map) != 1:
     container['map_server_%s' % map_id] = MapTileView(map, map.field)
     return render_template("mapserver.html", map_id = map_id), 200
 
-@app.route("/vertices/<vertices_id>")
+@app.route("/vertices/<vertices_id>/")
 def vertices_display(vertices_id):
     vertices = obj_query(vertices_id, "vertices")
     if len(vertices) != 1:
     print "RETURNING!"
     return rv
 
-@app.route("/image_collection/<collection_hash>")
+@app.route("/image_collection/<collection_hash>/")
 def image_collection(collection_hash = None):
     if collection_hash is None:
         return make_response("IMAGE COLLECTION NOT FOUND", 404)
         return make_response("Project not found!", 404)
     return render_template("project.html", s=project)
 
-@app.route("/projects")
+@app.route("/projects/")
 def projects():
     projects = [(p.user, p) for p in type_query("project")]
-    print projects
     projects.sort(key = lambda a: -getattr(a[1], "created", 0))
     return render_template("projects.html", projects = projects)