blob: 99bb6458a00e83c078dfb0e918e19be9129ab12f [file] [log] [blame]
# Copyright 2011 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
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module for rendering dashboard and component list.
The classes in this module are intended to serve as base classes for
iconic dashboard (Dashboard) and component list (Component).
from django.utils.translation import ugettext
from soc.views.template import Template
class Component(Template):
"""Base component for the list component."""
def __init__(self, data):
"""Initializes the list component.
data: The RequestData object
""" = data
def getListData(self):
"""Returns the list data as requested by the current request.
If the lists as requested is not supported by this component None is
# by default no list is present
return None
def post(self):
"""Handles a post request.
If posting to the list as requested is not supported by this component
False is returned.
# by default post is not supported
return False
class Dashboard(Template):
"""Base template to render iconic dashboard.
This class cannot be instantiated directly. Iconic dashboard must be
implemented by derived classes with at least title, name, and subpages set in
the context. Dashboard can be nested by supplying subpages_link's context.
Dashboard also can be rendered as a list component container by
supplying component's context (with list component as its value).
See soc.modules.gsoc.views.admin.MainDashboard and
soc.modules.gsoc.views.dashboard.ComponentsDashboard as an example of iconic
dashboard implementation.
def __init__(self, data, subpages=None):
"""Initializes the dashboard.
data: The RequestData object
subpages: Subpages of current dashboard
""" = data
self.subpages = subpages
def getSubpagesLink(self):
"""Returns the link to other dashboard that appears
on top of the dashboard.
return self.subpages
def templatePath(self):
"""Returns the path to the template that should be used in render()
return 'soc/dashboard/base.html'
def _divideSubPages(self, subpages):
"""Returns the subpages divided into two columns.
middle_ceil = (len(subpages) + 1) / 2
return [