def _render_slides(self): for slide in self.slides: concept = slide.concept parent = concept.get_parent() div = Pq('<div></div>') span = Pq('<span></span>') div.append(span) self.body.append(div) div.add_class('pres_slide step') div.attr('data-y', str(self.cur_y)) self.cur_y += self.y_step if parent.is_root() and concept.is_image(self.document.key): text = parent.title text = phrasing.distill_with_threshold( text, capitalization=phrasing.CAPITALIZE_TITLE) elif slide.is_image: sel_phr = parent.get_presentation_selected_phrasing( document=self.document) if sel_phr: text = sel_phr.phrasing.get().text else: text = parent.get_presentation_phrasing(self.document).text text = phrasing.distill_with_threshold( text, capitalization=phrasing.CAPITALIZE_TITLE) else: sel_phr = concept.get_presentation_selected_phrasing( document=self.document) if sel_phr: text = sel_phr.phrasing.get().text else: text = concept.get_presentation_phrasing( self.document).text text = phrasing.distill_with_threshold( text, capitalization=phrasing.CAPITALIZE_TITLE) h = Pq('<h1></h1>') header_span = Pq('<span></span>') header_span.add_class('presentation_span') header_span.append(text) h.append(header_span) span.append(h) if slide.is_image: caption = Pq('<h5></h5>') caption.add_class('pres-caption') caption.add_class('presentation_span') text = concept.get_presentation_phrasing(self.document).text caption.append(phrasing.distill_with_threshold(text)) image_container = Pq('<center></center>') img = Pq('<img>') img.add_class('slide-img') img.attr('src', '/media/download/%s' % concept.id) image_container.append(img) image_container.append(caption) span.append(image_container) else: ul = Pq('<ul></ul>') ul.attr('data-bullet-count', str(len(slide.bullets))) span.append(ul) for bullet in slide.bullets: li = Pq('<li></li>') bullet_span = Pq('<span></span>') bullet_span.add_class('presentation_span') text = bullet.get_presentation_phrasing(self.document).text bullet_span.append(phrasing.distill_with_threshold(text)) li.append(bullet_span) ul.append(li)
class PresentationPublisherEngine(object): def __init__(self, pro, doc, sc, minb, maxb, group, organization=None): self.project = pro self.document = doc self.slide_count = sc self.min_bullet = minb self.max_bullet = maxb self.groups = [group.key, Group.get_worldshare().key] self.organization = organization self.user = User() self.user.groups = self.groups self.walker = ConceptPublishWalker(pro) if organization: self.user.organization = organization.key self.html = '' self.body = Pq('<div></div>') self.body.attr('id', 'presentation-div') self.body.add_class('') self.con_count = 0 self.slides = [] self.cur_y = 0 self.y_step = 525 def _get_next_concept(self): for level in self.walker: for concept in level: yield concept def render(self): self._generate_slides() self._render_slides() press_wrapper = Pq('<div></div>') press_wrapper.attr('id', 'pres_wrapper') press_wrapper.append(self.body) self.html = press_wrapper.outer_html() def _generate_slides(self): con_slides = {} slide = Slide() con_slides[self.project.id] = slide for concept in self._get_next_concept(): if concept: if not concept.has_permission_read(self.user): continue if not concept.is_presentation_crawlable( document=self.document, project=self.project): continue attr = concept.get_attr_by_doc(self.document) is_image = attr and attr.is_image() parent = concept.get_parent() if (is_image or concept.is_parent( user=self.user)) and parent.id in con_slides: unprocessed_children = concept.get_children(user=self.user) if not is_image and len( unprocessed_children) < self.min_bullet: continue processed_children = [] if is_image: num_slide = 1 else: for child in unprocessed_children: child_attr = child.get_attr_by_doc(self.document) if not child_attr or not child_attr.is_image(): processed_children.append(child) num_slide = len(processed_children) / self.max_bullet remainder = len(processed_children) % self.max_bullet if remainder >= self.min_bullet: num_slide += 1 if num_slide == 0: continue par_slide = con_slides[parent.id] for i in xrange(num_slide): slide = Slide() slide.parent = par_slide slide.concept = concept slide.is_image = is_image slide.is_continue = i > 0 par_slide.slides.append(slide) con_slides[concept.id] = slide self.slides.append(slide) min_index = i * self.max_bullet max_index = min_index + self.max_bullet slide.bullets = processed_children[min_index:max_index] if len(self.slides) == self.slide_count: break if len(self.slides) == self.slide_count: break def _render_slides(self): for slide in self.slides: concept = slide.concept parent = concept.get_parent() div = Pq('<div></div>') span = Pq('<span></span>') div.append(span) self.body.append(div) div.add_class('pres_slide step') div.attr('data-y', str(self.cur_y)) self.cur_y += self.y_step if parent.is_root() and concept.is_image(self.document.key): text = parent.title text = phrasing.distill_with_threshold( text, capitalization=phrasing.CAPITALIZE_TITLE) elif slide.is_image: sel_phr = parent.get_presentation_selected_phrasing( document=self.document) if sel_phr: text = sel_phr.phrasing.get().text else: text = parent.get_presentation_phrasing(self.document).text text = phrasing.distill_with_threshold( text, capitalization=phrasing.CAPITALIZE_TITLE) else: sel_phr = concept.get_presentation_selected_phrasing( document=self.document) if sel_phr: text = sel_phr.phrasing.get().text else: text = concept.get_presentation_phrasing( self.document).text text = phrasing.distill_with_threshold( text, capitalization=phrasing.CAPITALIZE_TITLE) h = Pq('<h1></h1>') header_span = Pq('<span></span>') header_span.add_class('presentation_span') header_span.append(text) h.append(header_span) span.append(h) if slide.is_image: caption = Pq('<h5></h5>') caption.add_class('pres-caption') caption.add_class('presentation_span') text = concept.get_presentation_phrasing(self.document).text caption.append(phrasing.distill_with_threshold(text)) image_container = Pq('<center></center>') img = Pq('<img>') img.add_class('slide-img') img.attr('src', '/media/download/%s' % concept.id) image_container.append(img) image_container.append(caption) span.append(image_container) else: ul = Pq('<ul></ul>') ul.attr('data-bullet-count', str(len(slide.bullets))) span.append(ul) for bullet in slide.bullets: li = Pq('<li></li>') bullet_span = Pq('<span></span>') bullet_span.add_class('presentation_span') text = bullet.get_presentation_phrasing(self.document).text bullet_span.append(phrasing.distill_with_threshold(text)) li.append(bullet_span) ul.append(li)