예제 #1
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()
예제 #2
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()
예제 #3
0
def add(request, part_or_docnum, docnum):
    """ Add the notice to the db """
    part = part_or_docnum

    try:
        notice = json.loads(request.body)
    except ValueError:
        return user_error('invalid format')

    db.Notices().put(docnum, part, notice)
    return success()
예제 #4
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()
예제 #5
0
def add(request, docnum):
    """Add the notice to the db"""
    try:
        notice = anyjson.deserialize(request.body)
    except ValueError:
        return user_error('invalid format')

    #   @todo: write a schema that verifies the notice's structure
    cfr_parts = notice.get('cfr_parts', [])
    if 'cfr_part' in notice:
        cfr_parts.append(notice['cfr_part'])
        del notice['cfr_part']
    notice['cfr_parts'] = cfr_parts

    db.Notices().put(docnum, notice)
    return success()
예제 #6
0
def add_all(request, part_or_docnum):
    """ Add the notice for all applicable CFR parts, as specified in the
        notice body. """
    # NOTE: Be absolutely certain if you're PUTing /notice/1234-12345
    # that it actually does contain content for all the parts in cfr_parts.
    docnum = part_or_docnum

    try:
        notice = json.loads(request.body)
    except ValueError:
        return user_error('invalid format')

    # This supports old-style notices that apply to multiple CFR parts.
    cfr_parts = notice.get('cfr_parts', [])
    if 'cfr_part' in notice:
        cfr_parts.append(notice['cfr_part'])
    notice['cfr_parts'] = cfr_parts

    for cfr_part in cfr_parts:
        db.Notices().put(docnum, cfr_part, notice)

    return success()
예제 #7
0
def listing(request, part_or_docnum=None):
    """Find and return all notices"""
    part = part_or_docnum
    return success({'results': db.Notices().listing(part=part)})
예제 #8
0
def listing(request):
    """Find and return all notices"""
    return success(
        {'results': db.Notices().listing(request.GET.get('part', None))})