Exemplo n.º 1
0
class LexInputEvent(PyLexObject):
    currentIntent = types.ModelType(CurrentIntentProperty,
                                    default=CurrentIntentProperty())
    """ :type : CurrentIntentProperty """
    bot = types.ModelType(BotProperty, default=BotProperty())
    """ :type : BotProperty """
    userId = types.StringType()
    inputTranscript = types.StringType()
    invocationSource = types.StringType()
    outputDialogMode = types.StringType()
    messageVersion = types.StringType()
    sessionAttributes = types.DictType(types.StringType(), default={})
    requestAttributes = types.DictType(types.StringType(), default={})

    def is_all_slots_filled(self):
        return all(self.currentIntent.slots.values())

    @classmethod
    def create_class(cls, slots_property_class):
        class NewCurrentIntentProperty(CurrentIntentProperty):
            slots = types.ModelType(slots_property_class,
                                    default=slots_property_class())
            """ :type : SlotsProperty """

        class NewLexInputEvent(cls):
            currentIntent = types.ModelType(NewCurrentIntentProperty,
                                            default=NewCurrentIntentProperty())
            """ :type : CurrentIntentProperty """

        return NewLexInputEvent
Exemplo n.º 2
0
class StatusSettings(Model):
    """The settings of a status column

    __________
    Properties

        labels : `str`
            The index / label parings of a status column option.
        labels_colors : `dict`
            The index / color property parings of a status column option.
        labels_positions_v2 : `dict`
            The position of each label by ID.

    _______
    Methods

        get_index : `str`
            Get the label ID from the label value.
    """

    labels = types.DictType(types.StringType())
    labels_colors = types.DictType(types.DictType(types.StringType()))
    labels_positions_v2 = types.DictType(types.StringType())
    done_colors = types.ListType(types.IntType())
    hide_footer = types.BooleanType(default=False)

    def __repr__(self):
        return str(self.to_primitive())

    def get_index(self, label: str):
        """Get the label ID from the label value.

        __________
        Parameters

            label : `str`
                The status column option label value.

        _______
        Returns

            index : `int`
                The id of the status column option.
        """

        for key, value in dict(self.labels).items():
            if value == label:
                return int(key)
        return None

    def __getitem__(self, index: int):
        return dict(self.labels)[str(index)]
Exemplo n.º 3
0
class LexOutputResponse(PyLexObject):
    dialogAction = types.ModelType(DialogActionProperty,
                                   default=DialogActionProperty())
    """ :type : DialogActionProperty """
    sessionAttributes = types.DictType(types.StringType(), default={})
    """ :type : SessionAttributesProperty """
    def update_from_input(self, event):
        """

        :type event: LexInputEvent
        :return:
        """
        self.update_session_attributes(event)

    def update_session_attributes(self, event):
        for key, val in event.sessionAttributes.items():
            self.sessionAttributes[key] = val

    def to_primitive(self, role=None, app_data=None, **kwargs):
        d = deepcopy(
            super(LexOutputResponse, self).to_primitive(role=role,
                                                        app_data=app_data,
                                                        **kwargs))

        if hasattr(self.dialogAction,
                   'message') and not self.dialogAction.message.content:
            del d['dialogAction']['message']
        if hasattr(self.dialogAction, 'responseCard'
                   ) and self.dialogAction.responseCard.version is None:
            del d['dialogAction']['responseCard']
        return d
Exemplo n.º 4
0
class Task(models.Model):
    '''
        Task Data Structure
    '''
    uuid = types.UUIDType(default=uuid.uuid4)
    account = types.StringType(required=True)
    subject = types.StringType()
    description = types.StringType()
    data = types.StringType()
    assign = compound.ListType(types.StringType())
    public = types.BooleanType(default=False)
    source = types.StringType()
    destination = types.StringType()
    labels = types.DictType(types.StringType)
    start_time = types.TimestampType()
    ack_time = types.TimestampType()
    stop_time = types.TimestampType()
    deadline = types.TimestampType()
    duration = types.StringType()
    comments = compound.ListType(types.StringType())
    status = types.StringType(choices=['new', 'now', 'later', 'done'],
                              default='new',
                              required=True)
    history = compound.ListType(types.StringType())
    checked = types.BooleanType(default=False)
    checked_by = types.StringType()
    checked_at = types.TimestampType(default=arrow.utcnow().timestamp)
    created_by = types.StringType()
    created_at = types.TimestampType(default=arrow.utcnow().timestamp)
    last_update_by = types.StringType()
    last_update_at = types.TimestampType()
