def __init__(self, config_section=None): id = None if config_section: id = config_section.name super().__init__(id=id) self._company = Component('h4') self._title = Component('h5') self._date = Component('u') self._technologies = Table(rows=1, cols=self.TECHNOLOGY_COLUMNS, id=self.id + '-technologies', border="0", cellpadding="5") self._bullets = Container("ul", id=self.id + '-bullets') self._accomplishments = Container(id=self.id + '-accomplishments') self.add_component(self._company) self.add_component(self._title) self.add_component(self._date) self.add_component(Component("br")) self.add_component(Component("b", inline=True, text="Technologies")) self.add_component(self._technologies) self.add_component(Component("br")) self.add_component(Component("b", inline=True, text="Responsibilities")) self.add_component(self._bullets) self.add_component(self._accomplishments) if config_section: self.update_components(config_section)
def __init__(self, name, title, profile_pic=None): super().__init__(id="cv_titlebar") utils.add_class_attributes(self, "row", "p-3", "mb-2", "bg-primary", "text-white") self.body = Container(id="title_body") self.links = Table(id="title_links", rows=1, cols=2, border="0") if profile_pic: pic_col = Container(**{"class": "col-sm-2 align-self-center"}) pic_col.add_component( Component("img", src=profile_pic, **{"class": "rounded-circle img-thumbnail"})) self.add_component(pic_col) utils.add_class_attributes(self.body, "col-sm-7") else: utils.add_class_attributes(self.body, "col-sm-9") self.links_container = Container(title="title_links_container") self.links_container.add_component(self.links) utils.add_class_attributes(self.links_container, "col-sm-3") self.body.add_component( Component("h3", id="title_body_name", text=name, inline=True)) self.body.add_component( Component("h4", id="title_body_title", text=title, inline=True)) self.body.add_component(Component("br")) self.add_component(self.body) self.add_component(self.links_container)
def add_social_media(self, media, href): self.links.add_rows(1) row = self.links.rows() self.links.get_col(row, 1).add_component( Component("a", inline=True, text=media, style="color:white", href=href)) utils.add_class_attributes(self.links.get_col(row, 1), "text-right") span = Container("span", title=media) if media in font_awesome_classes: font_awesome = Component("i", inline=True, style="color:white", **{"aria-hidden": "true"}) utils.add_class_attributes(font_awesome, font_awesome_classes[media]) href = Container("a", href=href) href.add_component(font_awesome) span.add_component(href) self.links.get_col(row, 2).add_component(span)
def add_rows(self, rows: int): row_index = self.rows() + 1 for row in range(rows): index = row_index + row row_component = Container(self.ROW_TAG, id="{}_row_{}".format(self.id, index)) self.add_component(row_component) for col in range(self.cols()): col_component = Container(self.COL_TAG, id="{}_row_{}_col_{}".format( self.id, index, col + 1)) row_component.add_component(col_component)
def update_components(self, config_section): self._title.text = config_section['title'] self._company.text = config_section['company'] if config_section['to date']: self._date.text = config_section[ 'from date'] + ' - ' + config_section['to date'] else: self._date.text = config_section['from date'] col = 1 row = 1 for technology in config_list(config_section, 'technology'): self._technologies.get_col(row, col).add_component( Component("div", inline=True, text=config_section[technology])) col += 1 if col > self.TECHNOLOGY_COLUMNS: col = 1 row += 1 self._technologies.add_rows(1) for bullet in config_list(config_section, 'bullet'): self._bullets.add_component( Component("li", text=config_section[bullet])) accomplishment_text = Component("b", text="accomplishment: ") for accomplishment in config_list(config_section, 'accomplishment'): accomplishment_html = Container() accomplishment_html.add_component(accomplishment_text) accomplishment_html.add_component( Component("i", text=config_section[accomplishment])) self._accomplishments.add_component(accomplishment_html)
def test_add_component(self): c = Component(COMPONENT_TAG) self.assertFalse(c.get_attribute("id")) self.assertFalse(c in self.c.components) # Test that ID is added to components self.c.add_component(c) self.assertTrue(c.get_attribute("id")) self.assertTrue(c in self.c.components) # Test that indent is updated on nested objects c1 = Container() c2 = Container() c1.add_component(c2) self.assertTrue(c1.indent == c2.indent-1) self.c.add_component(c1) self.assertTrue(self.c.indent == c1.indent-1) self.assertTrue(c1.indent == c2.indent-1)
def add_cols(self, cols: int): col_index = self.cols() + 1 for col in range(cols): index = col_index + col for row in range(self.rows()): row_component = self.get_row(row + 1) if row_component: col_component = Container(self.COL_TAG, id="{}_row_{}_col_{}".format( self.id, row + 1, index)) row_component.add_component(col_component)
def test_get_component(self): component = Component(COMPONENT_TAG) container = Container() container.add_component(component) self.c.add_component(container) self.assertTrue(component in container.components) self.assertTrue(container in self.c.components) id = component.get_attribute("id").get_values() get_c = self.c.get_component(id) self.assertTrue(component is get_c) self.assertTrue(self.c.get_component('OBJECT_NOT_FOUND') is None)
def add_competency(self, competency, skill, confidence): competency_section = self.get_component("competency-" + competency) if competency_section is None: competency_section = Container(id="competency-" + competency) competency_section.add_component( Component("h3", inline=True, text=competency)) self.competencies.add_item(competency_section) skill_text = Component("small", text=skill, style="margin-left: 5px") utils.add_class_attributes(skill_text, "justify-content-left", "d-flex", "position-absolute", "w-100") skill_bar = ProgressBar(valuenow=confidence) utils.add_class_attributes(skill_bar, "m-1") skill_bar.get_component(skill_bar.id + '-progressbar').add_component(skill_text) competency_section.add_component(skill_bar)
def __init__(self, text: str = None, valuenow: int = 0, valuemin: int = 0, valuemax: int = 100, **attributes): attributes["class"] = "progress" super().__init__("div", **attributes) self.valuenow = valuenow self.valuemin = valuemin self.valuemax = valuemax progressbar = Container("div", text=text, role="progressbar", style="width: {}%".format(valuenow), id="{}-progressbar".format(self.id), **{"class": "progress-bar"}) self.add_component(progressbar)
def __init__(self): super().__init__(id="cv_sidebar") utils.add_class_attributes(self, "col-3", "p-3", "mb-2", "bg-secondary", "text-white") self.competencies = Carousel(pause_on_hover=True, controls=True, interval=int(self.INTERVAL * 1000), ride="carousel") self.competencies.add_attribute(Attribute("style", "height: 200px;")) self.competencies.del_component(self.competencies.id + '-prev') self.competencies.get_component(self.competencies.id + '-next').add_attribute( Attribute("style", "height: 25%;")) utils.add_class_attributes( self.competencies.get_component(self.competencies.id + '-next'), "self-align-top") self.add_component(self.competencies) self.add_component(Component("br")) self.add_component(Component("h3", text="Personal Projects")) self.projects = Container("ul") self.add_component(self.projects)
def add_item(self, item: Component): item_index = str(len(self.inner.components)) if self.indicators: # <li data-target="#carouselIndicators" data-slide-to="0" class="active"></li> indicator = Component( "li", inline=True, **{ "data-target": "#carouselIndicators", "data-slide-to": item_index, }, ) if item_index == "0": add_class_attributes(indicator, "active") self.indicators.add_component(indicator) item_container = Container("div", **{"class": "carousel-item"}) if item_index == "0": add_class_attributes(item_container, "active") item_container.add_component(item) self.inner.add_component(item_container)
def update_components(self): self.clear_components() self._titlebar = TitleBar(self.name, self.job_title, self.image) self._sidebar = SideBar() self._mainbody = MainBody() self.add_component(self._titlebar) row = Container(**{"class": "row"}) row.add_component(self._sidebar) row.add_component(self._mainbody) self.add_component(row) for key in self.config['social-media'].keys(): self._titlebar.add_social_media(key, self.config['social-media'][key]) for competency in [ c for c in self.config.keys() if c.startswith('competency-') ]: competency_name = competency.split('-')[1] for skill in self.config[competency].keys(): self._sidebar.add_competency( competency_name, skill, int(self.config[competency][skill])) for project in [ p for p in self.config.keys() if p.startswith('project-') ]: self._sidebar.add_project(self.config[project]["text"], self.config[project]["link"]) for job in config_list(self.config, "job", reverse=True): self._mainbody.add_component(Component("hr")) self._mainbody.add_component(Job(self.config[job]))
def setUp(self): self.c = Container()
def test_id_begins_with_alpha(self): exp = re.compile('^[a-z]') for i in range(100): c = Container() assert exp.match(c.id)
def __init__(self, controls=False, indicators=False, interval=5000, keyboard=True, pause_on_hover=False, ride=False, wrap=True, **attributes): attributes["class"] = "carousel slide" super().__init__("div", **attributes) self.indicators = indicators self.interval = interval self.keyboard = keyboard self.ride = ride self.wrap = wrap self.add_attributes(**{"data-interval": str(interval)}) self.add_attributes(**{"data-keyboard": str(keyboard).lower()}) self.add_attributes(**{"data-ride": str(ride).lower()}) self.add_attributes(**{"data-wrap": str(wrap).lower()}) if pause_on_hover: self.add_attributes(**{"data-pause": "hover"}) if indicators: self.indicators = Container("ol", **{"class": "carousel-indicators"}) self.add_component(self.indicators) self.inner = Container("div", **{"class": "carousel-inner"}) self.add_component(self.inner) if controls: control_prev = Container( "a", id=self.id + "-prev", href="#{}".format(self.id), role="button", **{ "class": "carousel-control-prev", "data-slide": "prev", }, ) control_prev.add_component( Component("span", id=control_prev.id + '-icon', inline=True, **{ "class": "carousel-control-prev-icon", "aria-hidden": "true" })) control_prev.add_component( Component("span", inline=True, **{"class": "sr-only"}, text="Previous")) control_next = Container( "a", id=self.id + "-next", href="#{}".format(self.id), role="button", **{ "class": "carousel-control-next", "data-slide": "next", }, ) control_next.add_component( Component("span", id=control_next.id + '-icon', inline=True, **{ "class": "carousel-control-next-icon", "aria-hidden": "true" })) control_next.add_component( Component("span", inline=True, **{"class": "sr-only"}, text="Next")) self.add_component(control_prev) self.add_component(control_next)
def add_project(self, text, href): list_item = Container("li") list_item.add_component( Component("a", href=href, text=text, **{"class": "text-white"})) self.projects.add_component(list_item)