Skip to content

Commit

Permalink
The test file
Browse files Browse the repository at this point in the history
  • Loading branch information
ohare93 committed Aug 23, 2022
1 parent d6e98a5 commit 6267d14
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
16 changes: 15 additions & 1 deletion brain_brew/build_tasks/overrides/headers_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,39 @@ def task_name(cls) -> str:
def yamale_schema(cls) -> str:
return f'''\
deck_description_html_file: str(required=False)
crowdanki_uuid: str(required=False)
name: str(required=False)
'''

@dataclass
class Representation(RepresentationBase):
deck_description_html_file: Optional[str]
crowdanki_uuid: Optional[str]
name: Optional[str]

@classmethod
def from_repr(cls, data: Union[Representation, dict]):
rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data)
return cls(
rep=rep,
deck_desc_html_file=HTMLFile.create_or_get(rep.deck_description_html_file)
deck_desc_html_file=HTMLFile.create_or_get(rep.deck_description_html_file),
crowdanki_uuid=rep.crowdanki_uuid,
name=rep.name
)

rep: Representation
deck_desc_html_file: Optional[HTMLFile]
crowdanki_uuid: Optional[str]
name: Optional[str]

def override(self, header: Headers):
if self.deck_desc_html_file:
header.description = self.deck_desc_html_file.get_data(deep_copy=True)

if self.crowdanki_uuid:
header.crowdanki_uuid = self.crowdanki_uuid

if self.name:
header.name = self.name

return header
1 change: 1 addition & 0 deletions brain_brew/representation/json/wrappers_for_crowd_anki.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CA_TYPE = "__type__"
CA_NAME = "name"
CA_DESCRIPTION = "desc"
CA_UUID = "crowdanki_uuid"

NOTE_MODEL = "note_model_uuid"
FLAGS = "flags"
Expand Down
14 changes: 13 additions & 1 deletion brain_brew/representation/yaml/headers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

from brain_brew.representation.json.wrappers_for_crowd_anki import CA_NAME, CA_DESCRIPTION
from brain_brew.representation.json.wrappers_for_crowd_anki import CA_NAME, CA_DESCRIPTION, CA_UUID
from brain_brew.representation.yaml.yaml_object import YamlObject


Expand All @@ -19,6 +19,10 @@ def encode(self) -> dict:
def name(self) -> str:
return self.data[CA_NAME]

@name.setter
def name(self, desc: str):
self.data[CA_NAME] = desc

@property
def description(self) -> str:
return self.data.get(CA_DESCRIPTION, "")
Expand All @@ -27,6 +31,14 @@ def description(self) -> str:
def description(self, desc: str):
self.data[CA_DESCRIPTION] = desc

@property
def crowdanki_uuid(self) -> str:
return self.data.get(CA_UUID, "")

@crowdanki_uuid.setter
def crowdanki_uuid(self, desc: str):
self.data[CA_UUID] = desc

@property
def data_without_name(self) -> dict:
return {k: v for k, v in self.data.items() if k != CA_NAME}
2 changes: 2 additions & 0 deletions brain_brew/schemas/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ headers_from_yaml_part:

headers_override:
deck_description_html_file: str(required=False)
crowdanki_uuid: str(required=False)
name: str(required=False)

media_group_from_crowd_anki:
part_id: str()
Expand Down

0 comments on commit 6267d14

Please sign in to comment.