Exemplo n.º 1
0
def zfwbimg_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    zfwbimgs = zfwbimg_get_by_uid(uid)
    for zfwbimg in zfwbimgs:
        zfwbimg.delete()
Exemplo n.º 2
0
def zfwbtext_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    zfwbtext = zfwbtext_get_by_mid(mid)
    if zfwbtext:
        zfwbtext.delete(session)
Exemplo n.º 3
0
def zfwbtext_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    zfwbtexts = zfwbtext_get_by_uid(uid)
    for zfwbtext in zfwbtexts:
        zfwbtext.delete(session)
Exemplo n.º 4
0
def zfwbtext_delete(id, session=None):
    if not session:
        session = get_session()

    zfwbtexts = zfwbtext_get_by_id(id)
    for zfwbtext in zfwbtexts:
        zfwbtext.delete(session)
Exemplo n.º 5
0
def zfwbimg_delete(id, session=None):
    if not session:
        session = get_session()

    zfwbimg = zfwbimg_get_by_id(id)
    if zfwbimg:
        zfwbimg.delete()
Exemplo n.º 6
0
def wbimg_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    wbimgs = wbimg_get_by_uid(uid)
    if wbimg in wbimgs:
        wbimg.delete()
Exemplo n.º 7
0
def weibo_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    weibo = weibo_get_by_mid(mid)
    if weibo:
        weibo.delete()
Exemplo n.º 8
0
def model_query(model, *args, **kwargs):
    """Query helper that accounts for context's `read_deleted` field.

    :param session: if present, the session to use
    :param read_deleted: if present, overrides context's read_deleted field.
    :param project_only: if present and context is user-type, then restrict
    query to match the context's project_id. If set to 'allow_none',
    restriction includes project_id = None.
    """
    read_deleted = kwargs.get('read_deleted', 'no')
    session = kwargs.get('session') or get_session()

    query = session.query(model, *args)

    if read_deleted == 'no':
        query = query.filter_by(deleted=False)
    elif read_deleted == 'yes':
        pass  # omit the filter to include deleted and active
    elif read_deleted == 'only':
        query = query.filter_by(deleted=True)
    else:
        raise Exception(
            _("Unrecognized read_deleted value '%s'") % read_deleted)

    return query
Exemplo n.º 9
0
def wbtext_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    wbtexts = wbtext_get_by_uid(uid)
    if wbtext in wbtexts:
        wbtext.delete()
Exemplo n.º 10
0
def wbimg_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    wbimg = wbimg_get_by_mid(mid)
    if wbimg:
        wbimg.delete()
Exemplo n.º 11
0
def wbtext_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    wbtext = wbtext_get_by_mid(mid)
    if wbtext:
        wbtext.delete()
Exemplo n.º 12
0
def weibo_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    weibos = weibo_get_by_uid(uid)
    if weibo in weibos:
        weibo.delete()
Exemplo n.º 13
0
def weibo_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    weibo = weibo_get_by_mid(mid)
    if weibo:
        weibo.delete()
Exemplo n.º 14
0
def wbimg_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    wbimgs = wbimg_get_by_uid(uid)
    for wbimg in wbimgs:
        wbimg.delete()
Exemplo n.º 15
0
def zfwbimg_delete(id, session=None):
    if not session:
        session = get_session()

    zfwbimg = zfwbimg_get_by_id(id)
    if zfwbimg:
        zfwbimg.delete()
Exemplo n.º 16
0
def zfwbtext_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    zfwbtexts = zfwbtext_get_by_uid(uid)
    if zfwbtext in zfwbtexts:
        zfwbtext.delete()
Exemplo n.º 17
0
def zfwbtext_delete(id, session=None):
    if not session:
        session = get_session()

    zfwtext = zfwbtext_get_by_id(id)
    if zfwbtext:
        zfwbtext.delete()
Exemplo n.º 18
0
def weibo_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    weibos = weibo_get_by_uid(uid)
    for weibo in weibos:
        weibo.delete()
Exemplo n.º 19
0
def zfwbtext_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    zfwbtext = zfwbtext_get_by_mid(mid)
    if zfwbtext:
        zfwbtext.delete()
Exemplo n.º 20
0
def wbtext_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    wbtext = wbtext_get_by_mid(mid)
    if wbtext:
        wbtext.delete()
Exemplo n.º 21
0
def wbtext_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    wbtexts = wbtext_get_by_uid(uid)
    for wbtext in wbtexts:
        wbtext.delete()
Exemplo n.º 22
0
def wbimg_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    wbimg = wbimg_get_by_mid(mid)
    if wbimg:
        wbimg.delete()
Exemplo n.º 23
0
def zfwbimg_delete_uid(uid, session=None):
    if not session:
        session = get_session()

    zfwbimgs = zfwbimg_get_by_uid(uid)
    if zfwbimg in zfwbimgs:
        zfwbimg.delete()
Exemplo n.º 24
0
def zfwbimg_delete_mid(mid, session=None):
    if not session:
        session = get_session()

    zfwbimgs = zfwbimg_get_by_mid(mid)
    for zfwbimg in zfwbimgs:
        zfwbimg.delete()
