Added basic files
This commit is contained in:
commit
114342bc9b
16 changed files with 1320 additions and 0 deletions
28
paramecio2/app.py
Normal file
28
paramecio2/app.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from flask import Flask, session, url_for, escape, request
|
||||
from settings import config
|
||||
from importlib import import_module
|
||||
#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
|
||||
|
||||
# Load blueprints
|
||||
|
||||
for added_app in config.apps:
|
||||
|
||||
a=import_module(added_app)
|
||||
#print(added_app, file=sys.stdout)
|
||||
app_name=getattr(a, config.apps[added_app][0])
|
||||
|
||||
app.register_blueprint(app_name)
|
||||
|
||||
#Add media files.
|
||||
|
||||
@app.route('/mediafrom/<module>/<media_file>')
|
||||
def send_media_file(module, media_file):
|
||||
|
||||
pass
|
||||
|
||||
0
paramecio2/libraries/__init__.py
Normal file
0
paramecio2/libraries/__init__.py
Normal file
96
paramecio2/libraries/i18n.py
Normal file
96
paramecio2/libraries/i18n.py
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from importlib import import_module
|
||||
#from paramecio.citoplasma.sessions import get_session
|
||||
import json
|
||||
from flask import session
|
||||
|
||||
yes_session=False
|
||||
|
||||
i18n_module={}
|
||||
|
||||
def load_lang(*args):
|
||||
|
||||
for module in args:
|
||||
|
||||
lang_path=module[0]+'.i18n.'+module[1]
|
||||
|
||||
try:
|
||||
|
||||
i18n_module[lang_path]=import_module(lang_path)
|
||||
|
||||
pass
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
# here load the language
|
||||
|
||||
|
||||
class I18n:
|
||||
|
||||
default_lang='en-US'
|
||||
|
||||
dict_i18n=['en-US', 'es-ES']
|
||||
|
||||
l={}
|
||||
|
||||
#@staticmethod
|
||||
#def set_lang(code_lang):
|
||||
# if default_lang
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_default_lang():
|
||||
|
||||
lang=I18n.default_lang
|
||||
|
||||
s=session
|
||||
|
||||
lang=s.get('lang', lang)
|
||||
|
||||
return lang
|
||||
|
||||
@staticmethod
|
||||
def lang(module, symbol, text_default, lang=None):
|
||||
|
||||
if not lang:
|
||||
lang=I18n.get_default_lang()
|
||||
|
||||
I18n.l[lang]=I18n.l.get(lang, {})
|
||||
|
||||
I18n.l[lang][module]=I18n.l[lang].get(module, {})
|
||||
|
||||
I18n.l[lang][module][symbol]=I18n.l[lang][module].get(symbol, text_default)
|
||||
|
||||
return I18n.l[lang][module][symbol]
|
||||
|
||||
@staticmethod
|
||||
def extract_value(value):
|
||||
|
||||
value=json.loads(value)
|
||||
|
||||
lang=I18n.get_default_lang()
|
||||
|
||||
if value[lang]!='':
|
||||
|
||||
return value[lang]
|
||||
|
||||
return value[I18n.default_lang]
|
||||
|
||||
"""
|
||||
@staticmethod
|
||||
def get_browser_lang():
|
||||
|
||||
return request.headers.get('Accept-Language', 'en-US')
|
||||
"""
|
||||
@staticmethod
|
||||
def lang_json(module, symbol, text_default):
|
||||
|
||||
arr_final={}
|
||||
|
||||
for l in I18n.dict_i18n:
|
||||
arr_final[l]=I18n.lang(module, symbol, text_default, l)
|
||||
|
||||
return json.dumps(arr_final)
|
||||
|
||||
97
paramecio2/libraries/mtemplates.py
Normal file
97
paramecio2/libraries/mtemplates.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# Template frontend from mako.
|
||||
|
||||
from mako.template import Template
|
||||
from flask import session
|
||||
from mako.lookup import TemplateLookup
|
||||
from os import path
|
||||
from settings import config
|
||||
import gettext
|
||||
import sys
|
||||
from paramecio2.libraries.i18n import I18n
|
||||
|
||||
def env_theme(module, cache_enabled=True, cache_impl='', cache_args={}, module_directory="./tmp/modules"):
|
||||
|
||||
ext=module[len(module)-3:]
|
||||
|
||||
if ext=='.py':
|
||||
|
||||
module=path.dirname(module)
|
||||
|
||||
standard_templates=path.dirname(__file__)+'/templates'
|
||||
|
||||
module_directory+='/'+module
|
||||
|
||||
module_templates=module+'/templates'
|
||||
|
||||
theme_templates='themes/'+config.theme+'/templates'
|
||||
|
||||
search_folders=[theme_templates, module_templates, standard_templates]
|
||||
|
||||
#if self.inject_folder is not None:
|
||||
#search_folders.insert(1, self.inject_folder+'/templates')
|
||||
|
||||
#Standard templates
|
||||
#print(standard_templates)
|
||||
return TemplateLookup(directories=search_folders, default_filters=['h'], input_encoding='utf-8', encoding_errors='replace', cache_enabled=cache_enabled, cache_impl=cache_impl, cache_args=cache_args, module_directory=module_directory, filesystem_checks=config.reloader)
|
||||
|
||||
class PTemplate:
|
||||
|
||||
templates_loaded={}
|
||||
|
||||
def __init__(self, environment, prepare_gettext=True):
|
||||
|
||||
self.autoescape_ext=('html', 'htm', 'xml', 'phtml', 'js')
|
||||
|
||||
self.env=environment
|
||||
|
||||
self.filters={}
|
||||
|
||||
self.add_filter(I18n.lang)
|
||||
|
||||
"""
|
||||
def gettext(self, text):
|
||||
return gettext.dgettext(self.domain_gettext, text)
|
||||
"""
|
||||
|
||||
def load_template(self, template_file, **arguments):
|
||||
"""
|
||||
if self.prepare_gettext:
|
||||
|
||||
module_lang_dir=self.env.directories[1].replace('/templates', '/locales')
|
||||
|
||||
module_name=path.basename(module_lang_dir.replace('/locales', ''))
|
||||
|
||||
en = gettext.translation(module_name, localedir=module_lang_dir, languages=['en'])
|
||||
en.install()
|
||||
_=en.gettext
|
||||
|
||||
arguments.update({'_': _})
|
||||
"""
|
||||
template = self.env.get_template(template_file)
|
||||
|
||||
arguments.update(self.filters)
|
||||
|
||||
return template.render(**arguments)
|
||||
|
||||
def guess_autoescape(self, template_name):
|
||||
|
||||
if template_name is None or '.' not in template_name:
|
||||
return False
|
||||
|
||||
ext = template_name.rsplit('.', 1)[1]
|
||||
|
||||
return ext in self.autoescape_ext
|
||||
|
||||
def render_template(self, template_file, **arguments):
|
||||
|
||||
if not str(self.env.directories)+'/'+template_file in PTemplate.templates_loaded:
|
||||
PTemplate.templates_loaded[str(self.env.directories)+'/'+template_file]=self.env.get_template(template_file)
|
||||
|
||||
arguments.update(self.filters)
|
||||
|
||||
return PTemplate.templates_loaded[str(self.env.directories)+'/'+template_file].render(**arguments)
|
||||
|
||||
def add_filter(self, filter_name):
|
||||
|
||||
self.filters[filter_name.__name__]=filter_name
|
||||
|
||||
0
paramecio2/modules/welcome/__init__.py
Normal file
0
paramecio2/modules/welcome/__init__.py
Normal file
20
paramecio2/modules/welcome/app.py
Normal file
20
paramecio2/modules/welcome/app.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from flask import Blueprint, render_template
|
||||
from settings import config
|
||||
from paramecio2.libraries.mtemplates import PTemplate, env_theme
|
||||
|
||||
env=env_theme(__file__)
|
||||
|
||||
t=PTemplate(env)
|
||||
|
||||
welcome_app=Blueprint('welcome_app', __name__)
|
||||
|
||||
@welcome_app.route('/welcome')
|
||||
def home():
|
||||
|
||||
return t.load_template('welcome.phtml', title="Welcome", content='Welcome to the real world')
|
||||
|
||||
#return render_template('welcome.html', title="Welcome")
|
||||
|
||||
if config.default_module=="welcome":
|
||||
|
||||
home=welcome_app.route("/")(home)
|
||||
9
paramecio2/modules/welcome/babel.cfg
Normal file
9
paramecio2/modules/welcome/babel.cfg
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Extraction from Python source files
|
||||
|
||||
[python: **.py]
|
||||
|
||||
# Extraction from Mako templates
|
||||
|
||||
[mako: templates/**.phtml]
|
||||
input_encoding = utf-8
|
||||
|
||||
79
paramecio2/modules/welcome/templates/welcome.html
Normal file
79
paramecio2/modules/welcome/templates/welcome.html
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Paramecio WebFramework</title>
|
||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
|
||||
<style type="text/css">
|
||||
|
||||
h1, h2, h3 {
|
||||
|
||||
|
||||
/*border: solid #cdcdcd 1px;*/
|
||||
padding:5px 10px 5px 10px;
|
||||
margin:0px;
|
||||
background: #b80505;
|
||||
color: #fbfbfb;
|
||||
|
||||
}
|
||||
|
||||
body {
|
||||
|
||||
background: #fbfbfb;
|
||||
margin-left:15px;
|
||||
margin-right:15px;
|
||||
font-size:14px;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
|
||||
}
|
||||
|
||||
#container {
|
||||
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
padding:10px 20px 10px 20px;
|
||||
margin:0px;
|
||||
|
||||
}
|
||||
|
||||
.body {
|
||||
|
||||
padding:10px 20px 10px 20px;
|
||||
border: solid #c4c4c4 1px;
|
||||
margin:0px;
|
||||
background: #fff;
|
||||
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
||||
text-align:right;
|
||||
padding:3px 6px 3px 6px;
|
||||
font-size:8pt;
|
||||
|
||||
}
|
||||
|
||||
.code {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
<h1>{{title}}</h1>
|
||||
|
||||
<div class="body">
|
||||
HELLO
|
||||
</div>
|
||||
|
||||
<div class="footer">Paramecio, a system created for create webapps</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
79
paramecio2/modules/welcome/templates/welcome.phtml
Normal file
79
paramecio2/modules/welcome/templates/welcome.phtml
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Paramecio WebFramework</title>
|
||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
|
||||
<style type="text/css">
|
||||
|
||||
h1, h2, h3 {
|
||||
|
||||
|
||||
/*border: solid #cdcdcd 1px;*/
|
||||
padding:5px 10px 5px 10px;
|
||||
margin:0px;
|
||||
background: #b80505;
|
||||
color: #fbfbfb;
|
||||
|
||||
}
|
||||
|
||||
body {
|
||||
|
||||
background: #fbfbfb;
|
||||
margin-left:15px;
|
||||
margin-right:15px;
|
||||
font-size:14px;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
|
||||
}
|
||||
|
||||
#container {
|
||||
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
padding:10px 20px 10px 20px;
|
||||
margin:0px;
|
||||
|
||||
}
|
||||
|
||||
.body {
|
||||
|
||||
padding:10px 20px 10px 20px;
|
||||
border: solid #c4c4c4 1px;
|
||||
margin:0px;
|
||||
background: #fff;
|
||||
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
||||
text-align:right;
|
||||
padding:3px 6px 3px 6px;
|
||||
font-size:8pt;
|
||||
|
||||
}
|
||||
|
||||
.code {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
<h1>${title}</h1>
|
||||
|
||||
<div class="body">
|
||||
${lang('cuchulutrip', 'FUCK', 'FUCK')}
|
||||
</div>
|
||||
|
||||
<div class="footer">Paramecio, a system created for create webapps</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
9
paramecio2/modules/welcome/welcome.py
Normal file
9
paramecio2/modules/welcome/welcome.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from flask import Blueprint
|
||||
|
||||
|
||||
welcome=Blueprint('welcome', __name__, template_folder='templates')
|
||||
|
||||
@welcome.route('/welcome')
|
||||
def home():
|
||||
|
||||
return "WELCOME TO FLASK APPLICATION"
|
||||
Loading…
Add table
Add a link
Reference in a new issue