diff --git a/paramecio2/app.py b/paramecio2/app.py index fb7cc2e..be9f274 100644 --- a/paramecio2/app.py +++ b/paramecio2/app.py @@ -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//') + @app.route('/mediafrom//') 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 diff --git a/paramecio2/libraries/urls.py b/paramecio2/libraries/urls.py new file mode 100644 index 0000000..1aa6feb --- /dev/null +++ b/paramecio2/libraries/urls.py @@ -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 diff --git a/paramecio2/modules/welcome/app.py b/paramecio2/modules/welcome/app.py index a31a985..61ec5b0 100644 --- a/paramecio2/modules/welcome/app.py +++ b/paramecio2/modules/welcome/app.py @@ -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": diff --git a/paramecio2/modules/welcome/templates/welcome.phtml b/paramecio2/modules/welcome/templates/welcome.phtml index 93ed084..d57c6d9 100644 --- a/paramecio2/modules/welcome/templates/welcome.phtml +++ b/paramecio2/modules/welcome/templates/welcome.phtml @@ -69,7 +69,7 @@

${title}

- ${lang('cuchulutrip', 'FUCK', 'FUCK')} + ${content}