Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
authorPawel Solyga <Pawel.Solyga@gmail.com>
Mon, 22 Sep 2008 14:08:37 +0000
changeset 185 2f3bd84bb106
parent 184 7c0b42aecd9b
child 186 da76f08b1752
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc). Add list default templates and CSS classes. Patch by: Pawel Solyga Reviewed by: to-be-reviewed
app/soc/content/css/soc.css
app/soc/templates/soc/list/list_heading.html
app/soc/templates/soc/list/list_main.html
app/soc/templates/soc/list/list_pagination.html
app/soc/templates/soc/list/list_row.html
app/soc/views/helpers/list_helpers.py
--- a/app/soc/content/css/soc.css	Mon Sep 22 13:42:53 2008 +0000
+++ b/app/soc/content/css/soc.css	Mon Sep 22 14:08:37 2008 +0000
@@ -100,8 +100,21 @@
   text-decoration: none;
 }
 
-a.selected:visited, .selected a:visited {
-  color: black;
+a.novisit {
+  color: #2a55a3;
+}
+
+a.noul, a.noulv {
+  color: #4182fa; /* #93b7fa; */
+  text-decoration: none;
+}
+
+a:hover.noul {
+  text-decoration: underline;
+}
+
+a:visited.noul {
+  color: #a32a91; /* #2a55a3; */
 }
 
 /* TABLES */
@@ -141,7 +154,21 @@
     font-weight: bold;
     color: #FF0000;
   }
-  
+
+/* TABLE QUEUES (used with .list) */
+table#queues {
+  border-collapse: collapse;
+  width: 100%;
+}
+
+  table#queues tr {
+    border-bottom: thin solid lightgray;
+  }
+
+  table#queues td {
+    padding: 2px;
+  }  
+
 /* 
  * PAGE ELEMENTS 
  */
@@ -284,10 +311,7 @@
     width: 125px;
   }
 
-/* 
- * BLOG FEEDS
- */
-
+/* BLOG FEEDS */
 .blog {
   border: 10px solid #e5ecf9;
   border-top: 1px solid #3366cc;
@@ -326,6 +350,46 @@
   background-color: white;
 }
 
+/* LIST */
+.list {
+  background-color: #E5ECF9;
+  border: 1px solid  #93b7fa;
+  border-bottom: 2px solid #93b7fa;
+  padding: 3px;
+  -moz-border-radius: 5px 5px 0px 0px;
+}
+
+  .list .pagination {
+    text-align: right;
+    padding: 3px;
+  }
+  
+  .list table{
+    background-color: white;
+  }
+  
+    .list table th {
+      background-color: #eeeeec;
+      border-right: 1px solid lightgray;
+      border-top: 1px solid lightgray;
+    }
+
+    .list table tr.on {
+      background-color: #ff9;
+    }
+
+    .list table tr.off {
+      background-color: #fff;
+    }
+
+    .list table td.last {
+      border-right: 1px solid lightgray;
+    }
+
+    .list table .first {
+      border-left: 1px solid lightgray;
+    }
+
 /* 
  * CUSTOM CLASSES 
  */
@@ -353,4 +417,10 @@
 .rounded_ul { background: url(/soc/content/images/ul.gif) no-repeat top left; }
 .rounded_ur { background: url(/soc/content/images/ur.gif) no-repeat top right; }
 .rounded_ll { background: url(/soc/content/images/ll.gif) no-repeat bottom left; }
