Esempio n. 1
0
def edit(modelclass, dbrow, ui):
    for metadata in sorted(models.get_metadata(modelclass)):
        editor = _EDITORS.get(metadata.coltype)
        if editor:
            editor(ui, modelclass, metadata, dbrow)
        else:
            ui.error("No user interface for %r of type %r." % (metadata.colname, metadata.coltype))
Esempio n. 2
0
 def show(self, argv):
     """show ...
 Show the selected row."""
     dbrow = self._select_one(argv)
     if dbrow is not None:
         for metadata in sorted(models.get_metadata(self._obj)):
             self._print("%20.20s: %s" % (metadata.colname, getattr(dbrow, metadata.colname)))
Esempio n. 3
0
def build_add_form(form, modelclass):
    BR = form.get_new_element("Br")
    outerfs = form.add_fieldset(modelclass.__name__)
    for metadata in sorted(models.get_metadata(modelclass)):
        new_input(outerfs, modelclass, metadata)
        outerfs.append(BR)
    form.add_input(type="submit", name="submit", value="submit")
Esempio n. 4
0
def build_add_form(form, modelclass):
    BR = form.get_new_element("Br")
    outerfs = form.add_fieldset(modelclass.__name__)
    for metadata in sorted(models.get_metadata(modelclass)):
        new_input(outerfs, modelclass, metadata)
        outerfs.append(BR)
    form.add_input(type="submit", name="submit", value="submit")
Esempio n. 5
0
def view(request, tablename=None, rowid=None):
    klass = get_model(tablename)
    dbrow = webhelpers.get_row(klass, rowid)
    resp = framework.ResponseDocument(request,
                                      doc_constructor,
                                      title="Table %s %s" % (tablename, dbrow))
    NM = resp.nodemaker
    resp.new_para((
        NM("A", {"href": request.get_url(addentry, tablename=tablename)},
           resp.get_icon("add")),
        NM("A",
           {"href": request.get_url(edit, tablename=tablename, rowid=rowid)},
           resp.get_icon("edit")),
        NM("A",
           {"href": "javascript:doDeleteItem(%r, %r);" % (tablename, rowid)},
           resp.get_icon("delete")),
    ))
    cycler = itertools.cycle(["row1", "row2"])
    tbl = resp.doc.add_table(width="100%", class_="rowdisplay")
    tbl.caption("%s #%s" % (tablename, rowid))
    tbl.new_headings("Field", "Value")
    for metadata in sorted(models.get_metadata(klass)):
        row = tbl.new_row()
        setattr(row, "class_", cycler.next())
        row.new_column(metadata.colname)
        row.new_column(str(getattr(dbrow, metadata.colname)))
    return resp.finalize()
Esempio n. 6
0
def build_edit_form(form, modelclass, row, error=None):
    BR = form.get_new_element("Br")
    if error is not None:
        form.new_para(error, class_="error")
    outerfs = form.add_fieldset(modelclass.__name__)
    for metadata in sorted(models.get_metadata(modelclass)):
        create_input(outerfs, modelclass, metadata, row)
        outerfs.append(BR)
    form.add_input(type="submit", name="submit", value="submit")
Esempio n. 7
0
def build_edit_form(form, modelclass, row, error=None):
    BR = form.get_new_element("Br")
    if error is not None:
        form.new_para(error, class_="error")
    outerfs = form.add_fieldset(modelclass.__name__)
    for metadata in sorted(models.get_metadata(modelclass)):
        create_input(outerfs, modelclass, metadata, row)
        outerfs.append(BR)
    form.add_input(type="submit", name="submit", value="submit")
Esempio n. 8
0
def create(modelclass, ui):
    data = {}
    for metadata in sorted(models.get_metadata(modelclass)):
        ctor = _CREATORS.get(metadata.coltype)
        if ctor:
            data[metadata.colname] = ctor(ui, modelclass, metadata)
        else:
            ui.error("No user interface for %r of type %r." % (metadata.colname, metadata.coltype))
    dbrow =  models.create(modelclass)
    return update_row(modelclass, dbrow, data)
Esempio n. 9
0
 def describe(self, argv):
     """describe
 Describe the table columns."""
     for metadata in sorted(models.get_metadata(self._obj)):
         if metadata.coltype == "RelationshipProperty":
             self._print("%20.20s: %s (%s) m2m=%s, nullable=%s, uselist=%s, collection=%s" % (
                     metadata.colname, metadata.coltype, metadata.default,
                     metadata.m2m, metadata.nullable, metadata.uselist, metadata.collection))
         else:
             self._print("%20.20s: %s (%s)" % (
                     metadata.colname, metadata.coltype, metadata.default))
