################################################################################## Copyright (c) 2013, Alexander Todorov <atodorov@nospam.dif.io>## 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.################################################################################### This module extends the standard `url' template tag in Django and adds support# for fully qualified domain name URLs.# It also can be extended with URL load balancing techniques if desired.#################################################################################try:fromsettingsimportFQDNexcept:FQDN=""# Note: we could use the sites framework but it stores the domain in the DB# not in local_settings.py which I don't like. It's also missing support for# web clusters which can serve the same content over different URLsfromdjango.templateimportLibraryfromdjango.templateimportdefaulttagsfromdjango.templatetagsimportfutureregister=Library()classFQDN_URLNode(defaulttags.URLNode):defrender(self,context):retval=super(FQDN_URLNode,self).render(context)retval=FQDN+retvalifself.asvar:context[self.asvar]=retvalreturn''else:returnretval@register.tagdeffqdn_url(parser,token):# NB change with defaulttags.url for Django 1.5 and laterretval=future.url(parser,token)retval.__class__=FQDN_URLNodereturnretval