85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
import os
|
|
from paramecio2.libraries.generate_admin_class import GenerateAdminClass
|
|
#from paramecio2.libraries.db.adminutils import make_admin_url
|
|
#from paramecio.citoplasma.urls import make_url
|
|
from paramecio2.libraries.i18n import I18n
|
|
from settings import config
|
|
from modules.pages2.models import pages
|
|
|
|
from paramecio2.libraries.db.coreforms import BaseForm
|
|
from paramecio2.modules.admin import admin_app, t as admin_t
|
|
from flask import url_for, g
|
|
from paramecio2.libraries.mtemplates import env_theme, PTemplate
|
|
try:
|
|
import ujson as json
|
|
except:
|
|
import json
|
|
|
|
env=env_theme(__file__)
|
|
|
|
t=PTemplate(env)
|
|
|
|
t.env.directories=admin_t.env.directories
|
|
|
|
t.env.directories.insert(1, os.path.dirname(__file__).replace('/admin', '')+'/templates/admin')
|
|
|
|
@admin_app.route('/admin/pages2/', methods=['GET', 'POST'])
|
|
def admin_pages2():
|
|
|
|
#t=admin_t
|
|
|
|
conn=g.connection
|
|
|
|
page=pages.Page2(conn)
|
|
|
|
page.enctype=True
|
|
|
|
page.fields['slugify'].name_form=BaseForm
|
|
|
|
page.fields['text'].name_form=TextEditorJsForm
|
|
|
|
#page.fields['text'].extra_parameters[0].t=t
|
|
|
|
#url=make_admin_url('pages')
|
|
url=url_for('admin_app.admin_pages2')
|
|
|
|
admin=GenerateAdminClass(page, url, t)
|
|
|
|
admin.list.fields_showed=['id', 'title', 'slugify']
|
|
|
|
form_admin=admin.show()
|
|
|
|
#return admin.show()
|
|
if type(form_admin).__name__=='str':
|
|
|
|
return t.load_template('content.phtml', title=I18n.lang('pages', 'pages', 'Pages'), contents=form_admin, path_module='admin_app.admin_pages2')
|
|
else:
|
|
|
|
return form_admin
|
|
|
|
class TextEditorJsForm(BaseForm):
|
|
"""Form for html texts, based in tinycme javascript library"""
|
|
|
|
def __init__(self, name, value, t_add=None):
|
|
"""
|
|
Args:
|
|
name (str): The html name for this form
|
|
value (str): The default value of this html form.
|
|
t_add (PTemplate): If you want change the standard html form, use other template loader
|
|
"""
|
|
|
|
super().__init__(name, value)
|
|
|
|
self.t=t_add
|
|
|
|
if t_add==None:
|
|
self.t=t
|
|
|
|
#if type(self.default_value)==dict:
|
|
|
|
# self.default_value=json.dumps(value)
|
|
|
|
def form(self):
|
|
|
|
return self.t.load_template('editorjsform.phtml', form=self)
|
|
|