commit 18a0d48c8c96c7a380cda54b285dbdcc6b547b99 Author: Antonio de la Rosa Date: Mon Dec 7 03:39:06 2015 +0100 Added new files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f72829 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*~ +*.pyc +__pycache__ +modules/* +!modules/welcome +!modules/admin +settings/* +!settings/__init__.py +!settings/config.py.sample +themes/* +!themes/default/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d6a9326 --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e2a4e0 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# A simple webframework based in Bottle and Mako for create nice webapps + diff --git a/REQUIREMENTS b/REQUIREMENTS new file mode 100644 index 0000000..57fd9a2 --- /dev/null +++ b/REQUIREMENTS @@ -0,0 +1,11 @@ +# REQUIREMENTS + +- Python >3.3 +- Bottle 0.12+ +- Jinja2 +- passlib +- cffi +- bcrypt + +Use PIP is recommended for new installations. + diff --git a/citoplasma/__init__.py b/citoplasma/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/citoplasma/check_i18n.py b/citoplasma/check_i18n.py new file mode 100644 index 0000000..47904e8 --- /dev/null +++ b/citoplasma/check_i18n.py @@ -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 + + \ No newline at end of file diff --git a/citoplasma/filterip.py b/citoplasma/filterip.py new file mode 100644 index 0000000..d820df6 --- /dev/null +++ b/citoplasma/filterip.py @@ -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 + \ No newline at end of file diff --git a/citoplasma/generate_admin_class.py b/citoplasma/generate_admin_class.py new file mode 100644 index 0000000..53d4e54 --- /dev/null +++ b/citoplasma/generate_admin_class.py @@ -0,0 +1,118 @@ +from citoplasma.lists import SimpleList +from bottle import request, redirect +from citoplasma.urls import add_get_parameters +from citoplasma.templates import set_flash_message +from cromosoma.formsutils import show_form +from citoplasma.i18n import I18n +from 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) + diff --git a/citoplasma/gunicornssl.py b/citoplasma/gunicornssl.py new file mode 100644 index 0000000..40f50de --- /dev/null +++ b/citoplasma/gunicornssl.py @@ -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() \ No newline at end of file diff --git a/citoplasma/hierarchy_links.py b/citoplasma/hierarchy_links.py new file mode 100644 index 0000000..d00b2af --- /dev/null +++ b/citoplasma/hierarchy_links.py @@ -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 ''+text+'' + + + def no_link(link, text): + + return text + diff --git a/citoplasma/httputils.py b/citoplasma/httputils.py new file mode 100644 index 0000000..63df909 --- /dev/null +++ b/citoplasma/httputils.py @@ -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 \ No newline at end of file diff --git a/citoplasma/i18n.py b/citoplasma/i18n.py new file mode 100644 index 0000000..8370d66 --- /dev/null +++ b/citoplasma/i18n.py @@ -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] + + diff --git a/citoplasma/lists.py b/citoplasma/lists.py new file mode 100644 index 0000000..21a6d68 --- /dev/null +++ b/citoplasma/lists.py @@ -0,0 +1,178 @@ +#By default id is not showed + +from citoplasma.pages import Pages +from citoplasma.urls import add_get_parameters +from citoplasma.sessions import get_session +from 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='
' + + 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(''+I18n.lang('common', 'edit', 'Edit')+'') + options.append(''+I18n.lang('common', 'delete', 'Delete')+'') + 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) + diff --git a/citoplasma/mtemplates.py b/citoplasma/mtemplates.py new file mode 100644 index 0000000..01d3ad2 --- /dev/null +++ b/citoplasma/mtemplates.py @@ -0,0 +1,189 @@ +#!/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_header_home) + + #self.auto_reload=True + + # Clean HeaderHTML + + HeaderHTML.css=[] + HeaderHTML.js=[] + HeaderHTML.header=[] + HeaderHTML.cache_header=[] + + def clean_header_cache(self): + + 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=module+'/templates' + + return TemplateLookup(directories=[theme_templates, module_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('') + + return "\n".join(final_js) + + def css_home(): + + final_css=[] + + for css in HeaderHTML.css: + final_css.append('') + + 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='
'+s['flash']+'
' + + s['flash']='' + + return message + diff --git a/citoplasma/pages.py b/citoplasma/pages.py new file mode 100644 index 0000000..2e2794b --- /dev/null +++ b/citoplasma/pages.py @@ -0,0 +1,72 @@ +#!/usr/bin/python3 + +from math import ceil, floor +from citoplasma.urls import add_get_parameters +from 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 += "1 << " + + arr_pages={} + + #for(x=initial_page;x"+str(num_page)+" " + arr_pages[begin_page]=''+str(num_page)+' '; + pages += arr_pages[x] + + + if last_page>> "+I18n.lang('common', 'last', 'Last')+"" + + + return pages + + diff --git a/citoplasma/sessions.py b/citoplasma/sessions.py new file mode 100644 index 0000000..247fce9 --- /dev/null +++ b/citoplasma/sessions.py @@ -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) \ No newline at end of file diff --git a/citoplasma/templates.py b/citoplasma/templates.py new file mode 100644 index 0000000..bcab461 --- /dev/null +++ b/citoplasma/templates.py @@ -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('') + + return "\n".join(final_js) + + def css_home(): + + final_css=[] + + for css in HeaderHTML.css: + final_css.append('') + + 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='
'+s['flash']+'
' + + s['flash']='' + + return message + diff --git a/citoplasma/urls.py b/citoplasma/urls.py new file mode 100644 index 0000000..81fbc3b --- /dev/null +++ b/citoplasma/urls.py @@ -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 \ No newline at end of file diff --git a/index.py b/index.py new file mode 100644 index 0000000..45f4ec8 --- /dev/null +++ b/index.py @@ -0,0 +1,112 @@ +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(): + + if config.yes_static==True: + + @route('/media/') + def send_static(filename): + return static_file(filename, root='themes/'+config.theme+'/media/') + + def add_func_static_module(module): + + @route('/mediafrom//') + def send_static_module(module, filename): + + path_module=module+'/media/' + + file_path_module=path_module+filename + + path=module+'/media/' + + 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: + + #dir_controllers=os.listdir(config.base_modules.replace('.', '/')+'/'+module) + + #arr_views=[x for x in dir_modules if x.find('.py')!=-1 and x.find('__init__')==-1] + """ + for controller in config.base_modules: + if controller.find('.py')!=-1 and controller.find('__init__')==-1: + controller=controller.replace('.py', '') + """ + controller_path=import_module(module) + + controller_base=os.path.dirname(controller_path.__file__) + + 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', '') + print(controller_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) + + 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) + + diff --git a/modules/admin/__init__.py b/modules/admin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/admin/admin/__init__.py b/modules/admin/admin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/admin/admin/ausers.py b/modules/admin/admin/ausers.py new file mode 100644 index 0000000..cafd2ca --- /dev/null +++ b/modules/admin/admin/ausers.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +from modules.admin.models.admin import UserAdmin +from citoplasma.urls import make_url +from citoplasma.generate_admin_class import GenerateAdminClass +from citoplasma.i18n import I18n +from 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() \ No newline at end of file diff --git a/modules/admin/index.py b/modules/admin/index.py new file mode 100644 index 0000000..6605b7d --- /dev/null +++ b/modules/admin/index.py @@ -0,0 +1,228 @@ +#!/usr/bin/python3 + +from citoplasma.mtemplates import ptemplate +from modules.admin.models.admin import UserAdmin +from citoplasma.i18n import load_lang, I18n +from citoplasma.urls import make_url, add_get_parameters +from citoplasma.sessions import get_session +from bottle import get,post +from settings import config +from settings import config_admin +from citoplasma.lists import SimpleList +from citoplasma.generate_admin_class import GenerateAdminClass +from citoplasma.httputils import GetPostFiles +from cromosoma.formsutils import show_form, pass_values_to_form +from 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+'/') +@post('/'+config.admin_folder+'/') +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 diff --git a/modules/admin/models/admin.py b/modules/admin/models/admin.py new file mode 100644 index 0000000..4cc709d --- /dev/null +++ b/modules/admin/models/admin.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 + +from citoplasma.i18n import I18n +from cromosoma.webmodel import WebModel +from cromosoma.usermodel import UserModel +from cromosoma import corefields +from cromosoma.extrafields.emailfield import EmailField +from 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')) + +""" \ No newline at end of file diff --git a/modules/welcome/__init__.py b/modules/welcome/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/welcome/ajax/index.py b/modules/welcome/ajax/index.py new file mode 100644 index 0000000..946b763 --- /dev/null +++ b/modules/welcome/ajax/index.py @@ -0,0 +1,6 @@ +#!/usr/bin/python3 + +def home(request, **args): + + return "Hello ajaaax" + diff --git a/modules/welcome/index.py b/modules/welcome/index.py new file mode 100644 index 0000000..05fadf5 --- /dev/null +++ b/modules/welcome/index.py @@ -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/') +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/') +def test(id): + + return make_url('welcome/test/5', {'ohmygod': 'This is gooood', 'shutup':'Shut up!!'}) + +if config.default_module=="welcome": + + home = route("/")(home) \ No newline at end of file diff --git a/modules/welcome/media/css/style.css b/modules/welcome/media/css/style.css new file mode 100644 index 0000000..3eabbc3 --- /dev/null +++ b/modules/welcome/media/css/style.css @@ -0,0 +1,5 @@ +body { + + margin:0px; + +} diff --git a/modules/welcome/media/images/pimkie.jpg b/modules/welcome/media/images/pimkie.jpg new file mode 100644 index 0000000..4df49d7 Binary files /dev/null and b/modules/welcome/media/images/pimkie.jpg differ diff --git a/modules/welcome/templates/index.html b/modules/welcome/templates/index.html new file mode 100644 index 0000000..590b0ed --- /dev/null +++ b/modules/welcome/templates/index.html @@ -0,0 +1,83 @@ + + + + + Paramecio WebFramework + + + + + +
+

${title}

+ +
+ <%block name="content"> +

This is an id from an url: ${id}

+

This is an query from an url with name value: ${value}

+ +
+ + +
+ + + + diff --git a/modules/welcome/templates/welcome.html b/modules/welcome/templates/welcome.html new file mode 100644 index 0000000..3893e68 --- /dev/null +++ b/modules/welcome/templates/welcome.html @@ -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. +