コード例 #1
0
ファイル: test_frontend.py プロジェクト: mohierf/flask-webui
    def test_6_all_domains(self):
        print ""
        print "get all domains"

        # Force authentication ...
        connection = frontend.login("admin", "admin", force=True)
        assert_true(frontend.authenticated)
        assert_true(frontend.token)

        connection = frontend.connect(username="******")
        assert_true(frontend.authenticated)
        assert_true(frontend.connected)

        # Get all pages
        print "get all elements at once"
        # Filter the templates ...
        for object_type in frontend.backend_available_objets:
            items = frontend.get_objects(object_type["title"], parameters=None, all_elements=False)
            print "Got %d %ss:" % (len(items), object_type)

            items = frontend.get_ui_data_model(object_type["title"])
            print "Got %d %ss:" % (len(items), object_type)
            # assert_true('_items' not in items)

        # Backend connection
        frontend.disconnect()
コード例 #2
0
ファイル: test_services.py プロジェクト: mohierf/flask-webui
    def test_1(self):
        print ''

        print 'Get element fields for UI: %s' % self.object_type
        fields_list = []
        fields=frontend.get_ui_data_model(self.object_type)
        print 'Got ', len(fields), ' items'
        ok_(len(fields))
        for field in fields:
            if 'ui' in field:
                print 'Field ', field
コード例 #3
0
ファイル: test_datatable.py プロジェクト: mohierf/flask-webui
    def test_1(self):
        print ""

        print "Get element fields for UI: %s" % self.object_type
        fields_list = []
        fields = frontend.get_ui_data_model(self.object_type)
        print "Got ", len(fields), " items"
        ok_(len(fields))
        for field in fields:
            if "ui" in field:
                print "Field ", field
コード例 #4
0
ファイル: element.py プロジェクト: mohierf/flask-webui
    def get(self, name):
        """ Call default datatables function """
        logger.debug("ElementsView, get: %s", name)

        # Update default parameters ...
        self.parameters['where'] = '{"host_name":"%s"}' % name

        resp = frontend.get_objects(self.object_type, parameters=self.parameters)
        logger.debug("ElementsView, response: %s", resp)
        if not '_items' in resp:
            # Not found
            logger.warning("HostsView, host: %s does not exist.", name)

            return render_template(
                'element.html',
                object_type=self.object_type,
                columns=None,
                object=None
            )
        else:
            fields = frontend.get_ui_data_model(self.object_type)
            if not fields:
                raise DatatableException(450, "table, trying to get table data for unmanaged data")

            # Create form dynamically
            class F(Form):
                pass

            table_columns = []
            # Objects are considered in the UI
            for field in fields:
                if field["name"] == "ui":
                    continue
                if not 'ui' in field:
                    continue
                if not 'visible' in field['ui']:
                    continue
                if not field["ui"]["visible"]:
                    continue

                # Ensuring data model is clean will avoid those tests ...
                field_default = ""
                if 'default' in field:
                    field_default = field["default"]
                field_title = field["name"]
                if 'title' in field["ui"]:
                    field_title = field["ui"]["title"]
                table_columns.append({
                    "name": field["name"],
                    "title": field_title,
                    "defaultContent": field_default,
                    "type": field["type"],
                    "format": field["ui"]["format"],
                    "orderable": field["ui"]["orderable"],
                    "searchable": field["ui"]["searchable"],
                    "data": field['name']
                })
                # Update form dynamically
                form_field = None
                valids = []
                if field["required"]:
                    valids.append(validators.InputRequired())

                if field["type"] == 'objectid':
                    logger.debug("ElementsView, field '%s' type: %s", field["name"], field["type"])
                    form_field = StringField(
                        label="Link to "+field_title,
                        description=field_title,
                        default=field_default,
                        validators=valids
                    )
                elif field["type"] == 'string':
                    logger.debug("ElementsView, field '%s' type: %s", field["name"], field["type"])
                    form_field = StringField(
                        label=field_title,
                        description=field_title,
                        default=field_default,
                        validators=valids
                    )
                elif field["type"] == 'boolean':
                    logger.debug("ElementsView, field '%s' type: %s", field["name"], field["type"])
                    form_field = BooleanField(
                        label=field_title,
                        description=field_title,
                        default=field_default,
                        validators=valids
                    )
                elif field["type"] == 'integer':
                    logger.debug("ElementsView, field '%s' type: %s", field["name"], field["type"])
                    form_field = IntegerField(
                        label=field_title,
                        description=field_title,
                        default=field_default,
                        validators=valids
                    )
                elif field["type"] == 'float':
                    logger.debug("ElementsView, field '%s' type: %s", field["name"], field["type"])
                    form_field = FloatField(
                        label=field_title,
                        description=field_title,
                        default=field_default,
                        validators=valids
                    )
                elif field["type"] == 'list':
                    logger.debug("ElementsView, field '%s' type: %s", field["name"], field["type"])
                    choices=[]
                    if "allowed" in field and field["allowed"]:
                        field["ui"]["format"] = {
                            "list_allowed": {
                                u"d": u"Down",
                                u"u": u"Up",
                                u"r": u"Recovery",
                                u"f": u"Flapping",
                                u"s": u"Downtime",
                                u"o": u"Downtime",
                                u"w": u"Warning",
                                u"n": u"None",
                                u"c": u"Critical",
                            }
                        }
                        if "list_allowed" in field["ui"]["format"]:
                            for choice in field["allowed"]:
                                choices.append( (choice, field["ui"]["format"]["list_allowed"][choice]))

                    form_field = SelectField(
                        label=field_title,
                        description=field_title,
                        default=field_default,
                        choices=choices,
                        validators=valids
                    )
                else:
                    logger.debug("ElementsView, field '%s' unspecified type", field["name"])
                    form_field = StringField(
                        label=field_title,
                        description=field_title,
                        default=field_default,
                        validators=valids
                    )

                # Fields may also be Date, DateTime, Decimal, File, Radio, Select, SelectMultiple

                setattr(
                    F,
                    field['name'],
                    form_field
                )

        # Current object
        object=resp['_items'][0]

        self.edit_form = F(request.form, obj=None, **object)
        logger.debug("ElementsView, form: %s", self.edit_form)
        logger.debug("ElementsView, form data: %s", self.edit_form.data)

        return render_template(
            '%s.html' % self.object_type,
            object_type=self.object_type,
            columns=table_columns,
            object=resp['_items'][0],
            form=self.edit_form
        )