Exemplo n.º 25
0
def model_query(model, *args, **kwargs):
    """Query helper that accounts for context's `read_deleted` field.

    :param session: if present, the session to use
    :param read_deleted: if present, overrides context's read_deleted field.
    :param project_only: if present and context is user-type, then restrict
    query to match the context's project_id. If set to 'allow_none',
    restriction includes project_id = None.
    """
    read_deleted = kwargs.get('read_deleted', 'no')
    session = kwargs.get('session') or get_session()

    query = session.query(model, *args)

    if read_deleted == 'no':
        query = query.filter_by(deleted=False)
    elif read_deleted == 'yes':
        pass  # omit the filter to include deleted and active
    elif read_deleted == 'only':
        query = query.filter_by(deleted=True)
    else:
        raise Exception(
                _("Unrecognized read_deleted value '%s'") % read_deleted)

    return query
Exemplo n.º 26
0
def weibo_update(values, session=None):
    if not session:
        session = get_session()
    mid = values.pop('mid')
    with session.begin():
        weibo = weibo_get_by_mid(mid, session=session)
        weibo.update(values)
        weibo.save(session=session)

    return weibo_get_by_mid(mid)
Exemplo n.º 27
0
def zfwbtext_update(values, session=None):
    if not session:
        session = get_session()
    mid = values.pop('mid')
    with session.begin():
        zfwbtext = zfwbtext_get_by_mid(mid, session=session)
        zfwbtext.update(values)
        zfwbtext.save(session=session)

    return zfwbtext_get_by_mid(mid)
Exemplo n.º 28
0
def zfwbimg_update(values, session=None):
    if not session:
        session = get_session()
    url = values.get('url')
    with session.begin():
        zfwbimg = zfwbimg_get_by_url(url, session=session)
        zfwbimg.update(values)
        zfwbimg.save(session=session)

    return zfwbimg_get_by_url(url)
Exemplo n.º 29
0
def userdata_update(values, session=None):
    if not session:
        session = get_session()
    uid = values.pop('uid')
    with session.begin():
        userdata = userdata_get_by_uid(uid, session=session)
        userdata.update(values)
        userdata.save(session=session)

    return userdata_get_by_uid(uid)
Exemplo n.º 30
0
def weibo_update(values, session=None):
    if not session:
        session = get_session()
    mid = values.pop('mid')
    with session.begin():
        weibo = weibo_get_by_mid(mid, session=session)
        weibo.update(values)
        weibo.save(session=session)

    return weibo_get_by_mid(mid)
Exemplo n.º 31
0
def zfwbimg_update(values, session=None):
    if not session:
        session = get_session()
    url = values.get('url')
    with session.begin():
        zfwbimg = zfwbimg_get_by_url(url, session=session)
        zfwbimg.update(values)
        zfwbimg.save(session=session)

    return zfwbimg_get_by_url(url)
Exemplo n.º 32
0
def userdata_update(values, session=None):
    if not session:
        session = get_session()
    uid = values.pop('uid')
    with session.begin():
        userdata = userdata_get_by_uid(uid, session=session)
        userdata.update(values)
        userdata.save(session=session)

    return userdata_get_by_uid(uid)
Exemplo n.º 33
0
def zfwbtext_update(values, session=None):
    if not session:
        session = get_session()
    mid = values.pop('mid')
    with session.begin():
        zfwbtext = zfwbtext_get_by_mid(mid, session=session)
        zfwbtext.update(values)
        zfwbtext.save(session=session)

    return zfwbtext_get_by_mid(mid)
Exemplo n.º 34
0
def service_update(service_id, values):
    session = get_session()
    with session.begin():
        service_ref = _service_get(service_id, session=session)
        # Only servicegroup.drivers.db.DbDriver._report_state() updates
        # 'report_count', so if that value changes then store the timestamp
        # as the last time we got a state report.
        if 'report_count' in values:
            if values['report_count'] > service_ref.report_count:
                service_ref.last_seen_up = timeutils.utcnow()
        service_ref.update(values)

    return service_ref
Exemplo n.º 35
0
def service_update(service_id, values):
    session = get_session()
    with session.begin():
        service_ref = _service_get(service_id, session=session)
        # Only servicegroup.drivers.db.DbDriver._report_state() updates
        # 'report_count', so if that value changes then store the timestamp
        # as the last time we got a state report.
        if 'report_count' in values:
            if values['report_count'] > service_ref.report_count:
                service_ref.last_seen_up = timeutils.utcnow()
        service_ref.update(values)

    return service_ref
Exemplo n.º 36
0
def userdata_create(values):
    session = get_session()
    userdata = _get_query(models.Userdata,
                                   models.Userdata.uid,
                                   values['uid'],
                                   session=session,
                                   read_deleted='no').first()
    if not userdata:
        userdata = models.Userdata()
        userdata.update(values)
        userdata.save(session=session)
    else:
        raise exception.UserdataNameExists(userdata_name=values['name'])

    return userdata_get_by_uid(userdata.uid)
