# Path: uploads/models.py
# class Document(models.Model):
#     """Note that a number of fields have indexes in the database despite
#     lacking them here:
# 
#     mysql> show index from uploads_document;
#         +------------------+-----------------+-------------+-------------+
#         | Table            | Key_name        | Column_name | Cardinality |
#         +------------------+-----------------+-------------+-------------+
#         | uploads_document | PRIMARY         | id          |    26652929 |
#         | uploads_document | court           | court       |         206 |
#         | uploads_document | court           | casenum     |     1025112 |
#         | uploads_document | court           | docnum      |    26652929 |
#         | uploads_document | court           | subdocnum   |    26652929 |
#         | uploads_document | docid_idx       | docid       |    26652929 |
#         | uploads_document | document_free_i | free_import |           2 |
#         | uploads_document | lastdateindex   | lastdate    |    26652929 |
#         | uploads_document | modifiedindex   | modified    |     6663232 |
#         +------------------+-----------------+-------------+-------------+
# 
#     (https://dev.mysql.com/doc/refman/5.0/en/show-index.html)
# 
#     """
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     docnum = models.CharField(
#         maxlength=30,
#     )
#     subdocnum = models.CharField(
#         maxlength=30,
#     )
#     docid = models.CharField(
#         maxlength=32,
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     de_seq_num = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     dm_id = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     sha1 = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True,
#     )
#     available = models.BooleanField(
#         default=0,
#     )
#     lastdate = models.DateTimeField(
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     modified = models.DateTimeField(
#         null=True,
#         blank=True,
#         auto_now_add=True,
#         db_index=True,
#     )
#     free_import = models.BooleanField(
#         default=0,
#         db_index=True,
#     )
#     team_name = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#                 "docnum",
#                 "subdocnum",
#             ),
#         )


import os
import sys
import InternetArchiveDirect as IADirect
import InternetArchiveCommon as IACommon
import DocketXML
import remove_docket, remove_document, urllib2
from uploads.models import Document
from optparse import OptionParser
    print "   Updated %s %s : %s" % (court, casenum, html_put_msg)

    return success_status

def get_documents(court, casenum, docrange, show_warning=True):
    docnum_list = []

    #if it's a single document
    if len(docrange.split(",")) == 1 and docrange.find('-') < 0:
       docnum_list.append(docrange)
    else:
       for d in docrange.split(","):
          if d.find("-") > -1:
              start, end = d.split("-")
              docnum_list += range(int(start), int(end)+1)
          else:
              docnum_list.append(d)


    query = Document.objects.filter(court=court,
                                    casenum=casenum,
                                    docnum__in=docnum_list,
                                    subdocnum=0)

    try:
        doc = query[0]
    except IndexError:
        print "could not find any documents, exiting..."
        exit()
    #after sanity checks above, add in all associated subdocuments

# Path: uploads/models.py
# class Document(models.Model):
#     """Note that a number of fields have indexes in the database despite
#     lacking them here:
# 
#     mysql> show index from uploads_document;
#         +------------------+-----------------+-------------+-------------+
#         | Table            | Key_name        | Column_name | Cardinality |
#         +------------------+-----------------+-------------+-------------+
#         | uploads_document | PRIMARY         | id          |    26652929 |
#         | uploads_document | court           | court       |         206 |
#         | uploads_document | court           | casenum     |     1025112 |
#         | uploads_document | court           | docnum      |    26652929 |
#         | uploads_document | court           | subdocnum   |    26652929 |
#         | uploads_document | docid_idx       | docid       |    26652929 |
#         | uploads_document | document_free_i | free_import |           2 |
#         | uploads_document | lastdateindex   | lastdate    |    26652929 |
#         | uploads_document | modifiedindex   | modified    |     6663232 |
#         +------------------+-----------------+-------------+-------------+
# 
#     (https://dev.mysql.com/doc/refman/5.0/en/show-index.html)
# 
#     """
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     docnum = models.CharField(
#         maxlength=30,
#     )
#     subdocnum = models.CharField(
#         maxlength=30,
#     )
#     docid = models.CharField(
#         maxlength=32,
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     de_seq_num = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     dm_id = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     sha1 = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True,
#     )
#     available = models.BooleanField(
#         default=0,
#     )
#     lastdate = models.DateTimeField(
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     modified = models.DateTimeField(
#         null=True,
#         blank=True,
#         auto_now_add=True,
#         db_index=True,
#     )
#     free_import = models.BooleanField(
#         default=0,
#         db_index=True,
#     )
#     team_name = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#                 "docnum",
#                 "subdocnum",
#             ),
#         )


# Path: uploads/modify_docket.py
import os
import sys
import InternetArchiveDirect as IADirect
import InternetArchiveCommon as IACommon
import DocketXML
import remove_docket, remove_document, urllib2
from uploads.models import Document
from optparse import OptionParser

    print "   Updated %s %s : %s" % (court, casenum, html_put_msg)

    return success_status

def get_documents(court, casenum, docrange, show_warning=True):
    docnum_list = []

    #if it's a single document
    if len(docrange.split(",")) == 1 and docrange.find('-') < 0:
       docnum_list.append(docrange)
    else:
       for d in docrange.split(","):
          if d.find("-") > -1:
              start, end = d.split("-")
              docnum_list += range(int(start), int(end)+1)
          else:
              docnum_list.append(d)


    query = Document.objects.filter(court=court,
                                    casenum=casenum,
                                    docnum__in=docnum_list,
                                    subdocnum=0)

    try:
        doc = query[0]
    except IndexError:
        print "could not find any documents, exiting..."
        exit()
    #after sanity checks above, add in all associated subdocuments

    query = Document.objects.filter(court=court,