Skip to content

Commit

Permalink
Merge pull request #107 from TrustTheVote-Project/dev-make-flat
Browse files Browse the repository at this point in the history
Ballot posted to reach Milestone 1
  • Loading branch information
stratofax authored Sep 7, 2022
2 parents 0cd8aca + e65183f commit 0052e4a
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 108 deletions.
45 changes: 29 additions & 16 deletions src/electos/ballotmaker/ballots/contest_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class BallotMeasureData:
choices: list = field(default_factory=list, init=False, repr=True)

def __post_init__(self):
self.id = "no_id_provided"
self.title = self._b_measure_con["title"]
self.district = self._b_measure_con["district"]
self.text = self._b_measure_con["text"]
self.choices = self._b_measure_con["choices"]
self.id = self._b_measure_con.get("id", "")
self.title = self._b_measure_con.get("title", "")
self.district = self._b_measure_con.get("district", "")
self.text = self._b_measure_con.get("text", "")
self.choices = self._b_measure_con.get("choices", [])
# for choice_data in _choices:
# self.choices.append(ChoiceData(choice_data))

Expand All @@ -45,29 +45,42 @@ class CandidateContestData:
district: str = field(init=False)
candidates: list = field(default_factory=list, init=False, repr=True)

# use dict.get() to assign defaults if key is missing
def __post_init__(self):
self.id = self._can_con["id"]
self.title = self._can_con["title"]
self.votes_allowed = self._can_con["votes_allowed"]
self.district = self._can_con["district"]
_candidates = self._can_con["candidates"]
self.id = self._can_con.get("id", "")
self.title = self._can_con.get("title", "")
self.votes_allowed = self._can_con.get("votes_allowed", 0)
self.district = self._can_con.get("district", "")
_candidates = self._can_con.get("candidates", [])
for candidate_data in _candidates:
self.candidates.append(CandidateData(candidate_data))


@dataclass
class CandidateData:
_can_data: dict = field(repr=False)
id: str = "no_id_provided"
name: str = field(init=False)
id: str = field(init=False)
_names: list = field(init=False, repr=False, default_factory=list)
party: str = field(init=False)
party_abbr: str = field(init=False)
write_in: bool = field(init=False)
name: str = field(init=True, default="")

def __post_init__(self):
self.name = self._can_data["name"]
party_dict = self._can_data["party"]
self.party = party_dict["name"]
self.party_abbr = party_dict["abbreviation"]
self.id = self._can_data.get("id", "")
self._names = self._can_data.get("name", [])
_party_dict = self._can_data.get("party", {})
self.party = _party_dict.get("name", "")
self.party_abbr = _party_dict.get("abbreviation", "")
self.write_in = self._can_data.get("write_in")
if self.write_in:
self.name = "or write in:"
else:
for count, can_name in enumerate(self._names):
# append " and " only if more than one name
if count > 0:
self.name += " and "
self.name += can_name


if __name__ == "__main__": # pragma: no cover
Expand Down
17 changes: 9 additions & 8 deletions src/electos/ballotmaker/ballots/contest_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
black,
font_bold,
normal_lead,
# sp_before=12,
sp_after=48,
keep_w_next=1,
)
Expand All @@ -54,7 +53,6 @@
font_bold,
normal_lead,
sp_before=12,
# sp_after=32,
keep_w_next=1,
)
PageLayout.define_custom_style(
Expand All @@ -65,7 +63,6 @@
black,
font_normal,
normal_lead,
# sp_before=12,
)


Expand Down Expand Up @@ -149,17 +146,16 @@ def __init__(self, width=400, height=200, *args, **kw):
self.width = oval_width + PageLayout.border_pad
self.height = oval_height + PageLayout.border_pad
oval_cx = self.width / 2
oval_cy = self.height / 2
down_shift = 2
oval_cy = (self.height / 2) - down_shift
self._add(
self,
Ellipse(oval_cx, oval_cy, oval_width, oval_height),
name="oval",
validate=None,
desc=None,
)
# self.oval.fillColor = PageLayout.white
self.oval.fillColor = white
# self.oval.strokeColor = PageLayout.black
self.oval.strokeColor = black
self.oval.strokeWidth = sm_line