Exemplo n.º 37
0
def userdata_create(values):
    session = get_session()
    userdata = _get_query(models.Userdata,
                          models.Userdata.uid,
                          values['uid'],
                          session=session,
                          read_deleted='no').first()
    if not userdata:
        userdata = models.Userdata()
        userdata.update(values)
        userdata.save(session=session)
    else:
        raise exception.UserdataNameExists(userdata_name=values['name'])

    return userdata_get_by_uid(userdata.uid)
Exemplo n.º 38
0
def zfwbtext_create(values, session=None):
    if not session:
        session = get_session()

    zfwbtext = _get_query(models.Zfwbtext,
                       models.Zfwbtext.mid,
                       values['mid'],
                       session=session,
                       read_deleted='no').first()

    if not zfwbtext:
        zfwbtext = models.Zfwbtext()
        zfwbtext.update(values)
        zfwbtext.save(session=session)
    else:
        raise exception.ZfwbtextMidExists(mid=mid)

    return zfwbtext_get_by_mid(zfwbtext.mid)
Exemplo n.º 39
0
def weibo_create(values, session=None):
    if not session:
        session = get_session()

    weibo = _get_query(models.Weibo,
                       models.Weibo.mid,
                       values['mid'],
                       session=session,
                       read_deleted='no').first()

    if not weibo:
        weibo = models.Weibo()
        weibo.update(values)
        weibo.save(session=session)
    else:
        raise exception.WeiboMidExists(mid=mid)

    return weibo_get_by_mid(weibo.mid)
Exemplo n.º 40
0
def weibo_create(values, session=None):
    if not session:
        session = get_session()

    weibo = _get_query(models.Weibo,
                       models.Weibo.mid,
                       values['mid'],
                       session=session,
                       read_deleted='no').first()

    if not weibo:
        weibo = models.Weibo()
        weibo.update(values)
        weibo.save(session=session)
    else:
        raise exception.WeiboMidExists(mid=values['mid'])

    return weibo_get_by_mid(weibo.mid)
Exemplo n.º 41
0
def zfwbtext_create(values, session=None):
    if not session:
        session = get_session()

    zfwbtext = _get_query(models.Zfwbtext,
                          models.Zfwbtext.mid,
                          values['mid'],
                          session=session,
                          read_deleted='no').first()

    if not zfwbtext:
        zfwbtext = models.Zfwbtext()
        zfwbtext.update(values)
        zfwbtext.save(session=session)
    else:
        raise exception.ZfwbtextMidExists(mid=values['mid'])

    return zfwbtext_get_by_mid(zfwbtext.mid)
Exemplo n.º 42
0
def zfwbimg_create(values, session=None):
    if not session:
        session = get_session()

    url = values['url']
    zfwbimg = _get_query(models.Zfwbimg,
                       models.Zfwbimg.url,
                       url,
                       session=session,
                       read_deleted='no').first()

    if not zfwbimg:
        zfwbimg = models.Zfwbimg()
        zfwbimg.update(values)
        zfwbimg.save(session=session)
    else:
        raise exception.ZfwbimgUrlExists(url=url)

    return zfwbimg_get_by_url(zfwbimg.url)
Exemplo n.º 43
0
def zfwbimg_create(values, session=None):
    if not session:
        session = get_session()

    url = values['url']
    zfwbimg = _get_query(models.Zfwbimg,
                         models.Zfwbimg.url,
                         url,
                         session=session,
                         read_deleted='no').first()

    if not zfwbimg:
        zfwbimg = models.Zfwbimg()
        zfwbimg.update(values)
        zfwbimg.save(session=session)
    else:
        raise exception.ZfwbimgUrlExists(url=url)

    return zfwbimg_get_by_url(zfwbimg.url)
Exemplo n.º 44
0
def userdata_delete_uid(uid):
    session = get_session()
    userdata = userdata_get_by_uid(uid)
    if userdata:
        userdata.delete()
Exemplo n.º 45
0
def userdata_get_all(session=None):
    if not session:
        session = get_session()
    result = model_query(models.Userdata, session=session)
    return result.all()
Exemplo n.º 46
0
def userdata_delete(id):
    session = get_session()
    userdata = userdata_get_by_id(id, session)
    if userdata:
        userdata.delete(session)
Exemplo n.º 47
0
def userdata_delete_name(name):
    session = get_session()
    userdata = userdata_get_by_name(name, session)
    if userdata:
        userdata.delete(session)
Exemplo n.º 48
0
def userdata_delete_name(name):
    session = get_session()
    userdata = userdata_get_by_name(name)
    if userdata:
        userdata.delete()
Exemplo n.º 49
0
def userdata_get_all(session=None):
    if not session:
        session = get_session()
    result = model_query(models.Userdata, session=session)
    return result.all()
Exemplo n.º 50
0
def userdata_delete(id):
    session = get_session()
    userdata = userdata_get_by_id(id, session)
    if userdata:
        userdata.delete(session)
Exemplo n.º 51
0
def userdata_delete_uid(uid):
    session = get_session()
    userdata = userdata_get_by_uid(uid)
    if userdata:
        userdata.delete()