Esempio n. 10
0
def update_row(modelclass, dbrow, data):
    for metadata in models.get_metadata(modelclass):
        value = data.get(metadata.colname)
        if not value and metadata.nullable:
            value = None
        if metadata.coltype == "RelationshipProperty":
            relmodel = getattr(modelclass, metadata.colname).property.mapper.class_
            if isinstance(value, list):
                if not value:
                    continue
                t = _session.query(relmodel).filter(relmodel.id.in_(value)).all()
                if metadata.collection == "MappedCollection":
                    setattr(dbrow, metadata.colname, dict((o.name, o) for o in t))
                else:
                    setattr(dbrow, metadata.colname, t)
            elif value is None:
                if metadata.uselist:
                    if metadata.collection == "MappedCollection":
                        value = {}
                    else:
                        value = []
                setattr(dbrow, metadata.colname, value)
            else:
                related = _session.query(relmodel).get(value)
                setattr(dbrow, metadata.colname, related)

        elif metadata.coltype == "PickleText":
            if value is None:
                if metadata.nullable:
                    setattr(dbrow, metadata.colname, value)
                else:
                    setattr(dbrow, metadata.colname, "")
            else:
                try:
                    value = eval(value, {}, {})
                except: # allows use of unquoted strings.
                    pass
                setattr(dbrow, metadata.colname, value)

        elif metadata.coltype == "JsonText":
            if value is None:
                if metadata.nullable:
                    setattr(dbrow, metadata.colname, value)
                else:
                    setattr(dbrow, metadata.colname, "")
            else:
                value = json.loads(value)
                setattr(dbrow, metadata.colname, value)
        else:
            setattr(dbrow, metadata.colname, value)
    return dbrow
Esempio n. 11
0
 def edit(self, argv):
     """edit [<fieldname>]
 Edit this row object."""
     if len(argv) > 1:
         for fname in argv[1:]:
             for metadata  in models.get_metadata(self._obj.__class__):
                 if metadata.colname == fname:
                     editor = _EDITORS.get(metadata.coltype)
                     if editor:
                         editor(self._ui, self._obj.__class__, metadata, self._obj)
                     else:
                         self._ui.error("No user interface for %r of type %r." % (metadata.colname, metadata.coltype))
     else:
         edit(self._obj.__class__, self._obj, self._ui)
Esempio n. 12
0
def view(request, tablename=None, rowid=None):
    klass = get_model(tablename)
    dbrow = webhelpers.get_row(klass, rowid)
    resp = framework.ResponseDocument(request, doc_constructor,
             title="Table %s %s" % (tablename, dbrow))
    NM = resp.nodemaker
    resp.new_para(
            (NM("A", {"href": request.get_url(addentry, tablename=tablename)},
                resp.get_icon("add")),
            NM("A", {"href": request.get_url(edit, tablename=tablename, rowid=rowid)},
                resp.get_icon("edit")),
            NM("A", {"href": "javascript:doDeleteItem(%r, %r);" % (tablename, rowid)},
                resp.get_icon("delete")),
            ))
    cycler = itertools.cycle(["row1", "row2"])
    tbl = resp.doc.add_table(width="100%", class_="rowdisplay")
    tbl.caption("%s #%s" % (tablename, rowid))
    tbl.new_headings("Field", "Value")
    for metadata in sorted(models.get_metadata(klass)):
        row = tbl.new_row()
        setattr(row, "class_", cycler.next())
        row.new_column(metadata.colname)
        row.new_column(str(getattr(dbrow, metadata.colname)))
    return resp.finalize()
Esempio n. 13
0
import itertools

from pycopia.WWW import framework
from pycopia.WWW.middleware import auth
from pycopia.WWW import HTML5

from pycopia.aid import IF
from pycopia.db import types
from pycopia.db import models
from pycopia.db import webhelpers

from sqlalchemy.exc import DataError, IntegrityError
#from sqlalchemy import and_, or_

TC_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestCase))
#TR_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestResult))

TINY_MCE_EDIT_INIT = """
    tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        editor_selector : "TEXT",
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "none"
        });
"""
Esempio n. 14
0
 def _setup(self, obj, prompt):
     super(CreateCommands, self)._setup(obj, prompt)
     self._metadata = sorted(models.get_metadata(obj.__class__))
Esempio n. 15
0
def get_table_metadata(modelname):
    klass = get_model(modelname)
    return models.get_metadata(klass)
Esempio n. 16
0
 def get_prompt(cls, dbrow):
     cls._metadata = sorted(models.get_metadata(dbrow.__class__))
     return "%%ISession%%N:%s> " % (dbrow.session_key,)
Esempio n. 17
0
 def get_prompt(cls, dbrow):
     cls._metadata = sorted(models.get_metadata(dbrow.__class__))
     mapper = models.class_mapper(dbrow.__class__)
     pkname = str(mapper.primary_key[0].name)
     return "%%I%s%%N:%s> " % (getattr(dbrow, pkname), dbrow)
Esempio n. 18
0
from pycopia.WWW import framework
from pycopia.WWW.middleware import auth
from pycopia.WWW import HTML5

from pycopia.aid import IF
from pycopia.db import types
from pycopia.db import models
from pycopia.db import webhelpers


from sqlalchemy.exc import DataError, IntegrityError
#from sqlalchemy import and_, or_



TC_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestCase))
#TR_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestResult))


TINY_MCE_EDIT_INIT="""
    tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        editor_selector : "TEXT",
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "none"
        });