Exemplo n.º 1
0
def get(request, label_id, old_version, new_version):
    """Find and return the diff with the provided label / versions"""
    diff = db.Diffs().get(label_id, old_version, new_version)
    if diff:
        return success(diff)
    else:
        return four_oh_four()
Exemplo n.º 2
0
def listing(request, label_id=None):
    """List versions of the requested (label_id) regulation; or all regulations
    if label_id is None"""
    if label_id:
        reg_versions = db.Regulations().listing(label_id)
        notices = db.Notices().listing(label_id.split("-")[0])
    else:
        reg_versions = db.Regulations().listing()
        notices = db.Notices().listing()

    by_date = defaultdict(list)
    for notice in (n for n in notices if "effective_on" in n):
        by_date[notice["effective_on"]].append(notice)

    regs = []
    for effective_date in sorted(by_date.keys(), reverse=True):
        notices = [(n["document_number"], n["effective_on"]) for n in by_date[effective_date]]
        notices = sorted(notices, reverse=True)
        found_latest = set()
        for doc_number, date in notices:
            for version, reg_part in reg_versions:
                if doc_number == version and reg_part in found_latest:
                    regs.append({"version": version, "regulation": reg_part})
                elif doc_number == version:
                    found_latest.add(reg_part)
                    regs.append({"version": version, "by_date": date, "regulation": reg_part})

    if regs:
        return success({"versions": regs})
    else:
        return four_oh_four()
Exemplo n.º 3
0
def get(request, doc_type, label_id, version=None):
    """Find and return the regulation with this version and label"""
    regulation = storage.for_documents.get(doc_type, label_id, version)
    if regulation is not None:
        return success(regulation)
    else:
        return four_oh_four()
Exemplo n.º 4
0
def get(request, name, label_id, version):
    """Find and return the layer with this name + version + label"""
    layer = db.Layers().get(name, label_id, version)
    if layer is not None:
        return success(layer)
    else:
        return four_oh_four()
Exemplo n.º 5
0
def get(request, doc_type, label_id, version=None):
    """Find and return the regulation with this version and label"""
    regulation = storage.for_documents.get(doc_type, label_id, version)
    if regulation is not None:
        return success(regulation)
    else:
        return four_oh_four()
Exemplo n.º 6
0
def get(request, label_id, version):
    """Find and return the regulation with this version and label"""
    regulation = db.Regulations().get(label_id, version)
    if regulation:
        return success(regulation)
    else:
        return four_oh_four()
Exemplo n.º 7
0
def listing(request, label_id):
    """List versions of this regulation"""
    part = label_id.split('-')[0]
    notices = db.Notices().listing(label_id)
    by_date = defaultdict(list)
    for notice in (n for n in notices if 'effective_on' in n):
        by_date[notice['effective_on']].append(notice)
    reg_versions = set(db.Regulations().listing(label_id))

    regs = []
    for effective_date in sorted(by_date.keys(), reverse=True):
        notices = [(n['document_number'], n['effective_on'])
                   for n in by_date[effective_date]]
        notices = sorted(notices, reverse=True)
        found_latest = False
        for version, effective in ((v, d) for v, d in notices
                                   if v in reg_versions):
            if found_latest:
                regs.append({'version': version})
            else:
                found_latest = True
                regs.append({'version': version, 'by_date': effective})

    if regs:
        return success({'versions': regs})
    else:
        return four_oh_four()
Exemplo n.º 8
0
def listing(request, doc_type, label_id=None):
    """List versions of the requested (label_id) regulation; or all regulations
    if label_id is None"""
    if label_id:
        reg_versions = storage.for_documents.listing(doc_type, label_id)
        notices = storage.for_notices.listing(label_id.split('-')[0])
    else:
        reg_versions = storage.for_documents.listing(doc_type)
        notices = storage.for_notices.listing()

    by_date = defaultdict(list)
    for notice in (n for n in notices if 'effective_on' in n):
        by_date[notice['effective_on']].append(notice)

    regs = []
    for effective_date in sorted(by_date.keys(), reverse=True):
        notices = [(n['document_number'], n['effective_on'])
                   for n in by_date[effective_date]]
        notices = sorted(notices, reverse=True)
        found_latest = set()
        for doc_number, date in notices:
            for version, reg_part in reg_versions:
                if doc_number == version and reg_part in found_latest:
                    regs.append({'version': version, 'regulation': reg_part})
                elif doc_number == version:
                    found_latest.add(reg_part)
                    regs.append({'version': version, 'by_date': date,
                                 'regulation': reg_part})

    if regs:
        return success({'versions': regs})
    else:
        return four_oh_four()
