blob: 3c9b1ac1d4b0e2477a761edca0b0454a01f3454f [file] [log] [blame]
# Copyright 2012 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 for managing URL generation."""
from django.core import urlresolvers
class Linker(object):
"""URL creator for Melange."""
def site(self, url_name):
"""Returns the URL of a named page on the site.
Args:
url_name: The name with which a url was registered with Django
(such as "edit_site_settings").
Returns:
The url of the site-wide page matching the given name.
"""
return urlresolvers.reverse(url_name)
def program(self, program, url_name):
"""Returns the URL of a program's named page.
Args:
program: A program.
url_name: The name with which a url was registered with Django.
Returns:
The url of the page matching the given name for the given program.
"""
kwargs = {
'program': program.link_id,
'sponsor': program.scope_path,
}
return urlresolvers.reverse(url_name, kwargs=kwargs)