Commits

Miki Tebeka committed 03a0364

User urls

Comments (0)

Files changed (3)

             <input type="submit" value="Shorten">
         </form>
 
+        {% if urls %}
+        <b>Your Urls</b>
+        <table class="urls">
+            <tr><th>URL</th><th>Created</th><th>Hits</th></tr>
+            {% for url in urls %}
+            <tr class=" {{ loop.cycle('odd', 'even') }}">
+                <td title="{{ url.long | escape }}">
+                    <a href="{{ url.long }}">{{ url.key().name() }}</a>
+                </td>
+                <td>{{ url.created.strftime("%Y-%m-%d %H:%M") }}</td>
+                <td>{{ url.hits }}</td>
+            </tr>
+            {% endfor %}
+        </table>
+        {% endif %}
+
         <div class="footer">
             G'day {{ user }}, we've shortened {{ count }} urls so far.
         </div>
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run.  If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED").  If you want to manage some indexes
+# manually, move them above the marker line.  The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
+
+- kind: Url
+  properties:
+  - name: user
+  - name: created
+    direction: desc
 
     db.run_in_transaction(txn)
 
+def user_urls(user, max=100):
+    '''Last 100 urls for user.'''
+    return Url.all().filter('user =' , user).order('-created').fetch(max)
+
 def fix_url(url):
     '''Fix url by appending http:// if needed.
 
     def reply(self, **kw):
         '''Fills index template with kw and other variables, send to client.'''
         template = get_template('index.html')
+        user = users.get_current_user()
         env = kw.copy()
         env.update({
             'login' : self.login_html(),
-            'user' : users.get_current_user() or 'stranger',
-            'count' : get_counter().count
+            'user' : user or 'stranger',
+            'count' : get_counter().count,
+            'urls' : user_urls(user) if user else None
         })
         self.response.out.write(template.render(**env))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.