Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Unembedded resources (from API refactor) #104

Merged
merged 41 commits into from
May 11, 2015
Merged

Conversation

arowla
Copy link
Contributor

@arowla arowla commented Apr 29, 2015

Known issues:

  • Candidate pages may show multiple primary committees
  • Financials (totals/reports) are not ready

Known issues:
- Candidate pages may show multiple primary committees
- Financials (totals/reports) are not ready
committee['candidates'].append(candidate)
# we should get rid of this after the refactor
cands.append(cand['candidate_id'])
url = fields.Function(lambda x: url_for('committee_page', c_id=x['committee_id']))
Copy link
Contributor

Choose a reason for hiding this comment

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

If we use flask-marshmallow, this can be slightly cleaner--something like

url = fields.URLFor('committee_page', c_id='<committee_id>')

arowla added 18 commits May 1, 2015 16:54
Conflicts:
	openfecwebapp/api_caller.py
- Also added missing committee_id
Conflicts:
	openfecwebapp/api_caller.py
	requirements.txt
... except:
- There are TODOs which are also captured in 18F/openFEC/#695
- Some tests are failing
This is a bit overkill to get just the years; we should really have
a little endpoint that just throws back a candidate's years
- And changed the name of the year range filter to match
- using has_authorized for committee display checks
- uses is_primary and is_authorized to discern committees to display
  stats/charts for
- only request financial data for primary and authorized committees
@arowla arowla changed the title [WIP] Unembedded resources (API refactor) Unembedded resources (from API refactor) May 5, 2015

@CommitteeSchema.error_handler
def handle_committee_errors(schema, errors, obj):
raise ValueError('An error occurred:\n{} \n\n...while marshalling the data:\n{}\n\n...for schema: {}'.format(errors, obj, schema))
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what raising a ValueError instead of the default ValidationError buys us. Both will raise a 500 in the app and throw a reasonable-looking traceback. If we want to throw a non-500 error on invalid data, we could call abort here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I wasn't using strict, and it was failing silently. But this
probably isn't needed now that strict is turned on.

On Tue, May 5, 2015 at 5:10 PM, Joshua Carp notifications@github.com
wrote:

In openfecwebapp/models/committees.py
#104 (comment):

  • organization_type = fields.Str(allow_none=True)
  • organization_type_full = fields.Str(allow_none=True)
  • party = fields.Str(allow_none=True)
  • party_full = fields.Str(allow_none=True)
  • class Meta:
  •    additional = (
    
  •        'committee_id', 'name', 'committee_type', 'committee_type_full',
    
  •        'treasurer_name', 'designation', 'designation_full',
    
  •        'treasurer_name', 'street_1', 'city', 'state', 'zip'
    
  •    )
    
    +@CommitteeSchema.error_handler
    +def handle_committee_errors(schema, errors, obj):
  • raise ValueError('An error occurred:\n{} \n\n...while marshalling the data:\n{}\n\n...for schema: {}'.format(errors, obj, schema))

Not sure what raising a ValueError instead of the default ValidationError
buys us. Both will raise a 500 in the app and throw a reasonable-looking
traceback. If we want to throw a non-500 error on invalid data, we could
call abort here instead.


Reply to this email directly or view it on GitHub
https://github.com/18F/openFEC-web-app/pull/104/files#r29713320.

Alison Rowland
Technical Lead, https://fbopen.gsa.gov | 18F
202-317-0124

arowla added 11 commits May 6, 2015 11:41
Conflicts:
	templates/committees-single.html
- Now in the style of (*args, **kwargs), _call_api will build up path
  components from the positional arguments and run `os.path.join` on them, and
  filters are passed in as keyword arguments
- So that the default() filter can still do its job
- Changed so default() is the last step
- Moved all filters into __init__
- Standardized on registering filters with a decorator
- Giving a high limit so that candidates with lots of committees don't
  get important things like their primary committee paginated out of
  the results
- render_page() -> render_candidate(), render_committee()
- Also stopped using Marshmallow for nested types
- Harmonized totals/financials data structure between candidate and
  committee pages and templates
- Also refactored out the type_map from the views
- Renamed the get_results_or_500 method to reflect that it pulls just
  the first result
- Removed now-tautological data_prep tests
@arowla arowla force-pushed the feature/unembed-resources branch from bcc5fdf to 6bb7097 Compare May 11, 2015 15:27
return render_template('candidates-single.html', **tmpl_vars)


def get_first_result_or_raise_500(data):
Copy link
Contributor

Choose a reason for hiding this comment

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

This behavior predates this patch, so we can defer discussion until later, but I'm not sure we should be throwing a 500 here. This behavior doesn't give much feedback to the user or to the developer, and it can potentially give incorrect feedback: for example, browsing to /candidate/fakecandidate should throw a 404, but this logic will throw a 500 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, let's talk about this at some point.

@jmcarp
Copy link
Contributor

jmcarp commented May 11, 2015

Added a few very minor comments inline, but LGTM 👍
Also, I ran the Selenium tests locally, and the only failures I noticed were issues that should be fixed after merging with develop and/or merging https://github.com/18F/openFEC/pull/719 and #156.

@jmcarp jmcarp merged commit 22e5ca4 into develop May 11, 2015
@jmcarp jmcarp removed the plz-review label May 11, 2015
@noahmanger noahmanger deleted the feature/unembed-resources branch August 3, 2015 22:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants