예제 #1
0
    def _add_user_to_schedule(self, userid, scheduleid, order=0):
        schedulepath = SchedulePath()
        schedulepath.path = "user"
        schedulepath.schedule_id = scheduleid
        schedulepath.pathid = userid
        schedulepath.order = order

        self.add_me(schedulepath)
예제 #2
0
def add_user_to_schedule(session, userid, scheduleid, order=0):
    schedulepath = SchedulePath()
    schedulepath.path = 'user'
    schedulepath.schedule_id = scheduleid
    schedulepath.pathid = userid
    schedulepath.order = order

    with flush_session(session):
        session.add(schedulepath)
예제 #3
0
    def _add_user_to_schedule(self, userid, scheduleid, order=0):
        schedulepath = SchedulePath()
        schedulepath.path = 'user'
        schedulepath.schedule_id = scheduleid
        schedulepath.pathid = userid
        schedulepath.order = order

        self.add_me(schedulepath)
예제 #4
0
def add_user_to_schedule(session, userid, scheduleid, order=0):
    schedulepath = SchedulePath()
    schedulepath.path = 'user'
    schedulepath.schedule_id = scheduleid
    schedulepath.pathid = userid
    schedulepath.order = order

    session.begin()
    try:
        session.add(schedulepath)
        session.commit()
    except Exception:
        session.rollback()
        raise
예제 #5
0
class Outcall(Base):

    __tablename__ = 'outcall'
    __table_args__ = (
        PrimaryKeyConstraint('id'),
        UniqueConstraint('name'),
    )

    id = Column(Integer, nullable=False)
    tenant_uuid = Column(String(36),
                         ForeignKey('tenant.uuid', ondelete='CASCADE'),
                         nullable=False)
    name = Column(String(128), nullable=False)
    context = Column(String(39))
    internal = Column(Integer, nullable=False, server_default='0')
    preprocess_subroutine = Column(String(39))
    hangupringtime = Column(Integer, nullable=False, server_default='0')
    commented = Column(Integer, nullable=False, server_default='0')
    description = Column(Text)

    dialpatterns = relationship(
        'DialPattern',
        primaryjoin="""and_(DialPattern.type == 'outcall',
                            DialPattern.typeid == Outcall.id)""",
        foreign_keys='DialPattern.typeid',
        cascade='all, delete-orphan',
    )

    extensions = association_proxy('dialpatterns', 'extension')

    outcall_trunks = relationship(
        'OutcallTrunk',
        order_by='OutcallTrunk.priority',
        collection_class=ordering_list('priority'),
        cascade='all, delete-orphan',
        back_populates='outcall',
    )

    trunks = association_proxy(
        'outcall_trunks',
        'trunk',
        creator=lambda _trunk: OutcallTrunk(trunk=_trunk),
    )

    _dialaction_actions = relationship(
        'Dialaction',
        primaryjoin="""and_(Dialaction.action == 'outcall',
                            Dialaction.actionarg1 == cast(Outcall.id, String))""",
        foreign_keys='Dialaction.actionarg1',
        cascade='all, delete-orphan',
    )

    schedule_paths = relationship(
        'SchedulePath',
        primaryjoin="""and_(SchedulePath.path == 'outcall',
                            SchedulePath.pathid == Outcall.id)""",
        foreign_keys='SchedulePath.pathid',
        cascade='all, delete-orphan',
    )
    schedules = association_proxy('schedule_paths',
                                  'schedule',
                                  creator=lambda _schedule: SchedulePath(
                                      path='outcall',
                                      schedule_id=_schedule.id,
                                      schedule=_schedule,
                                  ))

    rightcall_members = relationship(
        'RightCallMember',
        primaryjoin="""and_(RightCallMember.type == 'outcall',
                            RightCallMember.typeval == cast(Outcall.id, String))""",
        foreign_keys='RightCallMember.typeval',
        cascade='all, delete-orphan',
    )
    call_permissions = association_proxy(
        'rightcall_members',
        'rightcall',
        creator=lambda _call_permission: RightCallMember(
            type='outcall',
            typeval=str(_call_permission.id),
            rightcall=_call_permission,
        ))

    @hybrid_property
    def internal_caller_id(self):
        return self.internal == 1

    @internal_caller_id.expression
    def internal_caller_id(cls):
        return cast(cls.internal, Boolean)

    @internal_caller_id.setter
    def internal_caller_id(self, value):
        self.internal = int(value == 1)

    @hybrid_property
    def ring_time(self):
        if self.hangupringtime == 0:
            return None
        return self.hangupringtime

    @ring_time.expression
    def ring_time(cls):
        return func.nullif(cls.hangupringtime, 0)

    @ring_time.setter
    def ring_time(self, value):
        if value is None:
            self.hangupringtime = 0
        else:
            self.hangupringtime = value

    @hybrid_property
    def enabled(self):
        return self.commented == 0

    @enabled.expression
    def enabled(cls):
        return not_(cast(cls.commented, Boolean))

    @enabled.setter
    def enabled(self, value):
        self.commented = int(value is False)

    def associate_extension(self, extension, **kwargs):
        if extension not in self.extensions:
            extension.type = 'outcall'
            dialpattern = DialPattern(type='outcall',
                                      exten=extension.exten,
                                      **kwargs)
            self.dialpatterns.append(dialpattern)
            index = self.dialpatterns.index(dialpattern)
            self.dialpatterns[index].extension = extension
            self._fix_context()

    def dissociate_extension(self, extension):
        if extension in self.extensions:
            self.extensions.remove(extension)
            extension.type = 'user'
            extension.typeval = '0'
            self._fix_context()

    def update_extension_association(self, extension, **kwargs):
        for dialpattern in self.dialpatterns:
            if extension == dialpattern.extension:
                dialpattern.strip_digits = kwargs.get('strip_digits',
                                                      dialpattern.strip_digits)
                dialpattern.prefix = kwargs.get('prefix', dialpattern.prefix)
                dialpattern.external_prefix = kwargs.get(
                    'external_prefix', dialpattern.external_prefix)
                dialpattern.caller_id = kwargs.get('caller_id',
                                                   dialpattern.caller_id)

    def _fix_context(self):
        for extension in self.extensions:
            self.context = extension.context
            return
        self.context = None
