Commit be4877d3 authored by Francois Blackburn's avatar Francois Blackburn

dialaction: add propriety to separate action

parent e8ccebab
......@@ -15,8 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.schema import Column, PrimaryKeyConstraint, Index
from sqlalchemy.types import Integer, String, TypeDecorator
from sqlalchemy.sql import func
from xivo_dao.helpers.db_manager import Base
from xivo_dao.alchemy import enum
......@@ -72,3 +74,41 @@ class Dialaction(Base):
actionarg1=None,
actionarg2=None,
linked=1)
@hybrid_property
def type(self):
if not self.action:
return
return self.action.split(':', 1)[0]
@type.expression
def type(cls):
return func.split_part(cls.action, ':', 1)
@type.setter
def type(self, type_):
if not self.action:
self.action = type_
return
type_subtype = self.action.split(':', 1)
if len(type_subtype) == 2:
self.action = '{}:{}'.format(type_, type_subtype[1])
else:
self.action = type_
@hybrid_property
def subtype(self):
if not self.action:
return
type_subtype = self.action.split(':', 1)
if len(type_subtype) == 2:
return type_subtype[1]
return None
@subtype.expression
def subtype(cls):
return func.split_part(cls.action, ':', 2)
@subtype.setter
def subtype(self, subtype):
self.action = '{}:{}'.format(self.type, subtype)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment