コード例 #1
0
ファイル: import-texts.py プロジェクト: cerha/wiking
def import_texts(database, directory):
    connection = pytis.data.DBConnection(database=database)
    data = data_object('texts', ('text_id', 'label', 'lang', 'content'),
                       connection)
    label_data = data_object('text_labels', ('label', ), connection)
    label_column_type = label_data.columns()[0].type()
    for filename in os.listdir(directory):
        parts = filename.split('.')
        print("  - %s ..." % filename, end=' ')
        if filename.endswith('.txt') and len(parts) == 4:
            label = '.'.join(parts[:2])
            lang = parts[2]
            label_key = label_column_type.validate(label)[0]
            if not label_data.row(label_key):
                print("new label `%s' ..." % label, end=' ')
                label_data.insert(pytis.data.Row([('label', label_key)]))
            else:
                print("updating label `%s' ..." % label, end=' ')
            content = codecs.open(os.path.join(directory, filename), 'r',
                                  'utf-8').read()
            text_id = label + '@' + lang
            row_data = [(
                c.id(),
                c.type().validate(v)[0],
            ) for c, v in zip(data.columns(), [text_id, label, lang, content])]
            row = pytis.data.Row(row_data)
            error, success = data.update(row[0], row)
            if success:
                print("done")
            else:
                print("FAILED:", error)
        else:
            print("ignored (file name doesn't match the required pattern)")
コード例 #2
0
ファイル: import-texts.py プロジェクト: brailcom/wiking
def import_texts(database, directory):
    connection = pytis.data.DBConnection(database=database)
    data = data_object("texts", ("text_id", "label", "lang", "content"), connection)
    label_data = data_object("text_labels", ("label",), connection)
    label_column_type = label_data.columns()[0].type()
    for filename in os.listdir(directory):
        parts = filename.split(".")
        print "  - %s ..." % filename,
        if filename.endswith(".txt") and len(parts) == 4:
            label = ".".join(parts[:2])
            lang = parts[2]
            label_key = label_column_type.validate(label)[0]
            if not label_data.row(label_key):
                print "new label `%s' ..." % label,
                label_data.insert(pytis.data.Row([("label", label_key)]))
            else:
                print "updating label `%s' ..." % label,
            content = codecs.open(os.path.join(directory, filename), "r", "utf-8").read()
            text_id = label + "@" + lang
            row_data = [
                (c.id(), c.type().validate(v)[0]) for c, v in zip(data.columns(), [text_id, label, lang, content])
            ]
            row = pytis.data.Row(row_data)
            error, success = data.update(row[0], row)
            if success:
                print "done"
            else:
                print "FAILED:", error
        else:
            print "ignored (file name doesn't match the required pattern)"
コード例 #3
0
def check_form():
    """Zeptá se na název specifikace a zobrazí její report."""
    resolver = pytis.util.resolver()
    spec = pytis.form.run_dialog(pytis.form.InputDialog,
                                 message="Kontrola defsu",
                                 prompt="Specifikace",
                                 input_width=30)
    if spec:
        try:
            data_spec = resolver.get(spec, 'data_spec')
            view_spec = resolver.get(spec, 'view_spec')
        except pytis.util.ResolverError:
            msg = 'Specifikace nenalezena.'
            pytis.form.run_dialog(pytis.form.Warning, msg)
            return
        data = data_spec.create(dbconnection_spec=config.dbconnection)
        # Title
        obsah = "Title: %s\n" % (view_spec.title())
        # Název tabulky
        obsah += "Tabulka: %s\n\n" % (data.table(data.columns()[0].id()))
        # Políčka v bindings
        obsah += "Políčka v data_spec:\n%s\n\n" % \
                 "\n".join(["  - %s" % c.id()
                            for c in data.columns() if c.id() != 'oid'])
        # Políčka ve fields
        obsah += "Políčka ve fields:\n%s\n\n" % \
                 "\n".join(["  - %s" % f.id() for f in view_spec.fields()])
        # Actions - TODO: Bude třeba zohlednit vnořené seznamy a ActionGroup.
        # obsah += "\n\nAkce kontextového menu:\n\n"
        # actions = view_spec.actions()
        # if actions:
        #     obsah += "\n".join([a.title() for a in actions])
        # else:
        #     obsah += "Nejsou definovány"
        # Default select
        _get_default_select(spec)
        pytis.form.run_dialog(pytis.form.Message,
                              "DEFS: %s" % spec,
                              report=obsah)
コード例 #4
0
ファイル: defs.py プロジェクト: brailcom/pytis
def check_form():
    """Zeptá se na název specifikace a zobrazí její report."""
    resolver = pytis.util.resolver()
    spec = pytis.form.run_dialog(pytis.form.InputDialog,
                                 message="Kontrola defsu",
                                 prompt="Specifikace",
                                 input_width=30)
    if spec:
        try:
            data_spec = resolver.get(spec, 'data_spec')
            view_spec = resolver.get(spec, 'view_spec')
        except pytis.util.ResolverError:
            msg = 'Specifikace nenalezena.'
            pytis.form.run_dialog(pytis.form.Warning, msg)
            return
        data = data_spec.create(dbconnection_spec=config.dbconnection)
        # Title
        obsah = "Title: %s\n" % (view_spec.title())
        # Název tabulky
        obsah += "Tabulka: %s\n\n" % (data.table(data.columns()[0].id()))
        # Políčka v bindings
        obsah += "Políčka v data_spec:\n%s\n\n" % \
                 "\n".join(["  - %s" % c.id()
                            for c in data.columns() if c.id() != 'oid'])
        # Políčka ve fields
        obsah += "Políčka ve fields:\n%s\n\n" % \
                 "\n".join(["  - %s" % f.id() for f in view_spec.fields()])
        # Actions - TODO: Bude třeba zohlednit vnořené seznamy a ActionGroup.
        # obsah += "\n\nAkce kontextového menu:\n\n"
        # actions = view_spec.actions()
        # if actions:
        #     obsah += "\n".join([a.title() for a in actions])
        # else:
        #     obsah += "Nejsou definovány"
        # Default select
        _get_default_select(spec)
        pytis.form.run_dialog(pytis.form.Message, "DEFS: %s" % spec, report=obsah)
コード例 #5
0
ファイル: www.py プロジェクト: cerha/pytis
def form_validate(spec, prefill):
    # Sestavíme datový objekt
    data = pytis.util.data_object(spec)
    if not data:
        return None, None
    failed = []
    row = []
    for c in data.columns():
        if c.id() in prefill:
            value, error = c.type().validate(prefill[c.id()])
            if error:
                failed.append(c.id())
                continue
            else:
                row.append((c.id(), value))
    if len(failed) > 0:
        return None, failed
    else:
        return pytis.data.Row(row), None
コード例 #6
0
ファイル: www.py プロジェクト: nicLucian/pytis
def form_validate(spec, prefill):
    # Sestavíme datový objekt
    data = data_object(spec)
    if not data:
        return None, None
    failed = []
    row = []
    for c in data.columns():
        if c.id() in prefill:
            value, error = c.type().validate(prefill[c.id()])
            if error:
                failed.append(c.id())
                continue
            else:
                row.append((c.id(), value))
    if len(failed) > 0:
        return None, failed
    else:
        return pytis.data.Row(row), None