Commits

Dan Chudnov  committed 80e0239

Tag landing page

  • Participants
  • Parent commits 1b8970c

Comments (0)

Files changed (7)

 
 X 404/500
 
+X Tag landing page
+
   Entry form
 
   Bookmarklets 

File base/models.py

         else:
             # NOTE: postgresql-specific value
             private_clause = 'AND base_entry.is_private is false'
-        user_clause = 'AND base_entry.user_id=%s' % user.id
+            
+        if user:
+            user_clause = 'AND base_entry.user_id=%s' % user.id
+        else: 
+            user_clause = ''
         order_clause = 'ORDER BY COUNT(tag_id) DESC, name'
 
         if order == 'alpha':
             order_clause = 'ORDER BY name, COUNT(tag_id)'
+        elif order == 'recent':
+            order_clause = 'ORDER BY tag_id DESC, name'
         sql = """
-            SELECT COUNT(tag_id), name 
-            FROM base_entry_tags, base_entry, base_tag 
+            SELECT COUNT(tag_id), name, tag_id
+            FROM base_entry_tags, base_entry, base_tag, auth_user
             WHERE base_entry.id=base_entry_tags.entry_id 
+            AND base_tag.id=base_entry_tags.tag_id 
+            AND auth_user.id=base_entry.user_id
+            AND auth_user.is_active is true
             %s
-            AND base_tag.id=base_entry_tags.tag_id 
             %s
             GROUP BY tag_id, name 
             %s

File base/templates/500.html

 <h2>Whoops!</h2>
 
 <p>
-Sorry, something went wrong.  Try again, or something else!
+Sorry, something went wrong.  Try again, or try something else!
 </p>
 
 {% endblock %}

File base/templates/base.html

                     <td>
             <ul>
         		<li id='active'><a href='/'>Home</a></li>
-                <li><a href='/user'>People</a></li>
-                <li><a href='/tag'>Tags</a></li>
-                <li><a href='/group'>Groups</a></li>
+                <li><a href='/tags/'>Tags</a></li>
                 <li><a href='/about'>About</a></li>
                 <li><a href='/about/contact'>Contact</a></li>
                 <li><a href='http://onebiglibrary.net/taxonomy/term/1'>News</a></li>

File base/templates/tags.html

 {% extends "base.html" %}
 
 {% block content %}
+{% if browse_user %}
 <h2><a href='/user/{{ browse_user.username }}/'>{{ browse_user.username }}</a>'s tags</h2>
+{% else %}
+<h2>Tags for all users</h2>
+{% endif %}
 
 {% if page.object_list %}
+<table id='tag_set' width='100%'>
+	<tbody>
+		<tr>
+			<td width='50%'>
+				<h3>Sorted by count</h3>
 <table id='tags' class='gentable' cellspacing='1'>
 	<tbody>
 	{% for count, name in page.object_list %}
 		<tr>
 			<th valign='top'>{{ count }}</th>
+			{% if browse_user %}
 			<td class='coll1' valign='top'><a rel='tag' href='/user/{{ browse_user.username }}/tag/{{ name }}/'>{{ name }}</a></td>
+			{% else %}
+			<td class='coll1' valign='top'><a rel='tag' href='/tag/{{ name }}/'>{{ name }}</a></td>			
+			{% endif %}
 		</tr>
 	{% endfor %}
 	</tbody>
 </table>
+			</td>
+			
+			<td width='50%'>
+				<h3>Sorted by tag</h3>
+<table id='tags_alpha' class='gentable' cellspacing='1'>
+	<tbody>
+	{% for count, name in alpha_page.object_list %}
+		<tr>
+			<th valign='top'>{{ count }}</th>
+			<td class='coll1' valign='top'><a rel='tag' href='/tag/{{ name }}/'>{{ name }}</a></td>
+		</tr>
+	{% endfor %}
+	</tbody>
+</table>
+			</td>
+			
+			
+		</tr>
 
-<ul id='pagination'>
-    {% if page.has_previous %}
-    <li><a href='{{ request.path }}?p={{ page.previous_page_number }}'>Used more</a></li>
-    {% endif %}
+		<tr>
+			<td colspan='4'>
+				<ul id='pagination'>
+				    {% if page.has_previous %}
+				    <li><a href='{{ request.path }}?p={{ page.previous_page_number }}'>Previous</a></li>
+				    {% endif %}
 
-	{% if page.has_next %}
-    <li><a href='{{ request.path }}?p={{ page.next_page_number }}'>Used less</a></li>
-	{% endif %}
-</ul>
+					{% if page.has_next %}
+				    <li><a href='{{ request.path }}?p={{ page.next_page_number }}'>Next</a></li>
+					{% endif %}
+				</ul>
+			</td>
+		</tr>
+
+	</tbody>
+</table>
+
+
 
 
 {% endif %}

File base/views.py

         'feed_url': '/tag/%s/feed/' % tag_name,
         }, context)
 
+def tags_all(request):
+    """
+    Summary page for overall tag usage.
+    """
+    context = RequestContext(request)
+    qs_count = m.Tag.count()
+    count_paginator, count_page = pagify(request, qs_count)
+    qs_alpha = m.Tag.count(order='alpha')
+    alpha_paginator, alpha_page = pagify(request, qs_alpha)
+    return render_to_response('tags.html', {
+        'view_hidden': False,
+        'title': 'all tags',
+        'paginator': count_paginator, 'page': count_page,
+        'alpha_paginator': alpha_paginator, 'alpha_page': alpha_page,
+        }, context)
+
         
 def person(request, user_name):
     """
     url(r'^register/$', 'register_view', name='register'),
     
     url(r'^feed/$', 'index', {'format': 'atom'}),