예제 #6
0
 def _add_schedule_to_user(self, userid, scheduleid):
     path = SchedulePath(schedule_id=scheduleid,
                         path='user',
                         pathid=userid,
                         order=0)
     self.add_me(path)
예제 #7
0
 def add_schedule_path(self, **kwargs):
     kwargs.setdefault('path', 'user')
     kwargs.setdefault('pathid', 0)
     schedule_path = SchedulePath(**kwargs)
     self.add_me(schedule_path)
     return schedule_path
예제 #8
0
 def add_group_schedule(self, **kwargs):
     kwargs.setdefault('path', 'group')
     group_schedule = SchedulePath(**kwargs)
     self.add_me(group_schedule)
     return group_schedule
예제 #9
0
 def add_outcall_schedule(self, **kwargs):
     kwargs.setdefault('path', 'outcall')
     outcall_schedule = SchedulePath(**kwargs)
     self.add_me(outcall_schedule)
     return outcall_schedule
예제 #10
0
 def add_incall_schedule(self, **kwargs):
     kwargs.setdefault('path', 'incall')
     incall_schedule = SchedulePath(**kwargs)
     self.add_me(incall_schedule)
     return incall_schedule
예제 #11
0
class Incall(Base):

    __tablename__ = 'incall'
    __table_args__ = (PrimaryKeyConstraint('id'), )

    id = Column(Integer)
    tenant_uuid = Column(String(36),
                         ForeignKey('tenant.uuid', ondelete='CASCADE'),
                         nullable=False)
    preprocess_subroutine = Column(String(39))
    greeting_sound = Column(Text)
    commented = Column(Integer, nullable=False, server_default='0')
    description = Column(Text)

    caller_id = relationship(
        'Callerid',
        primaryjoin="""and_(Callerid.type == 'incall',
                            Callerid.typeval == Incall.id)""",
        foreign_keys='Callerid.typeval',
        cascade='all, delete-orphan',
        uselist=False,
    )

    caller_id_mode = association_proxy(
        'caller_id',
        'mode',
        creator=lambda _mode: Callerid(type='incall', mode=_mode),
    )
    caller_id_name = association_proxy(
        'caller_id',
        'name',
        creator=lambda _name: Callerid(type='incall', name=_name),
    )

    dialaction = relationship(
        'Dialaction',
        primaryjoin="""and_(Dialaction.category == 'incall',
                            Dialaction.categoryval == cast(Incall.id, String))""",
        foreign_keys='Dialaction.categoryval',
        cascade='all, delete-orphan',
        uselist=False,
    )

    extensions = relationship(
        'Extension',
        primaryjoin="""and_(Extension.type == 'incall',
                            Extension.typeval == cast(Incall.id, String))""",
        foreign_keys='Extension.typeval',
        viewonly=True,
    )

    schedule_paths = relationship(
        'SchedulePath',
        primaryjoin="""and_(SchedulePath.path == 'incall',
                            SchedulePath.pathid == Incall.id)""",
        foreign_keys='SchedulePath.pathid',
        cascade='all, delete-orphan',
    )

    schedules = association_proxy(
        'schedule_paths',
        'schedule',
        creator=lambda _schedule: SchedulePath(
            path='incall',
            schedule_id=_schedule.id,
            schedule=_schedule,
        ),
    )

    @property
    def destination(self):
        if self.dialaction is None:
            return Dialaction(action='none')
        return self.dialaction

    @destination.setter
    def destination(self, destination):
        if destination is None:
            self.dialaction = None
            return

        if not self.dialaction:
            destination.event = 'answer'
            destination.category = 'incall'
            self.dialaction = destination

        self.dialaction.action = destination.action
        self.dialaction.actionarg1 = destination.actionarg1
        self.dialaction.actionarg2 = destination.actionarg2

    @hybrid_property
    def user_id(self):
        if self.dialaction and self.dialaction.action == 'user':
            return int(self.dialaction.actionarg1)
        return None

    @user_id.expression
    def user_id(cls):
        return (select([
            cast(Dialaction.actionarg1, Integer)
        ]).where(Dialaction.action == 'user').where(
            Dialaction.category == 'incall').where(
                Dialaction.categoryval == cast(cls.id, String)).as_scalar())

    @hybrid_property
    def exten(self):
        for extension in self.extensions:
            return extension.exten
        return None

    @exten.expression
    def exten(cls):
        return (select(
            [Extension.exten]).where(Extension.type == 'incall').where(
                Extension.typeval == cast(cls.id, String)).as_scalar())