Esempio n. 1
0
 def assemble(self, links):
     toplinks = ['']
     bottomlinks = ['']
     for _type, result in [('toplinks', toplinks),
                           ('bottomlinks', bottomlinks)]:
         for x in links[_type]:
             if isinstance(x, dict):
                 link, media = x['value'], x['media']
             else:
                 link, media = x, None
             if link.endswith('.js'):
                 link = functions.url_for_static(link)
                 result.append(
                     '<script type="text/javascript" src="%s"></script>' %
                     link)
             elif link.endswith('.css'):
                 link = functions.url_for_static(link)
                 if media:
                     result.append(
                         '<link rel="stylesheet" type="text/css" href="%s" media="%s"/>'
                         % (link, media))
                 else:
                     result.append(
                         '<link rel="stylesheet" type="text/css" href="%s"/>'
                         % link)
             elif link.endswith('.less'):
                 link = functions.url_for_static(link)
                 result.append('<link rel="stylesheet/less" href="%s"/>' %
                               link)
             else:
                 result.append(link)
     return {
         'toplinks': '\n'.join(toplinks),
         'bottomlinks': '\n'.join(bottomlinks)
     }
Esempio n. 2
0
def get_user_image(user, size=20):
    """
    Get one's portrait from gravatar.com
    This code copies from http://blog.gravatar.com/2008/01/17/gravatars-in-python-25/
    
    if the user is loginned via weibo, then use image directly, it should be
    the image url
    """
    from uliweb import functions
    import urllib, hashlib
     
    if user:
        if user.login_type == '0': #login type
            email = user.email or "*****@*****.**"
            default = functions.url_for_static('images/user50x50.jpg', _external=True)
     
            # construct the url 
            gravatar_url = "http://www.gravatar.com/avatar.php?"
            gravatar_url += urllib.urlencode({'gravatar_id':hashlib.md5(email.lower()).hexdigest(), 'default':default, 'size':str(size)})
            
            return gravatar_url
        if user.login_type == '1': #weibo
            return user.image
    else:
        return functions.url_for_static('images/user%dx%d.jpg' % (size, size), _external=True)
Esempio n. 3
0
    def get_image(self):
        from uliweb import functions

        if self.image:
            return functions.get_href(self.image)
        else:
            return functions.url_for_static('tutorials/default_book.png')
Esempio n. 4
0
    def _clean_collection(self, existlinks):
        from uliweb.utils.sorteddict import SortedDict

        r = {'toplinks': SortedDict(), 'bottomlinks': SortedDict()}
        #process links, link could be (order, link) or link
        for _type in ['toplinks', 'bottomlinks']:
            t = self.links.get(_type, [])
            for link in t:
                #link will also be template string
                if '{{' in link and '}}' in link:
                    #link = template(link, self.env)
                    raise TemplateDefineError(
                        "Can't support tag {{}} in links")

                #process static combine
                if isinstance(link, dict):
                    link_key = link.get('value')
                    link_value = link.copy()
                    link_value.pop('value')
                else:
                    link_key = link
                    link_value = {}
                if link_key.endswith('.js') or link_key.endswith('.css'):
                    _link = functions.url_for_static(link_key)
                else:
                    _link = link_key
                if not link_key in r[_type] and not _link in existlinks:
                    link_value['link'] = _link
                    r[_type][link_key] = link_value
                    existlinks.append(_link)
        return r
Esempio n. 5
0
 def get_image(self):
     from uliweb import functions
     
     if self.logo:
         return functions.get_href(self.logo)
     else:
         return functions.url_for_static('classes/default_class.png')
Esempio n. 6
0
 def get_image(self):
     from uliweb import functions
     
     if self.image:
         return functions.get_href(self.image)
     else:
         return functions.url_for_static('tutorials/default_book.png')
Esempio n. 7
0
    def _clean_collection(self, existlinks):
        from uliweb.utils.sorteddict import SortedDict

        r = {'toplinks':SortedDict(), 'bottomlinks':SortedDict(), 'headlinks':SortedDict()}
        #process links, link could be (order, link) or link
        for _type in ['toplinks', 'bottomlinks', 'headlinks']:
            t = self.links.get(_type, [])
            for link in t:
                #link will also be template string
                if '{{' in link and '}}' in link:
                    #link = template(link, self.env)
                    raise TemplateDefineError("Can't support tag {{}} in links")
                    
                #process static combine
                if isinstance(link, dict):
                    link_key = link.get('value')
                    link_value = link.copy()
                    link_value.pop('value')
                else:
                    link_key = link
                    link_value = {}
                new_link = __static_mapping__.get(link_key, link_key)
                if new_link.endswith('.js') or new_link.endswith('.css'):
                    _link = functions.url_for_static(new_link)
                else:
                    _link = new_link
                if not new_link in r[_type] and not _link in existlinks:
                    link_value['link'] = _link
                    r[_type][new_link] = link_value
                    existlinks.append(_link)
        return r
