Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CareersBlock for Resource Page template sections streamblock(USAJobs API) #799

Merged
merged 21 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
383ff65
committing usajobs app and base/settings.py to register app
johnnyporkchops Jan 29, 2017
6dcfe03
usajobs/templates/fec_jobs_list.html
johnnyporkchops Jan 31, 2017
2b8f510
deleted unused files
johnnyporkchops Jan 31, 2017
0b0c5f1
removed unused app on INSATALLED APPS in base.py
johnnyporkchops Jan 31, 2017
20ea464
removed unused url definition and import statement
johnnyporkchops Jan 31, 2017
0d034eb
Merge remote-tracking branch 'origin' into feature/usa-jobs-templatetag
johnnyporkchops Feb 2, 2017
1c0eea3
added careers blocks and templatetag
johnnyporkchops Feb 3, 2017
218c1e2
restored fec/urls.py to match original on dev
johnnyporkchops Feb 3, 2017
fbcb9db
updated open_jobs.py, needed Positio URI variable
johnnyporkchops Feb 3, 2017
388dca2
make staging use the umbrella
LindsayYoung Feb 9, 2017
2ef91aa
removed API key did other requested edits
johnnyporkchops Feb 10, 2017
5336bc8
Fixes migrations in CMS develop branch
ccostino Feb 10, 2017
32bec7a
Merge pull request #807 from 18F/feature/new-api-url
Feb 11, 2017
c6c55b9
Merge pull request #811 from 18F/bug/fix-table-migration
Feb 14, 2017
c02b731
set API key as sensitive env var using UUPS in CF
johnnyporkchops Feb 14, 2017
271d313
Merge branch 'develop' into feature/usa-jobs-templatetag
johnnyporkchops Feb 14, 2017
9982536
padding to bottom of job entries
johnnyporkchops Feb 15, 2017
3cb9078
Merge branch 'feature/usa-jobs-templatetag' of github.com:18F/fec-cms…
johnnyporkchops Feb 15, 2017
fdd9724
fixed UL nesting...again
johnnyporkchops Feb 15, 2017
8556ce1
requested edits to Python
johnnyporkchops Feb 15, 2017
bd3294d
missed on lowercase change
johnnyporkchops Feb 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 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
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),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to add a preference to your text editor to strip out extraneous whitespace like this. Not a big deal, but will result in fewer false diffs.

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 @@ -89,6 +89,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 @@ -101,7 +108,8 @@ class ResourceBlock(blocks.StructBlock):
('external_button', ExternalButtonBlock()),
('page', blocks.PageChooserBlock(template='blocks/page-links.html')),
('document_list', blocks.ListBlock(FeedDocumentBlock(), template='blocks/document-list.html', icon='doc-empty')),
('current_commissioners', CurrentCommissionersBlock())
('current_commissioners', CurrentCommissionersBlock()),
('fec_jobs', CareersBlock())
])

aside = blocks.StreamBlock([
Expand Down
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 %}
17 changes: 17 additions & 0 deletions fec/home/templates/partials/jobs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% load wagtailcore_tags %}
<section class="slab slab--neutral" style="padding:1rem">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid inline styles. Does the default padding on the .slab class not work?

<ul>
{% for j in jobData %}
<li>
<h3><a href="{{ j.PositionURI }}">{{ j.PositionID }} , {{ j.PositionTitle}}</a></h3>
<ul>
<li class='t-sans'><strong>Open Period:</strong> {{ j.PositionStartDate }} - {{ j.PositionEndDate }}</li>
<li class='t-sans'><strong>Who May Apply:</strong> {{ j.WhoMayApply }}</li>
<li class='t-sans'><strong>Grade:</strong> {{ j.JobGrade }} - {{ j.LowGrade }} - {{ j.HighGrade }}</li>
</ul>
</li><br>
{% empty %}
<p>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.")</p>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<p> should be outside the <ul>

{% endfor %}
</ul>
</section>
44 changes: 44 additions & 0 deletions fec/home/templatetags/open_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

from django.shortcuts import render_to_response, redirect
from django import template

register = template.Library()

@register.inclusion_tag('partials/jobs.html')
def get_jobs():
from django.http import HttpResponse

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be at the top of the file.

import requests
import json
from datetime import datetime
import dateutil.parser
url = "https://data.usajobs.gov/api/Search"

querystring = {"Organization":"PU00","WhoMayApply":"All"}

headers = {
'authorization-key': "ZQbNd1iLrQ+rPN3Rj2Q9gDy2Qpi/3haXSXGuHbP1SRk=",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this key private? If so, it shouldn't be checked in and should instead be set as a secret env var (and should probably be replaced now if it is supposed to be private).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am waiting to hear back from USAjobs API support regarding a ticket I submitted to resolve this.

'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 = { "PositionTitle": i["MatchedObjectDescriptor"]["PositionTitle"] ,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small formatting things:

  • Each item should be on a new line (PositionURI is on the same line as PositionID)
  • Key names should be lower case and use underscores instead of camelCase

"PositionID": i["MatchedObjectDescriptor"]["PositionID"], "PositionURI": i ["MatchedObjectDescriptor"]["PositionURI"],
"PositionStartDate" : dateutil.parser.parse(i['MatchedObjectDescriptor']['PositionStartDate']),
"PositionEndDate" : dateutil.parser.parse(i['MatchedObjectDescriptor']['PositionEndDate']),
"WhoMayApply" : i['MatchedObjectDescriptor']['UserArea']['Details']['WhoMayApply']['Name'],
"JobGrade" : i['MatchedObjectDescriptor']['JobGrade'][0]['Code'],
"LowGrade" : i['MatchedObjectDescriptor']['UserArea']['Details']['LowGrade'],
"HighGrade" : i['MatchedObjectDescriptor']['UserArea']['Details']['HighGrade'] }
jobData.append(x)

return ({'jobData':jobData})