Nova postagem

查找

Artigo
· Jun. 20 4min de leitura

Uso del motor de plantillas Mako de Python para generar contenido dinámico.

Los motores de plantillas son esenciales para producir contenido dinámico personalizable, sin necesidad de compilación y ofreciendo grandes posibilidades de extensibilidad para quienes usáis las plantillas. Especialmente si el motor de plantillas es compatible con Python. Una solución popular es Mako. Es una biblioteca de plantillas escrita en Python. Ofrece una sintaxis familiar, no basada en XML, que se compila en módulos de Python para obtener el máximo rendimiento. La sintaxis y API de Mako toma ideas de otros sistemas como las plantillas de Django y Jinja2, Cheetah, Myghty y Genshi. En concepto, Mako es un lenguaje de Python embebido (es decir, tipo "Python Server Page") que refina las ideas conocidas de diseño por componentes y herencia para ofrecer uno de los modelos más claros y flexibles disponibles, manteniendo además una estrecha relación con la forma en que Python maneja llamadas y ámbitos. Mako es utilizado por reddit.com, donde sirve más de mil millones de páginas vistas al mes. Es el lenguaje de plantillas predeterminado en los frameworks web Pylons y Pyramid.
(fuente: https://www.makotemplates.org/)

Ejemplo simple con Mako

Este fragmento de código demuestra el poder de Mako para generar contenido dinámico con soporte completo de Python:

<%inherit file="base.html"/>
<%
    rows = [[v for v in range(0,10)] for row in range(0,10)]
%>
<table>
    % for row in rows:
        ${makerow(row)}
    % endfor
</table>
<%def name="makerow(row)">
    <tr>
    % for name in row:
        <td>${name}</td>\
    % endfor
    </tr>
</%def>

Sentencias de Mako:

Statement <% ... %> Ejecuta códigos Pyhton; utilizado para lógica, bucles, condicionales, etc.
Block (for loops, if) <% if condition: %> / <% for item in items: %> Comienza un bloque de control. Debe cerrarse correctamente.
End of Block <% end %> or dedent in Python Marca el final de un bloque de control (dependiendo de la sintaxis).
Include Statement <%include file="filename" /> Incluye otra plantilla o fichero.
Call Function <%call expr()%> Llama a un bloque o macro definida en la plantilla.
Macro Definition <%def name(args): %> Define una macro que puede reutilizarse.
Macro Call <%call name(args)%> Llama a una macro definida con <%def %>.

 

Uso de plantillas Mako con IRIS

He desarrollado una aplicación IRIS que utiliza Mako y el paquete health-gforms de Open Exchange (https://openexchange.intersystems.com/package/health-gforms). Para esta aplicación, se usó Mako para generar un mensaje JSON válido en formato FHIR, con el fin de crear un nuevo paciente en el servidor:

{
    "resourceType": "Patient",
    "name": [
        {
            "use": "official",
            "given": [
                "${data['name']}"
            ],
            "family": "${data['family']}"
        }
    ],
    "gender": "${data['gender']}",
    "birthDate": "${data['birthDate']}",
    "telecom": [
        {
            "value": "${data['telecom']}",
            "use": "mobile",
            "system": "phone"
        }
    ]
}

Mako recibirá un objeto de datos con los nombres de pila y apellidos del paciente, género, fecha de nacimiento y contacto telefónico. Mako obtiene estos valores para aplicarlos al contenido final usando la instrucción ${}.

Cuando se renderiza la plantilla, el resultado es:

{
    "resourceType": "Patient",
    "name": [
        {
            "use": "official",
            "given": [
                "Jack"
            ],
            "family": "Chain"
        }
    ],
    "gender": "male",
    "birthDate": "1956-01-01",
    "telecom": [
        {
            "value": "555-555-555",
            "use": "mobile",
            "system": "phone"
        }
    ]
}

El código Python embebido en IRIS para renderizar la plantilla es:

from mako.template import Template

...

for data in records:
        if getattr(data, "title") == "Given Name":
            makodata["name"] = getattr(data,"userResponse")
        elif getattr(data, "title") == "Family Name":
            makodata["family"] = getattr(data,"userResponse")
        elif getattr(data, "title") == "Gender":
            makodata["gender"] = getattr(data,"userResponse")
        elif getattr(data, "title") == "Birth Date":
            makodata["birthDate"] = getattr(data,"userResponse")
        elif getattr(data, "title") == "Phone":
            makodata["telecom"] = getattr(data,"userResponse")

template = Template(filename=templatepath)

return template.render(data=makodata)

1. Se crea una instancia de Template con el nombre del archivo de la plantilla.

2. El método template.render recibe makodata en la variable data y genera el contenido usando esos datos.

Discussão (0)0
Entre ou crie uma conta para continuar
Artigo
· Jun. 20 5min de leitura

非ミラー環境に、ミラー環境でオンラインバックアップしたバックアップファイルをリストアする方法

これは InterSystems FAQ サイトの記事です。

こちらの記事では、非ミラー環境にミラー環境でオンラインバックアップしたバックアップファイルをリストアする方法をご紹介します。

手順は大きく分けて2つになります。


1.バックアップファイルからリストアを行う

2.データベースファイルのミラー属性を削除する



1.バックアップファイルからリストアを行う

以下は、^DBREST ユーティリティによる対話形式のリストア方法になります。

%SYS>do ^DBREST
                        Cache DBREST Utility
         Restore database directories from a backup archive
 
Restore: 1. All directories
         2. Selected and/or renamed directories
         3. Display backup volume information
         4. Exit the restore program
    1 => 2    // <-- <Enter> ミラー環境でバックアップしたバックアップファイルを、ミラー環境ではない環境にリストアする場合は、2 を選択する必要があります
              //     ※『1. All directories』を選択した場合、リストア対象はミラーデータベースのみになるため、ミラーでなければリストアはされません
Do you want to set switch 10 so that other processes will be
prevented from running during the restore? Yes =>   // <-- <Enter>
// Yes の場合、リストア中に他のプロセスがグローバルデータにアクセスできないように制御するスイッチ10を設定します。   
Specify input file for volume 1 of backup 1
 (Type STOP to exit)
Device: C:\Backup\FullDBList_20250402_001.cbk   // <-- バックアップファイルパス
This backup volume was created by:
   IRIS for Windows (x86-64) 2024.1
The volume label contains:
   Volume number      1
   Volume backup      APR 2 2025 09:50AM Full
   Previous backup    DEC 23 2024 12:21PM Full
   Last FULL backup   DEC 23 2024 12:21PM
   Description        Full backup of all databases that are in the backup database list.
   Buffer Count       0
   Mirror name        TESTMIRROR
   Failover Member    MACHINEA
Is this the backup you want to start restoring? Yes =>   // <-- <Enter>
Restoring a mirror backup but this system is not a mirror member
 
For each database included in the backup file, you can:
 
 -- press RETURN to restore it to its original directory;
 -- type X, then press RETURN to skip it and not restore it at all.
 -- type a different directory name.  It will be restored to the directory
    you specify.  (If you specify a directory that already contains a
    database, the data it contains will be lost).
 
c:\intersystems\iris\mgr\mirrordata\ (:mirror:TESTMIRROR:MIRRORDATA) =>   // <-- 同じで良ければ <Enter>
Directory c:\intersystems\iris\mgr\mirrordata\ does not contain a database
or it can't be accessed.
Do you want to create this database? Yes =>   // <-- <Enter> IRIS.datがないときは作成する
Do you want to change this list of directories? No =>   // <-- <Enter>
Restore will overwrite the data in the old database. Confirm Restore? No => y   // <-- y+<Enter>
***Restoring c:\intersystems\iris\mgr\mirrordata\ at 10:22:10
84 blocks restored in 0.0 seconds for this pass, 84 total restored.
 
***Restoring c:\intersystems\iris\mgr\mirrordata\ at 10:22:10
2 blocks restored in 0.0 seconds for this pass, 86 total restored.
 
***Restoring c:\intersystems\iris\mgr\mirrordata\ at 10:22:10
2 blocks restored in 0.0 seconds for this pass, 88 total restored.
 
 
Specify input file for volume 1 of backup following APR 2 2025  09:50AM
 (Type STOP to exit)
Device: STOP   <-- STOP+<Enter>

Do you have any more backups to restore? Yes => N   // <-- 他になければ N+<Enter>
Mounting c:\intersystems\iris\mgr\mirrordata\ which is a mirrored DB
  c:\intersystems\iris\mgr\mirrordata\ ... (Mounted)

There are mirrored DBs restored, please make sure the mirror
journal files are copied to a specific directory in order to
let system restore the journal records.
Please enter the directory contains the mirror journal files:
<C:\InterSystems\IRIS\mgr\journal\>?    // <-- 特になければ <Enter>
*** WARNING **** Failed to restore the journal records for the mirrored DBs
// バックアップからリストアした後、さらに現時点のDBまでミラージャーナルファイルを使用してキャッチアップするかどうかの選択
// バックアップ時点までで良ければ、そのまま<Enter>するとディレクトリ内にリストア対象のミラージャーナルがないため、上記Warningが出てリストアは終了する
%SYS>


2.データベースファイルのミラー属性を削除する

ミラー環境で取得したバックアップを、非ミラー環境にリストアすると、そのままではDB書き込みができません。
これは、リストアされたデータベースは、読み取り専用でマウントされるためです。
(ミラーデータベースについては、別ミラー環境やミラー構成でない環境にリストアすると読み取り専用になります)
この為、リストア完了後に以下の操作にてデータベースファイルのミラー属性を削除する必要があります。

手順は、以下のようになります。

%SYS>do ^MIRROR
This instance is not initialized as a mirror member

1) List mirrored databases
2) Remove one or more mirrored databases
3) Create a Mirror
4) Join Mirror as Failover Member  // ミラーが有効になっている場合、この設定が表示されます
5) Join Mirror as Async Member    // ミラーが有効になっている場合、この設定が表示されます
Option? 2    // Mirror DBからMirror 属性を削除します
There are xxx mirrored databases on this system
Remove (O)ne mirrored database, (A)ll mirrored databases or (Q)uit? <quit> A  // A + <Enter> すべてのMirror DBを対象とします
// ミラーDBが1つしかないときは以下のようになります。Yでミラー属性を削除します
// There is one mirrored database on this system
// Remove it? <No> // Y + <Enter>
Removing c:\intersystems\iris\mgr\mirrordata\ ...succeeded
:
Press <enter> to return to the main menu...  // <Enter> で抜けます
1) List mirrored databases
2) Remove one or more mirrored databases
3) Enable Mirror Service
:
Option?
%SYS>