-    url(r'^tag/(?P<tag_name>[a-zA-Z0-9:._]+)/$', 'tag', name='base-tag'),
-    url(r'^tag/(?P<tag_name>[a-zA-Z0-9:._]+)/feed/$', 'tag', 
+
+    url(r'^tags/$', 'tags_all', name='tags-all'),
+    url(r'^tag/(?P<tag_name>[a-zA-Z0-9:._-]+)/$', 'tag', name='base-tag'),
+    url(r'^tag/(?P<tag_name>[a-zA-Z0-9:._-]+)/feed/$', 'tag', 
         {'format': 'atom'}),
     
     # Users
     url(r'^user/(?P<user_name>[a-zA-Z0-9._]+)/feed/$', 'user', {'format': 'atom'}),
     url(r'^user/(?P<user_name>[a-zA-Z0-9._]+)/tags/$', 'user_tags', 
         name='base-user-tags'),
-    url(r'^user/(?P<user_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._]+)/$', 
+    url(r'^user/(?P<user_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._-]+)/$', 
         'user_tag', name='base-user-tag'),
-    url(r'^user/(?P<user_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._]+)/feed/$', 
+    url(r'^user/(?P<user_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._-]+)/feed/$', 
         'user_tag', {'format': 'atom'}),
     # Legacy url pattern - redirect.
     url(r'^person/(?P<user_name>.*)/$', 'person', name='base-person'),
         {'format': 'atom'}),
     url(r'^group/(?P<group_name>[a-zA-Z0-9._]+)/tags/$', 'group_tag', 
         name='base-group-tags'),
-    url(r'^group/(?P<group_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._]+)/$', 
+    url(r'^group/(?P<group_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._-]+)/$', 
         'group_tag', name='base-group-tag'),
-    url(r'^group/(?P<group_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._]+)/feed/$', 
+    url(r'^group/(?P<group_name>[a-zA-Z0-9._]+)/tag/(?P<tag_name>[a-zA-Z0-9:._-]+)/feed/$', 
         'group_tag', {'format': 'atom'}),
 
     # URLs