ui_core.py 12.3 KB
Newer Older
1 2 3 4 5 6
# -*- coding: utf-8 -*-
"""User Interface for the core tables

"""
import plugin_dbui as dbui

7
from gluon import current
8 9 10

fieldsModifier = dbui.FieldsModifier
formModifier = dbui.FormModifier
11
gridModifier = dbui.GridModifier
12 13 14
storeModifier = dbui.StoreModifier


15
class CoreUi(object):
16

17
    @staticmethod
18 19 20
    def configure(db, T):
        """Configure the user interface for the history table and
        its foreign tables,
21

22 23 24
        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
25

26 27 28 29 30 31 32 33 34 35 36
        """
        CoreUi.domains(db, T)
        CoreUi.events(db, T)
        CoreUi.fundings(db, T)
        CoreUi.history(db, T)
        CoreUi.object_categories(db, T)
        CoreUi.objects(db, T)
        CoreUi.people_categories(db, T)
        CoreUi.people(db, T)
        CoreUi.projects(db, T)
        CoreUi.teams(db, T)
37

38 39 40 41 42 43 44 45 46
    @staticmethod
    def domains(db, T):
        """UI for the domains table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
47
        # ....................................................................
48 49 50 51 52 53 54 55 56 57 58 59 60 61
        #
        # Store
        #
        storeModifier("domains").orderby(db.domains.domain)

    @staticmethod
    def events(db, T):
        """UI for the events table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
62
        # ....................................................................
63 64 65 66 67 68 69 70 71 72
        #
        # Fields
        #
        mdf = fieldsModifier("events")
        mdf.configure_field("data",
                            colProperty={"width": 70},
                            colType={"width": 70},
                            fieldLabel="",
                            xtype="xuserdata")

LE GAC Renaud's avatar
LE GAC Renaud committed
73
        # ....................................................................
74 75 76 77 78 79 80 81 82 83 84
        #
        # Form
        #
        mdf = formModifier("events")

        mdf.merge_fields("event", "definition", title=T("General"))
        mdf.merge_fields("data", title=T("Data model"))

        mdf.set_mapper(dbui.map_tabpanel)
        mdf.configure(plugins=["pUserDataConsistency"], width=450)

LE GAC Renaud's avatar
LE GAC Renaud committed
85
        # ....................................................................
86 87 88
        #
        # Grid
        #
89
        mdf = gridModifier("events")
90 91 92 93
        mdf.configure_column("event", width=30)
        mdf.hide_columns("data")

        row_widget = {
94 95 96
            "expandOnDblClick": False,
            "selectRowOnExpand": False,
            "ptype": "pRowWidget",
97
            "widget": {
98
                "xtype": "xroweventdata",
99
                "bind": {
100
                    "eventData": "{record.EventsData}"
101
                },
102
                "padding": "10 0 12 50"
103 104 105 106 107
            }
        }

        mdf.configure(plugins=[row_widget])

LE GAC Renaud's avatar
LE GAC Renaud committed
108
        # ....................................................................
109 110 111 112 113 114 115 116 117 118 119 120 121 122
        #
        # Store
        #
        storeModifier("events").orderby(db.events.event)

    @staticmethod
    def fundings(db, T):
        """UI for the fundings table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
123
        # ....................................................................
124 125 126
        #
        # Grid
        #
127
        mdf = gridModifier("fundings")
128 129
        mdf.configure_column("agency", width=40)

LE GAC Renaud's avatar
LE GAC Renaud committed
130
        # ....................................................................
131 132 133 134 135 136 137 138 139 140 141 142 143 144
        #
        # Store
        #
        storeModifier("fundings").orderby(db.fundings.agency)

    @staticmethod
    def history(db, T):
        """UI for the history table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
145 146
        undef = current.T(dbui.UNDEF)

