ui_core.py 12 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 18 19
    @staticmethod
    def define(db, T):
        """Tune the user interface for the history table and its foreign tables,
20

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

25 26 27 28 29 30 31 32 33 34 35
        """
        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)
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    @staticmethod
    def domains(db, T):
        """UI for the domains table

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

        """
        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # Fields
        #
        mdf = fieldsModifier("events")
        mdf.configure_field("data",
                            colProperty={"width": 70},
                            colType={"width": 70},
                            fieldLabel="",
                            xtype="xuserdata")

        #.....................................................................
        #
        # 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)

        #.....................................................................
        #
        # Grid
        #
88
        mdf = gridModifier("events")
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
        mdf.configure_column("event", width=30)
        mdf.hide_columns("data")

        row_widget = {
            "ptype": "rowwidget",
            "widget": {
                "xtype": "xuserdata",
                "bind": {
                    "value": "{record.EventsData}"
                },
                "defaults": {"anchor": "90%"},
                "colProperty": {"width": 80},
                "colType": {"width": 80},
                "padding": "10 0 12 50",
                "readOnly": True
            }
        }

        mdf.configure(plugins=[row_widget])

        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # Grid
        #
128
        mdf = gridModifier("fundings")
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
        mdf.configure_column("agency", width=40)

        #.....................................................................
        #
        # 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

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

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 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 199 200 201 202 203
        #.....................................................................
        #
        # 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)

        #.....................................................................
        #
        # 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)

        #.....................................................................
        #
        # Grid
        #
204
        mdf = gridModifier("history")
205 206 207 208 209
        mdf.configure(plugins=["pGridRowEditorConfirmDelete",
                               "pGridRowEditorDblClick",
                               "pHistoryContextMenu",
                               "pGridToolbar",
                               "pGridPaging"])
210 211 212 213 214 215 216 217 218 219 220 221 222

        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")))
223
        mdf.append_filter(("id_people", "==", T("is equal to")))
224
        mdf.append_filter(("id_people_categories", "==", T("is equal to")))
225
        mdf.append_filter(("id_objects", "==", T("is equal to")))
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        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(
            ("data", "like", "key(s) is(are) equal to value(s). The jocker is %"),
            fieldLabel=T("Data"),
            header=[T("key"), T("value")],
            numColumns=2,
            numRows=3,
            xtype="xtablefield")

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

        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # Grid
        #
        mdf = gridModifier("object_categories")
        mdf.configure_column("code", width=20)
        mdf.configure_column("category", width=20)

        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # 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)


        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # Grid
        #
        mdf = gridModifier("people_categories")
        mdf.configure_column("code", width=20)
        mdf.configure_column("category", width=20)


        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # 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)

        #.....................................................................
        #
        # 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

        """
        #.....................................................................
        #
        # Grid
        #
        mdf = gridModifier("projects")
        mdf.configure_column("project", width=20)

        #.....................................................................
        #
        # STORE CONFIGURATiON
        #
        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

        """
        #.....................................................................
        #
        # Grid
        #
        mdf = gridModifier("teams")
        mdf.configure_column("team", width=20)

        #.....................................................................
        #
        # Store
        #
        storeModifier("teams").orderby(db.teams.team)