Esempio n. 8
0
    def get_image(self):
        from uliweb import functions

        if self.logo:
            return functions.get_href(self.logo)
        else:
            return functions.url_for_static('classes/default_class.png')
Esempio n. 9
0
    def get_image_url(self):
        from uliweb.contrib.upload import get_url
        from uliweb.contrib.staticfiles import url_for_static

        if self.image:
            return get_href(self.image)
        else:
            return functions.url_for_static('images/user%dx%d.jpg' % (50, 50))
Esempio n. 10
0
 def get_image_url(self):
     from uliweb.contrib.upload import get_url
     from uliweb.contrib.staticfiles import url_for_static
     
     if self.image:
         return functions.get_href(self.image)
     else:
         return functions.url_for_static('images/user%dx%d.jpg' % (50, 50))
Esempio n. 11
0
def get_user_image(user, size=50):
    from uliweb.contrib.staticfiles import url_for_static
    from uliweb import functions
    import os
    
    if user:
        image = functions.get_filename(_get_portrait_image_thumbnail(user.id, size))
        if os.path.exists(image):
            image_url = functions.get_href(_get_portrait_image_thumbnail(user.id, size))
            return image_url

    return functions.url_for_static('images/user%dx%d.jpg' % (size, size))
Esempio n. 12
0
    def _clean_collection(self, existlinks):
        from uliweb.utils.sorteddict import SortedDict

        r = {'toplinks': SortedDict(), 'bottomlinks': SortedDict()}
        #process links, link could be (order, link) or link
        for _type in ['toplinks', 'bottomlinks']:
            t = self.links.get(_type, [])
            for link in t:
                #link will also be template string
                if '{{' in link and '}}' in link:
                    #link = template(link, self.env)
                    raise TemplateDefineError(
                        "Can't support tag {{}} in links")

                #process static combine
                if isinstance(link, dict):
                    link_key = link.get('value')
                    link_value = link.copy()
                    link_value.pop('value')
                else:
                    link_key = link
                    link_value = {}
                new_link = __static_mapping__.get(link_key, link_key)
                if new_link.endswith('.js') or new_link.endswith('.css'):
                    _link = functions.url_for_static(new_link)
                else:
                    _link = new_link
                if not new_link in r[_type] and not _link in existlinks:
                    link_value['link'] = _link
                    _js_file, ext = os.path.splitext(new_link)
                    if new_link in __static_combine__ and ext == '.js':
                        _css_file = _js_file + '.css'
                        if _css_file in __static_combine__:
                            _new_link_value = link_value.copy()
                            _new_link_value['link'] = functions.url_for_static(
                                _css_file)
                            r[_type][_css_file] = _new_link_value
                    r[_type][new_link] = link_value
                    existlinks.append(_link)
        return r
Esempio n. 13
0
def get_user_image(user, size=50):
    from uliweb.contrib.staticfiles import url_for_static
    from uliweb import functions
    import os

    if user:
        image = functions.get_filename(
            _get_portrait_image_thumbnail(user.id, size))
        if os.path.exists(image):
            image_url = functions.get_href(
                _get_portrait_image_thumbnail(user.id, size))
            return image_url

    return functions.url_for_static('images/user%dx%d.jpg' % (size, size))
Esempio n. 14
0
 def assemble(self, links):
     toplinks = ['']
     bottomlinks = ['']
     for _type, result in [('toplinks', toplinks), ('bottomlinks', bottomlinks)]:
         for x in links[_type]:
             if isinstance(x, dict):
                 link, media = x['value'], x['media']
             else:
                 link, media = x, None
             if link.endswith('.js'):
                 link = functions.url_for_static(link)
                 result.append('<script type="text/javascript" src="%s"></script>' % link)
             elif link.endswith('.css'):
                 link = functions.url_for_static(link)
                 if media:
                     result.append('<link rel="stylesheet" type="text/css" href="%s" media="%s"/>' % (link, media))
                 else:
                     result.append('<link rel="stylesheet" type="text/css" href="%s"/>' % link)
             elif link.endswith('.less'):
                 link = functions.url_for_static(link)
                 result.append('<link rel="stylesheet/less" href="%s"/>' % link)
             else:
                 result.append(link)
     return {'toplinks':'\n'.join(toplinks), 'bottomlinks':'\n'.join(bottomlinks)}
Esempio n. 15
0
 def _clean_collection(self, existlinks):
     r = {'toplinks':[], 'bottomlinks':[]}
     links = {}
     #process links, link could be (order, link) or link
     for _type in ['toplinks', 'bottomlinks']:
         t = self.links.get(_type, [])
         for link in t:
             #link will also be template string
             if '{{' in link and '}}' in link:
                 link = template(link, self.env)
             if link.endswith('.js') or link.endswith('.css'):
                 _link = functions.url_for_static(link)
             else:
                 _link = link
             if not link in r[_type] and not _link in existlinks:
                 r[_type].append(link)
     return r
Esempio n. 16
0
 def _clean_collection(self, existlinks):
     r = {'toplinks':[], 'bottomlinks':[]}
     links = {}
     #process links, link could be (order, link) or link
     for _type in ['toplinks', 'bottomlinks']:
         t = self.links.get(_type, [])
         for link in t:
             #link will also be template string
             if '{{' in link and '}}' in link:
                 link = template(link, self.env)
             if link.endswith('.js') or link.endswith('.css'):
                 _link = functions.url_for_static(link)
             else:
                 _link = link
             if not link in r[_type] and not _link in existlinks:
                 r[_type].append(link)
     return r
Esempio n. 17
0
 def _clean_collection(self, existlinks):
     r = {'toplinks':[], 'bottomlinks':[]}
     links = {}
     #process links, link could be (order, link) or link
     for _type in ['toplinks', 'bottomlinks']:
         t = self.links.get(_type, [])
         for link in t:
             #link will also be template string
             if '{{' in link and '}}' in link:
                 #link = template(link, self.env)
                 raise TemplateDefineError("Can't support tag {{}} in links")
                 
             #process static combine
             new_link = __static_mapping__.get(link, link)
             if new_link.endswith('.js') or new_link.endswith('.css'):
                 _link = functions.url_for_static(new_link)
             else:
                 _link = new_link
             if not new_link in r[_type] and not _link in existlinks:
                 r[_type].append(new_link)
     return r
Esempio n. 18
0
    def _clean_collection(self, existlinks):
        r = {'toplinks': [], 'bottomlinks': []}
        links = {}
        #process links, link could be (order, link) or link
        for _type in ['toplinks', 'bottomlinks']:
            t = self.links.get(_type, [])
            for link in t:
                #link will also be template string
                if '{{' in link and '}}' in link:
                    #link = template(link, self.env)
                    raise TemplateDefineError(
                        "Can't support tag {{}} in links")

                #process static combine
                new_link = __static_mapping__.get(link, link)
                if new_link.endswith('.js') or new_link.endswith('.css'):
                    _link = functions.url_for_static(new_link)
                else:
                    _link = new_link
                if not new_link in r[_type] and not _link in existlinks:
                    r[_type].append(new_link)
        return r
Esempio n. 19
0
 def get_default_image_url(self, size=50):
     return functions.url_for_static('images/user%dx%d.jpg' % (size, size))
Esempio n. 20
0
 def get_image_url(self):
     if self.image:
         return functions.get_href(self.image)
     else:
         return functions.url_for_static('images/user%dx%d.jpg' % (50, 50))
Esempio n. 21
0
 def get_default_image_url(self, size=50):
     from uliweb.contrib.staticfiles import url_for_static
     return functions.url_for_static('images/user%dx%d.jpg' % (size, size))
Esempio n. 22
0
 def get_default_image_url(self, size=50):
     from uliweb.contrib.staticfiles import url_for_static
     return functions.url_for_static('images/user%dx%d.jpg' % (size, size))
Esempio n. 23
0
 def get_image_url(self):
     if self.image:
         return functions.get_href(self.image)
     else:
         return functions.url_for_static('images/user%dx%d.jpg' % (50, 50))
Esempio n. 24
0
 def get_default_image_url(self, size=50):
     return functions.url_for_static('images/user%dx%d.jpg' % (size, size))