# HG changeset patch # User Pawel Solyga # Date 1222092517 0 # Node ID 2f3bd84bb106221c3bd75c80842bf92a7b8a7b9a # Parent 7c0b42aecd9b8fcfb9e9b5291aca2c303f06c0bb 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 diff -r 7c0b42aecd9b -r 2f3bd84bb106 app/soc/content/css/soc.css --- 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; +} + diff -r 7c0b42aecd9b -r 2f3bd84bb106 app/soc/templates/soc/list/list_heading.html --- /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 @@ + + Default Heading + diff -r 7c0b42aecd9b -r 2f3bd84bb106 app/soc/templates/soc/list/list_main.html --- /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 @@ +
+ {% include list_pagination %} + + + {% if not list_data %} + + {% else %} + {% include list_heading %} + {% for data_element in list_data %} + {% include list_row %} + {% endfor %} + {% endif %} +
(None)
+ + {% include list_pagination %} + +
\ No newline at end of file diff -r 7c0b42aecd9b -r 2f3bd84bb106 app/soc/templates/soc/list/list_pagination.html --- /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 @@ + \ No newline at end of file diff -r 7c0b42aecd9b -r 2f3bd84bb106 app/soc/templates/soc/list/list_row.html --- /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 @@ + +
{{ data_element }} +
+ + diff -r 7c0b42aecd9b -r 2f3bd84bb106 app/soc/views/helpers/list_helpers.py --- /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" ', + ] + + +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