コード例 #1
0
ファイル: models.py プロジェクト: kevinpostal/mirskutils
 def render(self):
     
     photo = None
     if self.kind in [self.KINDS.text, self.KINDS.photo, self.KINDS.video] and self.content.get('photo',''):
         path = "%s%s" % (settings.MEDIA_URL, self.content['photo'])
         if int(self.content.get('size',self.SIZES.original)) != self.SIZES.original:
             path = srcThumbnail(path, int(self.content['size'])+65, 0)
         photo = { 'slug':self.slug, 'media':settings.MEDIA_URL, 'path': path }
         
     if self.kind == self.KINDS.text:
         rendered = """<p>%(text)s</p>""" % {'text':self.content.get('text','')}
         if photo:
             rendered = "<img src='%(path)s' />" % photo + rendered
         return ms(rendered)
     elif self.kind == self.KINDS.video:
         videos = self.content.get('video_url','').split(',')
         js = ["{url:'mp4:%s', autoPlay:%s}" % (sign_s3_url(v,10000), 'false' if not i else 'true') for i, v in enumerate(videos) if v]
         if photo:
             splash = "{url:'%(path)s', scaling:'orig', autoPlay:true}" % photo
             js.insert(0,splash)
         
         rendered = """<a href='#' class='video-container' id='video-%(id)s'></a>
         <div class="clips" style="display:none"><a href="${url}">video</a></div>
         <script>window.onload = function() { typecoach.player_init('video-%(id)s', [%(array)s]); }</script>
         """ % { 'id':self.pk, 'array': ','.join(js) }
         return ms(rendered)
     
     elif self.kind == self.KINDS.container:
         return ms("".join([b.contained.render() for b in self.contains.order_by('rank')]))
     elif self.kind == self.KINDS.photo:
         return ms("<img src='%(path)s' />" % photo)
     return ""
コード例 #2
0
ファイル: models.py プロジェクト: kevinpostal/mirskutils
 def as_divs(self):
     if self.kind == self.KINDS.container:
         items = [b.as_divs() for b in self.blocks.order_by('containers__rank') ] 
         
         #items = [ms("<div class='tc%(kind)s' id='%(slug)s'>%(render)s</div>" % p) for p in params]
         return ms("<div class='tc-container' id='%s'>%s</div>" % (self.slug, ("".join(items))))
     return ms("<div class='%(kind)s' id='%(slug)s'>%(render)s</div><div class='%(kind)s spacer'></div>" % { 'kind' : self.KINDS[self.kind],
                                                                                                             'slug' : self.slug,
                                                                                                             'render':self.render() })
コード例 #3
0
ファイル: models.py プロジェクト: kevinpostal/mirskutils
 def as_toc(self):
     if self.kind == self.KINDS.container:
         items = [ms("<li id='%s'><a href='%s'>%s</a></li>" % (b.slug, b.get_url(), b.title)) for b in self.blocks.all()]
         return ms("".join(items))
     return ms("<li id='%s'>%s</li>" % (self.slug, self.render()))       
コード例 #4
0
ファイル: models.py プロジェクト: kevinpostal/mirskutils
 def as_ul(self):
     if self.kind == self.KINDS.container:
         items = [ms("<li id='%s'>%s</li>" % (b.slug, b.render())) for b in self.blocks.all()]
         return ms("".join(items))
     return ms("<li id='%s'>%s</li>" % (self.slug, self.render()))