ui_harvester.py 6.72 KB
Newer Older
LE GAC Renaud's avatar
LE GAC Renaud committed
1 2 3
"""User Interface for the harvester tables

"""
4
from gluon import current
LE GAC Renaud's avatar
LE GAC Renaud committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 88 89 90 91 92 93 94 95 96 97 98 99
from plugin_dbui import (FieldsModifier,
                         FormModifier,
                         GridModifier,
                         StoreModifier)


class HarvesterUI(object):

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

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

        """
        HarvesterUI.affiliation_keys(db, T)
        HarvesterUI.controllers(db, T)
        HarvesterUI.harvesters(db, T)
        HarvesterUI.my_authors(db, T)

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

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

        """
        tr_contains = T("contains")

        # ....................................................................
        #
        # Grid
        #
        mdf = GridModifier("affiliation_keys")

        mdf.append_filter(("key_u", "contains", tr_contains))
        mdf.append_filter(("key_v", "contains", tr_contains))

        mdf.configure_filters(plugins=["pFormToolTip"], width=300)
        mdf.configure_gridWithFilter(selectorTitle=T("Filter"))

        mdf.configure(plugins=["pGridRowEditorConfirmDelete",
                               "pGridAffiliationKeysContextMenu"])

        # ....................................................................
        #
        # Store
        #
        affiliation_keys = db.affiliation_keys

        mdf = StoreModifier("affiliation_keys")
        mdf.orderby(affiliation_keys.key_u, affiliation_keys.key_v)

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

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

        """
        # ....................................................................
        #
        # Grid
        #
        mdf = GridModifier("controllers")
        mdf.configure_column("controller", width=15)

        # ....................................................................
        #
        # Store
        #
        StoreModifier("controllers").orderby(db.controllers.controller,
                                             db.categories.code)

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

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

        """
        # ....................................................................
        #
        # Fields
        #
        mdf = FieldsModifier("harvesters")
100
        mdf.configure_field("collections", height=250, xtype="textarea")
LE GAC Renaud's avatar
LE GAC Renaud committed
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        mdf.configure_field("ratio", hidden=True)
        mdf.configure_field("scan", hidden=True)

        # ....................................................................
        #
        # Form
        #
        harvesters = db.harvesters

        mdf = FormModifier("harvesters")

        mdf.link_comboboxes(master=harvesters.id_projects,
                            slave=harvesters.id_teams,
                            masterHasSlaveData="organisation",
                            slaveExtJS={"hidden": True})

        # Relation between harvester controller and publications category
        mdf.link_comboboxes(master=harvesters.controller,
                            slave=harvesters.id_categories,
                            masterHasSlaveData="controllers",
                            slaveExtJS={"hidden": False})

        mdf.configure(width=350)

        # ....................................................................
        #
        # Grid
        #
        tr_contains = T("contains")
        tr_equal = T("is equal to")

        mdf = GridModifier("harvesters")

        mdf.configure_column("id_teams", width=75)
        mdf.configure_column("collections", width=300)
        mdf.configure_column("max_records", width=70)
        mdf.configure_column("ratio", width=40)
        mdf.configure_column("scan", width=40)
        mdf.hide_columns("ratio", "scan")

        mdf.append_filter(("id_teams", "==", tr_equal))
        mdf.append_filter(("id_projects", "==", tr_equal))
        mdf.append_filter(("controller", "contains", tr_contains))
        mdf.append_filter(("host", "contains", tr_contains))
        mdf.append_filter(("id_categories", "==", tr_equal))

        mdf.configure_filters(plugins=["pFormToolTip"], width=300)
        mdf.configure_gridWithFilter(selectorTitle=T("Filter"))

150 151 152 153 154
        mdf.configure(plugins=[{
            "ptype": "pGridRowEditorAddWizard",
            "wizard": {
                "url": "/%s/wizards/harvester" % current.request.application,
                "xtype": "xwizardharvester"}}])
LE GAC Renaud's avatar
LE GAC Renaud committed
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 204 205 206 207 208 209 210

        # ....................................................................
        #
        # Store
        #
        StoreModifier("harvesters").orderby(db.teams.team,
                                            db.projects.project,
                                            harvesters.controller)

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

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

        """
        # ....................................................................
        #
        # Fields
        #
        mdf = FieldsModifier("my_authors")
        mdf.configure_field("authors", height=250)

        # ....................................................................
        #
        # Form
        #
        my_authors = db.my_authors

        mdf = FormModifier("my_authors")
        mdf.configure(width=400)

        mdf.link_comboboxes(master=my_authors.id_projects,
                            slave=my_authors.id_teams,
                            masterHasSlaveData="organisation",
                            slaveExtJS={"hidden": True})

        # ....................................................................
        #
        # Grid
        #
        tr_equal = T("is equal to")

        mdf = GridModifier("my_authors")
        mdf.configure_column("year", width=10)
        mdf.configure_column("id_teams", width=15)
        mdf.configure_column("id_projects", width=15)

        mdf.append_filter(("year", "==", tr_equal), allowBlank=True)
        mdf.append_filter(("id_teams", "==", tr_equal))
        mdf.append_filter(("id_projects", "==", tr_equal))

        mdf.configure_filters(plugins=["pFormToolTip"], width=300)
        mdf.configure_gridWithFilter(selectorTitle=T("Filter"))