Added setup.py
This commit is contained in:
parent
ef0f9e5100
commit
ac27d16cee
73 changed files with 55 additions and 0 deletions
0
paramecio/__init__.py
Normal file
0
paramecio/__init__.py
Normal file
0
paramecio/citoplasma/__init__.py
Normal file
0
paramecio/citoplasma/__init__.py
Normal file
49
paramecio/citoplasma/check_i18n.py
Normal file
49
paramecio/citoplasma/check_i18n.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
pattern=re.compile('^\w+\.py$')
|
||||
|
||||
ignored=re.compile('^[__|\.].*$')
|
||||
|
||||
lang_p=re.compile()
|
||||
|
||||
def start():
|
||||
|
||||
scandir('.')
|
||||
|
||||
pass
|
||||
|
||||
def scandir(path):
|
||||
|
||||
list=os.listdir(path)
|
||||
|
||||
for name in list:
|
||||
|
||||
new_path=path+'/'+name
|
||||
|
||||
if os.path.isdir(new_path):
|
||||
if ignored.match(name)==None:
|
||||
scandir(new_path)
|
||||
elif pattern.match(name)!=None and ignored.match(name)==None:
|
||||
|
||||
f=open(new_path)
|
||||
|
||||
|
||||
|
||||
f.close()
|
||||
|
||||
#print('archivo->'+path+'/'+name)
|
||||
# Open file
|
||||
# obtain modules, keys, and default text
|
||||
|
||||
# Open all files in a loop with modules from dictionary created from open files, if module not exists, the file is in i18n
|
||||
|
||||
# Load array from file, if file not exists, is created
|
||||
|
||||
# If not exists the key with text, add them in arrays loaded from created array
|
||||
|
||||
# Rewrite the file with the new arrys and close the file. Open next file
|
||||
|
||||
|
||||
18
paramecio/citoplasma/filterip.py
Normal file
18
paramecio/citoplasma/filterip.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# A simple utility for filter ips. Only use this if you don't use a server with blocking ips system
|
||||
|
||||
from settings import config
|
||||
from bottle import request
|
||||
|
||||
def filterip():
|
||||
#Check ip
|
||||
ip = request.environ.get('REMOTE_ADDR')
|
||||
|
||||
if ip in config.allowed_ips:
|
||||
|
||||
return True
|
||||
else:
|
||||
|
||||
return False
|
||||
|
||||
118
paramecio/citoplasma/generate_admin_class.py
Normal file
118
paramecio/citoplasma/generate_admin_class.py
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
from paramecio.citoplasma.lists import SimpleList
|
||||
from bottle import request, redirect
|
||||
from paramecio.citoplasma.urls import add_get_parameters
|
||||
from paramecio.citoplasma.mtemplates import set_flash_message
|
||||
from paramecio.cromosoma.formsutils import show_form
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
|
||||
class GenerateAdminClass:
|
||||
|
||||
def __init__(self, model, url, t):
|
||||
|
||||
self.model_name=''
|
||||
|
||||
self.model=model
|
||||
|
||||
self.t=t
|
||||
|
||||
self.list=SimpleList(model, url, t)
|
||||
|
||||
self.arr_fields_edit=model.fields.keys()
|
||||
|
||||
self.url=url
|
||||
|
||||
self.safe=0;
|
||||
|
||||
self.arr_links={}
|
||||
|
||||
self.hierarchy=None
|
||||
|
||||
self.text_add_item=''
|
||||
|
||||
self.no_insert=False
|
||||
|
||||
self.no_delete=False
|
||||
|
||||
self.title=''
|
||||
|
||||
self.id=0
|
||||
|
||||
self.template_insert='utils/insertform.phtml'
|
||||
|
||||
self.template_admin='utils/admin.phtml'
|
||||
|
||||
def show(self):
|
||||
|
||||
GetPostFiles.obtain_get()
|
||||
|
||||
GetPostFiles.get['op_admin']=GetPostFiles.get.get('op_admin', '0')
|
||||
|
||||
GetPostFiles.get['id']=GetPostFiles.get.get('id', '0')
|
||||
|
||||
if GetPostFiles.get['op_admin']=='1':
|
||||
|
||||
post=None
|
||||
|
||||
if len(self.model.forms)==0:
|
||||
self.model.create_forms(self.arr_fields_edit)
|
||||
|
||||
title_edit=I18n.lang('common', 'add_new_item', 'Add new item')
|
||||
|
||||
if GetPostFiles.get['id']!='0':
|
||||
post=self.model.select_a_row(GetPostFiles.get['id'])
|
||||
title_edit=I18n.lang('common', 'edit_new_item', 'Edit item')
|
||||
|
||||
if post==None:
|
||||
post={}
|
||||
|
||||
form=show_form(post, self.model.forms, self.t, False)
|
||||
|
||||
return self.t.load_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=GetPostFiles.get['id'])
|
||||
|
||||
elif GetPostFiles.get['op_admin']=='2':
|
||||
|
||||
GetPostFiles.obtain_post()
|
||||
|
||||
post=GetPostFiles.post
|
||||
|
||||
insert_row=self.model.insert
|
||||
|
||||
try:
|
||||
|
||||
GetPostFiles.get['id']=str(int(GetPostFiles.get['id']))
|
||||
|
||||
except:
|
||||
|
||||
GetPostFiles.get['id']='0'
|
||||
|
||||
title_edit=I18n.lang('common', 'add_new_item', 'Add new item')
|
||||
|
||||
|
||||
if GetPostFiles.get['id']!='0':
|
||||
insert_row=self.model.update
|
||||
title_edit=I18n.lang('common', 'edit_new_item', 'Edit item')
|
||||
self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [GetPostFiles.get['id']]]
|
||||
|
||||
if insert_row(post):
|
||||
set_flash_message(I18n.lang('common', 'task_successful', 'Task successful'))
|
||||
redirect(self.url)
|
||||
else:
|
||||
|
||||
form=show_form(post, self.model.forms, self.t, True)
|
||||
return self.t.load_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=GetPostFiles.get['id'])
|
||||
|
||||
|
||||
pass
|
||||
|
||||
elif GetPostFiles.get['op_admin']=='3':
|
||||
|
||||
if GetPostFiles.get['id']!='0':
|
||||
self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [GetPostFiles.get['id']]]
|
||||
self.model.delete()
|
||||
set_flash_message(I18n.lang('common', 'task_successful', 'Task successful'))
|
||||
redirect(self.url)
|
||||
|
||||
else:
|
||||
return self.t.load_template(self.template_admin, admin=self)
|
||||
|
||||
31
paramecio/citoplasma/gunicornssl.py
Normal file
31
paramecio/citoplasma/gunicornssl.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# This module is suitable for create ssl apis that don't need much performance, if you need more performance use nginx or apache proxiying for generate https content and Paramecio with gunicorn or others wsgi servers for generate the html/json content.
|
||||
|
||||
from bottle import ServerAdapter
|
||||
import ssl
|
||||
|
||||
class GunicornServerSSL(ServerAdapter):
|
||||
""" Untested. See http://gunicorn.org/configure.html for options. """
|
||||
|
||||
cert_pem=''
|
||||
privkey_pem=''
|
||||
workers=2
|
||||
|
||||
def run(self, handler):
|
||||
from gunicorn.app.base import Application
|
||||
|
||||
#'ciphers': 'TLSv1'
|
||||
#, 'ssl_version': ssl.PROTOCOL_TLSv1
|
||||
|
||||
config = {'bind': "%s:%d" % (self.host, int(self.port)), 'workers': self.workers, 'keyfile': self.privkey_pem, 'certfile': self.cert_pem, 'ssl_version': ssl.PROTOCOL_TLSv1}
|
||||
config.update(self.options)
|
||||
|
||||
class GunicornApplication(Application):
|
||||
def init(self, parser, opts, args):
|
||||
return config
|
||||
|
||||
def load(self):
|
||||
return handler
|
||||
|
||||
GunicornApplication().run()
|
||||
76
paramecio/citoplasma/hierarchy_links.py
Normal file
76
paramecio/citoplasma/hierarchy_links.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#/usr/bin/python3
|
||||
|
||||
class HierarchyLinks:
|
||||
|
||||
def __init__(arr_links):
|
||||
|
||||
self.arr_links=arr_links
|
||||
|
||||
self.arr_indexes={}
|
||||
|
||||
def update_links(self, link_father, link_son, text):
|
||||
|
||||
self.arr_links[link_father][link_son]=text
|
||||
|
||||
|
||||
def calculate_indexes():
|
||||
|
||||
#oreach(self.arr_links as $father_link => $arr_child_links)
|
||||
for father_link, arr_child_links in self.arr_links.items():
|
||||
|
||||
#foreach($arr_child_links as $link => $text)
|
||||
for link, text in self.arr_child_links.items():
|
||||
|
||||
self.arr_indexes[link]=father_link
|
||||
|
||||
|
||||
def result(last_link, arr_result=[], yes_last_link=0):
|
||||
|
||||
self.calculate_indexes()
|
||||
|
||||
if last_link in self.arr_indexes:
|
||||
|
||||
father=self.arr_indexes[last_link]
|
||||
|
||||
arr_last_link[0]=self.no_link
|
||||
|
||||
arr_last_link[1]=self.yes_link
|
||||
|
||||
yes_link_func=arr_last_link[yes_last_link]
|
||||
|
||||
if father!='':
|
||||
|
||||
arr_result.append(self.yes_link_func(last_link, self.arr_links[father][last_link]))
|
||||
|
||||
yes_last_link=1
|
||||
|
||||
arr_result=self.result(father, arr_result, yes_last_link)
|
||||
|
||||
return arr_result
|
||||
|
||||
else:
|
||||
|
||||
arr_result.append(self.yes_link_func(last_link, self.arr_links[father][last_link]))
|
||||
|
||||
return arr_result
|
||||
|
||||
return arr_result
|
||||
|
||||
|
||||
def show(link, separator='>>', class_link=''):
|
||||
|
||||
arr_result=self.result(link)
|
||||
|
||||
arr_result=array_reverse(arr_result)
|
||||
|
||||
return ' '+separator+' '.join(arr_result)
|
||||
|
||||
def yes_link(link, text):
|
||||
|
||||
return '<a href="'+link+'">'+text+'</a>'
|
||||
|
||||
|
||||
def no_link(link, text):
|
||||
|
||||
return text
|
||||
|
||||
31
paramecio/citoplasma/httputils.py
Normal file
31
paramecio/citoplasma/httputils.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from bottle import request
|
||||
|
||||
class GetPostFiles:
|
||||
|
||||
# Need this for obtain utf8 valid values
|
||||
get={}
|
||||
|
||||
post={}
|
||||
|
||||
files=None
|
||||
|
||||
@staticmethod
|
||||
def obtain_get():
|
||||
|
||||
GetPostFiles.get={}
|
||||
|
||||
GetPostFiles.get=request.query.decode()
|
||||
|
||||
@staticmethod
|
||||
def obtain_post():
|
||||
|
||||
GetPostFiles.post={}
|
||||
|
||||
GetPostFiles.post=request.forms.decode()
|
||||
|
||||
@staticmethod
|
||||
def obtain_files():
|
||||
|
||||
GetPostFiles.files=request.files
|
||||
32
paramecio/citoplasma/i18n.py
Normal file
32
paramecio/citoplasma/i18n.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from settings import config
|
||||
|
||||
def load_lang(*args):
|
||||
|
||||
for module in args:
|
||||
|
||||
if module in config.modules:
|
||||
|
||||
lang_path=config.base_modules+'.'+module+'.i18n'
|
||||
|
||||
else:
|
||||
lang_path='i18n'
|
||||
|
||||
# here load the language
|
||||
|
||||
|
||||
class I18n:
|
||||
|
||||
l={}
|
||||
|
||||
@staticmethod
|
||||
def lang(module, symbol, text_default):
|
||||
|
||||
I18n.l[module]=I18n.l.get(module, {})
|
||||
|
||||
I18n.l[module][symbol]=I18n.l[module].get(symbol, text_default)
|
||||
|
||||
return I18n.l[module][symbol]
|
||||
|
||||
|
||||
178
paramecio/citoplasma/lists.py
Normal file
178
paramecio/citoplasma/lists.py
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
#By default id is not showed
|
||||
|
||||
from paramecio.citoplasma.pages import Pages
|
||||
from paramecio.citoplasma.urls import add_get_parameters
|
||||
from paramecio.citoplasma.sessions import get_session
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from bottle import request
|
||||
import sys
|
||||
|
||||
class SimpleList:
|
||||
|
||||
def __init__(self, model, url, t):
|
||||
|
||||
self.t=t
|
||||
|
||||
self.model=model
|
||||
|
||||
if len(self.model.forms)==0:
|
||||
|
||||
self.model.create_forms()
|
||||
|
||||
self.fields=model.fields.keys()
|
||||
|
||||
self.fields_showed=self.fields
|
||||
|
||||
self.url=url
|
||||
|
||||
self.limit_pages=20
|
||||
|
||||
self.order_defaults=['ASC', 'DESC']
|
||||
|
||||
self.order_class=['up', 'down']
|
||||
|
||||
self.s=get_session()
|
||||
|
||||
#self.s['order']=self.s.get('order', 0)
|
||||
|
||||
self.order_by=self.order_defaults[0]
|
||||
|
||||
self.change_order={}
|
||||
|
||||
self.yes_search=True
|
||||
|
||||
self.search_text=''
|
||||
|
||||
self.initial_num_pages=20
|
||||
|
||||
request.query.get('begin_page', '0')
|
||||
|
||||
try:
|
||||
|
||||
self.begin_page=int(request.query.begin_page)
|
||||
|
||||
except ValueError:
|
||||
self.begin_page=0
|
||||
|
||||
if self.begin_page<0:
|
||||
self.begin_page=0
|
||||
|
||||
self.search_fields=self.fields
|
||||
|
||||
#self.yes_options=True
|
||||
|
||||
self.arr_extra_fields=[I18n.lang('common', 'options', 'Options')]
|
||||
|
||||
self.arr_extra_options=[SimpleList.standard_options]
|
||||
|
||||
self.jln='<br />'
|
||||
|
||||
def restore_fields(self):
|
||||
self.fields=self.model.fields.keys()
|
||||
|
||||
def obtain_order(self):
|
||||
|
||||
self.s['order']=self.s.get('order', 0)
|
||||
|
||||
order_k=self.s['order']
|
||||
|
||||
#Obtain from get
|
||||
|
||||
if 'order' in request.query.keys():
|
||||
|
||||
order_k=int(request.query.get('order', 0))
|
||||
|
||||
if order_k>1 or order_k<0:
|
||||
order_k=0
|
||||
|
||||
self.order_by=self.order_defaults[ order_k ]
|
||||
|
||||
self.s['order']=order_k
|
||||
|
||||
self.s.save()
|
||||
|
||||
def obtain_field_search(self):
|
||||
|
||||
self.s['order_field']=self.s.get('order_field', self.model.name_field_id)
|
||||
|
||||
field_k=self.s['order_field']
|
||||
|
||||
if 'order_field' in request.query.keys():
|
||||
field_k=request.query.order_field
|
||||
|
||||
if field_k in self.model.fields.keys():
|
||||
|
||||
self.s['order_field']=field_k
|
||||
|
||||
for field in self.fields:
|
||||
self.change_order[field]=self.s['order']
|
||||
|
||||
if self.s['order']==0:
|
||||
self.change_order[field_k]=1
|
||||
else:
|
||||
self.change_order[field_k]=0
|
||||
|
||||
self.s.save()
|
||||
|
||||
self.order_field=self.s['order_field']
|
||||
|
||||
def search(self):
|
||||
|
||||
request.query.get('search_text', '')
|
||||
|
||||
self.search_text=request.query.search_text
|
||||
|
||||
self.search_text=self.search_text.replace('"', '"')
|
||||
|
||||
#self.model.conditions='AND
|
||||
|
||||
self.search_field=request.query.get('search_field', '')
|
||||
|
||||
if self.search_field not in self.model.fields.keys():
|
||||
self.search_field=''
|
||||
|
||||
if self.search_field!='' and self.search_text!='':
|
||||
self.model.conditions[0]+=' AND '+self.search_field+' LIKE %s'
|
||||
self.model.conditions[1]=['%'+self.search_text+'%']
|
||||
|
||||
pass
|
||||
|
||||
def set_options(self, options_func, arr_row):
|
||||
#SimpleList.standard_options(arr_row)
|
||||
return self.jln.join(options_func(self.url, arr_row[self.model.name_field_id], arr_row))
|
||||
|
||||
@staticmethod
|
||||
def standard_options(url, id, arr_row):
|
||||
options=[]
|
||||
options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+I18n.lang('common', 'edit', 'Edit')+'</a>')
|
||||
options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+I18n.lang('common', 'delete', 'Delete')+'</a>')
|
||||
return options
|
||||
|
||||
def show(self):
|
||||
|
||||
self.obtain_order()
|
||||
|
||||
self.obtain_field_search()
|
||||
|
||||
self.search()
|
||||
|
||||
total_elements=self.model.select_count()
|
||||
|
||||
num_elements=self.limit_pages
|
||||
|
||||
link=add_get_parameters(self.url, search_text=self.search_text, search_field=self.search_field)
|
||||
|
||||
begin_page=self.begin_page
|
||||
|
||||
self.model.order_by='order by '+self.order_field+' '+self.order_by
|
||||
|
||||
self.model.limit='limit '+str(begin_page)+','+str(self.limit_pages)
|
||||
|
||||
list_items=self.model.select(self.fields)
|
||||
|
||||
pages=Pages.show( begin_page, total_elements, num_elements, link ,initial_num_pages=self.initial_num_pages, variable='begin_page', label='', func_jscript='')
|
||||
|
||||
self.begin_page=str(self.begin_page)
|
||||
|
||||
return self.t.load_template('utils/list.phtml', simplelist=self, list=list_items, pages=pages)
|
||||
|
||||
231
paramecio/citoplasma/mtemplates.py
Normal file
231
paramecio/citoplasma/mtemplates.py
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
from paramecio.citoplasma.urls import make_url, make_media_url, make_media_url_module, add_get_parameters
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from paramecio.citoplasma.sessions import get_session
|
||||
from settings import config
|
||||
from os import path
|
||||
|
||||
# Preparing envs for views of modules, and views of
|
||||
|
||||
""" A simple function for load views from themes using jinja2
|
||||
|
||||
Env use loader = FileSystemLoader(['/path/to/templates', '/other/path'])
|
||||
env = Environment(loader=FileSystemLoader(['/path/to/templates', '/other/path']))
|
||||
template = env.get_template('mytemplate.html')
|
||||
"""
|
||||
|
||||
class ptemplate:
|
||||
|
||||
def __init__(self, module):
|
||||
|
||||
module=path.dirname(module)
|
||||
|
||||
self.autoescape_ext=('html', 'htm', 'xml', 'phtml')
|
||||
|
||||
self.env=self.env_theme(module)
|
||||
|
||||
self.filters={}
|
||||
|
||||
#Adding basic filters for urls
|
||||
self.add_filter(make_url)
|
||||
|
||||
self.add_filter(make_media_url)
|
||||
|
||||
self.add_filter(make_media_url_module)
|
||||
|
||||
self.add_filter(add_get_parameters)
|
||||
|
||||
I18n_lang=I18n.lang
|
||||
|
||||
self.add_filter(I18n.lang)
|
||||
|
||||
self.add_filter(add_css_home)
|
||||
|
||||
self.add_filter(add_js_home)
|
||||
|
||||
self.add_filter(add_css_home_local)
|
||||
|
||||
self.add_filter(add_js_home_local)
|
||||
|
||||
self.add_filter(add_header_home)
|
||||
|
||||
#self.auto_reload=True
|
||||
|
||||
# Clean HeaderHTML
|
||||
|
||||
HeaderHTML.css=[]
|
||||
HeaderHTML.js=[]
|
||||
HeaderHTML.header=[]
|
||||
HeaderHTML.cache_header=[]
|
||||
HeaderHTML.css_local={}
|
||||
HeaderHTML.js_local={}
|
||||
|
||||
def clean_header_cache(self):
|
||||
|
||||
HeaderHTML.css=[]
|
||||
HeaderHTML.js=[]
|
||||
HeaderHTML.css_local={}
|
||||
HeaderHTML.js_local={}
|
||||
HeaderHTML.header=[]
|
||||
HeaderHTML.cache_header=[]
|
||||
|
||||
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 env_theme(self, module):
|
||||
|
||||
theme_templates='themes/'+config.theme+'/templates'
|
||||
|
||||
module_templates=module+'/templates'
|
||||
|
||||
#Standard templates
|
||||
|
||||
standard_templates=path.dirname(__file__)+'/templates'
|
||||
#print(standard_templates)
|
||||
return TemplateLookup(directories=[theme_templates, module_templates, standard_templates], default_filters=['h'], input_encoding='utf-8', encoding_errors='replace')
|
||||
|
||||
#return Environment(autoescape=self.guess_autoescape, auto_reload=True, loader=FileSystemLoader([theme_templates, module_templates]))
|
||||
|
||||
def load_template(self, template_file, **arguments):
|
||||
|
||||
template = self.env.get_template(template_file)
|
||||
|
||||
arguments['HeaderHTML']=HeaderHTML
|
||||
|
||||
arguments['show_flash_message']=show_flash_message
|
||||
|
||||
for filter_name, filter_ in self.filters.items():
|
||||
arguments[filter_name]=filter_
|
||||
|
||||
#Will be nice add hooks here
|
||||
|
||||
return template.render(**arguments)
|
||||
|
||||
def add_filter(self, filter_name):
|
||||
|
||||
self.filters[filter_name.__name__]=filter_name
|
||||
|
||||
|
||||
class HeaderHTML:
|
||||
|
||||
css=[]
|
||||
js=[]
|
||||
header=[]
|
||||
cache_header={}
|
||||
|
||||
def header_home():
|
||||
|
||||
final_header="\n".join(HeaderHTML.header)
|
||||
|
||||
HeaderHTML.header=[]
|
||||
|
||||
return final_header
|
||||
|
||||
def js_home():
|
||||
|
||||
final_js=[]
|
||||
|
||||
for js in HeaderHTML.js:
|
||||
final_js.append('<script language="Javascript" src="'+make_media_url('js/'+js)+'"></script>')
|
||||
|
||||
for module, arr_js in HeaderHTML.js_local.items():
|
||||
for js in arr_js:
|
||||
final_js.append('<script language="Javascript" src="'+make_media_url_module('js/'+js, module)+'"></script>')
|
||||
|
||||
return "\n".join(final_js)
|
||||
|
||||
def css_home():
|
||||
|
||||
final_css=[]
|
||||
|
||||
for css in HeaderHTML.css:
|
||||
final_css.append('<link href="'+make_media_url('css/'+css)+'" rel="stylesheet" type="text/css"/>')
|
||||
|
||||
for module, arr_css in HeaderHTML.css_local.items():
|
||||
|
||||
for css in arr_css:
|
||||
|
||||
final_css.append('<link href="'+make_media_url_module('css/'+css, module)+'" rel="stylesheet" type="text/css"/>')
|
||||
|
||||
return "\n".join(final_css)
|
||||
|
||||
|
||||
def add_header_home(variable, only_one_time=False):
|
||||
|
||||
|
||||
if only_one_time==True:
|
||||
HeaderHTML.cache_header.get(variable, 0)
|
||||
|
||||
if cache_header[variable]==1:
|
||||
return ''
|
||||
#HeaderHTML.cache_header[variable]=1
|
||||
|
||||
HeaderHTML.header.append(variable)
|
||||
|
||||
return ''
|
||||
|
||||
def add_css_home(css):
|
||||
|
||||
if not css in HeaderHTML.css:
|
||||
HeaderHTML.css.append(css)
|
||||
|
||||
return ''
|
||||
|
||||
def add_js_home(js):
|
||||
|
||||
if not js in HeaderHTML.js:
|
||||
HeaderHTML.js.append(js)
|
||||
|
||||
return ''
|
||||
|
||||
def add_css_home_local(css, module):
|
||||
|
||||
if not css in HeaderHTML.css_local:
|
||||
|
||||
HeaderHTML.css_local[module]=HeaderHTML.css_local.get(module, [])
|
||||
|
||||
HeaderHTML.css_local[module].append(css)
|
||||
|
||||
return ''
|
||||
|
||||
def add_js_home_local(js, module):
|
||||
|
||||
if not js in HeaderHTML.js_local:
|
||||
|
||||
HeaderHTML.js_local[module]=HeaderHTML.js_local.get(module, [])
|
||||
|
||||
HeaderHTML.js_local[module].append(js)
|
||||
|
||||
return ''
|
||||
|
||||
def set_flash_message(message):
|
||||
|
||||
s=get_session()
|
||||
|
||||
s['flash']=s.get('flash', "")
|
||||
|
||||
s['flash']=message
|
||||
|
||||
def show_flash_message():
|
||||
|
||||
message=""
|
||||
|
||||
s=get_session()
|
||||
|
||||
s['flash']=s.get('flash', "")
|
||||
|
||||
if s['flash']!="":
|
||||
message='<div class="flash">'+s['flash']+'</div>'
|
||||
|
||||
s['flash']=''
|
||||
|
||||
return message
|
||||
|
||||
72
paramecio/citoplasma/pages.py
Normal file
72
paramecio/citoplasma/pages.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from math import ceil, floor
|
||||
from paramecio.citoplasma.urls import add_get_parameters
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
class Pages:
|
||||
|
||||
css_class='link_pages'
|
||||
|
||||
@staticmethod
|
||||
def show( begin_page, total_elements, num_elements, link ,initial_num_pages=20, variable='begin_page', label='', func_jscript=''):
|
||||
|
||||
pages='';
|
||||
|
||||
if begin_page>total_elements:
|
||||
begin_page=0
|
||||
|
||||
# Calculamos el total de todas las páginas
|
||||
|
||||
total_page=ceil(total_elements/num_elements)
|
||||
|
||||
# Calculamos en que página nos encontramos
|
||||
|
||||
actual_page=ceil(begin_page/num_elements)
|
||||
|
||||
# Calculamos el total de intervalos
|
||||
|
||||
total_interval=ceil(total_page/initial_num_pages)
|
||||
|
||||
# Calculamos el intervalo en el que estamos
|
||||
|
||||
actual_interval=floor(actual_page/initial_num_pages)
|
||||
|
||||
# Calculamos el elemento de inicio del intervalo
|
||||
|
||||
initial_page=ceil(actual_interval*initial_num_pages*num_elements)
|
||||
|
||||
last_page=ceil(actual_interval*initial_num_pages*num_elements)+ceil(initial_num_pages*num_elements)
|
||||
|
||||
if last_page>total_elements:
|
||||
last_page=total_elements
|
||||
|
||||
if initial_page>0:
|
||||
initial_link=add_get_parameters(link, **{variable: '0'});
|
||||
middle_link=add_get_parameters(link, **{variable: str((initial_page-num_elements)) } );
|
||||
pages += "<a class=\""+Pages.css_class+"\" href=\""+initial_link+"\" onclick=\"func_jscript\">1</a> <a class=\""+Pages.css_class+"\" href=\""+middle_link+"\"><<</a> "
|
||||
|
||||
arr_pages={}
|
||||
|
||||
#for(x=initial_page;x<last_page;x+=num_elements)
|
||||
for x in range(initial_page, last_page, num_elements):
|
||||
|
||||
middle_link=add_get_parameters(link, **{variable: str(x)} )
|
||||
|
||||
num_page=ceil(x/num_elements)+1;
|
||||
arr_pages[x]="<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">"+str(num_page)+"</a> "
|
||||
arr_pages[begin_page]='<span class="selected_page">'+str(num_page)+'</span> ';
|
||||
pages += arr_pages[x]
|
||||
|
||||
|
||||
if last_page<total_elements:
|
||||
|
||||
middle_link=add_get_parameters(link, **{variable: str(x+num_elements)} );
|
||||
last_link=add_get_parameters(link, **{variable: str( ( ( total_page*num_elements ) - num_elements) ) } )
|
||||
|
||||
pages += "<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">>></a> <a class=\"link_pages\" href=\""+last_link+"\" onclick=\"func_jscript\">"+I18n.lang('common', 'last', 'Last')+"</a>"
|
||||
|
||||
|
||||
return pages
|
||||
|
||||
|
||||
7
paramecio/citoplasma/sessions.py
Normal file
7
paramecio/citoplasma/sessions.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from bottle import request
|
||||
from settings import config
|
||||
|
||||
def get_session():
|
||||
return request.environ.get(config.cookie_name)
|
||||
172
paramecio/citoplasma/templates.py
Normal file
172
paramecio/citoplasma/templates.py
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from jinja2 import Template, Environment, FileSystemLoader
|
||||
from citoplasma.urls import make_url, make_media_url, make_media_url_module, add_get_parameters
|
||||
from citoplasma.i18n import I18n
|
||||
from citoplasma.sessions import get_session
|
||||
from settings import config
|
||||
|
||||
# Preparing envs for views of modules, and views of
|
||||
|
||||
""" A simple function for load views from themes using jinja2
|
||||
|
||||
Env use loader = FileSystemLoader(['/path/to/templates', '/other/path'])
|
||||
env = Environment(loader=FileSystemLoader(['/path/to/templates', '/other/path']))
|
||||
template = env.get_template('mytemplate.html')
|
||||
"""
|
||||
|
||||
class ptemplate:
|
||||
|
||||
def __init__(self, module):
|
||||
|
||||
self.autoescape_ext=('html', 'htm', 'xml', 'phtml')
|
||||
|
||||
self.env=self.env_theme(module)
|
||||
|
||||
#Adding basic filters for urls
|
||||
|
||||
self.add_filter(make_url)
|
||||
|
||||
self.add_filter(make_media_url)
|
||||
|
||||
self.add_filter(make_media_url_module)
|
||||
|
||||
self.add_filter(add_get_parameters)
|
||||
|
||||
I18n_lang=I18n.lang
|
||||
|
||||
self.add_filter(I18n.lang)
|
||||
|
||||
self.add_filter(add_css_home)
|
||||
|
||||
self.add_filter(add_js_home)
|
||||
|
||||
self.add_filter(add_header_home)
|
||||
|
||||
self.auto_reload=True
|
||||
|
||||
# Clean HeaderHTML
|
||||
|
||||
HeaderHTML.css=[]
|
||||
HeaderHTML.js=[]
|
||||
HeaderHTML.header=[]
|
||||
HeaderHTML.cache_header=[]
|
||||
|
||||
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 env_theme(self, module):
|
||||
|
||||
theme_templates='themes/'+config.theme+'/templates'
|
||||
|
||||
module_templates=config.base_modules+'/'+module+'/templates'
|
||||
|
||||
return Environment(autoescape=self.guess_autoescape, auto_reload=True, loader=FileSystemLoader([theme_templates, module_templates]))
|
||||
|
||||
def load_template(self, template_file, **arguments):
|
||||
|
||||
template = self.env.get_template(template_file)
|
||||
|
||||
arguments['HeaderHTML']=HeaderHTML
|
||||
|
||||
arguments['show_flash_message']=show_flash_message
|
||||
|
||||
#Will be nice add hooks here
|
||||
|
||||
return template.render(arguments)
|
||||
|
||||
def add_filter(self, filter_name):
|
||||
|
||||
self.env.filters[filter_name.__name__]=filter_name
|
||||
|
||||
|
||||
class HeaderHTML:
|
||||
|
||||
css=[]
|
||||
js=[]
|
||||
header=[]
|
||||
cache_header={}
|
||||
|
||||
def header_home():
|
||||
|
||||
final_header="\n".join(HeaderHTML.header)
|
||||
|
||||
HeaderHTML.header=[]
|
||||
|
||||
return final_header
|
||||
|
||||
def js_home():
|
||||
|
||||
final_js=[]
|
||||
|
||||
for js in HeaderHTML.js:
|
||||
final_js.append('<script language="Javascript" src="'+make_media_url('js/'+js)+'"></script>')
|
||||
|
||||
return "\n".join(final_js)
|
||||
|
||||
def css_home():
|
||||
|
||||
final_css=[]
|
||||
|
||||
for css in HeaderHTML.css:
|
||||
final_css.append('<link href="'+make_media_url('css/'+css)+'" rel="stylesheet" type="text/css"/>')
|
||||
|
||||
return "\n".join(final_css)
|
||||
|
||||
|
||||
def add_header_home(variable, only_one_time=False):
|
||||
|
||||
|
||||
if only_one_time==True:
|
||||
HeaderHTML.cache_header.get(variable, 0)
|
||||
|
||||
if cache_header[variable]==1:
|
||||
return ''
|
||||
#HeaderHTML.cache_header[variable]=1
|
||||
|
||||
HeaderHTML.header.append(variable)
|
||||
|
||||
return ''
|
||||
|
||||
def add_css_home(css):
|
||||
|
||||
if not css in HeaderHTML.css:
|
||||
HeaderHTML.css.append(css)
|
||||
|
||||
return ""
|
||||
|
||||
def add_js_home(js):
|
||||
|
||||
if not js in HeaderHTML.js:
|
||||
HeaderHTML.js.append(js)
|
||||
|
||||
return ""
|
||||
|
||||
def set_flash_message(message):
|
||||
|
||||
s=get_session()
|
||||
|
||||
s['flash']=s.get('flash', "")
|
||||
|
||||
s['flash']=message
|
||||
|
||||
def show_flash_message():
|
||||
|
||||
message=""
|
||||
|
||||
s=get_session()
|
||||
|
||||
s['flash']=s.get('flash', "")
|
||||
|
||||
if s['flash']!="":
|
||||
message='<div class="flash">'+s['flash']+'</div>'
|
||||
|
||||
s['flash']=''
|
||||
|
||||
return message
|
||||
|
||||
4
paramecio/citoplasma/templates/admin/content.html
Normal file
4
paramecio/citoplasma/templates/admin/content.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<%inherit file="home.html" />
|
||||
<%block name="content">
|
||||
${content_index|n}
|
||||
</%block>
|
||||
45
paramecio/citoplasma/templates/admin/home.html
Normal file
45
paramecio/citoplasma/templates/admin/home.html
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>${title}</title>
|
||||
<!--<link href="{{'css/admin/admin.css'|make_media_url}}" rel="stylesheet" type="text/css"/>
|
||||
<link href="{{'css/font-awesome.min.css'|make_media_url}}" rel="stylesheet" type="text/css"/>-->
|
||||
${add_css_home_local('admin.css', 'admin')}
|
||||
${add_css_home_local('font-awesome.min.css', 'admin')}
|
||||
${HeaderHTML.css_home()|n}
|
||||
${add_js_home_local('jquery.min.js', 'admin')}
|
||||
${HeaderHTML.js_home()|n}
|
||||
${HeaderHTML.header_home()|n}
|
||||
</head>
|
||||
<body>
|
||||
<div id="languages_general">
|
||||
</div>
|
||||
<div id="logout">
|
||||
<a href="${make_url('admin/logout')}">Logout</a>
|
||||
</div>
|
||||
|
||||
<div id="center_body">
|
||||
<div id="header"><span id="title_phango">Paramecio</span> <span id="title_framework">Framework!</span> </div>
|
||||
<div class="content_admin">
|
||||
<div id="menu">
|
||||
<div class="menu_title">${lang('admin', 'applications', 'Applications')}</div>
|
||||
% for module in sorted(menu):
|
||||
% if type(menu[module]).__name__=='list':
|
||||
<a href="${make_url('admin/'+module)}">${menu[module][0]}</a>
|
||||
% else:
|
||||
<div class="father_admin">${menu[module]}</div>
|
||||
% endif
|
||||
% endfor
|
||||
</div>
|
||||
<div class="contents">
|
||||
<h1>${title}</h1>
|
||||
<%block name="content">
|
||||
</%block>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loading_ajax">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
9
paramecio/citoplasma/templates/admin/index.html
Normal file
9
paramecio/citoplasma/templates/admin/index.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<%inherit file="home.html"/>
|
||||
<%block name="content">
|
||||
<div class="title">
|
||||
Bienvenido al administrador
|
||||
</div>
|
||||
<div class="cont">
|
||||
Desde aquí podrá administrar su site
|
||||
</div>
|
||||
</%block>
|
||||
66
paramecio/citoplasma/templates/admin/login.phtml
Normal file
66
paramecio/citoplasma/templates/admin/login.phtml
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%block name="title">${lang('admin', 'login', 'Paramecio Login')}</%block></title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
|
||||
${add_js_home_local('jquery.min.js', 'admin')}
|
||||
${add_css_home_local('login.css', 'admin')}
|
||||
${add_css_home_local('font-awesome.min.css', 'admin')}
|
||||
${HeaderHTML.css_home()|n}
|
||||
${HeaderHTML.js_home()|n}
|
||||
<%block name="ajax">
|
||||
<script language="javascript">
|
||||
$(document).ready( function () {
|
||||
|
||||
$('#login_submit').click( function () {
|
||||
|
||||
$('#loading').show();
|
||||
|
||||
$.ajax({
|
||||
url: "${make_url('admin/login')}",
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
data: {'username': $('#username_form').val(), 'password': $('#password_form').val()}
|
||||
}).done(function(data) {
|
||||
|
||||
if(data.error==0)
|
||||
{
|
||||
|
||||
window.location.href="${make_url('admin')}";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$('#loading').hide('slow');
|
||||
|
||||
$('#username_error').html("${lang('common', 'error_login', 'Error, wrong username or password')}");
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</%block>
|
||||
</head>
|
||||
<body>
|
||||
<%block name="content">
|
||||
<form id="login">
|
||||
<div id="title">
|
||||
${lang('admin', 'login', 'Paramecio Login')}
|
||||
</div>
|
||||
${forms|n}
|
||||
<div id="submit_block">
|
||||
<input type="submit" value="${lang('common', 'login', 'Login')}" class="submit" id="login_submit"/>
|
||||
<span id="loading"> </span>
|
||||
</div>
|
||||
</form>
|
||||
</%block>
|
||||
</body>
|
||||
</html>
|
||||
60
paramecio/citoplasma/templates/admin/register.phtml
Normal file
60
paramecio/citoplasma/templates/admin/register.phtml
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<%inherit file="login.phtml"/>
|
||||
<%block name="ajax">
|
||||
<script language="Javascript">
|
||||
$(document).ready( function () {
|
||||
|
||||
$("#register_submit").click( function () {
|
||||
|
||||
$.ajax({
|
||||
url: "${make_url('admin/register')}",
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
data: {'username': $('#username_form').val(), 'email': $('#email_form').val(), 'password': $('#password_form').val(), 'repeat_password': $('#repeat_password_form').val()}
|
||||
}).done(function(data) {
|
||||
//$( this ).addClass( "done" );
|
||||
//Redirect if register
|
||||
|
||||
if(data.error==0)
|
||||
{
|
||||
|
||||
//$('#result_register').html('Done!. Redirecting...');
|
||||
$('#loading').show();
|
||||
|
||||
window.location.href="${make_url('admin/login')}";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//alert(JSON.stringify(data));
|
||||
//$('#result_register').html('Error');
|
||||
$('#username_error').html(data.username);
|
||||
$('#email_error').html(data.email);
|
||||
$('#password_error').html(data.password);
|
||||
|
||||
$('#repeat_password_error').html(data.password_repeat);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
</%block>
|
||||
<%block name="title">${lang('admin', 'sign_up', 'Paramecio Sign up')}</%block>
|
||||
<%block name="content">
|
||||
<form id="login">
|
||||
<div id="title">
|
||||
${lang('admin', 'sign_up', 'Paramecio Sign up')}
|
||||
</div>
|
||||
${forms|n}
|
||||
<div id="result_register"></div>
|
||||
<div id="submit_block">
|
||||
<input type="submit" value="${lang('common', 'sign_up', 'Sign up')}" class="submit" id="register_submit"/>
|
||||
<span id="loading"> </span>
|
||||
</div>
|
||||
</form>
|
||||
</%block>
|
||||
5
paramecio/citoplasma/templates/forms/modelform.html
Normal file
5
paramecio/citoplasma/templates/forms/modelform.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<div class="form">
|
||||
{% for form in forms.values() %}
|
||||
<p><label>{{form.label|safe}}</label>{{form.form()}}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
14
paramecio/citoplasma/templates/forms/modelform.phtml
Normal file
14
paramecio/citoplasma/templates/forms/modelform.phtml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<%def name="check_required(required)">
|
||||
% if required:
|
||||
${'*'}
|
||||
% endif
|
||||
</%def>
|
||||
<div class="form">
|
||||
% for form in forms.values():
|
||||
% if form.type!='hidden':
|
||||
<p><label>${form.label} ${check_required(form.required)}</label>${form.form()|n} <span class="error" id="${form.name}_error">${form.txt_error}</span></p>
|
||||
% else:
|
||||
${form.form()|n}
|
||||
% endif
|
||||
% endfor
|
||||
</div>
|
||||
4
paramecio/citoplasma/templates/utils/admin.phtml
Normal file
4
paramecio/citoplasma/templates/utils/admin.phtml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
${show_flash_message()|n}
|
||||
<h1>${admin.title}</h1>
|
||||
<a href="${add_get_parameters(admin.url, op_admin='1')}">${lang('common', 'add_item', 'Add new item')}</a>
|
||||
${admin.list.show()|n}
|
||||
13
paramecio/citoplasma/templates/utils/insertform.phtml
Normal file
13
paramecio/citoplasma/templates/utils/insertform.phtml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<p><a href="${admin.url}">${lang('common', 'home', 'Home')}</a> >>
|
||||
% if id!='0':
|
||||
${title_edit}
|
||||
%else:
|
||||
${title_edit}
|
||||
%endif
|
||||
</p>
|
||||
<form method="post" action="${add_get_parameters(admin.url, op_admin=2, id=id)}">
|
||||
<h2>${title_edit}</h2>
|
||||
<span class="error">${model.query_error}</span>
|
||||
${ form|n }
|
||||
<p><input type="submit" value="${lang('common', 'send', 'Send') }"></p>
|
||||
</form>
|
||||
53
paramecio/citoplasma/templates/utils/list.phtml
Normal file
53
paramecio/citoplasma/templates/utils/list.phtml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<!--{% set header_js_list %}
|
||||
<script language="Javascript">
|
||||
/*alert('pepe');*/
|
||||
</script>
|
||||
{% endset %}
|
||||
{{ header_js_list|add_header_home() }}-->
|
||||
<%def name="select_field()">
|
||||
% if simplelist.search_field==field:
|
||||
selected
|
||||
% endif
|
||||
</%def>
|
||||
<%def name="set_css_arrow(simplelist, field)">
|
||||
% if simplelist.order_field==field:
|
||||
fa fa-arrow-circle-${simplelist.order_class[simplelist.s['order']]}
|
||||
% endif
|
||||
</%def>
|
||||
% if simplelist.yes_search:
|
||||
<div class="form">
|
||||
<form method="get" action="{{simplelist.url}}">
|
||||
${lang('common','search', 'Search')}: <input type="text" name="search_text" value="${simplelist.search_text|n}">
|
||||
<select name="search_field">
|
||||
% for field in simplelist.search_fields:
|
||||
<option value="${simplelist.model.forms[field].name}" ${select_field()}>${simplelist.model.forms[field].label}</option>
|
||||
% endfor
|
||||
</select>
|
||||
<input type="submit" value="${lang('common', 'search', 'Search')}" />
|
||||
</form>
|
||||
</div>
|
||||
% endif
|
||||
<table class="table_list">
|
||||
<tr class="title_list">
|
||||
% for field in simplelist.fields_showed:
|
||||
<td><a href="${add_get_parameters(simplelist.url, order_field=simplelist.model.fields[field].name, begin_page=simplelist.begin_page, order=simplelist.change_order[field], search_text=simplelist.search_text, search_field=simplelist.search_field)}" class="${set_css_arrow(simplelist, field)}">${simplelist.model.fields[field].label}</a></td>
|
||||
% endfor
|
||||
% for extra_field in simplelist.arr_extra_fields:
|
||||
<td>${ extra_field }</td>
|
||||
% endfor
|
||||
</tr>
|
||||
% for row in list:
|
||||
<tr class="row_list">
|
||||
% for field in simplelist.fields_showed:
|
||||
<td>${simplelist.model.fields[field].show_formatted(row[field])}</td>
|
||||
% endfor
|
||||
|
||||
% for extra_field_func in simplelist.arr_extra_options:
|
||||
<td>${ simplelist.set_options(extra_field_func, row)|n }</td>
|
||||
% endfor
|
||||
</tr>
|
||||
% endfor
|
||||
</table>
|
||||
<p>
|
||||
${pages|n}
|
||||
</p>
|
||||
55
paramecio/citoplasma/urls.py
Normal file
55
paramecio/citoplasma/urls.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from settings import config
|
||||
|
||||
#Simple method for make urls
|
||||
|
||||
def make_url(path, query_args={}):
|
||||
|
||||
"""
|
||||
This is a method for create urls for the system
|
||||
|
||||
|
||||
Keyword arguments:
|
||||
module -- The module where search code to execute
|
||||
controller -- The controller where search code to execute
|
||||
method -- The method to execute
|
||||
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()] )
|
||||
|
||||
return config.base_url+path+get_query
|
||||
|
||||
def add_get_parameters(url, **args):
|
||||
|
||||
added_url='&'
|
||||
|
||||
if url.find('?')==-1:
|
||||
added_url='?'
|
||||
|
||||
return url+added_url+"&".join( [x+'='+str(y) for x,y in args.items()] )
|
||||
|
||||
if config.yes_static==True:
|
||||
|
||||
def make_media_url(file_path):
|
||||
|
||||
return '/media/'+file_path
|
||||
|
||||
def make_media_url_module(file_path, module):
|
||||
|
||||
return '/mediafrom/'+module+'/'+file_path
|
||||
else:
|
||||
|
||||
def make_media_url(file_path):
|
||||
|
||||
return config.media_url+'media/'+file_path
|
||||
|
||||
def make_media_url_module(file_path, module):
|
||||
|
||||
return config.media_url+'media/'+module+'/'+file_path
|
||||
167
paramecio/console.py
Normal file
167
paramecio/console.py
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import getpass
|
||||
from pathlib import Path
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.modules.admin.models.admin import UserAdmin
|
||||
|
||||
def start():
|
||||
|
||||
parser=argparse.ArgumentParser(description='A tool for create new paramecio sites')
|
||||
|
||||
parser.add_argument('--path', help='The path where the paramecio site is located', required=True)
|
||||
|
||||
parser.add_argument('--symlink', help='Set if create direct symlink to paramecio in new site', required=False, nargs='?', const='1')
|
||||
|
||||
args=parser.parse_args()
|
||||
|
||||
workdir=os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Create directory
|
||||
|
||||
path=Path(args.path)
|
||||
|
||||
try:
|
||||
path.mkdir(0o755, True)
|
||||
|
||||
except:
|
||||
|
||||
print('Error: cannot create the directory. Check if exists and if you have permissions')
|
||||
exit()
|
||||
# Create folder settings and copy index.py, admin.py
|
||||
|
||||
path_settings=args.path+'/settings'
|
||||
|
||||
try:
|
||||
|
||||
os.mkdir(path_settings, 0o755)
|
||||
except:
|
||||
print('Error: cannot create the directory. Check if exists and if you have permissions')
|
||||
|
||||
# Copy the files
|
||||
|
||||
try:
|
||||
|
||||
shutil.copy(workdir+'/settings/config.py.sample', path_settings+'/config.py')
|
||||
|
||||
except:
|
||||
|
||||
print('Error: cannot copy the file config.py. Check if exists and if you have permissions for this task')
|
||||
|
||||
try:
|
||||
|
||||
shutil.copy(workdir+'/frontend/index.py', args.path+'/index.py')
|
||||
|
||||
except:
|
||||
|
||||
print('Error: cannot copy the file index.py. Check if exists and if you have permissions for this task')
|
||||
|
||||
try:
|
||||
|
||||
shutil.copy(workdir+'/frontend/padmin.py', args.path+'/padmin.py')
|
||||
|
||||
except:
|
||||
|
||||
print('Error: cannot copy the file padmin.py. Check if exists and if you have permissions for this task')
|
||||
|
||||
if args.symlink!=None:
|
||||
try:
|
||||
os.symlink(workdir, args.path+'/paramecio', True)
|
||||
|
||||
except:
|
||||
print('Error: cannot symlink paramecio in new site')
|
||||
|
||||
# Question about mysql configuration? If yes, install configuration
|
||||
|
||||
s=input('Do you want use paramecio with MySQL database? y/n: ')
|
||||
|
||||
if s=='y' or s=='Y':
|
||||
|
||||
host_db=input('MySQL database server host, by default localhost: ').strip()
|
||||
|
||||
db=input('MySQL database name, by default paramecio_db: ').strip()
|
||||
|
||||
user_db=input('MySQL database user, by default root: ').strip()
|
||||
|
||||
pass_db=getpass.getpass('MySQL database password, by default "": ').strip()
|
||||
|
||||
if host_db=='':
|
||||
|
||||
host_db='localhost'
|
||||
|
||||
if user_db=='':
|
||||
|
||||
user_db='root'
|
||||
|
||||
#user=UserAdmin()
|
||||
|
||||
#Create db
|
||||
|
||||
if db=="":
|
||||
db='paramecio_db'
|
||||
|
||||
WebModel.connections={'default': {'name': 'default', 'host': host_db, 'user': user_db, 'password': pass_db, 'db': '', 'charset': 'utf8mb4', 'set_connection': False} }
|
||||
|
||||
connection_code="WebModel.connections={'default': {'name': 'default', 'host': '"+host_db+"', 'user': '"+user_db+"', 'password': '"+pass_db+"', 'db': '"+db+"', 'charset': 'utf8mb4', 'set_connection': False} }"
|
||||
|
||||
with open(path_settings+'/config.py', 'a') as f:
|
||||
f.write("\n\n"+connection_code)
|
||||
f.close()
|
||||
|
||||
sql='create database '+db
|
||||
|
||||
if not WebModel.query(WebModel, sql):
|
||||
print('Error: cannot create database, check the data of database')
|
||||
|
||||
else:
|
||||
|
||||
WebModel.query(WebModel, 'use '+db)
|
||||
|
||||
admin=input('Do you want create admin site? y/n: ')
|
||||
|
||||
if admin=='y' or admin=='Y':
|
||||
|
||||
try:
|
||||
|
||||
shutil.copy(workdir+'/settings/config_admin.py.sample', path_settings+'/config_admin.py')
|
||||
|
||||
useradmin=UserAdmin()
|
||||
|
||||
sql=useradmin.create_table()
|
||||
|
||||
if not WebModel.query(WebModel, sql):
|
||||
print('Error: cannot create table admin, you can create this table with padmin.py')
|
||||
else:
|
||||
|
||||
# Add admin module to config
|
||||
with open(path_settings+'/config.py', 'r') as f:
|
||||
|
||||
config_text=f.read()
|
||||
|
||||
f.close()
|
||||
|
||||
config_text=config_text.replace("modules=['paramecio.modules.welcome']", "modules=['paramecio.modules.welcome', 'paramecio.modules.admin']")
|
||||
|
||||
with open(path_settings+'/config.py', 'w') as f:
|
||||
|
||||
f.write(config_text)
|
||||
|
||||
f.close()
|
||||
|
||||
print('Created admin site...')
|
||||
|
||||
except:
|
||||
|
||||
print('Error: cannot copy the file padmin.py. Check if exists and if you have permissions for this task')
|
||||
|
||||
|
||||
pass
|
||||
|
||||
# Question about install admin site.
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
start()
|
||||
4
paramecio/cromosoma/.gitignore
vendored
Normal file
4
paramecio/cromosoma/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
*~
|
||||
*.pyc
|
||||
__pycache__
|
||||
|
||||
340
paramecio/cromosoma/LICENSE
Normal file
340
paramecio/cromosoma/LICENSE
Normal file
|
|
@ -0,0 +1,340 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
|
||||
1
paramecio/cromosoma/README.md
Normal file
1
paramecio/cromosoma/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# A very simple ORM for Python 3
|
||||
0
paramecio/cromosoma/__init__.py
Normal file
0
paramecio/cromosoma/__init__.py
Normal file
100
paramecio/cromosoma/corefields.py
Normal file
100
paramecio/cromosoma/corefields.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
from paramecio.cromosoma.webmodel import PhangoField
|
||||
from paramecio.cromosoma import coreforms
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
class IntegerField(PhangoField):
|
||||
|
||||
def __init__(self, name, size=11, required=False):
|
||||
super(IntegerField, self).__init__(name, size, required)
|
||||
|
||||
def check(self, value):
|
||||
|
||||
self.error=None
|
||||
self.txt_error=''
|
||||
|
||||
try:
|
||||
|
||||
value=str(int(value))
|
||||
|
||||
if value==0 and self.required==True:
|
||||
self.txt_error="The value is zero"
|
||||
self.error=True
|
||||
except:
|
||||
|
||||
self.error=True
|
||||
|
||||
return value
|
||||
|
||||
def get_type_sql(self):
|
||||
|
||||
return 'INT('+str(self.size)+') NOT NULL DEFAULT "0"'
|
||||
|
||||
class CharField(PhangoField):
|
||||
|
||||
pass
|
||||
|
||||
class ForeignKeyField(IntegerField):
|
||||
|
||||
def __init__(self, name, related_table, size=11, required=False, identifier_field='id', named_field="id", select_fields=[]):
|
||||
|
||||
self.table_id=related_table.name_field_id
|
||||
|
||||
self.table_name=related_table.name
|
||||
|
||||
self.identifier_field=identifier_field
|
||||
|
||||
self.named_field=named_field
|
||||
|
||||
self.select_fields=select_fields
|
||||
|
||||
super(ForeignKeyField, self).__init__(name, size, required)
|
||||
|
||||
self.foreignkey=True
|
||||
|
||||
class BooleanField(IntegerField):
|
||||
|
||||
def __init__(self, name, size=1):
|
||||
|
||||
required=False
|
||||
|
||||
self.yes=I18n.lang('common', 'yes', 'Yes')
|
||||
self.no=I18n.lang('common', 'no', 'No')
|
||||
|
||||
super(IntegerField, self).__init__(name, size, required)
|
||||
|
||||
def check(self, value):
|
||||
|
||||
self.error=False
|
||||
self.txt_error=''
|
||||
|
||||
try:
|
||||
|
||||
value=int(value)
|
||||
|
||||
if value<0 or value>1:
|
||||
self.txt_error="Need 0 or 1 value"
|
||||
self.error=True
|
||||
|
||||
except:
|
||||
|
||||
self.error=True
|
||||
value=0
|
||||
|
||||
value=str(value)
|
||||
|
||||
return value
|
||||
|
||||
def get_type_sql(self):
|
||||
|
||||
return 'BOOLEAN NOT NULL DEFAULT "0"'
|
||||
|
||||
def show_formatted(self, value):
|
||||
|
||||
value=int(value)
|
||||
|
||||
if value==0:
|
||||
value=self.yes_text
|
||||
else:
|
||||
value=self.no_text
|
||||
|
||||
return value
|
||||
76
paramecio/cromosoma/coreforms.py
Normal file
76
paramecio/cromosoma/coreforms.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
#Forms para python3
|
||||
|
||||
class BaseForm:
|
||||
|
||||
def __init__(self, name, value):
|
||||
|
||||
self.label=name
|
||||
self.name=name
|
||||
self.default_value=value
|
||||
self.css=''
|
||||
self.type='text'
|
||||
self.field=None
|
||||
self.required=False
|
||||
self.txt_error=''
|
||||
|
||||
def form(self):
|
||||
|
||||
return '<input type="'+self.type+'" class="'+self.css+'" name="'+self.name+'" id="'+self.name+'_form" value="'+self.setform(self.default_value)+'">'
|
||||
|
||||
def show_formatted(self, value):
|
||||
|
||||
return value
|
||||
|
||||
#Method for escape value for html input. DON'T CHANGE IF YOU DON'T KNOWN WHAT ARE YOU DOING
|
||||
|
||||
def setform(self, value):
|
||||
|
||||
value=str(value)
|
||||
|
||||
return value.replace('"', '"')
|
||||
|
||||
class TextForm(BaseForm):
|
||||
|
||||
def __init__(self, name, value):
|
||||
super(TextForm, self).__init__(name, value)
|
||||
|
||||
class PasswordForm(BaseForm):
|
||||
|
||||
def __init__(self, name, value):
|
||||
super(PasswordForm, self).__init__(name, value)
|
||||
self.type='password'
|
||||
|
||||
def setform(self, value):
|
||||
return ""
|
||||
|
||||
class HiddenForm(BaseForm):
|
||||
|
||||
def __init__(self, name, value):
|
||||
super(HiddenForm, self).__init__(name, value)
|
||||
self.type='hidden'
|
||||
|
||||
|
||||
class SelectForm(BaseForm):
|
||||
|
||||
def __init__(self, name, value):
|
||||
super(SelectForm, self).__init__(name, value)
|
||||
self.arr_select=OrderedDict()
|
||||
|
||||
def form(self):
|
||||
|
||||
the_form='<select name="'+self.name+'">\n'
|
||||
|
||||
arr_selected={self.default_value: 'selected'}
|
||||
|
||||
for k,v in self.arr_select.items():
|
||||
arr_selected[k]=arr_selected.get(k, '')
|
||||
the_form+="<option value=\""+str(k)+"\" "+arr_selected[k]+">"+v+"</option>"
|
||||
|
||||
the_form+='</select>\n'
|
||||
|
||||
return the_form
|
||||
|
||||
0
paramecio/cromosoma/databases/__init__.py
Normal file
0
paramecio/cromosoma/databases/__init__.py
Normal file
75
paramecio/cromosoma/databases/mysql.py
Normal file
75
paramecio/cromosoma/databases/mysql.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import pymysql.cursors
|
||||
|
||||
class SqlClass:
|
||||
|
||||
error_connection=""
|
||||
connection={}
|
||||
|
||||
def dummy_connect(self, connection, name_connection="default"):
|
||||
pass
|
||||
|
||||
def connect_to_db(self, connection, name_connection="default"):
|
||||
|
||||
try:
|
||||
|
||||
self.connection[name_connection] = pymysql.connect(connection['host'],
|
||||
user=connection['user'],
|
||||
password=connection['password'],
|
||||
db=connection['db'],
|
||||
charset='utf8mb4',
|
||||
cursorclass=pymysql.cursors.DictCursor)
|
||||
|
||||
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
v = sys.exc_info()[1]
|
||||
|
||||
self.error_connection="Error in connection: %s %s" % (e, v)
|
||||
|
||||
#return False
|
||||
raise NameError(self.error_connection)
|
||||
|
||||
#Make def query more simple if not debugging.
|
||||
|
||||
def query(self, sql_query, arguments=[], name_connection="default"):
|
||||
|
||||
#if fetch_type=="ASSOC":
|
||||
#fetch_type=pymysql.cursors.DictCursor
|
||||
|
||||
with self.connection[name_connection].cursor(pymysql.cursors.DictCursor) as cursor:
|
||||
|
||||
try:
|
||||
|
||||
cursor.execute(sql_query, arguments)
|
||||
self.connection[name_connection].commit()
|
||||
|
||||
return cursor
|
||||
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
v = sys.exc_info()[1]
|
||||
|
||||
if hasattr(cursor, '_last_executed'):
|
||||
sql_query=cursor._last_executed
|
||||
|
||||
self.error_connection="Error in query ||"+sql_query+"||: %s %s" % (e, v)
|
||||
|
||||
#return False
|
||||
raise NameError(self.error_connection)
|
||||
|
||||
#Fetcho row return dictionary if is defined in query.
|
||||
|
||||
#def fetch(self, cursor):
|
||||
|
||||
#return cursor.fetchone()
|
||||
|
||||
def close(self, name_connection="default"):
|
||||
|
||||
self.connection[name_connection].close()
|
||||
|
||||
pass
|
||||
|
||||
|
||||
338
paramecio/cromosoma/dbadmin.py
Normal file
338
paramecio/cromosoma/dbadmin.py
Normal file
|
|
@ -0,0 +1,338 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import os,traceback
|
||||
import sys, inspect
|
||||
import shutil
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from colorama import init, Fore, Back, Style
|
||||
from importlib import import_module, reload
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
|
||||
#from models import books
|
||||
|
||||
def start():
|
||||
|
||||
parser = argparse.ArgumentParser(description='A tool for create tables in databases using models from Cromosoma')
|
||||
|
||||
parser.add_argument('--model', help='Model python path', required=True)
|
||||
|
||||
parser.add_argument('--config', help='The config file', required=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
init()
|
||||
|
||||
#Import config
|
||||
|
||||
config_file='config'
|
||||
|
||||
if args.config!=None:
|
||||
config_file=args.config
|
||||
|
||||
try:
|
||||
|
||||
config=import_module('settings.'+config_file)
|
||||
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
v = sys.exc_info()[1]
|
||||
|
||||
print(Fore.WHITE+Back.RED+Style.BRIGHT+"Config file not found: %s %s" % (e, v))
|
||||
|
||||
exit(1)
|
||||
|
||||
#print(WebModel.connections)
|
||||
|
||||
try:
|
||||
|
||||
model=import_module(args.model)
|
||||
|
||||
for name, obj in inspect.getmembers(sys.modules[model.__name__]):
|
||||
if inspect.isclass(obj):
|
||||
if obj.__module__==args.model and hasattr(obj, 'webmodel'):
|
||||
|
||||
WebModel.model[name.lower()]=obj()
|
||||
|
||||
|
||||
#WebModel.modelobj
|
||||
|
||||
except:
|
||||
"""
|
||||
e = sys.exc_info()[0]
|
||||
v = sys.exc_info()[1]
|
||||
|
||||
print(Fore.WHITE+Back.RED+Style.BRIGHT +"Error, file with model not found: %s %s" % (e, v))
|
||||
"""
|
||||
print("Exception in user code:")
|
||||
print("-"*60)
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
print("-"*60)
|
||||
|
||||
exit(1)
|
||||
|
||||
#load the table of databases
|
||||
|
||||
cursor=WebModel.query(WebModel, "show tables")
|
||||
|
||||
table_exists=[]
|
||||
|
||||
for row in cursor:
|
||||
table=list(row.values())[0]
|
||||
|
||||
if table in WebModel.model:
|
||||
table_exists.append(table)
|
||||
|
||||
#If don't want order
|
||||
#set([1,2,3,4]) - set([2,5])
|
||||
|
||||
tables=list(WebModel.model.keys())
|
||||
|
||||
#Array diff ordered
|
||||
|
||||
new_tables=[x for x in tables if x not in table_exists]
|
||||
|
||||
#If don't want order
|
||||
#new_tables=set(tables)-set(table_exists)
|
||||
|
||||
#Need order new_tables
|
||||
|
||||
changes=0
|
||||
|
||||
#Create new tables
|
||||
|
||||
if len(new_tables)>0:
|
||||
print(Style.BRIGHT+"Creating new tables...")
|
||||
|
||||
changes+=1
|
||||
|
||||
for table in new_tables:
|
||||
print(Style.NORMAL+"--Creating table "+table+"...")
|
||||
WebModel.query(WebModel, WebModel.model[table].create_table())
|
||||
print("--Adding indexes and constraints for the new table")
|
||||
|
||||
for k_field, index in WebModel.arr_sql_index[table].items():
|
||||
print("---Added index to "+k_field)
|
||||
WebModel.query(WebModel, index)
|
||||
|
||||
for k_set, index_set in WebModel.arr_sql_set_index[table].items():
|
||||
|
||||
if index_set!="":
|
||||
WebModel.query(WebModel, index_set)
|
||||
print("---Added constraint to "+k_set)
|
||||
|
||||
print("--Adding uniques elements for the new table")
|
||||
|
||||
#See if changes exists
|
||||
|
||||
#Check if created tables are modified.
|
||||
|
||||
try:
|
||||
|
||||
model_old=import_module('backups.'+args.model)
|
||||
|
||||
for name, obj in inspect.getmembers(sys.modules[model_old.__name__]):
|
||||
if inspect.isclass(obj):
|
||||
if obj.__module__=='backups.'+args.model and hasattr(obj, 'webmodel'):
|
||||
|
||||
WebModel.model['old_'+name.lower()]=obj()
|
||||
|
||||
print(Style.BRIGHT+"Checking old versions of model for find changes...")
|
||||
|
||||
for table in tables:
|
||||
#WebModel.query(WebModel, "")
|
||||
#Check if new table
|
||||
|
||||
#fields_to_add, fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, fields_to_delete_index, fields_to_delete_unique, fields_to_delete_constraint, fields_to_delete
|
||||
|
||||
fields_to_add=[]
|
||||
fields_to_modify=[]
|
||||
fields_to_add_index=[]
|
||||
fields_to_add_constraint=[]
|
||||
fields_to_add_unique=[]
|
||||
fields_to_delete_index=[]
|
||||
fields_to_delete_unique=[]
|
||||
fields_to_delete_constraint=[]
|
||||
fields_to_delete=[]
|
||||
|
||||
old_table='old_'+table
|
||||
|
||||
for f, v in WebModel.model[table].fields.items():
|
||||
|
||||
if not f in WebModel.model[old_table].fields:
|
||||
|
||||
fields_to_add.append(f)
|
||||
|
||||
#Add index
|
||||
|
||||
if v.indexed==True:
|
||||
|
||||
fields_to_add_index.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
#Add unique
|
||||
|
||||
if v.unique==True:
|
||||
|
||||
fields_to_add_unique.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
#Add constraint
|
||||
|
||||
if v.foreignkey==True:
|
||||
|
||||
fields_to_add_constraint.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
changes+=1
|
||||
|
||||
#If exists field in old webmodel and new
|
||||
|
||||
else:
|
||||
|
||||
v_old=WebModel.model[old_table].fields[f]
|
||||
|
||||
if v.get_type_sql()!=v_old.get_type_sql():
|
||||
|
||||
fields_to_modify.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
#Add index
|
||||
|
||||
if v.indexed==True and v_old.indexed==False:
|
||||
|
||||
fields_to_add_index.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
if v.indexed==False and v_old.indexed==True:
|
||||
|
||||
fields_to_delete_index.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
#Add unique
|
||||
|
||||
if v.unique==True and v_old.unique==False:
|
||||
|
||||
fields_to_add_unique.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
if v.unique==False and v_old.unique==True:
|
||||
|
||||
fields_to_delete_unique.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
#Add constraint
|
||||
|
||||
if v.foreignkey==True and v_old.foreignkey==False:
|
||||
|
||||
fields_to_add_constraint.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
if v.foreignkey==False and v_old.foreignkey==True:
|
||||
|
||||
fields_to_delete_constraint.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
for f, v in WebModel.model[old_table].fields.items():
|
||||
|
||||
if not f in WebModel.model[table].fields:
|
||||
|
||||
#Add constraint
|
||||
|
||||
if v.foreignkey==True:
|
||||
|
||||
fields_to_delete_constraint.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
fields_to_delete.append(f)
|
||||
|
||||
changes+=1
|
||||
|
||||
WebModel.model[table].update_table(fields_to_add, fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, fields_to_delete_index, fields_to_delete_unique, fields_to_delete_constraint, fields_to_delete)
|
||||
|
||||
#for field_update in arr_update:
|
||||
|
||||
|
||||
#Make a for in fields, if the field not exist in old model, create, if is not same type, recreate. If no have index now, delete index, if is a new index, create, same thing with uniques
|
||||
|
||||
#for field in WebModel.model
|
||||
|
||||
except ImportError:
|
||||
|
||||
pass
|
||||
|
||||
except:
|
||||
|
||||
print("Exception in user code:")
|
||||
print("-"*60)
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
print("-"*60)
|
||||
|
||||
exit(1)
|
||||
|
||||
original_file_path=args.model.replace('.', '/')+'.py'
|
||||
|
||||
backup_path='backups/'+original_file_path
|
||||
|
||||
if changes>0:
|
||||
print(Style.BRIGHT+"Creating backup of the model. WARNING: DON'T DELETE BACKUPS DIRECTORY IF YOU WANT MAKE CHANGES IN THE FUTURE WITHOUT MODIFY DIRECTLY THE DATABASE")
|
||||
|
||||
create_backup(original_file_path, backup_path)
|
||||
|
||||
else:
|
||||
if not os.path.isfile(backup_path):
|
||||
create_backup(original_file_path, backup_path)
|
||||
|
||||
|
||||
print(Style.BRIGHT+"All tasks finished")
|
||||
|
||||
def create_backup(original_file_path, file_path):
|
||||
|
||||
#Create copy
|
||||
|
||||
path=os.path.dirname(file_path)
|
||||
|
||||
p=Path(path)
|
||||
|
||||
if not p.is_dir():
|
||||
p.mkdir(0o755, True)
|
||||
|
||||
#Create path
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
today = date.today()
|
||||
shutil.copy(file_path, file_path+'.'+today.strftime("%Y%M%d%H%M%S"))
|
||||
|
||||
new_file=""
|
||||
|
||||
f=open(original_file_path)
|
||||
|
||||
for line in f:
|
||||
"""
|
||||
new_line=line.replace("model[\"", "model[\"old_")
|
||||
new_line=new_line.replace("model['", "model['old_")
|
||||
|
||||
new_line=new_line.replace("WebModel(\"", "WebModel(\"old_")
|
||||
new_line=new_line.replace("WebModel('", "WebModel('old_")
|
||||
"""
|
||||
new_file+=line
|
||||
|
||||
f.close()
|
||||
|
||||
f=open(file_path, 'w')
|
||||
|
||||
f.write(new_file)
|
||||
|
||||
f.close()
|
||||
0
paramecio/cromosoma/extrafields/__init__.py
Normal file
0
paramecio/cromosoma/extrafields/__init__.py
Normal file
18
paramecio/cromosoma/extrafields/emailfield.py
Normal file
18
paramecio/cromosoma/extrafields/emailfield.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from paramecio.cromosoma.corefields import CharField
|
||||
import re
|
||||
|
||||
mail_pattern=re.compile("\w[\w\.-]*@\w[\w\.-]+\.\w+")
|
||||
|
||||
class EmailField(CharField):
|
||||
|
||||
def check(self, value):
|
||||
|
||||
self.error=False
|
||||
self.txt_error=''
|
||||
|
||||
if not mail_pattern.match(value):
|
||||
|
||||
self.error=True
|
||||
self.txt_error='No valid format'
|
||||
|
||||
return value
|
||||
49
paramecio/cromosoma/extrafields/passwordfield.py
Normal file
49
paramecio/cromosoma/extrafields/passwordfield.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
from paramecio.cromosoma.corefields import PhangoField
|
||||
from paramecio.cromosoma.coreforms import PasswordForm
|
||||
from passlib.hash import bcrypt
|
||||
|
||||
class PasswordField(PhangoField):
|
||||
|
||||
def __init__(self, name, size=255, required=False):
|
||||
|
||||
super(PasswordField, self).__init__(name, size, required)
|
||||
self.protected=True
|
||||
self.name_form=PasswordForm
|
||||
self.default_value=''
|
||||
|
||||
def check(self, value):
|
||||
|
||||
self.txt_error=''
|
||||
self.error=False
|
||||
|
||||
value.strip()
|
||||
|
||||
if value=='':
|
||||
|
||||
if self.model!=None:
|
||||
|
||||
if self.model.updated==True:
|
||||
self.required=False
|
||||
self.check_blank=True
|
||||
return ""
|
||||
else:
|
||||
|
||||
self.txt_error="The value is empty"
|
||||
self.error=True
|
||||
|
||||
else:
|
||||
self.txt_error="The value is empty"
|
||||
self.error=True
|
||||
|
||||
else:
|
||||
value = bcrypt.encrypt(value)
|
||||
|
||||
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def verify( password, h):
|
||||
|
||||
return bcrypt.verify(password, h)
|
||||
|
||||
|
||||
42
paramecio/cromosoma/formsutils.py
Normal file
42
paramecio/cromosoma/formsutils.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.cromosoma import corefields
|
||||
from bottle import request
|
||||
|
||||
def pass_values_to_form(post, arr_form, yes_error=True):
|
||||
|
||||
for key, value in arr_form.items():
|
||||
post[key]=post.get(key, '')
|
||||
|
||||
arr_form[key].default_value=post[key]
|
||||
|
||||
if arr_form[key].field==None:
|
||||
arr_form[key].field=corefields.CharField(key, 255, required=False)
|
||||
|
||||
# Recheck value if no set error field
|
||||
if arr_form[key].field.error == None:
|
||||
arr_form[key].field.check(post[key])
|
||||
|
||||
arr_form[key].txt_error=""
|
||||
|
||||
if arr_form[key].required==True and arr_form[key].field.error==True and yes_error==True:
|
||||
arr_form[key].txt_error=arr_form[key].field.txt_error
|
||||
|
||||
# Reset error on field.
|
||||
|
||||
arr_form[key].field.error=None
|
||||
|
||||
return arr_form
|
||||
|
||||
def show_form(post, arr_form, t, yes_error=True, modelform_tpl='forms/modelform.phtml'):
|
||||
|
||||
pass_values_to_form(post, arr_form, yes_error)
|
||||
|
||||
return t.load_template(modelform_tpl, forms=arr_form)
|
||||
|
||||
#Function for initial values for necessary fields.
|
||||
|
||||
def ini_fields(fields):
|
||||
pass
|
||||
|
||||
|
||||
136
paramecio/cromosoma/usermodel.py
Normal file
136
paramecio/cromosoma/usermodel.py
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma.coreforms import PasswordForm
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
|
||||
class UserModel(WebModel):
|
||||
|
||||
def __init__(self, name_field_id="id"):
|
||||
|
||||
super().__init__(name_field_id)
|
||||
|
||||
self.password_field='password'
|
||||
self.email_field='email'
|
||||
self.username_field='username'
|
||||
self.yes_repeat_password=True
|
||||
|
||||
def create_forms(self, arr_fields={}):
|
||||
|
||||
# Add password_repeat to forms from the model
|
||||
|
||||
super().create_forms(arr_fields)
|
||||
|
||||
if self.password_field in arr_fields and self.yes_repeat_password:
|
||||
|
||||
repeat_password=PasswordForm('repeat_password', '')
|
||||
|
||||
repeat_password.required=1
|
||||
|
||||
repeat_password.label=I18n.lang('common', 'repeat_password', 'Repeat Password')
|
||||
|
||||
repeat_password.field=self.fields['password']
|
||||
|
||||
self.create_form_after(self.password_field, repeat_password)
|
||||
"""
|
||||
def insert(self, dict_values, external_agent=True):
|
||||
|
||||
if 'password' in dict_values:
|
||||
|
||||
dict_values['repeat_password']=dict_values.get('repeat_password', '')
|
||||
|
||||
if dict_values['repeat_password']!=dict_values[self.password_field]:
|
||||
self.fields[self.password_field].error=True
|
||||
self.fields['password'].txt_error=I18n.lang('common', 'error_passwords_no_match', 'Error: passwords doesn\'t match')
|
||||
|
||||
return super().insert(dict_values, external_agent)
|
||||
"""
|
||||
|
||||
def check_all_fields(self, dict_values, external_agent, yes_update=False, errors_set="insert"):
|
||||
|
||||
try:
|
||||
|
||||
fields, values, update_values=super().check_all_fields(dict_values, external_agent, yes_update, errors_set)
|
||||
except:
|
||||
|
||||
return False
|
||||
|
||||
# Check if passwords matches
|
||||
|
||||
if self.password_field in dict_values:
|
||||
|
||||
dict_values['repeat_password']=dict_values.get('repeat_password', '')
|
||||
|
||||
if dict_values['repeat_password']!=dict_values[self.password_field]:
|
||||
|
||||
if dict_values[self.password_field].strip()!="":
|
||||
|
||||
self.fields[self.password_field].error=True
|
||||
self.fields[self.password_field].txt_error=I18n.lang('common', 'error_passwords_no_match', 'Error: passwords doesn\'t match')
|
||||
|
||||
return False
|
||||
|
||||
# Check if exists user with same email or password
|
||||
|
||||
get_id=0
|
||||
|
||||
if self.updated:
|
||||
# Need the id
|
||||
GetPostFiles.obtain_get()
|
||||
GetPostFiles.obtain_post()
|
||||
|
||||
get_id=GetPostFiles.get.get(self.name_field_id, '0')
|
||||
|
||||
post_id=GetPostFiles.post.get(self.name_field_id, '0')
|
||||
|
||||
if get_id!='0':
|
||||
get_id=int(get_id)
|
||||
|
||||
if post_id!='0':
|
||||
get_id=int(post_id)
|
||||
|
||||
pass
|
||||
|
||||
sql_id=''
|
||||
|
||||
original_conditions=self.conditions
|
||||
|
||||
self.reset_conditions()
|
||||
|
||||
if self.username_field in dict_values:
|
||||
|
||||
self.conditions=['WHERE (username=%s', [dict_values[self.username_field]]]
|
||||
|
||||
|
||||
if self.email_field in dict_values:
|
||||
|
||||
if len(self.conditions[1])>0:
|
||||
|
||||
self.conditions[0]+=' OR email=%s)'
|
||||
else:
|
||||
self.conditions[0]='WHERE (email=%s)'
|
||||
self.conditions[1]=[]
|
||||
|
||||
self.conditions[1].append([dict_values[self.email_field]])
|
||||
|
||||
if get_id>0:
|
||||
self.conditions[0]+=' AND '+self.name_field_id+'!=%s'
|
||||
self.conditions[1].append(get_id)
|
||||
|
||||
|
||||
if self.select_count()>0:
|
||||
|
||||
self.fields[self.username_field].error=True
|
||||
self.fields[self.username_field].txt_error=I18n.lang('common', 'error_username_or_password_exists', 'Error: username or email exists in database')
|
||||
|
||||
return False
|
||||
|
||||
self.conditions=original_conditions
|
||||
|
||||
return fields, values, update_values
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
913
paramecio/cromosoma/webmodel.py
Normal file
913
paramecio/cromosoma/webmodel.py
Normal file
|
|
@ -0,0 +1,913 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import re
|
||||
import uuid
|
||||
from importlib import import_module, reload
|
||||
from collections import OrderedDict
|
||||
from paramecio.cromosoma.databases.mysql import SqlClass
|
||||
from paramecio.cromosoma.coreforms import BaseForm, HiddenForm
|
||||
|
||||
# The most important class for the framework
|
||||
#
|
||||
# Webmodel is a class for create objects that represent models. This models are a mirage of SQL tables. You can create fields, add indexes, foreign keys, and more.
|
||||
#
|
||||
#
|
||||
|
||||
class WebModel:
|
||||
|
||||
#Globals class variables for internal tasks
|
||||
|
||||
arr_sql_index={}
|
||||
arr_sql_set_index={}
|
||||
arr_sql_unique={}
|
||||
arr_sql_set_unique={}
|
||||
last_query=""
|
||||
|
||||
make_connection=SqlClass.connect_to_db
|
||||
|
||||
#A dictionary for add models here
|
||||
|
||||
model=OrderedDict()
|
||||
|
||||
connections={'default': {'host': 'localhost', 'user': 'user', 'password': '', 'db': 'default', 'charset': 'utf8', 'set_connection': False} }
|
||||
|
||||
connection_id="default"
|
||||
|
||||
webmodel=True
|
||||
|
||||
# Init the class
|
||||
|
||||
def __init__(self, name_field_id="id"):
|
||||
|
||||
#The name of the table
|
||||
|
||||
self.name=type(self).__name__.lower()
|
||||
|
||||
self.label=self.name
|
||||
|
||||
self.label_general=self.name
|
||||
|
||||
self.name_field_id=name_field_id
|
||||
|
||||
#Fields of the table, inserte with register method
|
||||
|
||||
self.fields=OrderedDict()
|
||||
|
||||
#The tables related with foreignkeyfield to this table
|
||||
|
||||
self.related=[]
|
||||
|
||||
#A dictionary where forms of this model are saved
|
||||
|
||||
self.forms=OrderedDict()
|
||||
|
||||
self.cache_method=''
|
||||
|
||||
# A dictionary with the errors in fields.
|
||||
|
||||
self.fields_errors={}
|
||||
|
||||
self.errors={}
|
||||
|
||||
self.num_errors=0
|
||||
|
||||
self.query_error=""
|
||||
|
||||
self.conditions=["WHERE 1=1", []]
|
||||
|
||||
self.order_by="ORDER BY `"+self.name+"`.`id` ASC"
|
||||
|
||||
self.limit=""
|
||||
|
||||
self.related_models_deleted=[]
|
||||
|
||||
self.required_save={}
|
||||
|
||||
#Create id field
|
||||
self.register(PrimaryKeyField(self.name_field_id))
|
||||
|
||||
#self.model[name]=self
|
||||
|
||||
self.yes_reset_conditions=True
|
||||
|
||||
self.create_fields()
|
||||
|
||||
self.updated=False
|
||||
|
||||
self.valid_fields=[]
|
||||
|
||||
self.last_id=0
|
||||
|
||||
# A method where create the new fields of this model
|
||||
|
||||
def create_fields(self):
|
||||
|
||||
pass
|
||||
|
||||
# A method for register the fields
|
||||
|
||||
def register(self, field_model):
|
||||
|
||||
#self.fields_required[field_model]=field_model.required
|
||||
|
||||
self.fields[field_model.name]=field_model
|
||||
|
||||
self.fields[field_model.name].model=self
|
||||
|
||||
# A method for create the id field.
|
||||
|
||||
def create_id_field(self, field_name="id"):
|
||||
pass
|
||||
|
||||
# A method for select rows from a database.
|
||||
|
||||
def connect_to_db(self):
|
||||
|
||||
if WebModel.make_connection(SqlClass, self.connections[self.connection_id])==False:
|
||||
raise NameError(SqlClass.error_connection)
|
||||
|
||||
WebModel.make_connection=SqlClass.dummy_connect
|
||||
|
||||
def dummy_connect(self, connection):
|
||||
return True
|
||||
|
||||
# Static method for make queries
|
||||
@staticmethod
|
||||
def query(WebModel, str_query, args=[], connection_id='default'):
|
||||
WebModel.connect_to_db(WebModel)
|
||||
return SqlClass.query(SqlClass, str_query, args, connection_id)
|
||||
|
||||
# Insert method, for insert a row in database.using a dictionary
|
||||
# External agent define if the update is in code or from external source, how a form.
|
||||
|
||||
def insert(self, dict_values, external_agent=True):
|
||||
|
||||
# Connect to db
|
||||
|
||||
self.connect_to_db()
|
||||
|
||||
self.query_error=''
|
||||
|
||||
self.fields[self.name_field_id].required=False
|
||||
|
||||
try:
|
||||
|
||||
fields, values, update_values=self.check_all_fields(dict_values, external_agent)
|
||||
|
||||
except:
|
||||
self.query_error='Cannot insert the new row'
|
||||
|
||||
return False
|
||||
|
||||
sql="insert into `"+self.name+"` (`"+"`, `".join(fields)+"`) VALUES ("+", ".join(values)+")"
|
||||
|
||||
cursor=SqlClass.query(SqlClass, sql, self.conditions[1], self.connection_id)
|
||||
|
||||
if cursor.rowcount>0:
|
||||
|
||||
self.last_id=cursor.lastrowid
|
||||
|
||||
return True
|
||||
else:
|
||||
self.query_error='Cannot insert the new row'
|
||||
return False
|
||||
|
||||
# Update method. For update one or many rows.
|
||||
|
||||
def update(self, dict_values, external_agent=True):
|
||||
|
||||
# Connect to db
|
||||
|
||||
self.fields[self.name_field_id].required=False
|
||||
|
||||
if self.name_field_id in dict_values:
|
||||
del dict_values[self.name_field_id]
|
||||
|
||||
self.connect_to_db()
|
||||
|
||||
self.query_error=''
|
||||
|
||||
#try:
|
||||
self.updated=True
|
||||
|
||||
try:
|
||||
|
||||
fields, values, update_values=self.check_all_fields(dict_values, external_agent, True, 'update')
|
||||
|
||||
except:
|
||||
return False
|
||||
|
||||
sql="update `"+self.name+"` SET "+", ".join(update_values)+" "+self.conditions[0]
|
||||
|
||||
cursor=SqlClass.query(SqlClass, sql, self.conditions[1], self.connection_id)
|
||||
|
||||
if self.yes_reset_conditions:
|
||||
self.reset_conditions()
|
||||
|
||||
return True
|
||||
|
||||
"""
|
||||
if cursor.rowcount>0:
|
||||
|
||||
if self.yes_reset_conditions:
|
||||
self.reset_conditions()
|
||||
|
||||
return True
|
||||
|
||||
else:
|
||||
|
||||
self.query_error='Cannot update the row'
|
||||
|
||||
return False
|
||||
"""
|
||||
"""
|
||||
except:
|
||||
|
||||
#self.query_error=SqlClass.error_connection
|
||||
e = sys.exc_info()[0]
|
||||
v = sys.exc_info()[1]
|
||||
|
||||
self.error_connection="Error in query: %s %s" % (e, v)
|
||||
|
||||
return False
|
||||
"""
|
||||
|
||||
def reset_conditions(self):
|
||||
|
||||
self.conditions=["WHERE 1=1", []]
|
||||
|
||||
|
||||
# A method for select fields from a table in db. Support for foreignkeys.
|
||||
#Type assoc can be assoc for return dictionaries
|
||||
|
||||
def select(self, arr_select=[], raw_query=0):
|
||||
|
||||
# Connect to db
|
||||
|
||||
self.connect_to_db()
|
||||
|
||||
conditions=self.conditions
|
||||
|
||||
final_fields=[]
|
||||
|
||||
extra_fields=[]
|
||||
|
||||
self.query_error=''
|
||||
|
||||
#First table selecction
|
||||
|
||||
tables_to_select=['`'+self.name+'`']
|
||||
|
||||
keys=list(self.fields.keys())
|
||||
|
||||
if len(arr_select)==0:
|
||||
arr_select=keys
|
||||
|
||||
# Array intersect for obtain the valid fields
|
||||
|
||||
fields = list(set(keys) & set(arr_select))
|
||||
|
||||
#Creating the fields
|
||||
|
||||
for field in fields:
|
||||
|
||||
#Check if foreignkeyfield
|
||||
|
||||
if type(self.fields[field]).__name__=="ForeignKeyField" and raw_query==0:
|
||||
|
||||
table_name=self.fields[field].table_name
|
||||
|
||||
tables_to_select.append('`'+table_name+'`')
|
||||
|
||||
# Add field from related table
|
||||
# as "+table_name+"_"+self.fields[field].named_field
|
||||
extra_fields.append("`"+table_name+"`.`"+self.fields[field].named_field+"` as "+field)
|
||||
|
||||
# Add a condition to sql query for join the two tables.
|
||||
|
||||
conditions[0]+=" AND `"+table_name+"`.`"+self.fields[field].identifier_field+"`=`"+self.name+"`.`"+field+"`"
|
||||
|
||||
# Add extra fields from related table from select_fields ForeignKeyField class member
|
||||
|
||||
for extra_field in self.fields[field].select_fields:
|
||||
|
||||
extra_fields.append("`"+table_name+"`.`"+extra_field+"` as `"+table_name+"_"+extra_field+"`")
|
||||
else:
|
||||
# Add normal field to sql query
|
||||
|
||||
final_fields.append("`"+self.name+"`.`"+field+"`")
|
||||
|
||||
extra_sql_field=""
|
||||
|
||||
if len(extra_fields)>0:
|
||||
|
||||
extra_sql_field=", "+", ".join(extra_fields)
|
||||
|
||||
if len(final_fields)==0:
|
||||
self.query_error="Error: without fields to search"
|
||||
return False
|
||||
|
||||
sql= ("select "+", ".join(final_fields)+extra_sql_field+" from "+", ".join(tables_to_select)+' '+conditions[0]+' '+self.order_by+' '+self.limit).strip()
|
||||
|
||||
self.last_query=sql
|
||||
|
||||
if self.yes_reset_conditions:
|
||||
self.reset_conditions()
|
||||
|
||||
cursor=SqlClass.query(SqlClass, sql, conditions[1], self.connection_id)
|
||||
|
||||
if cursor==False:
|
||||
self.query_error=SqlClass.error_connection
|
||||
return False
|
||||
else:
|
||||
return cursor
|
||||
|
||||
# Show results in a dictionary
|
||||
|
||||
def fetch(self, cursor):
|
||||
|
||||
return cursor.fetchone()
|
||||
|
||||
def insert_id(self):
|
||||
|
||||
return self.last_id
|
||||
|
||||
def element_exists(self, id):
|
||||
|
||||
self.conditions=['WHERE `'+self.name_field_id+'`=%s', [id]]
|
||||
|
||||
count=self.select_count(self.name_field_id)
|
||||
|
||||
if self.yes_reset_conditions:
|
||||
self.reset_conditions()
|
||||
|
||||
if count>0:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def select_a_field(self, field):
|
||||
pass
|
||||
|
||||
def select_a_row(self, id, fields_selected=[], raw_query=0):
|
||||
|
||||
self.conditions=['WHERE `'+self.name+'`.`'+self.name_field_id+'`=%s', [id]]
|
||||
|
||||
self.limit="limit 1"
|
||||
|
||||
cursor=self.select(fields_selected, raw_query)
|
||||
|
||||
self.reset_conditions()
|
||||
|
||||
row=cursor.fetchone()
|
||||
|
||||
if row==None:
|
||||
row=False
|
||||
|
||||
return row
|
||||
|
||||
def select_a_row_where(self, fields_selected=[], raw_query=0):
|
||||
|
||||
self.limit="limit 1"
|
||||
|
||||
cursor=self.select(fields_selected, raw_query)
|
||||
|
||||
row=cursor.fetchone()
|
||||
|
||||
if row==None:
|
||||
row=False
|
||||
|
||||
return row
|
||||
|
||||
|
||||
def select_to_array(self, fields_selected=[], raw_query=0):
|
||||
|
||||
if len(fields_selected)==0:
|
||||
fields_selected=self.fields.keys()
|
||||
|
||||
if (self.name_field_id not in fields_selected):
|
||||
fields_selected.append(self.name_field_id)
|
||||
def del_row_id(row):
|
||||
del row[self.name_field_id]
|
||||
else:
|
||||
def del_row_id(row):
|
||||
pass
|
||||
|
||||
cursor=self.select(fields_selected, raw_query)
|
||||
|
||||
results={}
|
||||
|
||||
for row in cursor:
|
||||
|
||||
results[row[self.name_field_id]]=row
|
||||
del_row_id(results[row[self.name_field_id]])
|
||||
|
||||
return results
|
||||
|
||||
|
||||
# A method por count num rows affected for sql conditions
|
||||
|
||||
def select_count(self, field_to_count='id', raw_query=1):
|
||||
|
||||
# Connect to db
|
||||
|
||||
self.connect_to_db()
|
||||
|
||||
conditions=self.conditions
|
||||
|
||||
#First table selecction
|
||||
|
||||
tables_to_select=['`'+self.name+'`']
|
||||
|
||||
fields=list(self.fields.keys())
|
||||
|
||||
#Creating the fields
|
||||
|
||||
for field in fields:
|
||||
|
||||
#Check if foreignkeyfield
|
||||
|
||||
if type(self.fields[field]).__name__=="ForeignKeyField" and raw_query==0:
|
||||
|
||||
table_name=self.fields[field].table_name
|
||||
|
||||
tables_to_select.append('`'+table_name+'`')
|
||||
|
||||
# Add a condition to sql query for join the two tables.
|
||||
|
||||
conditions[0]+=" AND `"+table_name+"`.`"+self.fields[field].identifier_field+"`=`"+self.name+"`.`"+field+"`"
|
||||
|
||||
sql= "select count(`"+field_to_count+"`) from "+", ".join(tables_to_select)+conditions[0]
|
||||
|
||||
cursor=SqlClass.query(SqlClass, sql, conditions[1], self.connection_id)
|
||||
|
||||
count=list(cursor.fetchone().values())[0]
|
||||
|
||||
if self.yes_reset_conditions:
|
||||
self.reset_conditions()
|
||||
|
||||
return count
|
||||
|
||||
#+' ORDER BY '+self.order_by+' '+self.limit).strip()
|
||||
|
||||
# A method for delete rows using sql conditions
|
||||
|
||||
def delete(self):
|
||||
|
||||
self.connect_to_db()
|
||||
|
||||
#Need delete rows from other related tables save in self.related_models_deleted
|
||||
|
||||
sql="delete from `"+self.name+"` "+self.conditions[0]
|
||||
|
||||
result=SqlClass.query(SqlClass, sql, self.conditions[1], self.connection_id)
|
||||
|
||||
if self.yes_reset_conditions:
|
||||
self.reset_conditions()
|
||||
|
||||
if result.rowcount>0:
|
||||
|
||||
return True
|
||||
else:
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# Method for create sql tables
|
||||
|
||||
def create_table(self):
|
||||
|
||||
#self.connect_to_db()
|
||||
|
||||
self.arr_sql_index[self.name]={}
|
||||
self.arr_sql_set_index[self.name]={}
|
||||
self.arr_sql_unique[self.name]={}
|
||||
self.arr_sql_set_unique[self.name]={}
|
||||
|
||||
#foreach($this->components as $field => $data)
|
||||
table_fields=[]
|
||||
|
||||
#Create id field
|
||||
#Not neccesary
|
||||
#table_fields.append('`'+self.name_field_id+"` INT NOT NULL PRIMARY KEY AUTO_INCREMENT")
|
||||
|
||||
for field, data in self.fields.items():
|
||||
|
||||
table_fields.append('`'+field+'` '+data.get_type_sql())
|
||||
|
||||
#Check if indexed
|
||||
|
||||
if self.fields[field].indexed==True:
|
||||
|
||||
self.arr_sql_index[self.name][field]='CREATE INDEX `index_'+self.name+'_'+field+'` ON '+self.name+'(`'+field+'`);'
|
||||
self.arr_sql_set_index[self.name][field]=""
|
||||
|
||||
|
||||
#Check if unique
|
||||
|
||||
if self.fields[field].unique==True:
|
||||
|
||||
self.arr_sql_unique[self.name][field]='ALTER TABLE `'+self.name+'` ADD UNIQUE (`'+field+'`)'
|
||||
self.arr_sql_set_unique[self.name][field]=""
|
||||
|
||||
if type(self.fields[field]).__name__=="ForeignKeyField":
|
||||
|
||||
self.arr_sql_index[self.name][field]='CREATE INDEX `index_'+self.name+'_'+field+'` ON '+self.name+'(`'+field+'`);'
|
||||
|
||||
table_related=self.fields[field].table_name
|
||||
|
||||
id_table_related=self.fields[field].table_id
|
||||
|
||||
self.arr_sql_set_index[self.name][field]='ALTER TABLE `'+self.name+'` ADD CONSTRAINT `'+field+'_'+self.name+'IDX` FOREIGN KEY ( `'+field+'` ) REFERENCES `'+table_related+'` (`'+id_table_related+'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'
|
||||
|
||||
return "create table `"+self.name+"` (\n"+",\n".join(table_fields)+"\n) DEFAULT CHARSET=utf8;";
|
||||
|
||||
def update_table(self, fields_to_add, fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, fields_to_delete_index, fields_to_delete_unique, fields_to_delete_constraint, fields_to_delete):
|
||||
|
||||
#Obtain new fields
|
||||
|
||||
for field in fields_to_modify:
|
||||
print("---Updating "+field+" in "+self.name)
|
||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` MODIFY `'+field+'` '+self.fields[field].get_type_sql(), [], self.connection_id)
|
||||
|
||||
for field in fields_to_add:
|
||||
print("---Adding "+field+" in "+self.name)
|
||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` ADD `'+field+'` '+self.fields[field].get_type_sql(), [], self.connection_id)
|
||||
|
||||
for field in fields_to_add_index:
|
||||
print("---Adding index to "+field+" in "+self.name)
|
||||
WebModel.query(WebModel, 'CREATE INDEX `index_'+self.name+'_'+field+'` ON '+self.name+' (`'+field+'`);', [], self.connection_id)
|
||||
|
||||
for field in fields_to_add_constraint:
|
||||
|
||||
print("---Adding foreign key to "+field+" in "+self.name)
|
||||
|
||||
table_related=self.fields[field].table_name
|
||||
|
||||
id_table_related=self.fields[field].table_id
|
||||
|
||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` ADD CONSTRAINT `'+field+'_'+self.name+'IDX` FOREIGN KEY ( `'+field+'` ) REFERENCES `'+table_related+'` (`'+id_table_related+'`) ON DELETE RESTRICT ON UPDATE RESTRICT;', [], self.connection_id)
|
||||
|
||||
for field in fields_to_add_unique:
|
||||
|
||||
print("---Adding unique to "+field+" in "+self.name)
|
||||
|
||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` ADD UNIQUE (`'+field+'`)', [], self.connection_id)
|
||||
|
||||
for field in fields_to_delete_index:
|
||||
|
||||
print("---Deleting index from "+field+" in "+self.name)
|
||||
|
||||
WebModel.query(WebModel, 'DROP INDEX `index_'+self.name+'_'+field+'` ON '+self.name, [], self.connection_id)
|
||||
|
||||
for field in fields_to_delete_unique:
|
||||
|
||||
print("---Deleting unique from "+field+" in "+self.name)
|
||||
|
||||
WebModel.query(WebModel, 'DROP INDEX `'+field+'` ON '+self.name, [], self.connection_id)
|
||||
|
||||
for field in fields_to_delete_constraint:
|
||||
|
||||
print("---Deleting foreignkey from "+field+" in "+self.name)
|
||||
|
||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` DROP FOREIGN KEY '+field+'_'+self.name+'IDX', [], self.connection_id)
|
||||
|
||||
for field in fields_to_delete:
|
||||
|
||||
print("---Deleting "+field+" from "+self.name)
|
||||
|
||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` DROP `'+field+'`', [], self.connection_id)
|
||||
#Deleting indexes and constraints.
|
||||
|
||||
# Method for drop sql tables and related
|
||||
|
||||
def drop(self):
|
||||
return WebModel.query(WebModel, 'DROP TABLE '+self.name, [], self.connection_id)
|
||||
|
||||
#Return an array with all fields
|
||||
|
||||
def all_fields():
|
||||
pass
|
||||
|
||||
#Check of all fields in table.
|
||||
|
||||
def check_all_fields(self, dict_values, external_agent, yes_update=False, errors_set="insert"):
|
||||
|
||||
fields=[]
|
||||
values=[]
|
||||
update_values=[]
|
||||
self.errors[errors_set]=[]
|
||||
self.num_errors=0
|
||||
#A dictionary that define if update property is added
|
||||
|
||||
updated_field={}
|
||||
updated_field['insert']=0
|
||||
updated_field['update']=1
|
||||
|
||||
|
||||
error=False
|
||||
|
||||
if yes_update==True:
|
||||
f_update=lambda field, value: "`"+field+"`="+value+""
|
||||
else:
|
||||
f_update=lambda field, value: ""
|
||||
|
||||
# I can optimize this later
|
||||
|
||||
for k, v in self.fields.items():
|
||||
|
||||
#List where the errors are saved
|
||||
|
||||
self.fields_errors[k]=[]
|
||||
|
||||
if k in dict_values:
|
||||
|
||||
# If fields is protected, but external_agent =0, then insert
|
||||
# If fields is not protected always insert if not error checking
|
||||
|
||||
value=dict_values[k]
|
||||
|
||||
# Need rewrite the error because shitty python don't clean nothing
|
||||
|
||||
self.fields[k].error=False
|
||||
|
||||
if (self.fields[k].protected==None or self.fields[k].protected==False or external_agent==False) and k in self.valid_fields:
|
||||
|
||||
self.fields[k].update=updated_field[errors_set]
|
||||
|
||||
value=self.fields[k].check(value)
|
||||
|
||||
if self.fields[k].check_blank==False or self.updated==False:
|
||||
|
||||
# If error checking, value=False
|
||||
|
||||
if self.fields[k].error==True and self.fields[k].required==True:
|
||||
|
||||
#Error, need this fields.
|
||||
self.num_errors+=1
|
||||
|
||||
self.fields_errors[k].append("Error: "+v.label+" field required")
|
||||
|
||||
error=True
|
||||
|
||||
else:
|
||||
|
||||
fields.append(k)
|
||||
|
||||
final_value=self.fields[k].quot_open+value+self.fields[k].quot_close
|
||||
|
||||
values.append(final_value)
|
||||
|
||||
update_values.append(f_update(k, final_value))
|
||||
|
||||
else:
|
||||
self.num_errors+=1
|
||||
|
||||
self.fields_errors[k].append("Error: "+self.fields[k].label+" is protected field")
|
||||
self.fields[k].error=True
|
||||
self.fields[k].txt_error="Error: "+self.fields[k].label+" is protected field"
|
||||
error=True
|
||||
|
||||
elif v.required==True:
|
||||
|
||||
self.num_errors+=1
|
||||
|
||||
self.fields_errors[k].append("Error: "+v.label+" field required")
|
||||
error=True
|
||||
|
||||
if len(fields)==0:
|
||||
|
||||
self.num_errors+=1
|
||||
|
||||
self.errors[errors_set].append("Error: no elements to insert in table")
|
||||
|
||||
error=True
|
||||
|
||||
if error==True:
|
||||
|
||||
self.num_errors+=1
|
||||
|
||||
self.errors[errors_set].append("Error: error checking the values of the table")
|
||||
|
||||
return False
|
||||
|
||||
return (fields, values, update_values)
|
||||
|
||||
|
||||
#Reset the require field in fields
|
||||
|
||||
def reset_require(self):
|
||||
|
||||
for k, v in self.fields.items():
|
||||
|
||||
self.required_save[k]=self.fields[k].required
|
||||
self.fields[k].required=0
|
||||
|
||||
|
||||
#Reload the require field in fields
|
||||
|
||||
def reload_require(self):
|
||||
|
||||
for k,r in self.fields.items():
|
||||
self.fields[k].required=r
|
||||
|
||||
#Choose all fields to updated
|
||||
|
||||
def set_valid_fields(self, fields={}):
|
||||
|
||||
if len(fields)==0:
|
||||
fields=self.fields.keys()
|
||||
|
||||
self.valid_fields=fields
|
||||
|
||||
#Create a form based in table.
|
||||
|
||||
def create_forms(self, arr_fields={}):
|
||||
|
||||
if len(arr_fields)==0:
|
||||
arr_fields=self.fields.keys()
|
||||
|
||||
#for name_field, field in self.fields.items():
|
||||
for name_field in arr_fields:
|
||||
self.valid_fields.append(name_field)
|
||||
self.forms[name_field]=self.fields[name_field].create_form()
|
||||
|
||||
def create_form_after(self, form_after, new_form):
|
||||
|
||||
new_dict=OrderedDict()
|
||||
|
||||
for name_form, form in self.forms.items():
|
||||
new_dict[name_form]=form
|
||||
if name_form==form_after:
|
||||
new_dict[new_form.name]=new_form
|
||||
|
||||
self.forms=new_dict
|
||||
|
||||
@staticmethod
|
||||
def close():
|
||||
WebModel.make_connection=SqlClass.connect_to_db
|
||||
SqlClass.close(SqlClass)
|
||||
|
||||
@staticmethod
|
||||
def escape_sql(value):
|
||||
|
||||
value=str(value)
|
||||
|
||||
return value.replace("'","\\'").strip()
|
||||
|
||||
|
||||
class PhangoField:
|
||||
|
||||
def __init__(self, name, size=255, required=False):
|
||||
|
||||
# The name of the field in database table
|
||||
|
||||
self.name=name
|
||||
|
||||
# The label for the Field
|
||||
|
||||
self.label=name.replace('_', ' ').title()
|
||||
|
||||
# If field is required, self.required is True
|
||||
|
||||
self.required=required
|
||||
|
||||
# The size of field in database
|
||||
|
||||
self.size=size
|
||||
|
||||
# Protected, if this value != None, cannot use it in insert or update.
|
||||
|
||||
self.protected=None
|
||||
|
||||
# $quote_open is used if you need a more flexible sql sentence,
|
||||
# @warning USE THIS FUNCTION IF YOU KNOW WHAT YOU ARE DOING
|
||||
|
||||
self.quot_open='\''
|
||||
|
||||
# $quote_close is used if you need a more flexible sql sentence,
|
||||
# @warning USE THIS PROPERTY IF YOU KNOW WHAT YOU ARE DOING
|
||||
|
||||
self.quot_close='\''
|
||||
|
||||
# Variable where the basic text error is saved
|
||||
|
||||
self.error=None
|
||||
|
||||
self.txt_error=""
|
||||
|
||||
# Array for create initial parameters for form..
|
||||
self.parameters=[]
|
||||
|
||||
# Themodel where this component or field live
|
||||
|
||||
self.model=None
|
||||
|
||||
# Property used for set this field how indexed in the database table.
|
||||
|
||||
self.indexed=False
|
||||
|
||||
# Property used for set this field how unique value in the database table.
|
||||
|
||||
self.unique=False
|
||||
|
||||
# Simple property for make more easy identify foreignkeyfields.
|
||||
|
||||
self.foreignkey=False
|
||||
|
||||
# Property that define the default value for this field
|
||||
|
||||
self.default_value=""
|
||||
|
||||
# Property that define if this field is in an update operation or insert operation
|
||||
|
||||
self.update=False
|
||||
|
||||
# Property used for check if this value cannot change if is in blank and is filled
|
||||
|
||||
self.check_blank=False
|
||||
|
||||
# Define the form, when is created forms with create_forms you can change the properties of this class
|
||||
|
||||
self.name_form=BaseForm
|
||||
|
||||
# This method is used for describe the new field in a sql language format.
|
||||
|
||||
|
||||
def get_type_sql(self):
|
||||
|
||||
return 'VARCHAR('+str(self.size)+') NOT NULL DEFAULT "'+self.default_value+'"'
|
||||
|
||||
def show_formatted(self, value):
|
||||
|
||||
return value
|
||||
|
||||
# This method for check the value
|
||||
|
||||
|
||||
def check(self, value):
|
||||
|
||||
self.error=False
|
||||
self.txt_error=''
|
||||
|
||||
value=str(value)
|
||||
|
||||
value=WebModel.escape_sql(value)
|
||||
|
||||
if value=="":
|
||||
self.txt_error="The field is empty"
|
||||
self.error=True
|
||||
|
||||
|
||||
return value
|
||||
|
||||
def set_relationships(self):
|
||||
pass
|
||||
|
||||
def create_form(self):
|
||||
form=self.name_form(self.name, self.default_value)
|
||||
form.default_value=self.default_value
|
||||
form.required=self.required
|
||||
form.label=self.label
|
||||
form.field=self
|
||||
return form
|
||||
|
||||
class PrimaryKeyField(PhangoField):
|
||||
|
||||
def __init__(self, name, size=11, required=False):
|
||||
super(PrimaryKeyField, self).__init__(name, size, required)
|
||||
self.protected=True
|
||||
self.name_form=HiddenForm
|
||||
self.required=True
|
||||
|
||||
def check(self, value):
|
||||
|
||||
self.error=None
|
||||
self.txt_error=''
|
||||
|
||||
if value=='':
|
||||
value='0'
|
||||
|
||||
try:
|
||||
|
||||
value=str(int(value))
|
||||
|
||||
except:
|
||||
|
||||
value=0
|
||||
|
||||
if value==0:
|
||||
self.txt_error="The value is zero"
|
||||
self.error=True
|
||||
|
||||
|
||||
return value
|
||||
|
||||
def get_type_sql(self):
|
||||
|
||||
return 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT'
|
||||
|
||||
|
||||
|
||||
|
||||
8
paramecio/frontend/index.py
Normal file
8
paramecio/frontend/index.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.index import create_app, run_app
|
||||
|
||||
app=create_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_app(app)
|
||||
7
paramecio/frontend/padmin.py
Normal file
7
paramecio/frontend/padmin.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.cromosoma.dbadmin import start
|
||||
|
||||
start()
|
||||
|
||||
|
||||
116
paramecio/index.py
Normal file
116
paramecio/index.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import os, sys, traceback, inspect
|
||||
from importlib import import_module, reload
|
||||
from bottle import route, get, post, run, default_app, abort, request, static_file
|
||||
from settings import config
|
||||
from beaker.middleware import SessionMiddleware
|
||||
|
||||
#Prepare links for static.
|
||||
#WARNING: only use this feature in development, not in production.
|
||||
|
||||
def create_app():
|
||||
|
||||
arr_module_path={}
|
||||
|
||||
if config.yes_static==True:
|
||||
|
||||
@route('/media/<filename:path>')
|
||||
def send_static(filename):
|
||||
return static_file(filename, root='themes/'+config.theme+'/media/')
|
||||
|
||||
def add_func_static_module(module):
|
||||
|
||||
@route('/mediafrom/<module>/<filename:path>')
|
||||
def send_static_module(module, filename):
|
||||
|
||||
path_module=arr_module_path[module]+'/media/'
|
||||
|
||||
file_path_module=path_module+filename
|
||||
|
||||
path='themes/'+config.theme+'/media/'+module
|
||||
|
||||
file_path=path+filename
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
return static_file(filename, root=path)
|
||||
|
||||
else:
|
||||
return static_file(filename, root=path_module)
|
||||
else:
|
||||
|
||||
def add_func_static_module(module):
|
||||
pass
|
||||
|
||||
routes={}
|
||||
|
||||
module_loaded=None
|
||||
|
||||
#Import modules to load
|
||||
|
||||
for module in config.modules:
|
||||
|
||||
try:
|
||||
|
||||
controller_path=import_module(module)
|
||||
|
||||
controller_base=os.path.dirname(controller_path.__file__)
|
||||
|
||||
base_module=module.split('.')[-1]
|
||||
|
||||
arr_module_path[base_module]=controller_base
|
||||
|
||||
dir_controllers=os.listdir(controller_base)
|
||||
|
||||
for controller in dir_controllers:
|
||||
|
||||
if controller.find('.py')!=-1 and controller.find('__init__')==-1:
|
||||
|
||||
controller_py=controller.replace('.py', '')
|
||||
|
||||
import_module(module+'.'+controller_py)
|
||||
|
||||
add_func_static_module(controller_base)
|
||||
|
||||
except:
|
||||
|
||||
print("Exception in user code:")
|
||||
print("-"*60)
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
print("-"*60)
|
||||
|
||||
#exit()
|
||||
|
||||
#Prepare ssl
|
||||
|
||||
if config.ssl==True:
|
||||
|
||||
from citoplasma.gunicornssl import GunicornServerSSL
|
||||
|
||||
GunicornServerSSL.cert_pem=config.cert_pem
|
||||
GunicornServerSSL.privkey_pem=config.privkey_pem
|
||||
|
||||
config.server_used=GunicornServerSSL
|
||||
|
||||
#Prepare app
|
||||
|
||||
app = application = default_app()
|
||||
|
||||
if config.session_enabled==True:
|
||||
#Create dir for sessions
|
||||
|
||||
if not os.path.isdir(config.session_opts['session.data_dir']):
|
||||
os.makedirs(config.session_opts['session.data_dir'], 0o700, True)
|
||||
|
||||
app = SessionMiddleware(app, config.session_opts, environ_key=config.cookie_name)
|
||||
|
||||
return app
|
||||
|
||||
def run_app(app):
|
||||
|
||||
run(app=app, host=config.host, server=config.server_used, port=config.port, debug=config.debug, reloader=config.reloader)
|
||||
"""
|
||||
if __name__ == "__main__":
|
||||
run(app=app, host=config.host, server=config.server_used, port=config.port, debug=config.debug, reloader=config.reloader)
|
||||
#else:
|
||||
#return run(app=app, host=config.host, server=config.server_used, port=config.port, debug=config.debug, reloader=config.reloader)
|
||||
"""
|
||||
|
||||
0
paramecio/modules/__init__.py
Normal file
0
paramecio/modules/__init__.py
Normal file
0
paramecio/modules/admin/__init__.py
Normal file
0
paramecio/modules/admin/__init__.py
Normal file
0
paramecio/modules/admin/admin/__init__.py
Normal file
0
paramecio/modules/admin/admin/__init__.py
Normal file
31
paramecio/modules/admin/admin/ausers.py
Normal file
31
paramecio/modules/admin/admin/ausers.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.modules.admin.models.admin import UserAdmin
|
||||
from paramecio.citoplasma.urls import make_url
|
||||
from paramecio.citoplasma.generate_admin_class import GenerateAdminClass
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from paramecio.cromosoma.coreforms import SelectForm
|
||||
|
||||
def admin(t):
|
||||
|
||||
user_admin=UserAdmin()
|
||||
|
||||
user_admin.fields['privileges'].name_form=SelectForm
|
||||
|
||||
user_admin.create_forms(['username', 'password', 'email', 'privileges'])
|
||||
|
||||
user_admin.forms['privileges'].arr_select={0: I18n.lang('admin', 'without_privileges', 'Without privileges'), 1: I18n.lang('admin', 'selected_privileges', 'Selected privileges'), 2: I18n.lang('admin', 'administrator', 'Administrator')}
|
||||
|
||||
user_admin.fields['password'].protected=False
|
||||
|
||||
url=make_url('admin/ausers', {})
|
||||
|
||||
admin=GenerateAdminClass(user_admin, url, t)
|
||||
|
||||
admin.list.fields_showed=['username', 'privileges']
|
||||
|
||||
admin.list.search_fields=['username']
|
||||
|
||||
#admin.list.limit_pages=5
|
||||
|
||||
return admin.show()
|
||||
228
paramecio/modules/admin/index.py
Normal file
228
paramecio/modules/admin/index.py
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.mtemplates import ptemplate
|
||||
from paramecio.modules.admin.models.admin import UserAdmin
|
||||
from paramecio.citoplasma.i18n import load_lang, I18n
|
||||
from paramecio.citoplasma.urls import make_url, add_get_parameters
|
||||
from paramecio.citoplasma.sessions import get_session
|
||||
from bottle import get,post
|
||||
from settings import config
|
||||
from settings import config_admin
|
||||
from paramecio.citoplasma.lists import SimpleList
|
||||
from paramecio.citoplasma.generate_admin_class import GenerateAdminClass
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
from paramecio.cromosoma.formsutils import show_form, pass_values_to_form
|
||||
from paramecio.cromosoma.coreforms import PasswordForm
|
||||
from importlib import import_module, reload
|
||||
from bottle import redirect
|
||||
from collections import OrderedDict
|
||||
|
||||
#from citoplasma.login import LoginClass
|
||||
# Check login
|
||||
|
||||
t=ptemplate('admin')
|
||||
|
||||
load_lang('admin', 'common')
|
||||
@get('/'+config.admin_folder)
|
||||
@get('/'+config.admin_folder+'/<module>')
|
||||
@post('/'+config.admin_folder+'/<module>')
|
||||
def home(module=''):
|
||||
|
||||
t.clean_header_cache()
|
||||
|
||||
#check if login
|
||||
|
||||
user_admin=UserAdmin()
|
||||
|
||||
s=get_session()
|
||||
|
||||
if 'login' in s:
|
||||
|
||||
s['id']=s.get('id', 0)
|
||||
|
||||
user_admin.conditions=['WHERE id=%s', [s['id']]]
|
||||
|
||||
c=user_admin.select_count()
|
||||
|
||||
if c>0:
|
||||
|
||||
if s['privileges']==2:
|
||||
|
||||
#Load menu
|
||||
|
||||
menu=OrderedDict()
|
||||
|
||||
for key, mod in config_admin.modules_admin.items():
|
||||
if type(mod[1]).__name__!='dict':
|
||||
menu[key]=mod
|
||||
else:
|
||||
menu[key]=mod[0]
|
||||
|
||||
for subkey, submod in mod[1].items():
|
||||
menu[subkey]=submod
|
||||
#pass
|
||||
|
||||
if module in menu:
|
||||
|
||||
#Load module
|
||||
|
||||
new_module=import_module(menu[module][1])
|
||||
|
||||
if config.reloader:
|
||||
reload(new_module)
|
||||
|
||||
return t.load_template('admin/content.html', title=menu[module][0], content_index=new_module.admin(t), menu=menu)
|
||||
|
||||
else:
|
||||
return t.load_template('admin/index.html', title=I18n.lang('admin', 'welcome_to_paramecio', "Welcome to Paramecio Admin!!!"), menu=menu)
|
||||
|
||||
else:
|
||||
|
||||
logout()
|
||||
|
||||
else:
|
||||
|
||||
user_admin.conditions=['WHERE privileges=%s', [2]]
|
||||
|
||||
c=user_admin.select_count()
|
||||
|
||||
if c>0:
|
||||
|
||||
post={}
|
||||
|
||||
user_admin.yes_repeat_password=False
|
||||
|
||||
user_admin.fields['password'].required=True
|
||||
|
||||
user_admin.create_forms(['username', 'password'])
|
||||
|
||||
forms=show_form(post, user_admin.forms, t, yes_error=False)
|
||||
|
||||
return t.load_template('admin/login.phtml', forms=forms)
|
||||
|
||||
else:
|
||||
|
||||
post={}
|
||||
|
||||
set_extra_forms_user(user_admin)
|
||||
|
||||
forms=show_form(post, user_admin.forms, t, yes_error=False)
|
||||
|
||||
return t.load_template('admin/register.phtml', forms=forms)
|
||||
|
||||
@post('/'+config.admin_folder+'/login')
|
||||
def login():
|
||||
|
||||
user_admin=UserAdmin()
|
||||
|
||||
GetPostFiles.obtain_post()
|
||||
|
||||
GetPostFiles.post.get('username', '')
|
||||
GetPostFiles.post.get('password', '')
|
||||
|
||||
username=user_admin.fields['username'].check(GetPostFiles.post['username'])
|
||||
|
||||
password=GetPostFiles.post['password'].strip()
|
||||
|
||||
user_admin.conditions=['WHERE username=%s', [username]]
|
||||
|
||||
arr_user=user_admin.select_a_row_where(['id', 'password', 'privileges'])
|
||||
|
||||
if arr_user==False:
|
||||
|
||||
return {'error': 1}
|
||||
else:
|
||||
|
||||
if user_admin.fields['password'].verify(password, arr_user['password']):
|
||||
|
||||
s=get_session()
|
||||
|
||||
s['id']=arr_user['id']
|
||||
s['login']=1
|
||||
s['privileges']=arr_user['privileges']
|
||||
|
||||
return {'error': 0}
|
||||
else:
|
||||
return {'error': 1}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@post('/'+config.admin_folder+'/register')
|
||||
def register():
|
||||
|
||||
user_admin=UserAdmin()
|
||||
|
||||
user_admin.conditions=['WHERE privileges=%s', 2]
|
||||
|
||||
c=user_admin.select_count()
|
||||
|
||||
if c==0:
|
||||
|
||||
GetPostFiles.obtain_post()
|
||||
|
||||
GetPostFiles.post['privileges']=2
|
||||
|
||||
user_admin.valid_fields=['username', 'email', 'password', 'privileges']
|
||||
|
||||
user_admin.create_forms()
|
||||
|
||||
if user_admin.insert(GetPostFiles.post, False):
|
||||
|
||||
error= {'error': 0}
|
||||
|
||||
return error
|
||||
|
||||
else:
|
||||
|
||||
user_admin.check_all_fields(GetPostFiles.post, False)
|
||||
|
||||
pass_values_to_form(GetPostFiles.post, user_admin.forms, yes_error=True)
|
||||
|
||||
error={'error': 1}
|
||||
|
||||
for field in user_admin.fields.values():
|
||||
|
||||
error[field.name]=field.txt_error
|
||||
|
||||
#error['password_repeat']=I18n.lang('common', 'password_no_match', 'Passwords doesn\'t match')
|
||||
|
||||
return error
|
||||
|
||||
else:
|
||||
|
||||
return {'error': 1}
|
||||
|
||||
@get('/'+config.admin_folder+'/logout')
|
||||
def logout():
|
||||
|
||||
s=get_session()
|
||||
|
||||
if 'login' in s.keys():
|
||||
|
||||
del s['login']
|
||||
del s['privileges']
|
||||
|
||||
redirect('/'+config.admin_folder)
|
||||
|
||||
|
||||
def set_extra_forms_user(user_admin):
|
||||
|
||||
user_admin.fields['password'].required=True
|
||||
user_admin.fields['email'].required=True
|
||||
|
||||
user_admin.create_forms(['username', 'email', 'password'])
|
||||
|
||||
user_admin.forms['repeat_password']=PasswordForm('repeat_password', '')
|
||||
|
||||
user_admin.forms['repeat_password'].required=1
|
||||
|
||||
user_admin.forms['repeat_password'].label=I18n.lang('common', 'repeat_password', 'Repeat Password')
|
||||
|
||||
|
||||
"""user_admin.create_forms()
|
||||
|
||||
users=user_admin.select()"""
|
||||
|
||||
#By default id is not showed
|
||||
637
paramecio/modules/admin/media/css/admin.css
Normal file
637
paramecio/modules/admin/media/css/admin.css
Normal file
|
|
@ -0,0 +1,637 @@
|
|||
body
|
||||
{
|
||||
|
||||
margin:0px;
|
||||
background-color:#f7f6f1;
|
||||
font-family: sans, sans-serif, serif;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
|
||||
color: #1c6280;
|
||||
|
||||
}
|
||||
|
||||
a:hover
|
||||
{
|
||||
|
||||
color: #d54e21;
|
||||
|
||||
}
|
||||
|
||||
#header
|
||||
{
|
||||
|
||||
width:100%;
|
||||
height:47px;
|
||||
color:#000;
|
||||
font-size:22px;
|
||||
font-family:sans, serif;
|
||||
background-image:url('../images/background.png');
|
||||
background-position:top;
|
||||
background-repeat:repeat-x;
|
||||
background-color:#959595;
|
||||
line-height: 47px;
|
||||
|
||||
}
|
||||
|
||||
#title_phango
|
||||
{
|
||||
font-size:28px;
|
||||
padding-left:15px;
|
||||
color: #ffffff;
|
||||
font-style:italic;
|
||||
text-shadow:#000000 1px 1px 1px;
|
||||
filter: progid:DXImageTransform.Microsoft.Shadow(color='#000000', Direction=130, Strength=4);
|
||||
|
||||
}
|
||||
|
||||
#title_framework
|
||||
{
|
||||
|
||||
font-size:28px;
|
||||
padding-right:15px;
|
||||
color:#ff9b2f;
|
||||
font-style:italic;
|
||||
text-shadow:#000000 1px 1px 1px;
|
||||
filter: progid:DXImageTransform.Microsoft.Shadow(color='#000000', Direction=130, Strength=4);
|
||||
|
||||
}
|
||||
|
||||
h1
|
||||
{
|
||||
|
||||
font-family:sans, serif;
|
||||
font-size:26px;
|
||||
font-weight:normal;
|
||||
font-style:italic;
|
||||
color:#04004e;
|
||||
background-image:url('../images/button_head.png');
|
||||
background-repeat: no-repeat;
|
||||
/*padding-left:65px;*/
|
||||
/*height:60px;
|
||||
line-height:60px;*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
#logo_header
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#center_body {
|
||||
|
||||
background-position:left;
|
||||
background-repeat:repeat-y;
|
||||
height: auto !important;
|
||||
width:100%;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
overflow:auto;
|
||||
height: auto !important;
|
||||
min-height:300px;
|
||||
position:relative;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#menu
|
||||
{
|
||||
|
||||
float:left;
|
||||
width:18%;
|
||||
margin-right:25px;
|
||||
position:relative;
|
||||
}
|
||||
|
||||
#menu a
|
||||
{
|
||||
|
||||
font-size:12px;
|
||||
/*font-family:arial, sans;*/
|
||||
font-weight:bold;
|
||||
text-decoration:none;
|
||||
color:#6183b0;
|
||||
display:block;
|
||||
border:solid #cccccc;
|
||||
border-width:0px 1px 1px 1px;
|
||||
padding:5px;
|
||||
background: #ececec;
|
||||
}
|
||||
|
||||
#menu a:hover
|
||||
{
|
||||
|
||||
text-decoration:underline;
|
||||
color:#5072a0;
|
||||
background: #e7e7e7;
|
||||
|
||||
}
|
||||
|
||||
#menu a.sub_module
|
||||
{
|
||||
|
||||
color:#6183b1;
|
||||
background-color: #fbfbfb;
|
||||
text-decoration:none;
|
||||
|
||||
}
|
||||
|
||||
.menu_title
|
||||
{
|
||||
|
||||
padding:5px;
|
||||
font-size:14px;
|
||||
/*font-family:arial, sans;*/
|
||||
font-weight:bold;
|
||||
padding:5px;
|
||||
background-image:url('../images/background_title.png');
|
||||
background-position:top;
|
||||
background-repeat: repeat-x;
|
||||
background-color: #fcf7fd;
|
||||
border-radius: 8px 8px 0px 0px;
|
||||
border:solid #cccccc;
|
||||
border-width:1px 1px 1px 1px;
|
||||
color: #333333;
|
||||
|
||||
}
|
||||
|
||||
.father_admin {
|
||||
|
||||
padding:5px;
|
||||
font-size:14px;
|
||||
display: block;
|
||||
color: #fbfbfb;
|
||||
font-weight:bold;
|
||||
background: rgba(76,76,76,1);
|
||||
background: -moz-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%);
|
||||
background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(76,76,76,1)), color-stop(12%, rgba(89,89,89,1)), color-stop(25%, rgba(102,102,102,1)), color-stop(39%, rgba(71,71,71,1)), color-stop(50%, rgba(44,44,44,1)), color-stop(51%, rgba(0,0,0,1)), color-stop(60%, rgba(17,17,17,1)), color-stop(76%, rgba(43,43,43,1)), color-stop(91%, rgba(28,28,28,1)), color-stop(100%, rgba(19,19,19,1)));
|
||||
background: -webkit-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%);
|
||||
background: -o-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%);
|
||||
background: -ms-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%);
|
||||
background: linear-gradient(to bottom, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313', GradientType=0 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
.content_admin
|
||||
{
|
||||
|
||||
margin:auto;
|
||||
background-color:#ffffff;
|
||||
padding:10px 10px 10px 10px;
|
||||
border:solid #dfdfdf;
|
||||
border-width: 1px;
|
||||
font-size:12px;
|
||||
position:relative;
|
||||
overflow:auto;
|
||||
margin-bottom:40px;
|
||||
|
||||
}
|
||||
|
||||
.contents
|
||||
{
|
||||
float:right;
|
||||
width:79%;
|
||||
padding:0px 0px 15px 0px;
|
||||
}
|
||||
|
||||
.content
|
||||
{
|
||||
|
||||
/*border: solid #000 0px;
|
||||
float:right;
|
||||
width:80%;*/
|
||||
|
||||
}
|
||||
|
||||
.title
|
||||
{
|
||||
|
||||
font-size:18px;
|
||||
font-weight:bold;
|
||||
font-family:arial, sans;
|
||||
text-decoration:none;
|
||||
color:#000000;
|
||||
padding:5px;
|
||||
background-image:url('../images/background_title.png');
|
||||
background-position:top;
|
||||
background-repeat: repeat-x;
|
||||
background-color: #fcf7fd;
|
||||
border-radius: 8px 8px 0px 0px;
|
||||
border:solid #cccccc;
|
||||
border-width:1px 1px 1px 1px;
|
||||
}
|
||||
|
||||
#inform {
|
||||
|
||||
margin:auto;
|
||||
|
||||
}
|
||||
|
||||
/*Styles for common templates...*/
|
||||
|
||||
.form {
|
||||
|
||||
border: solid #cbcbcb 1px;
|
||||
padding:10px;
|
||||
margin:10px 0px 10px 0px;
|
||||
border-radius:5px;
|
||||
|
||||
}
|
||||
|
||||
.form textarea {
|
||||
|
||||
width:100%;
|
||||
height:200px;
|
||||
|
||||
}
|
||||
|
||||
.form label {
|
||||
display: block;
|
||||
/*width: 150px;*/
|
||||
float: left;
|
||||
margin-bottom: 10px;
|
||||
text-align: left;
|
||||
width: 350px;
|
||||
padding-right: 20px;
|
||||
/*border: #000000 solid;
|
||||
border-width:1px;*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
.form p {
|
||||
clear: left;
|
||||
}
|
||||
|
||||
img {
|
||||
|
||||
display:block;
|
||||
|
||||
}
|
||||
|
||||
.panel {
|
||||
|
||||
display:block;
|
||||
float:left;
|
||||
/*clear:left;*/
|
||||
text-align:center;
|
||||
border: #000000 solid;
|
||||
border-width:0px;
|
||||
min-width:200px;
|
||||
width:200px !important;
|
||||
padding:0px;
|
||||
margin:0px;
|
||||
min-height:100px;
|
||||
height:100px !important;
|
||||
position:relative;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.panel p {
|
||||
|
||||
position:absolute;
|
||||
bottom:0px;
|
||||
/*padding-bottom:0px;*/
|
||||
text-align:center;
|
||||
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
|
||||
}
|
||||
|
||||
.panel img {
|
||||
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
|
||||
}
|
||||
|
||||
.table_list {
|
||||
|
||||
|
||||
width:100%;
|
||||
|
||||
}
|
||||
|
||||
.title_list td {
|
||||
|
||||
border:solid #cccccc;
|
||||
border-width:1px;
|
||||
padding:8px;
|
||||
background-image:url('../images/background_title.png');
|
||||
background-position:top;
|
||||
background-repeat: repeat-x;
|
||||
font-size:14px;
|
||||
font-weight:bold;
|
||||
|
||||
}
|
||||
|
||||
.row_list td {
|
||||
|
||||
border:solid #cccccc;
|
||||
border-width:1px;
|
||||
padding:4px;
|
||||
|
||||
}
|
||||
|
||||
.cont_text, .cont
|
||||
{
|
||||
|
||||
margin:auto;
|
||||
background-color:#ffffff;
|
||||
padding:10px 10px 10px 10px;
|
||||
border:solid #dfdfdf;
|
||||
border-width: 0px 1px 1px 1px;
|
||||
font-size:12px;
|
||||
position:relative;
|
||||
overflow:auto;
|
||||
margin-bottom:10px;
|
||||
border-radius: 0px 0px 5px 5px;
|
||||
|
||||
}
|
||||
|
||||
.cont_top {
|
||||
|
||||
border-width: 1px 1px 1px 1px;
|
||||
border-radius: 5px 5px 5px 5px;
|
||||
}
|
||||
|
||||
.search {
|
||||
|
||||
border-width: 1px;
|
||||
border-radius:5px;
|
||||
margin-top:5px;
|
||||
|
||||
}
|
||||
|
||||
.right_cont
|
||||
{
|
||||
|
||||
width:78%;
|
||||
|
||||
}
|
||||
|
||||
.none_cont
|
||||
{
|
||||
|
||||
/*width:100%;*/
|
||||
|
||||
}
|
||||
|
||||
.contview
|
||||
{
|
||||
|
||||
border:solid #cccccc;
|
||||
border-width:1px 1px 1px 1px;
|
||||
padding:15px;
|
||||
margin: 0px 0px 5px 0px;
|
||||
|
||||
}
|
||||
|
||||
.error
|
||||
{
|
||||
|
||||
color: #ff0000;
|
||||
font-weight:bold;
|
||||
|
||||
}
|
||||
|
||||
.hidden_form
|
||||
{
|
||||
|
||||
display: none;
|
||||
/*clear:left;*/
|
||||
|
||||
}
|
||||
|
||||
.no_hidden_form
|
||||
{
|
||||
|
||||
display: inline;
|
||||
/*float:left;
|
||||
clear:left right;*/
|
||||
|
||||
}
|
||||
|
||||
a.no_choose_flag
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=50);
|
||||
-moz-opacity: .5;
|
||||
opacity: .5;
|
||||
float:left;
|
||||
margin: 2px;
|
||||
|
||||
}
|
||||
|
||||
a.choose_flag
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=100);
|
||||
-moz-opacity: 100;
|
||||
opacity: 100;
|
||||
float:left;
|
||||
margin: 2px;
|
||||
|
||||
}
|
||||
|
||||
a:hover.no_choose_flag
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=100);
|
||||
-moz-opacity: 100;
|
||||
opacity: 100;
|
||||
float:left;
|
||||
margin: 2px;
|
||||
|
||||
}
|
||||
|
||||
#languages
|
||||
{
|
||||
width:100%;
|
||||
clear:left;
|
||||
|
||||
}
|
||||
|
||||
/** input **/
|
||||
|
||||
#center_body input {
|
||||
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
height:20px;
|
||||
border-radius:5px;
|
||||
background: #eeeeee;
|
||||
|
||||
}
|
||||
|
||||
#center_body input:hover {
|
||||
|
||||
background: #fafafa;
|
||||
|
||||
}
|
||||
|
||||
#center_body input[type="submit"]
|
||||
{
|
||||
|
||||
font-family: arial,sans;
|
||||
font-size:12px;
|
||||
height:25px;
|
||||
border-radius:25px;
|
||||
background: #eee;
|
||||
|
||||
}
|
||||
|
||||
#center_body input:hover[type="submit"]
|
||||
{
|
||||
|
||||
background: #fff;
|
||||
|
||||
}
|
||||
|
||||
#center_body input[type="button"]
|
||||
{
|
||||
|
||||
font-family: arial,sans;
|
||||
font-size:12px;
|
||||
height:25px;
|
||||
border-radius:25px;
|
||||
background: #eee;
|
||||
|
||||
}
|
||||
|
||||
#center_body input:hover[type="button"]
|
||||
{
|
||||
|
||||
background: #fff;
|
||||
|
||||
}
|
||||
|
||||
#center_body textarea {
|
||||
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
|
||||
}
|
||||
|
||||
#center_body select {
|
||||
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
|
||||
}
|
||||
|
||||
#languages_general, #logout
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
margin: 0px 0px 0px 0px;
|
||||
top:54px;
|
||||
z-index:3;
|
||||
right:0px;
|
||||
width:50px;
|
||||
|
||||
}
|
||||
|
||||
#logout
|
||||
{
|
||||
|
||||
top:16px;
|
||||
right:5px;
|
||||
font-weight:bold;
|
||||
font-size:12px;
|
||||
}
|
||||
|
||||
a.no_choose_flag_general
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=50);
|
||||
-moz-opacity: .5;
|
||||
opacity: .5;
|
||||
float:left;
|
||||
margin: 2px;
|
||||
|
||||
}
|
||||
|
||||
a.choose_flag_general
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=100);
|
||||
-moz-opacity: 100;
|
||||
opacity: 100;
|
||||
float:left;
|
||||
margin: 2px;
|
||||
|
||||
}
|
||||
|
||||
a:hover.no_choose_flag_general
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=100);
|
||||
-moz-opacity: 100;
|
||||
opacity: 100;
|
||||
float:left;
|
||||
margin: 2px;
|
||||
|
||||
}
|
||||
|
||||
a.form_button_tab, a.form_button_tab_selected
|
||||
{
|
||||
|
||||
border: solid #121212 1px;
|
||||
border-radius:10px;
|
||||
padding:10px;
|
||||
display:inline-block;
|
||||
text-decoration:none;
|
||||
color:#fbfbfb;
|
||||
background: #000;
|
||||
|
||||
}
|
||||
|
||||
a.form_button_tab_selected
|
||||
{
|
||||
|
||||
background:#fbfbfb;
|
||||
color: #000;
|
||||
|
||||
}
|
||||
|
||||
a.form_button_tab:hover
|
||||
{
|
||||
|
||||
|
||||
color:#000;
|
||||
background:#fbfbfb;
|
||||
|
||||
}
|
||||
|
||||
.flash
|
||||
{
|
||||
border-radius:15px;
|
||||
margin-top:15px;
|
||||
padding:25px;
|
||||
color:#fbfbfb;
|
||||
text-shadow:#000000 1px 1px 1px;
|
||||
filter: progid:DXImageTransform.Microsoft.Shadow(color='#000000', Direction=130, Strength=4);
|
||||
|
||||
background: #ff3019; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #ff3019 0%, #cf0404 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ff3019), color-stop(100%,#cf0404)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #ff3019 0%,#cf0404 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #ff3019 0%,#cf0404 100%); /* Opera 11.10+ */
|
||||
background: -ms-linear-gradient(top, #ff3019 0%,#cf0404 100%); /* IE10+ */
|
||||
background: linear-gradient(to bottom, #ff3019 0%,#cf0404 100%); /* W3C */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff3019', endColorstr='#cf0404',GradientType=0 ); /* IE6-9 */
|
||||
|
||||
}
|
||||
4
paramecio/modules/admin/media/css/font-awesome.min.css
vendored
Normal file
4
paramecio/modules/admin/media/css/font-awesome.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
142
paramecio/modules/admin/media/css/login.css
Normal file
142
paramecio/modules/admin/media/css/login.css
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
body {
|
||||
|
||||
margin:0px;
|
||||
background: #fbfbfb;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
|
||||
}
|
||||
|
||||
#title {
|
||||
|
||||
padding:10px;
|
||||
color: #fbfbfb;
|
||||
background: #ff7153 url("../images/background_title_login.png") right no-repeat;
|
||||
font-size:1.5em;
|
||||
/*text-shadow: 1px 1px 0px rgba(0, 0, 0, 1);*/
|
||||
|
||||
}
|
||||
|
||||
.form {
|
||||
|
||||
margin:10px 15px 10px 10px;
|
||||
position:relative;
|
||||
|
||||
}
|
||||
|
||||
input {
|
||||
|
||||
width:100%;
|
||||
border: solid #bcbcbc 1px;
|
||||
font-size:2em;
|
||||
border-radius:5px;
|
||||
padding:2px;
|
||||
|
||||
}
|
||||
|
||||
input:focus {
|
||||
|
||||
border-color: #FF7052;
|
||||
outline:1px;
|
||||
|
||||
}
|
||||
|
||||
.submit {
|
||||
|
||||
width:250px;
|
||||
display: block;
|
||||
margin: 0 auto 18px auto;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #FF7052;
|
||||
color: #FF7052;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0px 0px 0px 7px #fff;
|
||||
transition: 0.2s ease-out;
|
||||
position:relative;
|
||||
}
|
||||
|
||||
.submit:hover,
|
||||
.submit:focus {
|
||||
background: #FF7052;
|
||||
color: #fff;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.error {
|
||||
|
||||
font-weight:bold;
|
||||
color: #ff0000;
|
||||
|
||||
}
|
||||
|
||||
#submit_block {
|
||||
|
||||
position:relative;
|
||||
|
||||
}
|
||||
|
||||
#loading {
|
||||
|
||||
top:10px;
|
||||
right:40px;
|
||||
position:absolute;
|
||||
display:block;
|
||||
width:16px;
|
||||
height:16px;
|
||||
border: solid #000 0px;
|
||||
background: url('../images/ajax-loader.gif') center no-repeat;
|
||||
display:none;
|
||||
|
||||
}
|
||||
|
||||
/* Phones */
|
||||
@media (max-width: 767px) {
|
||||
|
||||
#login {
|
||||
|
||||
width:100%;
|
||||
border: solid #cbcbcb;
|
||||
border-width:0px 0px 1px 0px;
|
||||
margin-top:5px;
|
||||
margin:0px;
|
||||
overflow:hidden;
|
||||
background: #eaeaea;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Tablets */
|
||||
@media (min-width: 780px) and (max-width: 979px) {
|
||||
|
||||
#login {
|
||||
|
||||
position:relative;
|
||||
width:400px;
|
||||
border: solid #cbcbcb 1px;
|
||||
margin-top:5px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
overflow:hidden;
|
||||
background: #eaeaea;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Desktops */
|
||||
@media (min-width: 980px) {
|
||||
|
||||
#login {
|
||||
|
||||
position:relative;
|
||||
width:400px;
|
||||
border: solid #cbcbcb 1px;
|
||||
margin-top:5px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
overflow:hidden;
|
||||
background: #eaeaea;
|
||||
}
|
||||
|
||||
}
|
||||
902
paramecio/modules/admin/media/css/style.css
Normal file
902
paramecio/modules/admin/media/css/style.css
Normal file
|
|
@ -0,0 +1,902 @@
|
|||
/* General styles */
|
||||
|
||||
body
|
||||
{
|
||||
|
||||
margin:0px;
|
||||
background:url('../images/background.png') repeat-y center #e0e5e6;
|
||||
|
||||
}
|
||||
|
||||
iframe
|
||||
{
|
||||
|
||||
width:100%;
|
||||
border:solid #5b5b5b;
|
||||
border-width:1px;
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
|
||||
font-size:12px;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:none;
|
||||
color: #3434cc;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
a:hover
|
||||
{
|
||||
|
||||
font-size:12px;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:underline;
|
||||
color: #4545dd;
|
||||
font-weight:bold;
|
||||
|
||||
}
|
||||
|
||||
strong
|
||||
{
|
||||
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
img {
|
||||
|
||||
/*display:block;*/
|
||||
|
||||
}
|
||||
|
||||
/** center_body is the principal class **/
|
||||
|
||||
#center_body {
|
||||
|
||||
position:relative;
|
||||
height: auto !important;
|
||||
width:958px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
overflow:auto;
|
||||
height: auto !important;
|
||||
min-height:600px;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** input **/
|
||||
|
||||
#center_body input {
|
||||
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
height:20px;
|
||||
border-radius:5px;
|
||||
background: #eeeeee;
|
||||
|
||||
}
|
||||
|
||||
#center_body input:hover {
|
||||
|
||||
background: #fafafa;
|
||||
|
||||
}
|
||||
|
||||
#center_body input[type="submit"]
|
||||
{
|
||||
|
||||
font-family: verdana,arial,sans;
|
||||
font-size:12px;
|
||||
height:25px;
|
||||
border-radius:25px;
|
||||
background: #eee;
|
||||
|
||||
}
|
||||
|
||||
#center_body input:hover[type="submit"]
|
||||
{
|
||||
|
||||
background: #fff;
|
||||
|
||||
}
|
||||
|
||||
#center_body textarea {
|
||||
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
|
||||
}
|
||||
|
||||
#center_body select {
|
||||
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
|
||||
}
|
||||
|
||||
/* header elements classes */
|
||||
|
||||
#header
|
||||
{
|
||||
|
||||
width:952px;
|
||||
border:solid #000000;
|
||||
border-width:0px;
|
||||
border-right-width:0px;
|
||||
padding-left:5px;
|
||||
color: #676767;
|
||||
text-align:middle;
|
||||
height:120px;
|
||||
margin-bottom:4px;
|
||||
line-height: 35px;
|
||||
|
||||
}
|
||||
|
||||
#header a
|
||||
{
|
||||
|
||||
color: #555555;
|
||||
|
||||
}
|
||||
|
||||
#logo_img
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
top:20px;
|
||||
left:0px;
|
||||
|
||||
}
|
||||
|
||||
#your_account
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
top:25px;
|
||||
right:5px;
|
||||
background-image: url('../images/my-account.png');
|
||||
background-repeat: no-repeat;
|
||||
background-position:left;
|
||||
padding-left:25px;
|
||||
|
||||
}
|
||||
|
||||
#cart
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
top:50px;
|
||||
right:5px;
|
||||
background-image: url('../images/cart.gif');
|
||||
background-repeat: no-repeat;
|
||||
background-position:left;
|
||||
padding-left:25px;
|
||||
font-size:12px;
|
||||
|
||||
}
|
||||
|
||||
#change_currency
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
top:70px;
|
||||
right:5px;
|
||||
background-image: url('../images/currency.gif');
|
||||
background-repeat: no-repeat;
|
||||
background-position:left;
|
||||
padding-left:25px;
|
||||
font-size:12px;
|
||||
|
||||
}
|
||||
|
||||
/* Languages styles in header. */
|
||||
|
||||
#languages
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
margin: 0px 0px 0px 0px;
|
||||
top:10px;
|
||||
right:5px;
|
||||
/*right:50px;*/
|
||||
|
||||
}
|
||||
|
||||
a.no_choose_flag
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=50);
|
||||
-moz-opacity: .5;
|
||||
opacity: .5;
|
||||
|
||||
}
|
||||
|
||||
a.choose_flag
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=100);
|
||||
-moz-opacity: 100;
|
||||
opacity: 100;
|
||||
|
||||
}
|
||||
|
||||
a:hover.no_choose_flag
|
||||
{
|
||||
|
||||
filter: Alpha(opacity=100);
|
||||
-moz-opacity: 100;
|
||||
opacity: 100;
|
||||
|
||||
}
|
||||
|
||||
#menu_barr
|
||||
{
|
||||
|
||||
height:40px;
|
||||
background-image:url('../images/background_barr.png');
|
||||
background-repeat: repeat-x;
|
||||
border:solid #cbcbcb;
|
||||
border-width:1px;
|
||||
border-radius:8px;
|
||||
text-align:center;
|
||||
font-size:16px;
|
||||
line-height:40px;
|
||||
margin-bottom:18px;
|
||||
|
||||
}
|
||||
|
||||
#menu_barr a
|
||||
{
|
||||
|
||||
font-size:16px;
|
||||
|
||||
}
|
||||
|
||||
/* Menus in left and right sides... */
|
||||
|
||||
#menu
|
||||
{
|
||||
|
||||
|
||||
width:175px;
|
||||
/*border:solid #ffffff;
|
||||
border-width:5px;*/
|
||||
margin:0px 0px 5px 0px;
|
||||
padding:0px;
|
||||
|
||||
}
|
||||
|
||||
#menu a
|
||||
{
|
||||
|
||||
font-size:14px;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:none;
|
||||
color: #3434cc;
|
||||
font-weight:bold;
|
||||
padding:5px;
|
||||
}
|
||||
|
||||
#menu a:hover
|
||||
{
|
||||
|
||||
font-size:14px;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:underline;
|
||||
color: #4545dd;
|
||||
padding:5px;
|
||||
|
||||
}
|
||||
|
||||
.title_block
|
||||
{
|
||||
|
||||
font-size:20px;
|
||||
font-weight:normal;
|
||||
font-family:verdana;
|
||||
text-decoration:none;
|
||||
color: #fff;
|
||||
background-image:url('../images/block_bg.png');
|
||||
background-repeat:repeat-x;
|
||||
background-position:bottom;
|
||||
background-color:#4e8df6;
|
||||
border:solid #256753;
|
||||
border-width:1px;
|
||||
padding:8px 4px 0px 8px;
|
||||
margin:0px;
|
||||
position:relative;
|
||||
height:40px;
|
||||
border-radius: 8px 8px 0px 0px;
|
||||
|
||||
}
|
||||
|
||||
.url_block
|
||||
{
|
||||
|
||||
font-size:12px;
|
||||
font-family:verdana;
|
||||
text-decoration:none;
|
||||
color: #676767;
|
||||
border:solid #cbcbcb;
|
||||
border-width:0px 1px 0px 1px;
|
||||
padding:8px 4px 8px 4px;
|
||||
margin:0px;
|
||||
position:relative;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.static_block
|
||||
{
|
||||
|
||||
font-size:12px;
|
||||
font-family:verdana;
|
||||
text-decoration:none;
|
||||
color: #676767;
|
||||
/*background-image:url('../images/block_bg_link.png');*/
|
||||
border:solid #cbcbcb;
|
||||
border-width:0px 1px 0px 1px;
|
||||
padding:4px;
|
||||
margin:0px;
|
||||
position:relative;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.block_end
|
||||
{
|
||||
|
||||
background-image:url('../images/block_end.png');
|
||||
height:15px;
|
||||
border:solid #cbcbcb;
|
||||
border-width:0px 1px 1px 1px;
|
||||
border-radius:0px 0px 5px 5px;
|
||||
margin-bottom:5px;
|
||||
|
||||
}
|
||||
|
||||
.link_menu a
|
||||
{
|
||||
|
||||
color:#ff0000;
|
||||
|
||||
}
|
||||
|
||||
.menu_left
|
||||
{
|
||||
|
||||
float:left;
|
||||
|
||||
}
|
||||
|
||||
.menu_right
|
||||
{
|
||||
|
||||
float:right;
|
||||
|
||||
}
|
||||
|
||||
/* styles in content */
|
||||
|
||||
#content
|
||||
{
|
||||
|
||||
display:block;
|
||||
padding:0px 5px 0px 5px;
|
||||
font-size:12px;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:none;
|
||||
color: #676767;
|
||||
margin-top:0px;
|
||||
overflow:auto;
|
||||
position:relative;
|
||||
font-weight:lighter;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
.content
|
||||
{
|
||||
|
||||
overflow:auto;
|
||||
position:relative;
|
||||
|
||||
}
|
||||
|
||||
.content_all
|
||||
{
|
||||
|
||||
width:598px;
|
||||
float:left;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.content_right
|
||||
{
|
||||
|
||||
width:772px;
|
||||
float:left;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.title
|
||||
{
|
||||
|
||||
font-size:18px;
|
||||
font-weight:bold;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:none;
|
||||
color: #232323;
|
||||
border:solid #cbcbcb;
|
||||
border-width:1px;
|
||||
padding:10px;
|
||||
margin-bottom:5px;
|
||||
background-color:#1ca34f;
|
||||
background-image:url('../images/background_barr.png');
|
||||
background-repeat:repeat-x;
|
||||
border-radius:8px;
|
||||
text-shadow: 1px 1px 2px rgba(150, 150, 150, 1);
|
||||
|
||||
}
|
||||
|
||||
.cont {
|
||||
|
||||
border:solid #dbdbdb;
|
||||
border-width:1px 1px 1px 1px;
|
||||
padding:10px 20px 10px 20px;
|
||||
margin-bottom:5px;
|
||||
position:relative;
|
||||
/*text-align:justify;*/
|
||||
overflow:hidden;
|
||||
height:100%;
|
||||
|
||||
}
|
||||
|
||||
#inform {
|
||||
|
||||
margin:auto;
|
||||
|
||||
}
|
||||
|
||||
#options {
|
||||
|
||||
position:absolute;
|
||||
top:50px;
|
||||
left:600px;
|
||||
}
|
||||
|
||||
/*Styles for common templates...*/
|
||||
|
||||
.form label {
|
||||
display: block;
|
||||
width: 150px;
|
||||
float: left;
|
||||
margin-bottom: 10px;
|
||||
text-align: left;
|
||||
width: 300px;
|
||||
padding-right: 20px;
|
||||
|
||||
}
|
||||
|
||||
.form textarea {
|
||||
|
||||
width:100%;
|
||||
height:150px;
|
||||
clear:both;
|
||||
|
||||
}
|
||||
|
||||
.form p {
|
||||
clear: left;
|
||||
}
|
||||
|
||||
.panel {
|
||||
|
||||
|
||||
}
|
||||
|
||||
.panel p {
|
||||
|
||||
text-align:center;
|
||||
|
||||
}
|
||||
|
||||
.panel img {
|
||||
|
||||
display:block;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
|
||||
}
|
||||
|
||||
/* Table list config */
|
||||
|
||||
.table_list {
|
||||
|
||||
border:solid #cbcbcb;
|
||||
border-width:1px;
|
||||
width:100%;
|
||||
clear:left;
|
||||
border-radius:8px;
|
||||
|
||||
}
|
||||
|
||||
.head_list
|
||||
{
|
||||
|
||||
/*width:100%;*/
|
||||
margin:4px;
|
||||
display:block;
|
||||
position:relative;
|
||||
float:left;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px;*/
|
||||
width:60%;
|
||||
}
|
||||
|
||||
.head_list_right
|
||||
{
|
||||
|
||||
/*width:100%;*/
|
||||
margin:4px;
|
||||
display:block;
|
||||
position:relative;
|
||||
/*clear:left;*/
|
||||
float:right;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px;*/
|
||||
width:35%;
|
||||
bottom:0px;
|
||||
text-align:right;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.title_list
|
||||
{
|
||||
|
||||
|
||||
width:100%;
|
||||
position:relative;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px 1px 1px 1px;*/
|
||||
|
||||
}
|
||||
|
||||
.title_list td
|
||||
{
|
||||
|
||||
font-size:14px;
|
||||
font-weight:bold;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:none;
|
||||
color: #fff;
|
||||
border:solid #cbcbcb;
|
||||
border-width:1px 1px 1px 1px;
|
||||
padding:5px 5px 5px 5px;
|
||||
margin:4px;
|
||||
margin-bottom:5px;
|
||||
background-color:#d75a09;
|
||||
background-repeat:repeat-x;
|
||||
text-align:center;
|
||||
border-radius:8px;
|
||||
|
||||
}
|
||||
|
||||
.row_list
|
||||
{
|
||||
|
||||
|
||||
width:100%;
|
||||
position:relative;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px 1px 1px 1px;*/
|
||||
|
||||
}
|
||||
|
||||
.row_list td
|
||||
{
|
||||
|
||||
font-size:12px;
|
||||
font-weight:bold;
|
||||
font-family:verdana, verdana;
|
||||
text-decoration:none;
|
||||
color: #676767;
|
||||
border:solid #ffffff;
|
||||
border-width:1px 1px 1px 1px;
|
||||
padding:5px 5px 5px 5px;
|
||||
margin:4px;
|
||||
margin-bottom:5px;
|
||||
text-align:center;
|
||||
/*background-color:#d75a09;
|
||||
background-image:url('../images/fondo_titulo.png');
|
||||
background-repeat:repeat-x;*/
|
||||
/*float:left;*/
|
||||
|
||||
}
|
||||
|
||||
/* styles in private messages */
|
||||
|
||||
.new_message
|
||||
{
|
||||
|
||||
display:block;
|
||||
width:60px;
|
||||
height:30px;
|
||||
float:left;
|
||||
padding:0px;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px;*/
|
||||
background-image:url('../images/new_message.png');
|
||||
background-repeat:no-repeat;
|
||||
background-position:center;
|
||||
|
||||
}
|
||||
|
||||
.message
|
||||
{
|
||||
|
||||
display:block;
|
||||
width:60px;
|
||||
height:30px;
|
||||
float:left;
|
||||
padding:0px;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px;*/
|
||||
background-image:url('../images/message.png');
|
||||
background-repeat:no-repeat;
|
||||
background-position:center;
|
||||
|
||||
}
|
||||
|
||||
.error
|
||||
{
|
||||
|
||||
color: #ff0000;
|
||||
font-weight:bold;
|
||||
|
||||
}
|
||||
|
||||
#footer
|
||||
{
|
||||
|
||||
height:100px;
|
||||
border: solid #bcbcbc;
|
||||
border-width:1px;
|
||||
border-radius:8px;
|
||||
margin-bottom:15px;
|
||||
text-align:center;
|
||||
line-height:100px;
|
||||
position:relative;
|
||||
font-size:12px;
|
||||
font-family:verdana;
|
||||
color:#555555;
|
||||
background-image:url('../images/background_foot.png');
|
||||
background-repeat:repeat-x;
|
||||
background-position:bottom;
|
||||
background-color: #fff;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*Products style*/
|
||||
|
||||
.product
|
||||
{
|
||||
|
||||
display:block;
|
||||
position:relative;
|
||||
height:100%;
|
||||
margin-bottom:10px;
|
||||
|
||||
}
|
||||
|
||||
.title_product
|
||||
{
|
||||
|
||||
border:solid #ffffff;
|
||||
border-width:1px 0px 0px 0px;
|
||||
font-size:15px;
|
||||
font-weight:bold;
|
||||
display:block;
|
||||
/*clear:right;*/
|
||||
margin-bottom:4px;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px;*/
|
||||
|
||||
}
|
||||
|
||||
.image_list_prod
|
||||
{
|
||||
|
||||
border:solid #ffffff;
|
||||
border-width:1px;
|
||||
float:left;
|
||||
position:relative;
|
||||
padding:0px;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.description_product
|
||||
{
|
||||
|
||||
float:left;
|
||||
padding:20px;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.img_desc
|
||||
{
|
||||
|
||||
border:solid #ffffff;
|
||||
border-width:1px;
|
||||
margin-left:30px;
|
||||
margin-right:30px;
|
||||
|
||||
}
|
||||
|
||||
.desc_product
|
||||
{
|
||||
|
||||
border:solid #ffffff;
|
||||
border-width:0px 0px 1px 0px;
|
||||
overflow:auto;
|
||||
height:100%;
|
||||
padding-bottom:5px;
|
||||
|
||||
|
||||
}
|
||||
|
||||
a.ship {
|
||||
|
||||
display: block;
|
||||
border: solid #cbcbcb;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
background-image:url('../images/background_barr.png');
|
||||
background-position:bottom center;
|
||||
background-repeat:repeat-x;
|
||||
text-align:center;
|
||||
min-width:100px;
|
||||
min-height: 28px;
|
||||
float:left;
|
||||
line-height:28px;
|
||||
padding:5px;
|
||||
color: #868686;
|
||||
|
||||
}
|
||||
|
||||
a.ship:hover {
|
||||
|
||||
/*background-position: -87px 0px;*/
|
||||
|
||||
}
|
||||
|
||||
a.see {
|
||||
|
||||
display: block;
|
||||
min-width: 126px;
|
||||
min-height: 28px;
|
||||
border: solid #cbcbcb;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
background-image:url('../images/background_barr.png');
|
||||
background-position:bottom center;
|
||||
background-repeat:repeat-x;
|
||||
line-height:28px;
|
||||
text-align:center;
|
||||
float:left;
|
||||
margin-right:2px;
|
||||
padding:5px;
|
||||
color: #868686;
|
||||
|
||||
}
|
||||
|
||||
.see_products {
|
||||
|
||||
display: block;
|
||||
min-width: 126px;
|
||||
min-height: 28px;
|
||||
border: solid #cbcbcb;
|
||||
border-width:1px;
|
||||
border-radius:5px;
|
||||
background-image:url('../images/background_barr.png');
|
||||
background-position:bottom center;
|
||||
background-repeat:repeat-x;
|
||||
line-height:28px;
|
||||
text-align:center;
|
||||
/*border:solid #ffffff;
|
||||
border-width:1px 1px 1px 1px;*/
|
||||
float:left;
|
||||
margin-right:2px;
|
||||
padding:5px;
|
||||
color: #868686;
|
||||
|
||||
}
|
||||
#show_process_buying
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
|
||||
}
|
||||
|
||||
/*view big image css*/
|
||||
|
||||
#show_big_images
|
||||
{
|
||||
|
||||
display:none;
|
||||
position:fixed;
|
||||
width:100%;
|
||||
height:100%;
|
||||
z-index:150;
|
||||
background-color: #000;
|
||||
|
||||
}
|
||||
|
||||
#center_frame_image
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
width:100%;
|
||||
height:100%;
|
||||
z-index:151;
|
||||
|
||||
}
|
||||
|
||||
#frame_image
|
||||
{
|
||||
display:none;
|
||||
width:300px;
|
||||
height:300px;
|
||||
border: solid #ffffff;
|
||||
border-width:4px;
|
||||
border-radius:10px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-top:20px;
|
||||
position:relative;
|
||||
z-index:151;
|
||||
background-image:url('../images/loading_image_black.gif');
|
||||
background-position:center;
|
||||
background-repeat: no-repeat;
|
||||
background-color: #000;
|
||||
overflow:visible;
|
||||
|
||||
}
|
||||
|
||||
#icon_close_frame_image
|
||||
{
|
||||
|
||||
position:absolute;
|
||||
background-image:url('../images/close_black.png');
|
||||
background-position:center;
|
||||
background-repeat: no-repeat;
|
||||
width:30px;
|
||||
height:30px;
|
||||
display:block;
|
||||
z-index:152;
|
||||
color:#fff;
|
||||
right:0px;
|
||||
|
||||
}
|
||||
|
||||
.units
|
||||
{
|
||||
|
||||
width:40px;
|
||||
text-align:center;
|
||||
|
||||
}
|
||||
BIN
paramecio/modules/admin/media/images/ajax-loader.gif
Normal file
BIN
paramecio/modules/admin/media/images/ajax-loader.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 500 B |
BIN
paramecio/modules/admin/media/images/background.png
Normal file
BIN
paramecio/modules/admin/media/images/background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 332 B |
BIN
paramecio/modules/admin/media/images/background_title.png
Normal file
BIN
paramecio/modules/admin/media/images/background_title.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 476 B |
BIN
paramecio/modules/admin/media/images/background_title_login.png
Normal file
BIN
paramecio/modules/admin/media/images/background_title_login.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5 KiB |
BIN
paramecio/modules/admin/media/images/logo.png
Normal file
BIN
paramecio/modules/admin/media/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
5
paramecio/modules/admin/media/js/jquery.min.js
vendored
Normal file
5
paramecio/modules/admin/media/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
68
paramecio/modules/admin/models/admin.py
Normal file
68
paramecio/modules/admin/models/admin.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma.usermodel import UserModel
|
||||
from paramecio.cromosoma import corefields
|
||||
from paramecio.cromosoma.extrafields.emailfield import EmailField
|
||||
from paramecio.cromosoma.extrafields.passwordfield import PasswordField
|
||||
|
||||
class PrivilegesField(corefields.IntegerField):
|
||||
pass
|
||||
|
||||
def show_formatted(self, value):
|
||||
|
||||
value=int(value)
|
||||
|
||||
if value==0:
|
||||
return I18n.lang('admin', 'without_privileges', 'Without privileges')
|
||||
elif value==1:
|
||||
return I18n.lang('admin', 'selected_privileges', 'Selected privileges')
|
||||
elif value==2:
|
||||
return I18n.lang('admin', 'administrator', 'Administrator')
|
||||
|
||||
class UserAdmin(UserModel):
|
||||
|
||||
def create_fields(self):
|
||||
|
||||
# I can change other fields here, how the name.
|
||||
|
||||
self.register(corefields.CharField('username'))
|
||||
|
||||
self.fields['username'].required=True
|
||||
|
||||
self.register(PasswordField('password'))
|
||||
|
||||
self.fields['password'].required=True
|
||||
|
||||
self.register(EmailField('email'))
|
||||
|
||||
self.fields['email'].required=True
|
||||
|
||||
self.register(corefields.CharField('token_recovery'))
|
||||
|
||||
self.register(PrivilegesField('privileges'))
|
||||
|
||||
"""
|
||||
|
||||
user_admin=WebModel('user_admin')
|
||||
|
||||
user_admin.register(corefields.CharField('username'))
|
||||
|
||||
user_admin.fields['username'].required=True
|
||||
|
||||
user_admin.register(corefields.CharField('password'))
|
||||
|
||||
user_admin.fields['password'].required=True
|
||||
|
||||
user_admin.register(EmailField('email'))
|
||||
|
||||
user_admin.fields['email'].required=True
|
||||
|
||||
user_admin.register(corefields.CharField('token_recovery'))
|
||||
|
||||
user_admin.register(corefields.BooleanField('privileges'))
|
||||
|
||||
#user_admin.register(corefields.CharField('prueba'))
|
||||
|
||||
"""
|
||||
0
paramecio/modules/welcome/__init__.py
Normal file
0
paramecio/modules/welcome/__init__.py
Normal file
6
paramecio/modules/welcome/ajax/index.py
Normal file
6
paramecio/modules/welcome/ajax/index.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
def home(request, **args):
|
||||
|
||||
return "Hello ajaaax"
|
||||
|
||||
27
paramecio/modules/welcome/index.py
Normal file
27
paramecio/modules/welcome/index.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.mtemplates import ptemplate
|
||||
from paramecio.citoplasma.urls import make_url
|
||||
from bottle import route, request
|
||||
from settings import config
|
||||
|
||||
t=ptemplate(__file__)
|
||||
|
||||
@route('/welcome')
|
||||
def home():
|
||||
|
||||
return t.load_template('welcome.html', title="Welcome to Paramecio!!!", content="The simple web framework writed in Python3!!!")
|
||||
|
||||
@route('/welcome/<id:int>')
|
||||
def page(id):
|
||||
|
||||
return t.load_template('index.html', title="A simple example of a page", id=id, value=request.query.value)
|
||||
|
||||
@route('/welcome/test/<id:int>')
|
||||
def test(id):
|
||||
|
||||
return make_url('welcome/test/5', {'ohmygod': 'This is gooood', 'shutup':'Shut up!!'})
|
||||
|
||||
if config.default_module=="welcome":
|
||||
|
||||
home = route("/")(home)
|
||||
5
paramecio/modules/welcome/media/css/style.css
Normal file
5
paramecio/modules/welcome/media/css/style.css
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
body {
|
||||
|
||||
margin:0px;
|
||||
|
||||
}
|
||||
BIN
paramecio/modules/welcome/media/images/pimkie.jpg
Normal file
BIN
paramecio/modules/welcome/media/images/pimkie.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 528 KiB |
83
paramecio/modules/welcome/templates/index.html
Normal file
83
paramecio/modules/welcome/templates/index.html
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<!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">
|
||||
<%block name="content">
|
||||
<p><strong>This is an id from an url</strong>: ${id}</p>
|
||||
<p><strong>This is an query from an url with name value</strong>: ${value}</p>
|
||||
</%block>
|
||||
</div>
|
||||
|
||||
<div class="footer">Paramecio, a system created for create webapps</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
4
paramecio/modules/welcome/templates/welcome.html
Normal file
4
paramecio/modules/welcome/templates/welcome.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<%inherit file="index.html"/>
|
||||
<%block name="content">
|
||||
This is Paramecio, a simple web framework based in Bottle, Mako and Python 3.
|
||||
</%block>
|
||||
0
paramecio/settings/__init__.py
Normal file
0
paramecio/settings/__init__.py
Normal file
88
paramecio/settings/config.py.sample
Normal file
88
paramecio/settings/config.py.sample
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# You need install cromosoma for use this.
|
||||
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
|
||||
#server_used="wsgiref"
|
||||
|
||||
#Host/IP where bind the server
|
||||
|
||||
port=8080
|
||||
|
||||
debug=True
|
||||
|
||||
reloader=True
|
||||
|
||||
admin_folder='admin'
|
||||
|
||||
host='localhost'
|
||||
|
||||
allowed_ips=[]
|
||||
|
||||
#The theme by default
|
||||
|
||||
theme='default'
|
||||
|
||||
#Base directory for save modules
|
||||
|
||||
#base_modules="modules"
|
||||
|
||||
#Type server used for connect to the internet...
|
||||
|
||||
server_used="wsgiref"
|
||||
|
||||
#Module showed in index
|
||||
|
||||
default_module="welcome"
|
||||
|
||||
#Modules with permissions to access for users
|
||||
|
||||
modules=['paramecio.modules.welcome']
|
||||
|
||||
#Activate sessions?
|
||||
|
||||
session_enabled=True
|
||||
|
||||
#Variables for beaker sessions
|
||||
|
||||
cookie_name = 'paramecio.session'
|
||||
|
||||
session_opts = {
|
||||
'session.type': 'file',
|
||||
'session.cookie_expires': False,
|
||||
'session.data_dir': './sessions',
|
||||
'session.auto': True
|
||||
}
|
||||
|
||||
cache_session_opts = {
|
||||
|
||||
}
|
||||
|
||||
#The base url
|
||||
|
||||
base_url='/'
|
||||
|
||||
#Can be absolute or relative
|
||||
|
||||
media_url='/'
|
||||
|
||||
#SSL support built in server. You need cherrypy installed for use this.
|
||||
|
||||
ssl=False
|
||||
|
||||
# Cert file for ssl
|
||||
|
||||
cert_pem=''
|
||||
|
||||
# Key file for ssl
|
||||
|
||||
privkey_pem=''
|
||||
|
||||
#WARNING: only use this feature in development, not in production.
|
||||
|
||||
yes_static=True
|
||||
|
||||
#Database mysql config, if you want anything...
|
||||
|
||||
#WebModel.connections={'default': {'name': 'default', 'host': 'localhost', 'user': 'root', 'password': '', 'db': 'example', 'charset': 'utf8mb4', 'set_connection': False} }
|
||||
7
paramecio/settings/config_admin.py.sample
Normal file
7
paramecio/settings/config_admin.py.sample
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
modules_admin={'ausers': [I18n.lang('admin', 'users_admin', 'User\'s Admin'), 'paramecio.modules.admin.admin.ausers']}
|
||||
|
||||
#modules_admin={'ausers': [I18n.lang('admin', 'users_admin', 'User\'s Admin'), 'paramecio.modules.admin.admin.ausers'], 'module_father': [ I18n.lang('common', 'submodule', 'ModuleFather') , {'submodule': ['This is a module', 'paramecio.modules.admin.admin.ausers'] } ] }
|
||||
Loading…
Add table
Add a link
Reference in a new issue