예제 #1
0
 def get_theme(
         self, theme_ids, server=_LOCAL, isfree=True, size=Image.Iph4_5s):
     '''
     get theme by theme ids and paid
     '''
     theme_list = []
     Theme = classing_model('theme')
     theme_infos = Theme.find(
         self.appname,
         cond={'id': {'$in': theme_ids}, 'isfree': isfree, 'size': size},
         fields={'_id': 0}, toarray=True)
     if not theme_infos:
         return theme_list
     for theme_id in theme_ids:
         for theme_info in theme_infos:
             if theme_id == theme_info.get('id'):
                 icon_url = fetch_icon_url(
                     self.appname, theme_info.get('icon'), server)
                 banner_url = fetch_icon_url(
                     self.appname, theme_info.get('logo'), server)
                 locale_titles = theme_info.get('themelocale')
                 theme_dict = {
                     'type': 'theme',
                     'themeId': theme_id,
                     'name': theme_info.get('name'),
                     'titles': self.localize_titles(locale_titles),
                     'downloadUrl': banner_url,
                     'thumbnailUrl': icon_url,
                     'price': theme_info.get('prize', ''),
                     'productId': theme_info.get('paidID', '')}
                 theme_list.append(theme_dict)
     return theme_list
예제 #2
0
 def get_themefolder(self, folder_ids, server, isfree, size=Image.Iph4_5s):
     folder_list = []
     if not folder_ids:
         return folder_list
     ThemeFolder = classing_model('themefolder')
     folders = ThemeFolder.find(
         self.appname,
         cond={'id': {'$in': folder_ids}, 'isfree': isfree, 'size': size},
         fields={'_id': 0}, toarray=True)
     if not folders:
         return folder_list
     for folder_id in folder_ids:
         for folder in folders:
             if folder_id == folder.get('id'):
                 themes = sorted(
                     folder.get('theme'), key=lambda x: x['order'])
                 theme_ids = [t.get('id') for t in themes]
                 theme_infos = self.get_theme(
                     theme_ids, server=server, isfree=isfree, size=size)
                 icon_url = fetch_icon_url(
                     self.appname, folder.get('icon'), server)
                 locale_titles = folder.get('themelocale')
                 folder_dict = {
                     'type': 'folder',
                     'folderId': folder.get('id'),
                     'name': folder.get('name'),
                     'titles': self.localize_titles(locale_titles),
                     'thumbnailUrl': icon_url,
                     'themes': theme_infos}
                 folder_list.append(folder_dict)
     return folder_list