LE GAC Renaud's avatar
LE GAC Renaud committed
147
        # ....................................................................
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
        #
        # Fields
        #
        mdf = fieldsModifier("history")

        mdf.configure_field("data",
                            dictFieldData="EventsData",
                            dictFieldEvent="EventsEvent",
                            dictFieldIdEvent="EventsId",
                            formFieldIdEvent="HistoryId_events",
                            store="eventsStore",
                            trUndefined=undef,
                            xtype="xuserdatamultidefault")

        mdf.configure_field("start_date", flex=1)
        mdf.configure_field("end_date", flex=1)
        mdf.merge_fields("start_date", "end_date", fieldLabel=T("Period"))

        mdf.configure_field("note", height=150)

LE GAC Renaud's avatar
LE GAC Renaud committed
168
        # ....................................................................
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
        #
        # Form
        #
        mdf = formModifier("history")
        mdf.merge_fields("id_domains",
                         "id_teams",
                         "id_projects",
                         "id_fundings",
                         title=T("Metadata"))

        mdf.merge_fields("id_people",
                         "id_people_categories",
                         "percentage",
                         title=T("Person"))

        mdf.merge_fields("id_objects",
                         "id_object_categories",
                         title=T("Object"))

        mdf.merge_fields("id_events",
                         "start_date",
                         "data",
                         title=T("Event"))

        mdf.merge_fields("note", title=T("Note"))

        mdf.set_mapper(dbui.map_tabpanel)

        mdf.configure(buttonAlign="right", width=450)

LE GAC Renaud's avatar
LE GAC Renaud committed
199
        # ....................................................................
200 201 202
        #
        # Grid
        #
203
        mdf = gridModifier("history")
204 205 206 207 208 209 210 211 212 213 214 215 216 217

        row_widget = {
            "expandOnDblClick": False,
            "selectRowOnExpand": False,
            "ptype": "pRowWidget",
            "widget": {
                "xtype": "xrowhistorydata",
                "bind": {
                    "historyData": "{record.HistoryData}"
                },
                "padding": "10 0 12 50"
            }
        }

218 219 220 221
        mdf.configure(plugins=["pGridRowEditorConfirmDelete",
                               "pGridRowEditorDblClick",
                               "pHistoryContextMenu",
                               "pGridToolbar",
222 223
                               "pGridPaging",
                               row_widget])
224 225 226 227 228 229 230 231 232 233 234 235 236

        mdf.hide_columns("data",
                         "id_domains",
                         "id_object_categories",
                         "id_people_categories",
                         "note",
                         "percentage")

        mdf.append_filter(("id_events", "==", T("is equal to")))
        mdf.append_filter(("id_domains", "==", T("is equal to")))
        mdf.append_filter(("id_teams", "==", T("is equal to")))
        mdf.append_filter(("id_projects", "==", T("is equal to")))
        mdf.append_filter(("id_fundings", "==", T("is equal to")))
237
        mdf.append_filter(("id_people", "==", T("is equal to")))
238
        mdf.append_filter(("id_people_categories", "==", T("is equal to")))
239
        mdf.append_filter(("id_objects", "==", T("is equal to")))
240 241 242 243 244
        mdf.append_filter(("id_object_categories", "==", T("is equal to")))
        mdf.append_filter(("start_date", ">=", T("greater or equal to")))
        mdf.append_filter(("end_date", "<=", T("less or equal to")))

        mdf.append_filter(
LE GAC Renaud's avatar
LE GAC Renaud committed
245 246 247 248

            ("data", "like",
             "key(s) is(are) equal to value(s). The jocker is %"),

249 250 251 252 253 254 255 256 257 258
            fieldLabel=T("Data"),
            header=[T("key"), T("value")],
            numColumns=2,
            numRows=3,
            xtype="xtablefield")

        mdf.configure_filters(plugins=["pFormToolTip"],
                              width=300,
                              xtype="xhistorygridfilter")

LE GAC Renaud's avatar
LE GAC Renaud committed
259
        # ....................................................................