-.rounded_lr { background: url(/soc/content/images/lr.gif) no-repeat bottom right; }
\ No newline at end of file
+.rounded_lr { background: url(/soc/content/images/lr.gif) no-repeat bottom right; }
+
+/* Disabled text. */
+.disabled {
+  color: gray;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/list/list_heading.html	Mon Sep 22 14:08:37 2008 +0000
@@ -0,0 +1,3 @@
+<tr align="left">
+  <th class="first" align="right">Default Heading</th>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/list/list_main.html	Mon Sep 22 14:08:37 2008 +0000
@@ -0,0 +1,17 @@
+<div class="list">
+  {% include list_pagination %}
+
+  <table id="queues">
+    {% if not list_data %}
+      <tr><td colspan="9"><span class="disabled">(None)</span></td></tr>
+    {% else %}
+      {% include list_heading %}
+      {% for data_element in list_data %}
+        {% include list_row %}
+      {% endfor %}
+    {% endif %}
+  </table>
+
+  {% include list_pagination %}
+
+</div>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/list/list_pagination.html	Mon Sep 22 14:08:37 2008 +0000
@@ -0,0 +1,11 @@
+<div class="pagination">
+  {% if newest %}
+    <a class="novisit" href="{{newest}}">&laquo; First</a>
+  {% endif %}
+  {% if prev %}
+    <a class="novisit" href="{{prev}}">&lsaquo; Previous</a>
+  {% endif %}
+  <b>{{ first }}{% if last %} - {{ last }}{% endif %}</b>
+  {% if next %}<a class="novisit" href="{{next}}">Next &rsaquo;</a>
+  {% else %}<span style="color:gray">Next &rsaquo;</span>{% endif %}
+</div>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/list/list_row.html	Mon Sep 22 14:08:37 2008 +0000
@@ -0,0 +1,7 @@
+<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
+onclick="document.location.href=''" name="name">
+  <td align="right"><div class="id"><a class="noul"
+         href="">{{ data_element }}</a>
+     </div>
+  </td>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/helpers/list_helpers.py	Mon Sep 22 14:08:37 2008 +0000
@@ -0,0 +1,133 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Helpers used to render lists.
+"""
+
+__authors__ = [
+  '"Pawel Solyga" <pawel.solyga@gmail.com>',
+  ]
+
+
+DEF_LIMIT = 10
+
+def getListParemeters(offset=None, limit=None):
+  """Updates and validates offset and limit values of the list.
+
+  Args:
+    offset: offset in list which defines first item to return
+    limit: max amount of items per page
+
+  Returns:
+    updated offset and limit values
+  """
+  # update offset value 
+  if offset:
+    try:
+      offset = int(offset)
+    except:
+      offset = 0
+    else:
+      offset = max(0, offset)
+  else:
+    offset = 0
+  
+  # update limit value
+  if limit:
+    try:
+      limit = int(limit)
+    except:
+      limit = DEF_LIMIT
+    else:
+      limit = max(1, min(limit, 100))
+  else:
+    limit = DEF_LIMIT
+  
+  return offset, limit
+
+DEF_LIST_TEMPLATES = {'list_main': 'soc/list/list_main.html',
+                      'list_pagination': 'soc/list/list_pagination.html',
+                      'list_row': 'soc/list/list_row.html',
+                      'list_heading': 'soc/list/list_heading.html'}
+
+def setList(request, context, list_data,
+            offset=0, limit=0, list_templates=DEF_LIST_TEMPLATES):
+  """Updates template context dict with variables used for rendering lists.
+
+  Args:
+    request: the Django HTTP request object
+    context: the template context dict to be updated in-place (pass in a copy
+      if the original must not be modified), or None if a new one is to be
+      created; any existing fields already present in the context dict passed
+      in by the caller are left unaltered 
+    list_data: array of data to be displayed in the list
+    offset: offset in list which defines first item to return
+    limit: max amount of items per page
+    list_templates: templates that are used when rendering list
+
+  Returns:
+    updated template context dict supplied by the caller or a new context
+    dict if the caller supplied None
+
+    {
+      'list_data': list data to be displayed 
+      'list_main': url to list main template
+      'list_pagination': url to list pagination template
+      'list_row': url to list row template
+      'list_heading': url to list heading template
+      'limit': max amount of items per page,
+      'newest': url to first page of the list 
+      'prev': url to previous page 
+      'next': url to next page
+      'first': offset of the first item in the list
+      'last': offest of the lst item in the list
+    }
+  """  
+  if not list_data:
+    list_data = []
+  
+  more = bool(list_data[limit:])
+  if more:
+    del list_data[limit:]
+  if more:
+    next = request.path + '?offset=%d&limit=%d' % (offset+limit, limit)
+  else:
+    next = ''
+  if offset > 0:
+    prev = request.path + '?offset=%d&limit=%d' % (max(0, offset-limit), limit)
+  else:
+    prev = ''
+  newest = ''
+  if offset > limit:
+    newest = request.path + '?limit=%d' % limit
+  
+  if not context:
+    context = {}
+  
+  context.update(
+    {'list_data': list_data, 
+     'list_main': list_templates['list_main'],
+     'list_pagination': list_templates['list_pagination'],
+     'list_row': list_templates['list_row'],
+     'list_heading': list_templates['list_heading'],
+     'limit': limit,
+     'newest': newest, 
+     'prev': prev, 
+     'next': next,
+     'first': offset+1,
+     'last': len(list_data) > 1 and offset+len(list_data) or None})
+  
+  return context
\ No newline at end of file