コード例 #5
0
ファイル: datatable.py プロジェクト: mohierf/flask-webui
    def table(self):
        """
        Request for elements list

        Returns an HTML page containing filtered elements for an object_type (displays host,
        service, contact, ...) formatted in a jQuery datatable.

        1/ request for data model objects definition
        2/ get main information for objects:
            - list page title,
            - ...
        3/ filter to retain only fields that are managed in the UI

        """
        logger.debug("request for %s list ...", self.object_type)

        # Data model ...
        table_columns = []
        table_links = {}
        ui_dm = {"title": "All %s (XXX items)" % self.object_type}
        fields = frontend.get_ui_data_model(self.object_type)
        if not fields:
            raise DatatableException(450, "table, trying to get table data for unmanaged data")

        # Objects are considered in the UI
        for field in fields:
            logger.debug("%s field: %s", self.object_type, field)
            if field["name"] == "ui":
                ui_dm["title"] = field["ui"]["title"]
                continue

            if 'ui' in field and 'visible' in field['ui'] and field["ui"]["visible"]:
                # Ensuring data model is clean will avoid those tests ...
                field_default = ""
                if 'default' in field:
                    field_default = field["default"]
                field_title = field["name"]
                if 'title' in field['ui']:
                    field_title = field["ui"]["title"]
                if 'schema' in field and 'data_relation' in field['schema']:
                    table_links.update({
                        field["name"]: field['schema']['data_relation']['resource']
                    })

                table_columns.append({
                    "name": field["name"],
                    "title": field_title,
                    "defaultContent": field_default,
                    "type": field['type'],
                    "format": field["ui"]["format"],
                    "orderable": field["ui"]["orderable"],
                    "searchable": field["ui"]["searchable"],
                    # "render": 'function () { console.log("Render %s"); }' % field["name"],
                    "data": field['name']
                })

        table_columns.sort(key=lambda field: field['name'])

        resp = frontend.get_objects(self.object_type)

        # Update title with number of elements
        if '_items' in resp and '%d' in ui_dm["title"]:
            ui_dm["title"] = ui_dm["title"] % len(resp['_items'])

        return render_template(
            'list.html',
            object_type=self.object_type,
            title=ui_dm["title"],
            columns=table_columns,
            links=table_links,
            list=resp['_items'] if '_items' in resp else resp
        )