paramecio2fm/paramecio2/libraries/urls.py

82 lines
2.1 KiB
Python

from settings import config
import urllib.parse
def make_url(path, query_args={}):
"""
This is a method for create urls for the system
Keyword arguments:
path -- The path to the module
query_args -- a ser of get variables for add to url
"""
get_query=''
if len(query_args)>0:
get_query='?'+urllib.parse.urlencode(query_args)
return config.application_root+path+get_query
def make_url_domain(path, query_args={}):
"""
This is a method for create urls for the system, using the domain_url config variable how prefix
Keyword arguments:
path -- The path to the module
query_args -- a ser of get variables for add to url
"""
return config.domain_url+make_url(path, query_args)
def make_external_url(path, query_args={}):
"""
This is a method for create urls for external systems
Keyword arguments:
path -- The base url of the url
query_args -- a ser of get variables for add to url
"""
get_query=''
if len(query_args)>0:
#get_query='?'+"&".join( [x+'='+y for x,y in query_args.items()] )
get_query='?'+urllib.parse.urlencode(query_args)
return path+get_query
if config.yes_static==True:
def make_media_url(file_path, module):
"""
This is a method for create urls for media resources.
Keyword arguments:
file_path -- The relative path of module
module -- the module where you can find the resource
"""
return config.media_url+'mediafrom/'+module+'/'+file_path
else:
def make_media_url(file_path, module):
"""
This is a method for create urls for media resources.
Keyword arguments:
file_path -- The relative path of module
module -- the module where you can find the resource
"""
return config.media_url+'media/'+module+'/'+file_path