Added urls library
This commit is contained in:
parent
114342bc9b
commit
0d57d44037
4 changed files with 118 additions and 8 deletions
|
|
@ -1,14 +1,25 @@
|
|||
from flask import Flask, session, url_for, escape, request
|
||||
from flask import Flask, session, url_for, escape, request, send_file, abort
|
||||
from settings import config
|
||||
from importlib import import_module
|
||||
#import sys
|
||||
import os
|
||||
import sys
|
||||
|
||||
def start_app():
|
||||
|
||||
|
||||
app=Flask(__name__, static_url_path=config.static_url_path, static_folder=config.static_folder)
|
||||
|
||||
app.secret_key=config.secret_key
|
||||
|
||||
application_root='/'
|
||||
|
||||
if hasattr(config, 'application_root'):
|
||||
application_root=config.application_root
|
||||
|
||||
|
||||
app.config.update(
|
||||
APPLICATION_ROOT=application_root
|
||||
)
|
||||
|
||||
# Load blueprints
|
||||
|
||||
for added_app in config.apps:
|
||||
|
|
@ -19,10 +30,21 @@ def start_app():
|
|||
|
||||
app.register_blueprint(app_name)
|
||||
|
||||
#Add media files.
|
||||
#Add media files support. Only for development.
|
||||
|
||||
workdir=os.getcwd()
|
||||
|
||||
@app.route('/mediafrom/<module>/<media_file>')
|
||||
@app.route('/mediafrom/<module>/<path:media_file>')
|
||||
def send_media_file(module, media_file):
|
||||
|
||||
pass
|
||||
file_path=workdir+'/themes/'+config.theme+'/media/'+module+'/'+media_file
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
file_path=workdir+'/modules/'+module+'/media/'+media_file
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
abort(404)
|
||||
|
||||
return send_file(file_path)
|
||||
|
||||
return app
|
||||
|
|
|
|||
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
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from flask import Blueprint, render_template
|
||||
from flask import Blueprint, redirect
|
||||
from settings import config
|
||||
from paramecio2.libraries.mtemplates import PTemplate, env_theme
|
||||
|
||||
|
|
@ -14,6 +14,12 @@ def home():
|
|||
return t.load_template('welcome.phtml', title="Welcome", content='Welcome to the real world')
|
||||
|
||||
#return render_template('welcome.html', title="Welcome")
|
||||
"""
|
||||
@welcome_app.route('/welcome/redirect')
|
||||
def welcome_redirect():
|
||||
|
||||
return redirect('/welcome')
|
||||
"""
|
||||
|
||||
if config.default_module=="welcome":
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@
|
|||
<h1>${title}</h1>
|
||||
|
||||
<div class="body">
|
||||
${lang('cuchulutrip', 'FUCK', 'FUCK')}
|
||||
${content}
|
||||
</div>
|
||||
|
||||
<div class="footer">Paramecio, a system created for create webapps</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue