Example #1
0
 def save_file(self):
     newFilePath = self.create_file_name()
     oldFilePath = self.multimedia.get(
         fields='url'
         ,where='id=?'
         ,params=self.idImage
         ,format='strList')
     # The row associate to the image data already exists in the
     # database becaus this row has been create previusly. So I use the
     # update operation.
     self.multimedia.update(
         fields = {
             'last_modified': self.currentDate,
             'url': newFilePath,
             'type': self.image_type,
         }
         ,where='id=?'
         ,params=self.idImage
     )
     with self.open(newFilePath, mode='wb') as imageFile:
         old = oldFilePath[0] if len(oldFilePath) else None
         try:
             self.remove(old)
         except:
             pass
         imageFile.write(self.rawImage)
     # Add the params because I need update this data in the single image
     # template.
     full_file_path = security.set_absolute_path(newFilePath)
     self.form.update(url=full_file_path)
Example #2
0
def set_responsive_image(src='', _type='image', alt=''):
    path = security.set_absolute_path(src)
    sizes = getattr(settings, _type)

    if settings.production:
        template = \
            '<img class="smallImage"      src="http://src.sencha.io/jpg{quality}/{wsmall}/{small}/{path}" alt="{altText}" height="{small}" />'\
            '<img class="mediumImage"     src="http://src.sencha.io/jpg{quality}/{wmedium}/{medium}/{path}" alt="{altText}" height="{medium}" />'\
            '<img class="largeImage"      src="http://src.sencha.io/jpg{quality}/{wlarge}/{large}/{path}" alt="{altText}" height="{large}" />'\
            '<img class="extralargeImage" src="http://src.sencha.io/jpg{quality}/{wextralarge}/{extralarge}/{path}" alt="{altText}" height="{extralarge}" />'
    else:
        template = \
            '<img class="smallImage"      src="{path}" alt="{altText}" height="{small}" />'\
            '<img class="mediumImage"     src="{path}" alt="{altText}" height="{medium}" />'\
            '<img class="largeImage"      src="{path}" alt="{altText}" height="{large}" />'\
            '<img class="extralargeImage" src="{path}" alt="{altText}" height="{extralarge}" />'
    return template.format(
        path=path
        ,altText=alt
        ,small=sizes['small']
        ,medium=sizes['medium']
        ,large=sizes['large']
        ,extralarge=sizes['extralarge']
        ,wsmall=round(sizes['small']*16/9)
        ,wmedium=round(sizes['medium']*16/9)
        ,wlarge=round(sizes['large']*16/9)
        ,wextralarge=round(sizes['extralarge']*16/9)
        ,quality=settings.JPGQuality)
    def get_article_multimedia(self):
        self.articleName = self.articles.get(
            fields='article_name'
            ,where='edit_url=?'
            ,params=helpers.remove_user_name(self.articleURL)
            ,distinct=True)
        self.multimedia = self.serverCollection.get('multimedia')
        _database_result = self.multimedia.get(
            fields=('id', 'url', 'description', 'type', 'cover', 'article_name')
            ,where='article_name=?'
            ,params=self.articleName[0]
            ,format='dictList')
        result = []
        for item in _database_result:
            # add the hostname and the protocol to the url if is an file path
            if item['type'] == 'image_file':
                item['url'] = security.set_absolute_path(item['url'])

            # add the video id key if is an youtube video
            elif item['type'] == 'video_link':
                url_tuple = parse.urlparse(item['url'])
                queries = parse.parse_qs(url_tuple.query)
                # check if the url have the 'v' key
                if queries.get('v'):
                    item['vid'] = queries['v'][0]
                else:
                    item['vid'] = ''
            result.append(item)

        return [result]
    def test_set_secure_path_in_shared_ssl(self):
        """Here should complete the path with the shared ssl adress.
        """
        # See the condition:
        self.environ = {'HTTPS': 'yes'}
        self.config.enableSharedSSL = True
        self.config.enableHTTPS = False

        expected = 'https://shared.ssl/~username/request'
        
        obtained = security.set_absolute_path(
            'request', self.environ, self.config)
        self.assertEqual(expected, obtained)
    def test_set_non_secure_path(self):
        """Should set an non secure path if the condition. Only fill the 
        path with the protocol, the server name and the 'request' string.
        """
        # See the condition:
        self.environ = {'HTTPS': None}
        self.config.enableSharedSSL = False
        self.config.enableHTTPS = False

        expected = 'http://server.name/request'

        obtained = security.set_absolute_path(
            'request', self.environ, self.config)
        self.assertEqual(expected, obtained)
    def test_set_secure_path(self):
        """Should set the secure protocol if the environ has the https key.
        Then set the server name and the path name ('request').
        """
        # See the condition:
        self.environ = {'HTTPS': 'yes'}
        self.config.enableSharedSSL = False
        self.config.enableHTTPS = False

        expected = 'https://server.name/request'

        obtained = security.set_absolute_path(
            'request', self.environ, self.config)
        self.assertEqual(expected, obtained)
Example #7
0
def set_video(src='', _type='normal'):
    path = security.set_absolute_path(src)
    if _type is 'normal':
        sizes = settings.image
    elif _type is 'thumbnail':
        sizes = settings.thumbnail
    template = \
        '<iframe class="smallImage"      height="315" src="{youtube_url}" frameborder="0" allowfullscreen></iframe>'\
        '<iframe class="mediumImage"     height="315" src="{youtube_url}" frameborder="0" allowfullscreen></iframe>'\
        '<iframe class="largeImage"      height="315" src="{youtube_url}" frameborder="0" allowfullscreen></iframe>'\
        '<iframe class="extralargeImage" height="315" src="{youtube_url}" frameborder="0" allowfullscreen></iframe>'
    return template.format(
        path=path
        ,altText=alt
        ,small=sizes['small']
        ,medium=sizes['medium']
        ,large=sizes['large']
        ,extralarge=sizes['extralarge'])