(user, uid, user_agent, undelete=True)
return client
Loads or creates the device indicated by user, uid.

    If the device has been deleted and undelete=True, it is undeleted.
Loads or creates the device indicated by user, uid.
Loads or creates the device indicated by user uid .
def get_device(user, uid, user_agent, undelete=True):
    """
    Loads or creates the device indicated by user, uid.

    If the device has been deleted and undelete=True, it is undeleted.
    """

    store_ua = user.profile.settings.get_wksetting(STORE_UA)

    # list of fields to update -- empty list = no update
    update_fields = []

    try:
        with transaction.atomic():
            client = Client(id=uuid.uuid1(), user=user, uid=uid)
            client.clean_fields()
            client.clean()
            client.save()

    except IntegrityError:
        client = Client.objects.get(user=user, uid=uid)

    if client.deleted and undelete:
        client.deleted = False
        update_fields.append("deleted")

    if store_ua and user_agent and client.user_agent != user_agent:
        client.user_agent = user_agent
        update_fields.append("user_agent")

    if update_fields:
        client.save(update_fields=update_fields)

    return client
def get_device ( user , uid , user_agent , undelete = True ) : store_ua = user . profile . settings . get_wksetting ( STORE_UA ) # list of fields to update -- empty list = no update update_fields = [ ] try : with transaction . atomic ( ) : client = Client ( id = uuid . uuid1 ( ) , user = user , uid = uid ) client . clean_fields ( ) client . clean ( ) client . save ( ) except IntegrityError : client = Client . objects . get ( user = user , uid = uid ) if client . deleted and undelete : client . deleted = False update_fields . append ( "deleted" ) if store_ua and user_agent and client . user_agent != user_agent : client . user_agent = user_agent update_fields . append ( "user_agent" ) if update_fields : client . save ( update_fields = update_fields ) return client