Expand All @@ -183,8 +179,13 @@ def __init__(self, contest_data: CandidateContestData):
oval = SelectionOval()
for candidate in self.candidates:
# add newlines around " and "
# if candidate.find(" and "):
# candidate = candidate.replace(" and ", "<br />and<br />")
if candidate.name.find(" and "):
candidate.name = candidate.name.replace(
" and ", "<br />and<br />"
)
# add line for write ins
if candidate.write_in:
candidate.name += ("<br />" * 2) + ("_" * 20)
contest_line = f"<b>{candidate.name}</b>"
if candidate.party_abbr != "":
contest_line += f"<br />{candidate.party_abbr}"
Expand Down
2 changes: 1 addition & 1 deletion src/electos/ballotmaker/ballots/demo_ballot.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def build_ballot() -> str:
elements.append(NextPageTemplate("3col"))
elements.append(layout_1.contest_table)
elements.append(layout_2.contest_table)
elements.append(layout_3.contest_table)
elements.append(CondPageBreak(c_height * inch))
elements.append(layout_4.contest_table)
elements.append(layout_3.contest_table)
elements.append(NextPageTemplate("1col"))
elements.append(PageBreak())
elements.append(layout_5.contest_table)
Expand Down
153 changes: 101 additions & 52 deletions src/electos/ballotmaker/demo_data/spacetown_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,31 @@
"district": "Orbit City",
"candidates": [
{
"name": "Cosmo Spacely",
"id": "recTKcXLCzRvKB9U0",
"name": [
"Cosmo Spacely"
],
"party": {
"name": "The Lepton Party",
"abbreviation": "LEP"
}
},
"write_in": false
},
{
"name": "Spencer Cogswell",
"id": "recKD6dBvkNhEU4bg",
"name": [
"Spencer Cogswell"
],
"party": {
"name": "The Hadron Party of Farallon",
"abbreviation": "HAD"
}
},
"write_in": false
},
{
"id": "recqq21kO6HWgpJZV",
"write_in": true
}
],
"write_ins": [
"recqq21kO6HWgpJZV"
]
},
{
Expand All @@ -38,30 +47,46 @@
"district": "Aldrin Space Transport District",
"candidates": [
{
"name": "Jane Jetson",
"id": "recvYvTb9hWH7tptb",
"name": [
"Jane Jetson"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"name": "Harlan Ellis",
"id": "recBnJZEgCKAnfpNo",
"name": [
"Harlan Ellis"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"name": "Rudy Indexer",
"id": "recwNuOnepWNGz67V",
"name": [
"Rudy Indexer"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"id": "rec9Eev970VhohqKi",
"write_in": true
},
{
"id": "recFiGYjGCIyk5LBe",
"write_in": true
}
],
"write_ins": [
"rec9Eev970VhohqKi",
"recFiGYjGCIyk5LBe"
]
},
{
Expand All @@ -73,45 +98,72 @@
"district": "Gadget County",
"candidates": [
{
"name": "Sally Smith",
"id": "recbxvhKikHJNZYbq",
"name": [
"Sally Smith"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"name": "Hector Gomez",
"id": "recigPkqYXXDJEaCE",
"name": [
"Hector Gomez"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"name": "Rosashawn Davis",
"id": "recJvikmG5MrUKzo1",
"name": [
"Rosashawn Davis"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"name": "Oliver Tsi",
"id": "recvjB3rgfiicf0RP",
"name": [
"Oliver Tsi"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"name": "Glavin Orotund",
"id": "recbN7UUMaSuOYGQ6",
"name": [
"Glavin Orotund"
],
"party": {
"name": "",
"abbreviation": ""
}
},
"write_in": false
},
{
"id": "recYurH2CLY3SlYS8",
"write_in": true
},
{
"id": "recI5jfcXIsbAKytC",
"write_in": true
},
{
"id": "recn9m0o1em7gLahj",
"write_in": true
}
],
"write_ins": [
"recYurH2CLY3SlYS8",
"recI5jfcXIsbAKytC",
"recn9m0o1em7gLahj"
]
},
{
Expand All @@ -123,36 +175,33 @@
"district": "United States of America",
"candidates": [
{
"name": "Anthony Alpha",
"party": {
"name": "The Lepton Party",
"abbreviation": "LEP"
}
"id": "recPod2L8VhwagiDl",
"write_in": true
},
{
"name": "Betty Beta",
"id": "recQK3J9IJq42hz2n",
"name": [
"Anthony Alpha",
"Betty Beta"
],
"party": {
"name": "The Lepton Party",
"abbreviation": "LEP"
}
},
"write_in": false
},
{
"name": "Gloria Gamma",
"id": "reccUkUdEznfODgeL",
"name": [
"Gloria Gamma",
"David Delta"
],
"party": {
"name": "The Hadron Party of Farallon",
"abbreviation": "HAD"
}
},
{
"name": "David Delta",
"party": {
"name": "The Hadron Party of Farallon",
"abbreviation": "HAD"
}
},
"write_in": false
}
],
"write_ins": [
"recPod2L8VhwagiDl"
]
}
],
Expand All @@ -179,4 +228,4 @@
}
]
}
}
}
Loading

0 comments on commit 0052e4a

Please sign in to comment.