def display_pagination(current_shard): "Filter generates pagination view based on the current shard" pagination_template = template.loader.get_template( 'cc-pagination.html') current_int = int(current_shard.split(":")[-1]) shard_pattern = current_shard[:-2] total_int = int(REDIS_DATASTORE.get('global {0}'.format(shard_pattern))) previous_int = current_int -1 next_int = current_int +1 if previous_int < 1: previous_int = 1 shards = [] for i in range(1, total_int): shards.append('{0}:{1}'.format(shard_pattern, i)) previous_shard = '{0}:{1}'.format(shard_pattern, previous_int) next_shard = '{0}:{1}'.format(shard_pattern, next_int) return mark_safe(pagination_template.render( template.Context({'previous': previous_shard, 'next': next_shard, 'shard_num': current_int})))
def get_work_total(work_name): work_key = "global bf:{0}".format(work_name) if REDIS_DATASTORE.exists(work_key): work_total = '{0:,}'.format(int(REDIS_DATASTORE.get(work_key))) else: work_total = 0 return mark_safe(work_total)
def get_news(): news = [] # In demo mode, just create a news item regarding the # statistics of the REDIS_DATASTORE if REDIS_DATASTORE is not None: body_text = "<p><strong>Totals:</strong>" for key in CREATIVE_WORK_CLASSES: body_text += '{0} = {1}<br>'.format( key, REDIS_DATASTORE.get('global bf:{0}'.format(key))) body_text += '</p><p>Total number of keys={0}</p>'.format( REDIS_DATASTORE.dbsize()) item = {'heading': 'Current Statistics for Redis Datastore', 'body': body_text} news.append(item) ## body_html = '<ul>' ## for row in REDIS_DATASTORE.zrevrange('prospector-holdings', ## 0, ## -1, ## withscores=True): ## org_key, score = row[0], row[1] ## body_html += '''<li>{0} Total Holdings={1}</li>'''.format( ## REDIS_DATASTORE.hget(org_key, 'label'), ## score) ## body_html += '</ul>' ## item2 = {'heading': 'Institutional Collections', ## 'body': body_html} ## news.append(item2) return news
def display_collection(placeholder): output = "" for i in range(1, int(REDIS_DATASTORE.get('global bf:Manuscript'))): work_key = 'bf:Manuscript:{0}'.format(i) title_key = REDIS_DATASTORE.hget(work_key, 'title') instance_key = REDIS_DATASTORE.hget(work_key, 'hasInstance') title = REDIS_DATASTORE.hget(title_key, 'titleValue') pdf_location = REDIS_DATASTORE.hget(instance_key, 'schema:contentUrl') output += """<li><a href="/apps/discovery/Manuscript/{0}">{1}</a> <a href="{2}"><img src="/static/img/pdficon_small.png"></a></li> """.format(i, title, pdf_location) return mark_safe(output)
def display_collection(placeholder): output = "" for i in range(1, int(REDIS_DATASTORE.get('global bf:Manuscript'))): work_key = 'bf:Manuscript:{0}'.format(i) title_key = REDIS_DATASTORE.hget(work_key, 'title') instance_key = REDIS_DATASTORE.hget(work_key, 'hasInstance') title = REDIS_DATASTORE.hget(title_key, 'titleValue') pdf_location = REDIS_DATASTORE.hget(instance_key, 'schema:contentUrl') output += """<li><a href="/apps/discovery/Manuscript/{0}">{1}</a> <a href="{2}"><img src="/static/img/pdficon_small.png"></a></li> """.format(i, title, pdf_location) return mark_safe(output)
def display_topic_cloud(placeholder): topics = [] for i in range(1, int(REDIS_DATASTORE.get('global bf:Topic'))): topic_key = 'bf:Topic:{0}'.format(i) topic_works_key = '{0}:works'.format(topic_key) total_works = int(REDIS_DATASTORE.scard(topic_works_key)) if total_works < 3: topic_size = 12 elif total_works < 10: topic_size = 16 else: topic_size = total_works topics.append("""<a style="font-size: {0}px" href="/apps/discovery/Topic/{1}">{2}</a>""".format( topic_size, i, REDIS_DATASTORE.hget(topic_key, 'label'))) return mark_safe(", ".join(topics))
def display_topic_cloud(placeholder): topics = [] for i in range(1, int(REDIS_DATASTORE.get('global bf:Topic'))): topic_key = 'bf:Topic:{0}'.format(i) topic_works_key = '{0}:works'.format(topic_key) total_works = int(REDIS_DATASTORE.scard(topic_works_key)) if total_works < 3: topic_size = 12 elif total_works < 10: topic_size = 16 else: topic_size = total_works topics.append("""<a style="font-size: {0}px" href="/apps/discovery/Topic/{1}">{2}</a>""".format( topic_size, i, REDIS_DATASTORE.hget(topic_key, 'label'))) return mark_safe(", ".join(topics))