| # Copyright 2014 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. |
| |
| """Module containing a template for top message.""" |
| |
| from soc.views import template |
| |
| |
| TEMPLATE_PATH = 'melange/profile/_form_below_header.html' |
| |
| class ProfileFormBelowHeader(template.Template): |
| """Template for a message to be displayed on the profile form just |
| below the title. |
| """ |
| |
| def __init__(self, data, agreement_name, agreement_url): |
| """Initializes a new instance of this class. |
| |
| Args: |
| data: request_data.RequestData object for the current request. |
| template_path: Path to the HTML template to use for rendering. |
| message: String with a message to be displayed. |
| """ |
| super(ProfileFormBelowHeader, self).__init__(data) |
| self._agreement_name = agreement_name |
| self._agreement_url = agreement_url |
| |
| def templatePath(self): |
| """See template.Template.templatePath for specification.""" |
| return TEMPLATE_PATH |
| |
| def context(self): |
| """See template.Template.context for specification.""" |
| return { |
| 'agreement_name': self._agreement_name, |
| 'agreement_url': self._agreement_url, |
| } |
| |
| def Create(data, agreement=None): |
| """Helper function for creating a ProfileFormBelowHeader. |
| |
| Returns None if there is no agreement specified. |
| |
| Args: |
| data: a data object.for the current request. |
| agreement: a Document representing an agreement. |
| |
| Returns: |
| A ProfileFormBelowHeader (Template) if an agreement is |
| specified, otherwise None. |
| """ |
| if agreement: |
| return ProfileFormBelowHeader( |
| data, |
| agreement.title, |
| data.redirect.document(agreement).url()) |
| else: |
| return None |