Ejemplo n.º 1
0
    def save(self, **kwargs):

        db = get_session()

        c = db.query(Category).filter_by(id = kwargs.get('id')).first()
        if not c:
            c = Category()
            db.add(c)

        c.order = kwargs.get('order', c.order if c.order else 0)
        c.label = toUnicode(kwargs.get('label'))
        c.path = toUnicode(kwargs.get('path'))
        c.ignored = toUnicode(kwargs.get('ignored'))
        c.preferred = toUnicode(kwargs.get('preferred'))
        c.required = toUnicode(kwargs.get('required'))
        c.destination = toUnicode(kwargs.get('destination'))

        db.commit()

        category_dict = c.to_dict()

        return {
            'success': True,
            'category': category_dict
        }
Ejemplo n.º 2
0
    def save(self, **kwargs):

        try:
            db = get_session()

            c = db.query(Category).filter_by(id=kwargs.get('id')).first()
            if not c:
                c = Category()
                db.add(c)

            c.order = kwargs.get('order', c.order if c.order else 0)
            c.label = toUnicode(kwargs.get('label', ''))
            c.ignored = toUnicode(kwargs.get('ignored', ''))
            c.preferred = toUnicode(kwargs.get('preferred', ''))
            c.required = toUnicode(kwargs.get('required', ''))
            c.destination = toUnicode(kwargs.get('destination', ''))

            db.commit()

            category_dict = c.to_dict()

            return {'success': True, 'category': category_dict}
        except:
            log.error('Failed: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return {'success': False, 'category': None}