示例#1
0
def is_locked(request, app, model, id):
    obj = utils.gather_lockable_models()[app][model].objects.get(pk=id)
    response = simplejson.dumps({
        "is_active": obj.is_locked,
        "for_user": getattr(obj.locked_by, 'username', None),
        "applies": obj.lock_applies_to(request.user),
        })
    return HttpResponse(response, mimetype='application/json')
示例#2
0
文件: tests.py 项目: sprezz/leadfrod
    def test_gather_lockable_models(self):
        from locking import utils
        from locking.tests import models


        lockable_models = utils.gather_lockable_models()
        self.assertTrue("story" in lockable_models["tests"])
        self.assertTrue("unlockable" not in lockable_models["tests"])
示例#3
0
def lock(request, app, model, id):
    obj = utils.gather_lockable_models()[app][model].objects.get(pk=id)

    try:
        obj.lock_for(request.user)
        obj.save()
        return HttpResponse(status=200)
    except models.ObjectLockedError:
        # The user tried to overwrite an existing lock by another user.
        # No can do, pal!
        return HttpResponse(status=403)
示例#4
0
文件: views.py 项目: sprezz/leadfrod
def is_locked(request, app, model, id):
    obj = utils.gather_lockable_models()[app][model].objects.get(pk=id)

    response = dumps(
        {
            "is_active": obj.is_locked,
            "for_user": getattr(obj.locked_by, "username", None),
            "applies": obj.lock_applies_to(request.user),
        }
    )
    return HttpResponse(response)
示例#5
0
def is_locked(request, app, model, id):
    obj = utils.gather_lockable_models()[app][model].objects.get(pk=id)

    response = simplejson.dumps({
        "is_active":
        obj.is_locked,
        "for_user":
        getattr(obj.locked_by, 'username', None),
        "applies":
        obj.lock_applies_to(request.user),
    })
    return HttpResponse(response)
示例#6
0
def unlock(request, app, model, id):
    obj = utils.gather_lockable_models()[app][model].objects.get(pk=id)

    # Users who don't have exclusive access to an object anymore may still
    # request we unlock an object. This happens e.g. when a user navigates
    # away from an edit screen that's been open for very long.
    # When this happens, LockableModel.unlock_for will throw an exception, 
    # and we just ignore the request.
    # That way, any new lock that may since have been put in place by another 
    # user won't get accidentally overwritten.
    try:
        obj.unlock_for(request.user)
        obj.save()    
        return HttpResponse(status=200)
    except models.ObjectLockedError:
        return HttpResponse(status=403)
示例#7
0
def unlock(request, app, model, id):
    obj = utils.gather_lockable_models()[app][model].objects.get(pk=id)

    # Users who don't have exclusive access to an object anymore may still
    # request we unlock an object. This happens e.g. when a user navigates
    # away from an edit screen that's been open for very long.
    # When this happens, LockableModel.unlock_for will throw an exception,
    # and we just ignore the request.
    # That way, any new lock that may since have been put in place by another
    # user won't get accidentally overwritten.
    try:
        obj.unlock_for(request.user)
        obj.save()
        return HttpResponse(status=200)
    except models.ObjectLockedError:
        return HttpResponse(status=403)
示例#8
0
 def test_gather_lockable_models(self):
     from locking import utils
     from locking.tests import models
     lockable_models = utils.gather_lockable_models()
     self.assertTrue("story" in lockable_models["tests"])
     self.assertTrue("unlockable" not in lockable_models["tests"])