# Path: uploads/models.py
# class BucketLock(models.Model):
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     uploaderid = models.IntegerField()
#     nonce = models.CharField(
#         maxlength=6,
#     )
#     ready = models.BooleanField(
#         default=0,
#     )
#     processing = models.BooleanField(
#         default=0,
#     )
#     locktime = models.DateTimeField(
#         auto_now_add=True,
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#             ),
#         )
# 
#     def __unicode__(self):
#         return str(self.court) + "." + str(self.casenum)


import logging
import DocketXML
from MySQLdb import IntegrityError
from uploads.models import BucketLock
        lockquery = BucketLock.objects.filter(court=court) \
            .filter(casenum=casenum)
        try:
            lock = lockquery[0]
        except IndexError:
            # No lock exists anymore-- must have just missed it.
            return None, "Locked."
        else:
            # Lock already exists

            # This prevents two cron jobs from requesting the same lock
            if lock.uploaderid == uploaderid and one_per_uploader:
                return lock.nonce, "You already own this lock (Another cron job?)"
            if lock.uploaderid == uploaderid and not lock.ready:
                return lock.nonce, ""
            if lock.uploaderid == uploaderid and lock.ready and not lock.processing:
                # If we're not currently processing the case, let the same
                # uploader modify it
                lock.ready = 0
                lock.save()
                return lock.nonce, ""
            else:
                return None, "Locked by another user."
    else:
        # Success.
        return nonce, ""


def drop_lock(court, casenum, uploaderid, modified=1,
              nolocaldb=0, ignore_nonce=0):

# Path: uploads/models.py
# class BucketLock(models.Model):
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     uploaderid = models.IntegerField()
#     nonce = models.CharField(
#         maxlength=6,
#     )
#     ready = models.BooleanField(
#         default=0,
#     )
#     processing = models.BooleanField(
#         default=0,
#     )
#     locktime = models.DateTimeField(
#         auto_now_add=True,
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#             ),
#         )
# 
#     def __unicode__(self):
#         return str(self.court) + "." + str(self.casenum)


# Path: uploads/BucketLockManager.py
import logging
import DocketXML
from MySQLdb import IntegrityError
from uploads.models import BucketLock

        lockquery = BucketLock.objects.filter(court=court) \
            .filter(casenum=casenum)
        try:
            lock = lockquery[0]
        except IndexError:
            # No lock exists anymore-- must have just missed it.
            return None, "Locked."
        else:
            # Lock already exists

            # This prevents two cron jobs from requesting the same lock
            if lock.uploaderid == uploaderid and one_per_uploader:
                return lock.nonce, "You already own this lock (Another cron job?)"
            if lock.uploaderid == uploaderid and not lock.ready:
                return lock.nonce, ""
            if lock.uploaderid == uploaderid and lock.ready and not lock.processing:
                # If we're not currently processing the case, let the same
                # uploader modify it
                lock.ready = 0
                lock.save()
                return lock.nonce, ""
            else:
                return None, "Locked by another user."
    else:
        # Success.
        return nonce, ""


def drop_lock(court, casenum, uploaderid, modified=1,
              nolocaldb=0, ignore_nonce=0):

    lockquery = BucketLock.objects.filter(court=court) \