Exemplo n.º 9
0
def get(request, docnum):
    """Find and return the notice with this docnum"""
    notice = storage.for_notices.get(docnum)
    if notice is not None:
        return success(notice)
    else:
        return four_oh_four()
Exemplo n.º 10
0
def get(request, docnum):
    """Find and return the notice with this docnum"""
    notice = storage.for_notices.get(docnum)
    if notice is not None:
        return success(notice)
    else:
        return four_oh_four()
Exemplo n.º 11
0
def get(request, label_id, version):
    """Find and return the regulation with this version and label"""
    regulation = db.Regulations().get(label_id, version)
    if regulation:
        return success(regulation)
    else:
        return four_oh_four()
Exemplo n.º 12
0
def get(request, docnum):
    """Find and return the notice with this docnum"""
    notice = db.Notices().get(docnum)
    if notice:
        return success(notice)
    else:
        return four_oh_four()
Exemplo n.º 13
0
def get(request, docnum):
    """Find and return the notice with this docnum"""
    notice = db.Notices().get(docnum)
    if notice:
        return success(notice)
    else:
        return four_oh_four()
Exemplo n.º 14
0
def get(request, label_id, old_version, new_version):
    """Find and return the diff with the provided label / versions"""
    diff = storage.for_diffs.get(label_id, old_version, new_version)
    if diff is not None:
        return success(diff)
    else:
        return four_oh_four()
Exemplo n.º 15
0
def get(request, name, doc_type, doc_id):
    """Find and return the layer with this name, referring to this doc_id"""
    params = standardize_params(doc_type, doc_id)
    layer = storage.for_layers.get(name, params.doc_type, params.doc_id)
    if layer is not None:
        return success(layer)
    else:
        return four_oh_four()
Exemplo n.º 16
0
def get(request, part_or_docnum, docnum):
    """ Find and return the notice with this docnum and part """
    part = part_or_docnum
    notice = db.Notices().get(doc_number=docnum, part=part)
    if notice:
        return success(notice)
    else:
        return four_oh_four()
Exemplo n.º 17
0
def get(request, part_or_docnum, docnum):
    """ Find and return the notice with this docnum and part """
    part = part_or_docnum
    notice = db.Notices().get(doc_number=docnum, part=part)
    if notice:
        return success(notice)
    else:
        return four_oh_four()
Exemplo n.º 18
0
def listing(request, doc_type, label_id=None):
    """List versions of the requested (label_id) regulation; or all regulations
    if label_id is None"""
    if label_id:
        reg_versions = storage.for_documents.listing(doc_type, label_id)
        notices = storage.for_notices.listing(label_id.split('-')[0])
    else:
        reg_versions = storage.for_documents.listing(doc_type)
        notices = storage.for_notices.listing()

    by_date = defaultdict(list)
    for notice in (n for n in notices if 'effective_on' in n):
        by_date[notice['effective_on']].append(notice)

    regs = []
    for effective_date in sorted(by_date.keys(), reverse=True):
        notices = [(n['document_number'], n['effective_on'])
                   for n in by_date[effective_date]]
        notices = sorted(notices, reverse=True)
        found_latest = set()
        for doc_number, date in notices:
            for version, reg_part in reg_versions:
                if doc_number == version and reg_part in found_latest:
                    regs.append({'version': version, 'regulation': reg_part})
                elif doc_number == version:
                    found_latest.add(reg_part)
                    regs.append({
                        'version': version,
                        'by_date': date,
                        'regulation': reg_part
                    })

    if regs:
        return success({'versions': regs})
    else:
        return four_oh_four()