Пример #1
0
 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
    def render(self, name, value, attrs=None):
        
        context = {'name':name}

        if value and hasattr(value, 'url'):
            context['url'] = srcThumbnail(value.url, self.width, self.height)
            
        t = Template('''{% if url %}<img id="{{ name }}-img" src="{{ url }}">
        <div>
            <label for="{{ name }}-clear_id">Clear</label>     
            <input id="{{ name }}-clear_id" name="{{ name }}-clear" type="checkbox" />
        </div>
        {% endif %}
        <div style="margin-top:10px; padding:0px;">
            {% if url %}<label for="{{ name }}">Change</label>{% endif %}
            <input id="id_%(name)ss" name="{{ name }}" type="file" />
        </div>
        ''')
        
        return mark_safe(t.render(Context(context)))    
Пример #3
0
    def render(self, name, value, attrs=None):
        
        context = {'name':name}

        if value and hasattr(value, 'url'):
            context['url'] = srcThumbnail(value.url, self.width, self.height)
            
        t = Template('''{% if url %}<img style="float:left" class="image-file-input" id="{{ name }}-img" src="{{ url }}">
        <div style="float:left; margin-left:50px;" class="image-file-input-clear">
            <label for="{{ name }}-clear_id">Clear</label>     
            <input id="{{ name }}-clear_id" name="{{ name }}-clear" type="checkbox" />
        </div>
        {% endif %}
        <div class="image-file-input-browse" style="float:left; margin-left:50px">
            {% if url %}<label for="{{ name }}">Change</label>{% endif %}
            <input id="id_%(name)ss" name="{{ name }}" type="file" />
        </div>
        <div style="clear:both">&nbsp;</div
        ''')
        
        return mark_safe(t.render(Context(context)))