これで、リストアは完了です。

詳細は以下のドキュメントをご覧ください。
ミラーリングされたデータベースのフルバックアップ・リストア

Discussão (0)0
Entre ou crie uma conta para continuar
Anúncio
· Jun. 20

Discount Kitchen Worktops

Simply Stone Worktops specialises in crafting premium discount kitchen worktops. Based in the UK, they offer bespoke designs, expert installation, and high-quality materials, ensuring stunning, durable surfaces tailored to individual needs. 

Discussão (0)1
Entre ou crie uma conta para continuar
InterSystems Oficial
· Jun. 19 4min de leitura

2025.1 打造时尚现代的互操作性用户体验

互操作性用户界面现在包括可以在所有互操作性产品中使用的 DTL 编辑器生产配置应用程序的现代化用户体验。您可以在现代化视图与标准视图之间切换。所有其他互操作性屏幕仍采用标准用户界面。请注意,仅对这两个应用程序进行了更改,我们在下面确定了当前可用的功能。

要在升级前试用新屏幕,您可以点击这里,从我们的社区工具包网页中下载 2025.1 版:https://evaluation.intersystems.com/Eval/。请观看“学习服务”中的简短教程构建集成:一种新的用户体验,了解对这些屏幕进行的用户增强!

Discussão (0)0
Entre ou crie uma conta para continuar
Pergunta
· Jun. 19

Namespace vs database

I'm confused about the differences between a namespace and a database.

I understand that a database is a single IRIS.DATA file in a directory in the os hosting IRIS.

What is the difference between a namespace and a database?

Can I write data into a database without specifying a namespace?
If so how do I write to a particlar DB in objectscript?

Does a database have to be in a namespace?
Can a database be in more than one namespace?

Can a namespace have only one 'routine' database and only one 'data' database?

2 novos comentários
Discussão (8)5
Entre ou crie uma conta para continuar