Skip to content

Commit

Permalink
improve Ruling model and Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
thundergolfer-two committed Apr 23, 2018
1 parent 86bb614 commit 1f50ae5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 10 additions & 0 deletions politifact/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ def __init__(
self.ruling = ruling
self.statement_url = statement_url
self.subjects = subjects


class Ruling():
def __init__(self, name, slug, graphic):
self.name = name
self.slug = slug
self.graphic = graphic

def __str__(self):
return self.name
8 changes: 1 addition & 7 deletions politifact/rulings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

class Ruling():
def __init__(self, name, slug, graphic):
self.name = name
self.slug = slug
self.graphic = graphic

from politifact.models import Ruling

PANTS_ON_FIRE = Ruling(
'Pants on Fire!',
Expand Down
10 changes: 9 additions & 1 deletion politifact/schemas.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from marshmallow import Schema, fields, post_load

from politifact.rulings import map_ruling_slug_to_ruling
from politifact.models import Statement
from politifact.models import Statement, Ruling


class RulingSchema(Schema):
ruling = fields.Str()
ruling_slug = fields.Str()
canonical_ruling_graphic = fields.URL()

@post_load
def make_ruling(self, data):
return Ruling(
data['ruling'],
data['ruling_slug'],
data['canonical_ruling_graphic']
)


class PartySchema(Schema):
party = fields.Str()
Expand Down

0 comments on commit 1f50ae5

Please sign in to comment.