Exemplo n.º 5
0
class RequiredBase(models.Model):
    '''
        Very self explanatory
    '''
    status = types.StringType(required=False)
    account = types.StringType(required=True)
    role = types.StringType(required=False)
    email = types.EmailType(required=True)
    phone_number = types.StringType()
    extension = types.StringType()
    country_code = types.StringType()
    timezone = types.StringType()
    affiliation = types.StringType()
    location = types.StringType()
    phones = compound.ListType(compound.ModelType(Phone))
    emails = compound.ListType(compound.ModelType(Email))
    labels = types.DictType(types.StringType)
    history = compound.ListType(types.StringType())
    checked = types.BooleanType(default=False)
    checked_by = types.StringType()
    checked_at = types.TimestampType()
    created_by = types.StringType(required=True)
    created_at = types.TimestampType(default=arrow.utcnow().timestamp)
    last_update_by = types.StringType()
    last_update_at = types.TimestampType()
Exemplo n.º 6
0
class Game(models.Model):
    '''
        Game Data Structure
    '''
    uuid = types.UUIDType(default=uuid.uuid4)
    game = types.IntType(required=True)
    status = types.StringType(
        choices=['new', 'starting', 'in-progress', 'completed', 'deleted'],
        default='new')
    labels = types.DictType(types.StringType)
    history = compound.ListType(types.StringType())
    address = types.IPAddressType()
    session = types.UUIDType()
    bots = types.StringType(required=True)
    map = types.StringType(required=True)
    replay = types.StringType()
    home = types.StringType()
    home_is_winner = types.BooleanType(default=False)
    home_crashed = types.BooleanType(default=False)
    home_timed_out = types.BooleanType(default=False)
    home_building_score = types.IntType()
    home_razing_score = types.IntType()
    home_unit_score = types.IntType()
    away = types.StringType()
    away_is_winner = types.BooleanType(default=False)
    away_crashed = types.BooleanType(default=False)
    away_timed_out = types.BooleanType(default=False)
    away_building_score = types.IntType()
    away_razing_score = types.IntType()
    away_unit_score = types.IntType()
    created_by = types.UUIDType()
    created_at = types.DateTimeType(default=datetime.datetime.utcnow)
    last_update_by = types.UUIDType()
    last_update_at = types.TimestampType()
Exemplo n.º 7
0
class User(Model):
    id = types.UUIDType(required=False)
    name = types.StringType(required=False)
    email = EmailType(required=True)
    created_at = types.DateTimeType(required=False)
    updated_at = types.DateTimeType(required=False)
    deleted_at = types.DateTimeType(required=False)
    profile = types.DictType(types.StringType, default={}, required=False)
Exemplo n.º 8
0
class Users(BaseAccount):
    '''
        User account
    '''
    role = types.StringType(choices=['admin', 'user'],
                            default='user',
                            required=True)
    account_type = types.StringType(choices=[
        'user',
    ],
                                    default='user',
                                    required=True)
    nickname = types.StringType()
    first_name = types.StringType()
    middle_name = types.StringType()
    last_name = types.StringType()
    password = types.StringType(required=True)
    orgs = compound.ListType(types.DictType(types.StringType))
    teams = compound.ListType(types.DictType(types.StringType))
Exemplo n.º 9
0
class LexPostTextResponse(PyLexObject):
    intentName = types.StringType(default='')
    slots = types.DictType(types.StringType())
    sessionAttributes = types.DictType(types.StringType())
    message = types.StringType(default='')
    messageFormat = types.StringType(default='')
    dialogState = types.StringType(default='')
    slotToElicit = types.StringType(default='')
    responseCard = types.ModelType(ResponseCardRuntimeProperty,
                                   serialize_when_none=False,
                                   default=ResponseCardRuntimeProperty())

    def is_plain_text(self):
        return self.messageFormat == MessageFormats.PlainText

    def is_ssml(self):
        return self.messageFormat == MessageFormats.SSML

    def is_composite(self):
        return self.messageFormat == MessageFormats.Composite

    def is_custom_payload(self):
        return self.messageFormat == MessageFormats.CustomPayload

    def is_elicit_intent(self):
        return self.dialogState == DialogStates.ElicitIntent

    def is_confirm_intent(self):
        return self.dialogState == DialogStates.ConfirmIntent

    def is_elicit_slot(self):
        return self.dialogState == DialogStates.ElicitSlot

    def is_fulfilled(self):
        return self.dialogState == DialogStates.Fulfilled

    def is_ready_for_fulfillment(self):
        return self.dialogState == DialogStates.ReadyForFulfillment

    def is_failed(self):
        return self.dialogState == DialogStates.Failed
Exemplo n.º 10
0
class Orgs(BaseAccount):
    '''
        Org account
    '''
    account_type = types.StringType(
        choices=['org', ],
        default='org',
        required=True
    )
    name = types.StringType()
    description = types.StringType()
    members = compound.ListType(types.StringType())
    owners = compound.ListType(types.StringType())
    teams = compound.ListType(types.DictType(types.StringType))
Exemplo n.º 11
0
class ModifyTask(models.Model):
    '''
        Modify task

        This model is similar to Task.

        It lacks of require and default values on it's fields.

        The reason of it existence is that we need to validate
        every input data that came from outside the system, with
        this we prevent users from using PATCH to create fields
        outside the scope of the resource.
    '''
    uuid = types.UUIDType(default=uuid.uuid4)
    account = types.StringType()
    subject = types.StringType()
    description = types.StringType()
    data = types.StringType()
    assign = compound.ListType(types.StringType())
    public = types.BooleanType(default=False)
    source = types.StringType()
    destination = types.StringType()
    labels = types.DictType(types.StringType)
    start_time = types.TimestampType()
    ack_time = types.TimestampType()
    stop_time = types.TimestampType()
    deadline = types.TimestampType()
    duration = types.StringType()
    comments = compound.ListType(types.StringType())
    status = types.StringType(choices=['new', 'now', 'later', 'done'],
                              default='new',
                              required=True)
    history = compound.ListType(types.StringType())
    checked = types.BooleanType(default=False)
    checked_by = types.StringType()
    checked_at = types.TimestampType(default=arrow.utcnow().timestamp)
    created_by = types.StringType()
    created_at = types.TimestampType(default=arrow.utcnow().timestamp)
    last_update_by = types.StringType()
    last_update_at = types.TimestampType()
Exemplo n.º 12
0
def option_map(cls: Type[_B],
               *,
               default: _DefaultArg[Dict[str, _B]] = None,
               example: _DefaultArg[Dict[str, _B]] = None,
               help: str):
    """Create a configuration option that contains a mapping of string keys to *cls* values.

    :param cls:         Option type (see :func:`is_allowable_type`)
    :param default:     Default value if no value is supplied (default: empty list)
    :param example:     Default value when generating example configuration (default: empty list)
    :param help:        Description of option, included when generating example configuration
    """
    if not is_allowable_type(cls):
        raise TypeError(
            f"cls must be subclass of Config or one of {_TYPE_MAP.keys()}")

    if default is None:
        default = dict

    if is_config(cls):
        inner_field = types.ModelType(cls, required=True)
    else:
        inner_field = _TYPE_MAP[cls](required=True)

    field_kwargs = {
        "required": True,  # Disallow None as a value, empty dict is fine
        "default": _Default(default, example),
        "metadata": {
            _METADATA_KEY:
            _OptionMetadata(
                type=cls,
                kind=_OptionKind.STRUCTURE_MAP
                if is_config(cls) else _OptionKind.SIMPLE_MAP,
                help=help,
            ),
        },
    }
    return types.DictType(inner_field, **field_kwargs)
Exemplo n.º 13
0
 class Model(optplan.ProblemGraphNode):
     type = types.StringType(default="Model")
     value = types.DictType(optplan.ReferenceType(optplan.ProblemGraphNode))
Exemplo n.º 14
0
 class Model(optplan.ProblemGraphNode):
     type = types.StringType(default="Model")
     value = types.DictType(types.ModelType(ModelB))
Exemplo n.º 15
0
class CurrentIntentProperty(PyLexObject):
    name = types.StringType()
    slots = types.DictType(types.StringType())
    slotDetails = types.DictType(types.ModelType(SlotDetailValueProperty))
    confirmationStatus = types.StringType()