Beispiel #1
0
def committee_meeting(event_id):
    """
    Display committee meeting details, including report and any other related content.
    """

    event = load_from_api('committee-meeting', event_id)

    if event.get('premium_content_excluded'):
        premium_committees = load_from_api('committee/premium', return_everything=True)['results']
    else:
        premium_committees = None

    audio, related_docs = classify_attachments(event.get('files', []))

    attendance = load_from_api(
        'v2/committee-meetings/%s/attendance' % event_id,
        return_everything=True)['results']
    attendance = [a for a in attendance if a['attendance'] != 'A']
    sorter = lambda x: x['member']['name']
    attendance = sorted([a for a in attendance if a['chairperson']], key=sorter) + \
                 sorted([a for a in attendance if not a['chairperson']], key=sorter)

    return render_template(
        'committee_meeting.html',
        event=event,
        committee=event['committee'],
        audio=audio,
        related_docs=related_docs,
        attendance=attendance,
        premium_committees=premium_committees,
        content_date=event['date'],
        admin_edit_url=admin_url('committee-meeting', event_id),
        SOUNDCLOUD_APP_KEY_ID=app.config['SOUNDCLOUD_APP_KEY_ID'])
Beispiel #2
0
def question_replies(page=0):
    """
    Page through all available question_replies + committee_questions.
    """
    logger.debug("question_replies page called")
    committees = load_from_api('committee/question_reply', return_everything=True)['results']
    filters = {}
    params = {}
    filters["committee"] = params[
        'filter[committee_id]'] = request.args.get('filter[committee]')
    questions = load_from_api(
        'minister-questions-combined',
        page=page,
        params=params)
    count = questions["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))

    url = "/question_replies"

    return render_template(
        'question_list.html',
        questions=questions,
        hide_replies=True,
        url=url,
        num_pages=num_pages,
        per_page=per_page,
        page=page,
        icon="question-circle",
        title="Questions and Replies",
        content_type="minister_question",
        committees=committees,
        all_committees_option="All Ministries",
        filters=filters)
Beispiel #3
0
def tabled_committee_reports(page=0):
    """
    Page through all available tabled-committee-reports.
    """

    logger.debug("tabled-committee-reports page called")
    committees = load_from_api('committee', return_everything=True)['results']
    filters = {}
    params = {}
    filters["committee"] = params[
        'filter[committee_id]'] = request.args.get('filter[committee]')
    tabled_committee_reports_list = load_from_api(
        'tabled-committee-report',
        page=page,
        params=params)
    count = tabled_committee_reports_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    tabled_committee_reports = tabled_committee_reports_list['results']
    url = "/tabled-committee-reports"
    return render_template(
        'list.html',
        results=tabled_committee_reports,
        content_type="tabled_committee_report",
        title="Tabled Committee Reports",
        num_pages=num_pages,
        page=page,
        url=url,
        icon="briefcase",
        committees=committees,
        filters=filters)
Beispiel #4
0
def calls_for_comments(page=0):
    """
    Page through all available calls-for-comments.
    """

    logger.debug("calls-for-comments page called")
    committees = load_from_api('committee', return_everything=True)['results']
    filters = {}
    params = {}
    filters["committee"] = params[
        'filter[committee_id]'] = request.args.get('filter[committee]')
    call_for_comment_list = load_from_api(
        'call-for-comment',
        page=page,
        params=params)
    count = call_for_comment_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    calls_for_comments = call_for_comment_list['results']
    url = "/calls-for-comments"
    return render_template(
        'list.html',
        results=calls_for_comments,
        num_pages=num_pages,
        page=page,
        url=url,
        icon="comments",
        content_type="call_for_comment",
        title="Calls for Comments",
        committees=committees,
        filters=filters)
Beispiel #5
0
def committee_meetings(page=0):
    """
    Page through all available committee meetings.
    """
    committees = load_from_api('committee', return_everything=True)['results']
    filters = {'committee': None}
    params = {}

    if request.args.get('filter[committee]'):
        filters["committee"] = params['filter[committee_id]'] = request.args.get('filter[committee]')

    committee_meetings_list = load_from_api('committee-meeting', page=page, params=params)
    committee_meetings = committee_meetings_list['results']
    count = committee_meetings_list["count"]

    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    url = "/committee-meetings"
    return render_template(
        'list.html',
        results=committee_meetings,
        num_pages=num_pages,
        page=page,
        url=url,
        title="Committee Meeting Reports",
        content_type="committee-meeting",
        icon="comment",
        committees=committees,
        filters=filters)
Beispiel #6
0
def index():
    committee_meetings = load_from_api('v2/committee-meetings', fields=['id', 'date', 'title', 'committee.name'], params={'per_page': 11})['results']
    bills = load_from_api('bill/current', return_everything=True)["results"]
    bills.sort(key=lambda b: b['updated_at'], reverse=True)
    questions = load_from_api('v2/minister-questions', fields=['id', 'question_to_name', 'question', 'date'], params={'per_page': 11})['results']

    return render_template(
        'index.html',
        committee_meetings=committee_meetings,
        bills=bills[:11],
        questions=questions,
        stock_pic="sa-parliament.jpg",
        featured_content=get_featured_content(),
    )
Beispiel #7
0
def daily_schedule(daily_schedule_id):
    logger.debug("daily_schedule page called")
    daily_schedule = load_from_api('daily-schedule', daily_schedule_id)
    return render_template(
        'daily_schedule_detail.html',
        daily_schedule=daily_schedule,
        admin_edit_url=admin_url('schedule', daily_schedule_id))
Beispiel #8
0
def member(member_id):
    logger.debug("member page called")
    member = load_from_api('member', member_id)
    return render_template(
        'member_detail.html',
        member=member,
        admin_edit_url=admin_url('member', member_id))
Beispiel #9
0
def committee_subscriptions():
    """
    Manage subscriptions to premium content.
    """

    premium_committees = load_from_api('committee/premium', return_everything=True)['results']
    return render_template('user_management/committee_subscriptions.html', premium_committees=premium_committees)
def committee_subscriptions():
    """
    Manage subscriptions to premium content.
    """

    premium_committees = load_from_api('committee/premium',
                                       return_everything=True)['results']
    return render_template('user_management/committee_subscriptions.html',
                           premium_committees=premium_committees)
Beispiel #11
0
def policy_document(policy_document_id):
    """
    Policy Document
    """
    logger.debug("policy-document page called")
    policy_document = load_from_api('policy-document', policy_document_id)
    logger.debug(policy_document)
    return render_template(
        'policy_document_detail.html',
        policy_document=policy_document,
        content_date=policy_document['start_date'],
        admin_edit_url=admin_url('policy', policy_document_id))
Beispiel #12
0
def hansard(event_id):
    event = load_from_api('hansard', event_id)
    audio, related_docs = classify_attachments(event.get('files', []))

    return render_template(
        'hansard_detail.html',
        event=event,
        audio=audio,
        related_docs=related_docs,
        content_date=event['date'],
        admin_edit_url=admin_url('hansard', event_id),
        SOUNDCLOUD_APP_KEY_ID=app.config['SOUNDCLOUD_APP_KEY_ID'])
Beispiel #13
0
def committee_question(question_id):
    """ Display a single committee question.
    """
    question = load_from_api('committee-question', question_id)
    committee = question['committee']

    return render_template('committee_question.html',
                           committee=committee,
                           question=question,
                           hide_replies=False,
                           content_date=question['date'],
                           admin_edit_url=admin_url('committee-question', question_id))
Beispiel #14
0
def gazette(gazette_id):
    """
    Policy Document
    """
    logger.debug("gazette page called")
    gazette = load_from_api('gazette', gazette_id)
    logger.debug(gazette)
    return render_template(
        'gazette_detail.html',
        gazette=gazette,
        content_date=gazette['start_date'],
        admin_edit_url=admin_url('gazette', gazette_id))
Beispiel #15
0
def email_alerts():
    """
    Allow a user to manage their notification alerts.
    """
    next_url = request.values.get('next', '')

    if current_user.is_authenticated() and request.method == 'POST':
        ids = request.form.getlist('committees')
        current_user.committee_alerts = Committee.query.filter(Committee.id.in_(ids)).all()
        current_user.subscribe_daily_schedule = bool(request.form.get('subscribe_daily_schedule'))

        db.session.commit()

        # register a google analytics event
        ga_event('user', 'change-alerts')

        if next_url:
            return redirect(next_url)

        return ''

    committees = load_from_api(
        'v2/committees', return_everything=True, params={'monitored':
                                                         True})['results']
    if current_user.is_authenticated():
        subscriptions = set(c.id for c in current_user.committee_alerts)
    else:
        subscriptions = set()

    provincial_committees = OrderedDict()
    for committee in committees:
        house = committee['house']
        house_name = house['name']
        if house['sphere'] == 'provincial':
            if house_name not in provincial_committees:
                provincial_committees[house_name] = []
            provincial_committees[house_name].append(committee)

    saved_searches = defaultdict(list)
    if current_user.is_authenticated():
        for ss in current_user.saved_searches:
            saved_searches[ss.search].append(ss)

    return render_template(
        'user_management/email_alerts.html',
        committees=committees,
        after_signup=bool(next_url),
        subscriptions=subscriptions,
        next_url=next_url,
        saved_searches=saved_searches,
        provincial_committees=provincial_committees
    )
def email_alerts():
    """
    Allow a user to manage their notification alerts.
    """
    next_url = request.values.get('next', '')

    if current_user.is_authenticated() and request.method == 'POST':
        ids = request.form.getlist('committees')
        current_user.committee_alerts = Committee.query.filter(
            Committee.id.in_(ids)).all()
        current_user.subscribe_daily_schedule = bool(
            request.form.get('subscribe_daily_schedule'))

        db.session.commit()

        # register a google analytics event
        ga_event('user', 'change-alerts')

        if next_url:
            return redirect(next_url)

        return ''

    committees = load_from_api('v2/committees',
                               return_everything=True,
                               params={'monitored': True})['results']
    if current_user.is_authenticated():
        subscriptions = set(c.id for c in current_user.committee_alerts)
    else:
        subscriptions = set()

    provincial_committees = OrderedDict()
    for committee in committees:
        house = committee['house']
        house_name = house['name']
        if house['sphere'] == 'provincial':
            if house_name not in provincial_committees:
                provincial_committees[house_name] = []
            provincial_committees[house_name].append(committee)

    saved_searches = defaultdict(list)
    if current_user.is_authenticated():
        for ss in current_user.saved_searches:
            saved_searches[ss.search].append(ss)

    return render_template('user_management/email_alerts.html',
                           committees=committees,
                           after_signup=bool(next_url),
                           subscriptions=subscriptions,
                           next_url=next_url,
                           saved_searches=saved_searches,
                           provincial_committees=provincial_committees)
Beispiel #17
0
def members():
    """ All MPs.
    """
    members = load_from_api('v2/members', return_everything=True)['results']

    # partition by house
    members_by_house = {}
    for member in members:
        if member.get('house') and member['current']:
            members_by_house.setdefault(member['house']['name'], []).append(member)
    colsize = 12 / len(members_by_house)

    return render_template('member_list.html', members_by_house=members_by_house, colsize=colsize)
Beispiel #18
0
def tabled_committee_report(tabled_committee_report_id):
    """
    Tabled Committee Report
    """
    logger.debug("tabled-committee-report page called")
    tabled_committee_report = load_from_api(
        'tabled-committee-report',
        tabled_committee_report_id)
    logger.debug(tabled_committee_report)
    return render_template(
        'tabled_committee_report_detail.html',
        tabled_committee_report=tabled_committee_report,
        content_date=tabled_committee_report['start_date'],
        admin_edit_url=admin_url('tabled-committee-report', tabled_committee_report_id))
Beispiel #19
0
def call_for_comment(call_for_comment_id):
    """
    Tabled Committee Report
    """
    logger.debug("call-for-comment page called")
    call_for_comment = load_from_api(
        'call-for-comment',
        call_for_comment_id)
    logger.debug(call_for_comment)
    return render_template(
        'call_for_comment_detail.html',
        call_for_comment=call_for_comment,
        content_date=call_for_comment['start_date'],
        admin_edit_url=admin_url('call-for-comment', call_for_comment_id))
Beispiel #20
0
def question_reply(question_reply_id):
    question_reply = load_from_api('question_reply', question_reply_id)

    if question_reply.get('committee'):
        template = 'committee_question_reply.html'
    else:
        template = 'question_reply_detail.html'

    return render_template(
        template,
        question_reply=question_reply,
        committee=question_reply.get('committee'),
        content_date=question_reply['start_date'],
        admin_edit_url=admin_url('question', question_reply_id))
Beispiel #21
0
def committees():
    """
    Page through all available committees.
    """
    committees = load_from_api('v2/committees', return_everything=True, fields=['id', 'name', 'premium', 'ad_hoc', 'house'])['results']

    nat = {
        'name': 'National Assembly',
        'committees': []
    }
    ncp = {
        'name': 'National Council of Provinces',
        'committees': []
    }
    jnt = {
        'name': 'Joint Committees',
        'committees': []
    }

    adhoc_committees = OrderedDict((('nat', nat), ('ncp', ncp), ('jnt', jnt)))
    reg_committees = deepcopy(adhoc_committees)
    committees_type = None

    for committee in committees:
        if committee['ad_hoc'] is True:
            committees_type = adhoc_committees
        else:
            committees_type = reg_committees

        if current_user.is_authenticated():
            user_following = current_user.following

            # Check if user is following committee
            if current_user.is_authenticated() and committee['id'] in [ufc.id for ufc in user_following]:
                committee['followed'] = True

        if committee['house']:
            if committee['house']['id'] is Committee.NATIONAL_ASSEMBLY:
                committees_type['nat']['committees'].append(committee)
            elif committee['house']['id'] is Committee.NAT_COUNCIL_OF_PROV:
                committees_type['ncp']['committees'].append(committee)
            elif committee['house']['id'] is Committee.JOINT_COMMITTEE:
                committees_type['jnt']['committees'].append(committee)

    return render_template(
        'committee_list.html',
        reg_committees=reg_committees,
        adhoc_committees=adhoc_committees
    )
Beispiel #22
0
def committee_detail(committee_id):
    """
    Display all available detail for the committee.
    """
    committee = load_from_api('v2/committees', committee_id)['result']
    filtered_meetings = {}

    # calls for comment
    committee['calls_for_comments'] = load_from_api(
        'v2/committees/%s/calls-for-comment' % committee_id,
        fields=['id', 'title', 'start_date'],
        return_everything=True)['results']

    # tabled reports
    committee['tabled_committee_reports'] = load_from_api(
        'v2/committees/%s/tabled-reports' % committee_id,
        fields=['id', 'title', 'start_date'],
        return_everything=True)['results']

    # memberships
    committee['memberships'] = load_from_api(
        'v2/committees/%s/members' % committee_id,
        return_everything=True)['results']

    recent_questions = load_from_api('minister-questions-combined', params={'filter[committee_id]': committee_id})['results']

    # meetings
    all_meetings = load_from_api('v2/committees/%s/meetings' % committee_id,
                                 fields=['id', 'title', 'date'], return_everything=True)['results']

    for meeting in all_meetings:
        d = meeting['parsed_date'] = datetime.strptime(meeting['date'][:10], "%Y-%m-%d")
        if d.year not in filtered_meetings:
            filtered_meetings[d.year] = []
        filtered_meetings[d.year].append(meeting)

    latest_year = max(y for y in filtered_meetings) if filtered_meetings else None
    earliest_year = min(y for y in filtered_meetings) if filtered_meetings else None
    now = datetime.now()
    six_months = timedelta(days=30 * 6)  # 6 months
    filtered_meetings['six-months'] = [m for m in all_meetings if (now - m['parsed_date']) <= six_months]

    if filtered_meetings['six-months']:
        starting_filter = 'six-months'
    else:
        starting_filter = latest_year

    return render_template('committee_detail.html',
                           current_year=now.year,
                           earliest_year=earliest_year,
                           filtered_meetings=filtered_meetings,
                           committee=committee,
                           has_meetings=len(all_meetings) > 0,
                           starting_filter=starting_filter,
                           recent_questions=recent_questions,
                           admin_edit_url=admin_url('committee', committee_id))
Beispiel #23
0
def bill(bill_id):
    bill = load_from_api('bill', bill_id)
    stages = {
        'enacted': '5',
        'president': '4',
        'ncop': '3',
        'returned-to-na': '3',
        'na': '2',
        'introduced': 1,
    }
    history = bill_history(bill)
    return render_template('bills/detail.html',
                           bill=bill,
                           history=history,
                           stages=stages,
                           admin_edit_url=admin_url('bill', bill_id))
Beispiel #24
0
def daily_schedules(page=0):
    """
    Page through all available daily_schedules.
    """

    logger.debug("daily_schedules page called")
    daily_schedules_list = load_from_api('daily-schedule', page=page)
    count = daily_schedules_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    daily_schedules = daily_schedules_list['results']
    url = "/daily-schedules"
    return render_template(
        'list.html',
        results=daily_schedules,
        num_pages=num_pages,
        page=page,
        url=url,
        icon="calendar",
        title="Daily Schedules",
        content_type="daily_schedule")
Beispiel #25
0
def hansards(page=0):
    """
    Page through all available hansards.
    """

    logger.debug("hansards page called")
    hansards_list = load_from_api('hansard', page=page)
    count = hansards_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    hansards = hansards_list['results']
    url = "/hansards"
    return render_template(
        'list.html',
        results=hansards,
        num_pages=num_pages,
        page=page,
        url=url,
        icon="archive",
        title="Hansards",
        content_type="hansard")
Beispiel #26
0
def policy_documents(page=0):
    """
    Page through all available policy-documents.
    """

    logger.debug("policy-documents page called")
    policy_documents_list = load_from_api('policy-document', page=page)
    count = policy_documents_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    policy_documents = policy_documents_list['results']
    url = "/policy-documents"
    return render_template(
        'list.html',
        results=policy_documents,
        num_pages=num_pages,
        page=page,
        url=url,
        icon="file-text-o",
        content_type="policy_document",
        title="Policy Documents")
Beispiel #27
0
def gazettes(page=0):
    """
    Page through all available gazettes.
    """

    logger.debug("gazettes page called")
    gazettes_list = load_from_api('gazette', page=page)
    count = gazettes_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    gazettes = gazettes_list['results']
    url = "/gazettes"
    return render_template(
        'list.html',
        results=gazettes,
        num_pages=num_pages,
        page=page,
        url=url,
        icon="file-text-o",
        content_type="gazette",
        title="Gazettes")
Beispiel #28
0
def bills(bill_type, year=None):
    if bill_type == 'current':
        # don't paginate by year
        year_list = None
        params = {}

    else:
        year_list = range(MIN_YEAR, date.today().year + 1)
        year_list.reverse()
        params = {}

        if not year:
            return redirect(url_for('bills', bill_type=bill_type, year=year_list[0]))

        if year not in year_list:
            abort(404)
        params = 'filter[year]=%d' % year

    api_url = 'bill' if bill_type == 'all' else 'bill/%s' % bill_type
    bills = load_from_api(api_url, return_everything=True, params=params)['results']

    bills.sort(key=lambda b: [-b['year'], b['type']['prefix'], b.get('number', 0), b['title']])

    status_dict = {
        "na": ("in progress", "label-primary"),
        "ncop": ("in progress", "label-primary"),
        "assent": ("submitted to the president", "label-warning"),
        "enacted": ("signed into law", "label-success"),
        "withdrawn": ("withdrawn", "label-default"),
        "lapsed": ("lapsed", "label-default"),
    }

    return render_template(
        'bills/list.html',
        results=bills,
        status_dict=status_dict,
        year=year,
        year_list=year_list,
        bill_type=bill_type)
Beispiel #29
0
def briefings(page=0):
    """
    Page through all available briefings.
    """

    logger.debug("briefings page called")
    briefings_list = load_from_api('briefing', page=page)
    count = briefings_list["count"]
    per_page = app.config['RESULTS_PER_PAGE']
    num_pages = int(math.ceil(float(count) / float(per_page)))
    briefings = briefings_list['results']
    url = "/briefings"
    return render_template(
        'list.html',
        results=briefings,
        num_pages=num_pages,
        page=page,
        url=url,
        icon="bullhorn",
        title="Media Briefings",
        content_type="briefing",
    )
Beispiel #30
0
def search(page=0):
    """
    Display search page
    """
    filters = {}
    filters["type"] = request.args.get('filter[type]', '')
    filters["start_date"] = request.args.get('filter[start_date]', '')
    filters["end_date"] = request.args.get('filter[end_date]', '')
    filters["committee"] = request.args.get('filter[committee]', '')

    # support legacy search URLs that allowed "None" as a value
    for k, v in filters.iteritems():
        if v == "None":
            filters[k] = None
    q = request.args.get('q', '').strip()

    params = dict(filters)
    params["q"] = q
    params["page"] = page

    # do the search
    search = {}
    try:
        if q:
            search = load_from_api('search', params=params)
    except ApiException as e:
        if e.code == 422:
            # bad search, eg: "   "
            q = ""
        else:
            raise e

    years = range(1997, datetime.now().year + 1)
    years.reverse()

    bincount = {}
    yearcount = {}
    if search:
        for bin in search["bincount"]["types"]:
            bincount[bin["key"]] = bin["doc_count"]

        for year in search["bincount"]["years"]:
            yearcount[int(year["key_as_string"][:4])] = year["doc_count"]

        search['friendly_data_type'] = Search.friendly_data_types.get(filters['type'], None)

    committees = load_from_api('committee', return_everything=True)['results']

    def search_url(**kwargs):
        args = dict(filters)
        args.update(kwargs)
        args = {('filter[%s]' % k): v for k, v in args.iteritems() if v}
        return url_for('search', q=q, **args)

    saved_search = None
    if not current_user.is_anonymous():
        saved_search = SavedSearch.find(
            current_user,
            q,
            content_type=filters['type'] or None,
            committee_id=filters['committee'] or None)

    if filters['committee']:
        for committee in committees:
            if committee['id'] == int(filters['committee']):
                search['filtered_committee_name'] = committee['name']
                break

    # suggest a phrase search?
    if q and ' ' in q and '"' not in q:
        suggest_phrase = '"%s"' % q
        kwargs = {('filter[%s]' % k): v for k, v in filters.iteritems() if v}
        kwargs['q'] = suggest_phrase
        suggest_phrase_url = url_for('search', **kwargs)
    else:
        suggest_phrase = False
        suggest_phrase_url = None

    return render_template(
        'search.html',
        q=q,
        search=search,
        num_pages=search.get("pages"),
        page=search.get("page"),
        per_page=search.get("per_page"),
        search_url=search_url,
        url=url_for('search')[:-1],
        query_string=request.query_string,
        filters=filters,
        years=years,
        bincount=bincount,
        yearcount=yearcount,
        committees=committees,
        search_types=Search.friendly_data_types.items(),
        saved_search=saved_search,
        suggest_phrase=suggest_phrase,
        suggest_phrase_url=suggest_phrase_url)