Skip to content

Commit

Permalink
Merge pull request #799 from 18F/feature/usa-jobs-templatetag
Browse files Browse the repository at this point in the history
CareersBlock for Resource Page template sections streamblock(USAJobs API)
  • Loading branch information
Noah Manger authored Feb 15, 2017
2 parents 0bddac0 + bd3294d commit 92d646f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 3 deletions.
3 changes: 3 additions & 0 deletions fec/fec/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'search',
'home',
'data_loader',

)

MIDDLEWARE_CLASSES = (
Expand Down Expand Up @@ -171,6 +172,7 @@
from fec import constants
from .env import env

USAJOBS_API_KEY = env.get_credential('USAJOBS_API_KEY')
FEC_APP_URL = os.getenv('FEC_APP_URL')
FEC_API_URL = os.getenv('FEC_API_URL', 'http://localhost:5000')
FEC_API_VERSION = os.getenv('FEC_API_VERSION', 'v1')
Expand Down Expand Up @@ -217,6 +219,7 @@
'dsn': os.getenv('SENTRY_DSN'),
}


if FEC_CMS_ENVIRONMENT != 'LOCAL':
AWS_QUERYSTRING_AUTH = False
AWS_ACCESS_KEY_ID = env.get_credential('CMS_AWS_ACCESS_KEY_ID')
Expand Down
2 changes: 1 addition & 1 deletion fec/fec/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^search/$', search_views.search, name='search'),
url(r'^updates/$', home_views.updates),

url(r'', include(wagtail_urls)),
]

Expand Down
10 changes: 9 additions & 1 deletion fec/home/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ class Meta:
admin_text = 'Show current commissioners in a grid. No configuration needed.'
template = 'blocks/commissioners.html'

class CareersBlock(blocks.StaticBlock):
"""A block that displays the open FEC jobs"""
class Meta:
icon = 'group'
admin_text = 'Show open fec jobs from USAJobs.gov. No configuration needed.'
template = 'blocks/careers.html'

class ResourceBlock(blocks.StructBlock):
"""A section of a ResourcePage"""
title = blocks.CharBlock(required=True)
Expand All @@ -103,7 +110,8 @@ class ResourceBlock(blocks.StructBlock):
('page', blocks.PageChooserBlock(template='blocks/page-links.html')),
('document_list', blocks.ListBlock(FeedDocumentBlock(), template='blocks/document-list.html', icon='doc-empty')),
('current_commissioners', CurrentCommissionersBlock()),
('table', TableBlock()),
('fec_jobs', CareersBlock()),
('table', TableBlock())
])

aside = blocks.StreamBlock([
Expand Down
16 changes: 16 additions & 0 deletions fec/home/migrations/0061_merge_20170210_2230.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-10 22:30
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('home', '0060_auto_20170209_2030'),
('home', '0058_auto_20170210_2136'),
]

operations = [
]
4 changes: 4 additions & 0 deletions fec/home/templates/blocks/careers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load wagtailcore_tags %}
{% load open_jobs %}

{% get_jobs %}
19 changes: 19 additions & 0 deletions fec/home/templates/partials/jobs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load wagtailcore_tags %}
<section class="slab slab--neutral slab--inline" >
<div class="container">
<ul>
{% for j in jobData %}
<li>
<h3><a href="{{ j.position_uri }}">{{ j.position_id }} , {{ j.position_title}}</a></h3>
<ul class="u-padding--bottom">
<li class='t-sans'><strong>Open Period:</strong> {{ j.position_start_date }} - {{ j.position_end_date }}</li>
<li class='t-sans'><strong>Who May Apply:</strong> {{ j.who_may_apply }}</li>
<li class='t-sans'><strong>Grade:</strong> {{ j.job_grade }} - {{ j.low_grade }} - {{ j.high_grade }}</li>
</ul>
</li>
{% empty %}
<li class='t-sans'>There are currently no open positions available. Please check back on this page or Job Announcements on <a href='https://www.usajobs.gov/' title='USAJobs website'>USAJOBs</a> for the latest FEC Vacancy Announcements.")</li>
{% endfor %}
</ul>
</div>
</section>
43 changes: 43 additions & 0 deletions fec/home/templatetags/open_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

from django import template
import requests
from django.conf import settings
from django.conf import os
import dateutil.parser

register = template.Library()

@register.inclusion_tag('partials/jobs.html')
def get_jobs():
url = "https://data.usajobs.gov/api/Search"

querystring = {"Organization":"LF00","WhoMayApply":"All"}
headers = {
'authorization-key': settings.USAJOBS_API_KEY,
'user-agent': "[email protected]",
'host': "data.usajobs.gov",
'cache-control': "no-cache",
}

response = requests.request("GET", url, headers=headers, params=querystring)

responses=response.json()

jobData = []
for i in responses['SearchResult']['SearchResultItems']:
x= {}
x = {
"position_title": i["MatchedObjectDescriptor"]["PositionTitle"] ,
"position_id": i["MatchedObjectDescriptor"]["PositionID"],
"position_uri": i ["MatchedObjectDescriptor"]["PositionURI"],
"position_start_date" : dateutil.parser.parse(i['MatchedObjectDescriptor']['PositionStartDate']),
"position_end_date" : dateutil.parser.parse(i['MatchedObjectDescriptor']['PositionEndDate']),
"who_may_apply" : i['MatchedObjectDescriptor']['UserArea']['Details']['WhoMayApply']['Name'],
"job_grade" : i['MatchedObjectDescriptor']['JobGrade'][0]['Code'],
"low_grade" : i['MatchedObjectDescriptor']['UserArea']['Details']['LowGrade'],
"high_grade" : i['MatchedObjectDescriptor']['UserArea']['Details']['HighGrade'] }
jobData.append(x)

return ({'jobData':jobData})


2 changes: 1 addition & 1 deletion manifest_stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- fec-creds-stage
- fec-rds-stage
env:
FEC_API_URL: https://fec-stage-api.18f.gov
FEC_API_URL: https://api-stage.open.fec.gov
FEC_APP_URL: https://fec-stage-proxy.18f.gov/data
FEC_CMS_ENVIRONMENT: stage
NEW_RELIC_APP_NAME: beta.fec.gov | cms | stage

0 comments on commit 92d646f

Please sign in to comment.