Ejemplo n.º 1
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        for i in range(self.number_of_questions.data):
            question = md.Question(
                text=self.question_text.data or _('Question %(num)s', num=i+1),
                order_number=i+1,
                show_values=True,
                container=section
            )
            md.db.session.add(question)
            for j in range(self.number_of_choices.data):
                md.db.session.add(md.Value(
                    text=_('Answer'),
                    question=question,
                    order_number=j+1,
                    points=0
                ))

        return section
Ejemplo n.º 2
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        answers = [x.strip() for x in self.answers.data.split(',')]

        for i in range(len(answers)):
            question = md.Question(
                text=self.question_text.data or _('Question %(num)s', num=i+1),
                order_number=i+1,
                show_values=True,
                container=section
            )
            md.db.session.add(question)
            for (j, ans) in enumerate(answers):
                md.db.session.add(md.Value(
                    text=ans,
                    question=question,
                    order_number=j+1,
                    points=0
                ))

        return section
Ejemplo n.º 3
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        for i in range(self.number_of_questions.data):
            question = md.Question(
                text=_('Statement %(num)s', num=i+1),
                order_number=i+1,
                show_values=False,
                bonus=True,
                container=section
            )
            md.db.session.add(question)
            for ans in self.answer.data.split(','):
                text = ans.strip()
                md.db.session.add(md.Value(
                    text=text,
                    question=question,
                    allowed_misses=int(len(text) / 4) + 1,
                    points=self.number_of_questions.data-i
                ))

        return section
Ejemplo n.º 4
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        order_number = 1

        for i in range(self.number_of_questions.data-1):
            question = md.Question(
                text=_('Question %(num)s', num=i+1),
                order_number=order_number,
                show_values=False,
                container=section
            )
            order_number += 1
            md.db.session.add(question)
            md.db.session.add(md.Value(
                text=_('Answer'),
                question=question,
                allowed_misses=3,
                points=1
            ))
            if i < self.opportunities.data:
                question = md.Question(
                    text=_('What is the connection? (+%(num)s/-1)', num=self.opportunities.data - i),
                    order_number=order_number,
                    show_values=False,
                    bonus=True,
                    container=section
                )
                order_number += 1
                md.db.session.add(question)
                for ans in self.connection.data.split(','):
                    text = ans.strip()
                    md.db.session.add(md.Value(
                        text=text,
                        question=question,
                        allowed_misses=int(len(text) / 4) + 1,
                        points=self.opportunities.data + 1 - i
                    ))

        question = md.Question(
            text=_('What is the connection?'),
            order_number=order_number,
            show_values=False,
            bonus=True,
            container=section
        )
        md.db.session.add(question)
        for ans in self.connection.data.split(','):
            text = ans.strip()
            md.db.session.add(md.Value(
                text=text,
                question=question,
                allowed_misses=int(len(text) / 4) + 1,
                points=1
            ))


        return section
Ejemplo n.º 5
0
def update_lists(jsonrpc):
    # safety check omitted for brevity
    data = jsonrpc["params"]["data"]
    url = jsonrpc["params"]["url"]

    # Remove if exist slash at the end of url
    if url.endswith('/'):
        url = url[:-1]

    # if GW posting list of ids
    if "id" in data:
        for i in data["id"]:
            print(i)
        return

    # else data contain object
    item_id = jsonrpc["params"]["data"][":id"]

    if jsonrpc["method"] == "PUT":
        # url contain UUID at the end
        item = url.split('/')[-2]
        # TODO check what kingd of item and update item
        print(Colors.WARNING + "TODO --- Update item: " + item + Colors.ENDC)
        return

    # else - POST
    item = url.split('/')[-1]
    parent_id = url.split('/')[-2]

    if item == "gateway":
        global gateway
        gateway = model.Gateway(data, url, None)
        print(gateway)

    if item == "network":
        global network
        network = model.Network(data, url, None)
        print(network)

    if item == "device":
        device = model.Device(data, url, parent_id)
        if device.data["included"] == "0":
            device.data["included"] = "1"
            client = Client("/tmp/zero_interface")
            client.includeDevice(device)
        else:
            create_update_item(device, devices)
            if device.data['product']:
                print('product: {}'.format(device.data['product']))
            if device.data['version_hardware']:
                print("version_hardware: {}".format(
                    device.data['version_hardware']))
            if device.data['version_stack']:
                print("version_stack: {}".format(device.data['version_stack']))
            if device.data['version_boot']:
                print("version_boot: {}".format(device.data['version_boot']))
            if device.data['version_application']:
                print("version_application: {}".format(
                    device.data['version_application']))

    if item == "service":
        service = model.Service(data, url, parent_id)
        create_update_item(service, services)

    if item == "value":
        value = model.Value(data, url, parent_id)
        create_update_item(value, values)

    if item == "status":
        level = data["level"]
        status_type = data["type"]
        message = data["message"]
        print(Colors.OKGREEN + "Status level: '" + level + "' type: '" +
              status_type + "' message: '" + message + "'" + Colors.ENDC)

    if item == "configuration":
        configuration = model.Configuration(data, url, parent_id)
        create_update_item(configuration, configurations)

    if item == "partner":
        partner = model.Partner(data, url, parent_id)
        create_update_item(partner, partners)

    if item == "action":
        action = model.Action(data, url, parent_id)
        create_update_item(action, actions)

    if item == "calendar":
        calendar = model.Calendar(data, url, parent_id)
        create_update_item(calendar, calendars)

    if item == "calculation":
        calculation = model.Calculation(data, url, parent_id)
        create_update_item(calculation, calculations)

    if item == "timer":
        timer = model.Timer(data, url, parent_id)
        create_update_item(timer, timers)

    if item == "statemachine":
        machine = model.StateMachine(data, url, parent_id)
        create_update_item(machine, statemachines)
Ejemplo n.º 6
0
def p_ConstValue_null(p):
    """ConstValue : null"""
    p[0] = model.Value(type=model.Value.NULL, value=p[1])
Ejemplo n.º 7
0
def p_ConstValue_float(p):
    """ConstValue : FLOAT"""
    p[0] = model.Value(type=model.Value.FLOAT, value=p[1])
Ejemplo n.º 8
0
def p_ConstValue_integer(p):
    """ConstValue : INTEGER"""
    p[0] = model.Value(type=model.Value.INTEGER, value=p[1])
Ejemplo n.º 9
0
def p_ConstValue_boolean(p):
    """ConstValue : BooleanLiteral"""
    p[0] = model.Value(type=model.Value.BOOLEAN, value=p[1])
Ejemplo n.º 10
0
def p_DefaultValue_string(p):
    """DefaultValue : STRING"""
    p[0] = model.Value(type=model.Value.STRING, value=p[1])