260 261 262 263 264 265 266 267 268 269 270 271 272 273
        #
        # Store
        #
        storeModifier("history").orderby(~db.history.id)

    @staticmethod
    def object_categories(db, T):
        """UI for the object_categories table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
274
        # ....................................................................
275 276 277 278 279 280 281
        #
        # Grid
        #
        mdf = gridModifier("object_categories")
        mdf.configure_column("code", width=20)
        mdf.configure_column("category", width=20)

LE GAC Renaud's avatar
LE GAC Renaud committed
282
        # ....................................................................
283 284 285 286 287 288 289 290 291 292 293 294 295 296
        #
        # Store
        #
        storeModifier("object_categories").orderby(db.object_categories.code)

    @staticmethod
    def objects(db, T):
        """UI for the objects table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
297
        # ....................................................................
298 299 300 301 302 303 304 305 306 307 308
        #
        # Grid
        #
        mdf = gridModifier("objects")

        mdf.append_filter(("reference", "contains", T("contains")))
        mdf.append_filter(("serial_number", "contains", T("contains")))
        mdf.append_filter(("batch_number", "contains", T("contains")))

        mdf.configure_filters(plugins=["pFormToolTip"], width=300)

LE GAC Renaud's avatar
LE GAC Renaud committed
309
        # ....................................................................
310 311 312 313 314 315 316 317 318 319 320 321 322 323
        #
        # Store
        #
        storeModifier("objects").orderby(db.objects.reference)

    @staticmethod
    def people_categories(db, T):
        """UI for the people_categories table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
324
        # ....................................................................
325 326 327 328 329 330 331
        #
        # Grid
        #
        mdf = gridModifier("people_categories")
        mdf.configure_column("code", width=20)
        mdf.configure_column("category", width=20)

LE GAC Renaud's avatar
LE GAC Renaud committed
332
        # ....................................................................
333 334 335 336 337 338 339 340 341 342 343 344 345 346
        #
        # Store
        #
        storeModifier("people_categories").orderby(db.people_categories.code)

    @staticmethod
    def people(db, T):
        """UI for the people table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
347
        # ....................................................................
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
        #
        # Grid
        #
        mdf = gridModifier("people")
        mdf.configure_column("birth_date", width=20)
        mdf.configure_column("first_name", width=30)
        mdf.configure_column("initials", width=15)
        mdf.configure_column("last_name", width=30)

        mdf.append_filter(("last_name", "contains", T("contains")))
        mdf.append_filter(("first_name", "contains", T("contains")))
        mdf.append_filter(("initials", "contains", T("contains")))

        mdf.configure_filters(plugins=["pFormToolTip"], width=300)

LE GAC Renaud's avatar
LE GAC Renaud committed
363
        # ....................................................................
364 365 366 367 368 369 370 371 372 373 374 375 376 377
        #
        # Store
        #
        storeModifier("people").orderby(db.people.last_name)

    @staticmethod
    def projects(db, T):
        """UI for the projects table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
378
        # ....................................................................
379 380 381 382 383 384
        #
        # Grid
        #
        mdf = gridModifier("projects")
        mdf.configure_column("project", width=20)

LE GAC Renaud's avatar
LE GAC Renaud committed
385
        # ....................................................................
386
        #
LE GAC Renaud's avatar
LE GAC Renaud committed
387
        # Store
388 389 390 391 392 393 394 395 396 397 398 399
        #
        storeModifier("projects").orderby(db.projects.project)

    @staticmethod
    def teams(db, T):
        """UI for the teams table

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
400
        # ....................................................................
401 402 403 404 405 406
        #
        # Grid
        #
        mdf = gridModifier("teams")
        mdf.configure_column("team", width=20)

LE GAC Renaud's avatar
LE GAC Renaud committed
407
        # ....................................................................
408 409 410 411
        #
        # Store
        #
        storeModifier("teams").orderby(db.teams.team)