blob: 2e5b1f2f5321fb8bd378ce039565f4a957941664 [file] [log] [blame]
#!/usr/bin/env python2.5
# 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 dual buttons for enabling/disabling feature.
from django.utils.translation import ugettext
from soc.views.template import Template
class ButtonTemplate(Template):
"""Template to render buttons on proposal review page.
'This functionality is already enabled. To disable this functionality, '
'press the button adjacent to this.')
'This functionality is already disabled. To enable this functionality, '
'press the button adjacent to this.')
def __init__(self, data, title, id, url_name, enable=True,
disabled_msgs=None, labels=None):
"""Instantiates the template for rendering review page buttons.
data: RequestData object
title: The text that must be displayed before the button
id: value to be given to HTML id attribute for button
url_name: The name with which the RequestHandler has registered
enable: if True Enable button is activated otherwise Disable button
disabled_msgs : dictionary containing the message to be shown for
each button when clicked in the disabled state
labels: dictionary containing the label for each of the two buttons
super(ButtonTemplate, self).__init__(data)
self.title = title
self.labels = labels
self._id = id
self._url_name = url_name
self._enable = enable
self._disabled_msgs = disabled_msgs
def context(self):
"""The context for this template used in render().
context = {
'title': self.title,
'state': self.state,
if self.labels:
context['enable_label'] = self.labels.get('enable')
context['disable_label'] = self.labels.get('disable')
return context
def state(self):
"""Returns the state as needed by the Javascript and HTML.
return "enable" if self._enable else "disable"
def link(self):
"""Returns the post url for the button.
def id(self):
"""Returns the id to be used for the button.
return self._id
def enable_btn_disabled_msg(self):
"""Returns the message to be displayed when the enable button is
pressed when it is disabled.
msg = self._disabled_msgs.get('enable')
return msg if msg else self.DEF_ENABLE_BTN_DISABLED
def disable_btn_disabled_msg(self):
"""Returns the message to be displayed when the disable button is
pressed when it is disabled.
msg = self._disabled_msgs.get('disable')
return msg if msg else self.DEF_DISABLE_BTN_DISABLED
def templatePath(self):
return 'soc/_button.html'