示例#1
0
 def test_is_locked_expired(self):
     """`Lock.is_locked` method should return False for expired locks"""
     lock = Lock.objects.create(locked_by=self.user,
                                content_type=self.article_ct,
                                object_id=self.article1.pk)
     Lock.objects.filter(pk=lock.pk).update(date_expires=self.past)
     self.assertFalse(Lock.is_locked(self.article1))
示例#2
0
def lock(request, app, model, id):
    # TODO: What do we do if the model doesn't exist?  Edge case
    # for later
    ct = get_ct(app, model)
    if ct is None:
        return HttpResponse(status=404)

    try:
        obj = Lock.objects.get(content_type=ct, object_id=id)
    except Lock.DoesNotExist:
        obj = Lock(content_type=ct, object_id=id)
    
    try:
        obj.lock_for(request.user)
    except ObjectLockedError:
        # The user tried to overwrite an existing lock by another user.
        # No can do, pal!
        return HttpResponse(status=403)

    obj.save()
    return HttpResponse(status=200)
示例#3
0
def lock(request, app, model, id):
    if request.user and id and app and model:
        try:
            obj = Lock.objects.get(entry_id=id, app=app, model=model)
            obj.lock_for(request.user)
            obj.save()
            return HttpResponse(status=200)
        except:
            try:
                obj = Lock()
                obj.entry_id = id
                obj.app = app
                obj.model = model
                obj.lock_for(request.user)
                obj.save()
                return HttpResponse(status=200)
            except ObjectLockedError:
                # The user tried to overwrite an existing lock by another user.
                # No can do, pal!
                return HttpResponse(status=403)
    else:
        return HttpResponse(status=200)
示例#4
0
def lock(request, app, model, id):
    if request.user and id and app and model:
        try:
    		obj = Lock.objects.get(entry_id=id, app=app, model=model)
    		obj.lock_for(request.user)
    		obj.save()
    		return HttpResponse(status=200)
    	except:
    		try:
    			obj = Lock()
    			obj.entry_id = id
    			obj.app = app
    			obj.model= model
    			obj.lock_for(request.user)
    			obj.save()
    			return HttpResponse(status=200)
    		except ObjectLockedError:
    			# The user tried to overwrite an existing lock by another user.
    			# No can do, pal!
    			return HttpResponse(status=403)
    else:
        return HttpResponse(status=200)
 def test_is_locked_expired(self):
     """`Lock.is_locked` method should return False for expired locks"""
     lock = Lock.objects.create(locked_by=self.user, content_type=self.article_ct,
         object_id=self.article1.pk)
     Lock.objects.filter(pk=lock.pk).update(date_expires=self.past)
     self.assertFalse(Lock.is_locked(self.article1))
 def test_is_locked_unexpired(self):
     """`Lock.is_locked` method should return True for unexpired locks"""
     Lock.objects.create(locked_by=self.user, content_type=self.article_ct,
         object_id=self.article1.pk)
     self.assertTrue(Lock.is_locked(self.article1))
示例#7
0
 def test_is_locked_unexpired(self):
     """`Lock.is_locked` method should return True for unexpired locks"""
     Lock.objects.create(locked_by=self.user,
                         content_type=self.article_ct,
                         object_id=self.article1.pk)
     self.assertTrue(Lock.is_locked(self.article1))