Added urls library
This commit is contained in:
parent
114342bc9b
commit
0d57d44037
4 changed files with 118 additions and 8 deletions
82
paramecio2/libraries/urls.py
Normal file
82
paramecio2/libraries/urls.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue