Beispiel #1
0
    def save_scenario(self, id, **kw):

        if kw.has_key("scenario[]"):
            scenario = kw["scenario[]"]
        else:
            log.error(u"No scenario to save ???")
            scenario = None
            return dict(result=0)  # XXX ?

        positions = {}
        if type(kw["positions[]"]) != type([]):
            kw["positions[]"] = (kw["positions[]"],)
        for p in kw["positions[]"]:
            log.debug(p)
            (context, top, left) = p.split("::")
            positions[context] = (int(float(top)), int(float(left)))

        log.info("save_scenario %s, type %s" % (id, type(scenario)))
        application = DBSession.query(Application).get(int(id))

        # 1. Delete old entries
        DBSession.query(Scenario).filter(Scenario.app_id == int(id)).delete()

        # 2. Create new ones
        if scenario:
            if type(scenario) != type([]):
                scenario = (scenario,)
            for s in scenario:
                sc = Scenario()
                (c, i, e, p, a, m) = s.split("::", 5)
                p = 1 + int(p)
                (sc.comments, sc.app_id, sc.context, sc.extension, sc.step, sc.action, sc.parameters) = (
                    c,
                    id,
                    i,
                    e,
                    p,
                    a,
                    m,
                )
                if p == 1:
                    i = "context_%s" % i
                    log.debug(u"position %s" % i)
                    if i in positions.keys():
                        sc.top = positions[i][0]
                        sc.left = positions[i][1]
                DBSession.add(sc)

        return dict(result=generate_dialplan())
Beispiel #2
0
    def create(self, name, exten, dnis, comment, app_begin=None, app_end=None, active=True, owner_id=None, **kw):
        """ Add new application  and initial dialplan to DB
      """
        a = Application()
        a.name = name
        a.exten = exten
        a.dnis = dnis
        a.active = active
        a.begin = app_begin
        a.end = app_end
        a.comment = comment
        a.created_by = request.identity["user"].user_id
        if owner_id:
            a.owner_id = owner_id
        else:
            a.owner_id = request.identity["user"].user_id

        # Try to insert file in DB: might fail if name already exists
        try:
            DBSession.add(a)
            DBSession.flush()
        except:
            log.error(u"Insert failed %s" % a)
            flash(u"Impossible de créer l'application (vérifier son nom)", "error")
            redirect("/applications/")

        s = Scenario()
        s.app_id = a.app_id
        s.context = "Entrant"
        s.extension = "s"
        s.step = 1
        s.action = 0
        s.parameters = None
        DBSession.add(s)

        flash(u'Nouvelle application "%s" créée' % (name))
        redirect("/applications/")