def show_gallery(self, data=None, error=None): "" if data is not None and not error: self.obj = widget.Gallery('page', data) self.compile( "#gallery-t", ".breadcrumb", after=True, thumb="/static/img/default.png", title=self.obj.title(), artists=data['artists'], lang="test", inbox=data["inbox"], fav=data["fav"], published=moment.unix(data['pub_date']).format("LL"), updated=moment.unix(data['last_updated']).format("LLL"), read=moment.unix(data['last_read']).format("LLL"), added=moment.unix(data['timestamp']).format("LLL"), rel_added=moment.unix(data['timestamp']).fromNow(), rel_updated=moment.unix(data['last_updated']).fromNow(), rel_read=moment.unix(data['last_read']).fromNow()) widget.Thumbnail("#profile", "big", "Gallery", self.obj['id']).fetch_thumb() elif error: pass else: client.call_func("get_item", self.show_gallery, item_type='Gallery', item_id=int(self.g_id))
def get_items(data=None, error=None): if data is not None and not error: this.setState({"items": data, 'loading': False}) elif error: state.app.notif("Failed to fetch item type: {}".format( this.props.item_type), level="error") else: item = this.props.item_type func_kw = { 'item_type': item, 'page': max(int(this.state.page) - 1, 0), 'limit': this.props.limit or this.state.default_limit } if this.props.view_filter: func_kw['view_filter'] = this.props.view_filter if this.state.search_query: func_kw['search_query'] = this.state.search_query if this.props.related_type: func_kw['related_type'] = this.props.related_type if this.props.item_id: func_kw['item_id'] = this.props.item_id if item: client.call_func("library_view", this.get_items, **func_kw) this.setState({'loading': True})
def get_grouping(data=None, error=None): if data is not None and not error: this.setState({"group_data":data, "loading_group":False}) if data.status_id: client.call_func("get_item", this.get_status, item_type=ItemType.Status, item_id=data.status_id) elif error: state.app.notif("Failed to fetch grouping ({})".format(this.state.id), level="error")
def show_items(self, data=None, error=None, page=None): if not page: page = self.current_page if data is not None and not error: self.set_properties() self.artists.clear() _view = self.get_property('view') items = [] if _view == 'Gallery': if not self._properties['iscroll']: self.items.clear() S("#items").empty() self.grid.reload() for g in data: g_obj = widget.Gallery('medium', g) self.items[g['id']] = g_obj items.append(g_obj) for a in g['artists']: a_id = a['id'] if a_id in self.artists: self.artists[a_id]['count'] += 1 else: self.artists[a_id] = a self.artists[a_id]['count'] = 1 self.update_sidebar(artist_obj=self.artists) if items: for i in items: self.grid.append(i.compile("#items", append=True)) widget.MassThumbnail(items, 'gallery').mass_fetch( 'medium', lambda: setTimeout(self.grid.layout, 1000)) if not items: self.grid.reload() self.show_nothing("#items") self.grid.layout() elif error: pass else: view = self.get_property('view') client.call_func("library_view", self.show_items, item_type=view, limit=self.item_limit, page=page - 1, search_query=self._properties['search_query'])
def tr(that, t_id, default_txt): if t_id: t_txt = _translations_d.get(current_locale, {}).get(t_id) if t_txt is None: fargs = {"t_id": t_id, "locale": current_locale} if that: client.call_func("translate", add_translation_component, { 'cmp': that, 't_id': t_id }, **fargs) else: client.call_func("translate", add_translation, t_id, **fargs) else: default_txt = t_txt return default_txt
def _fetch_artists(self, data=None, error=None): if data is not None and not error: self.artists = data if self.node and self.artists: anames = data[0]['names'] if anames: anode = self.node.find('.gartist') anode.text(anames[0]['name']) elif error: pass else: client.call_func("get_related_items", self._fetch_artists, item_id=self.id, item_type=self.item_type, related_type=ItemType.get('artist'))
def fetch_gfilters(self, data=None, error=None): "" if data is not None and not error: lists_data = [] for gl in data: self.gfilters[gl['id']] = gl lists_data.append({'name': gl['name']}) self.compile("#side-lists-t", "#side-lists .list-group", append=True, side_lists=lists_data) elif error: pass else: client.call_func("get_items", self.fetch_gfilters, item_type='galleryfilter')
def get_items_count(data=None, error=None): if data is not None and not error: this.setState({"item_count": data['count']}) elif error: pass else: item = this.props.item_type func_kw = {'item_type': item} if this.props.view_filter: func_kw['view_filter'] = this.props.view_filter if this.state.search_query: func_kw['search_query'] = this.state.search_query if this.props.related_type: func_kw['related_type'] = this.props.related_type if this.props.item_id: func_kw['item_id'] = this.props.item_id if item: client.call_func("get_view_count", this.get_items_count, **func_kw)
def show_pagination(self, data=None, error=None): "" if data is not None and not error: pages = data['count'] / self.item_limit if pages < 1: pages = 1 # check if number is whole if pages % 1 == 0: # Note: will fail on very large numbers eg. 999999999999999999999 pages = int(pages) else: pages = int(pages) + 1 self._page_list = range(1, pages + 1) self.update_pagination() elif error: pass else: client.call_func("get_view_count", self.show_pagination, item_type=self.get_property('view'), search_query=self.get_property('search_query'))
def get_item(data=None, error=None): if data is not None and not error: this.setState({"data":data, "loading":False, 'loading_group':True}) if data.grouping_id: client.call_func("get_related_items", this.get_grouping, item_type=ItemType.Grouping, related_type=this.state.item_type, item_id=data.grouping_id) if data.language_id: client.call_func("get_item", this.get_lang, item_type=ItemType.Language, item_id=data.language_id) if data.id: client.call_func("get_tags", this.get_tags, item_type=this.state.item_type, item_id=data.id) elif error: state.app.notif("Failed to fetch item ({})".format(this.state.id), level="error") else: item = this.state.item_type item_id = this.state.id if item and item_id: client.call_func("get_item", this.get_item, item_type=item, item_id=item_id) this.setState({'loading':True})