コード例 #1
0
ファイル: __init__.py プロジェクト: mashuq05/ka-lite-central
def serialize(models, sign=True, increment_counters=True, dest_version=VERSION, *args, **kwargs):
    """
    This function encapsulates serialization, and ensures that any final steps needed before syncing
    (e.g. signing, incrementing counters, etc) are done.
    """
    from securesync.devices.models import Device
    from .models import SyncedModel
    own_device = Device.get_own_device()

    for model in models:
        resave = False

        if increment_counters or sign:
            assert isinstance(model, SyncedModel), "Can only serialize SyncedModel instances"

        if increment_counters and not model.counter:
            model.counter = own_device.increment_counter_position()
            resave = True

        if sign and not model.signature:
            model.sign()
            resave = True

        if resave:
            super(SyncedModel, model).save()

    return serializers.serialize("versioned-json", models, dest_version=dest_version, *args, **kwargs)
コード例 #2
0
ファイル: my_filters.py プロジェクト: Aypak/ka-lite
def jsonify(object):
    try:
        if isinstance(object, QuerySet):
            return serialize('json', object)
    except:
        pass

    str = mark_safe(json.dumps(object, default=_dthandler))
    if str == "null":
        str = mark_safe("[%s]" % (",".join([json.dumps(o, default=_dthandler) for o in object])))
    return str
コード例 #3
0
ファイル: my_filters.py プロジェクト: jeepurs/ka-lite-central
def jsonify(object):
    try:
        if isinstance(object, QuerySet):
            return serialize('json', object)
    except:
        pass

    str = mark_safe(simplejson.dumps(object, default=_dthandler))
    if str == "null":
        str = mark_safe("[%s]" % (",".join(
            [simplejson.dumps(o, default=_dthandler) for o in object])))
    return str