def get_topic_curators(topic): result = [] for curator in services.get_topic_curators(topic): position = services.get_user_topic_position(curator.user, topic) result.append({ 'obj': curator, 'name': curator.user.get_full_name(), 'photo': curator.photo, 'title': curator.title, 'position_image': _get_position_image( position, 'img/actor-positive.png', 'img/actor-negative.png', 'img/actor-neutral.png', ), }) return result
def get_posts(user, topic, posts): result = [] user_votes = services.get_user_topic_votes(user, topic) if user.is_authenticated else {} curator_votes = services.get_curator_topic_votes(user, topic) if user.is_authenticated else {} for post in posts: if post['type'] == 'event': event = post['event'] result.append({ 'type': 'event', 'post': _get_post_context(post['post'], user_votes, curator_votes), 'event': { 'position_image': _get_position_image( event.position, 'img/event-positive.png', 'img/event-negative.png', 'img/event-neutral.png', ), 'name': event.title, 'timestamp': event.timestamp.strftime('%Y-%m-%d'), 'source': { 'link': event.source_link, 'name': event.source_title, }, }, }) elif post['type'] == 'curator': curator = post['curator'] position = services.get_user_topic_position(curator.user, topic) result.append({ 'type': 'curator', 'post': _get_post_context(post['post'], user_votes, curator_votes), 'curator': { 'position_image': _get_position_image( position, 'img/actor-positive.png', 'img/actor-negative.png', 'img/actor-neutral.png', ), 'name': str(curator.user), 'title': curator.title, 'photo': curator.photo, }, }) else: # post['type'] == 'quote' source = post['source'] actor = source.actor result.append({ 'type': 'quotes', 'source': { 'link': source.source_link, 'name': source.source_title, 'actor': { 'name': str(actor), 'title': source.actor_title or actor.title, 'photo': actor.photo, 'position_image': _get_position_image( source.position, 'img/actor-positive.png', 'img/actor-negative.png', 'img/actor-neutral.png', ), }, }, 'quotes': [{ 'text': quote.text, 'post': _get_post_context(post, user_votes, curator_votes), 'vote': { 'img': { 'top': 'img/thumb-up.png', 'bottom': 'img/thumb-down.png', }, }, 'arguments': [{ 'name': argument.title, 'classes': 'text-%s' % ('danger' if argument.position < 0 else 'success'), 'counterargument': { 'classes': 'glyphicon glyphicon-%s' % ('remove' if argument.counterargument else 'tag'), } } for argument in quote.postargument_set.order_by('pk')], } for post, quote in post['quotes']], }) return result
def get_posts(user, topic, posts): result = [] user_votes = services.get_user_topic_votes(user, topic) if user.is_authenticated() else {} curator_votes = services.get_curator_topic_votes(user, topic) if user.is_authenticated() else {} for post in posts: if post['type'] == 'event': event = post['event'] result.append({ 'type': 'event', 'post': _get_post_context(post['post'], user_votes, curator_votes), 'event': { 'position_image': _get_position_image( event.position, 'img/event-positive.png', 'img/event-negative.png', 'img/event-neutral.png', ), 'name': event.title, 'timestamp': event.timestamp.strftime('%Y-%m-%d'), 'source': { 'link': event.source_link, 'name': event.source_title, }, }, }) elif post['type'] == 'curator': curator = post['curator'] position = services.get_user_topic_position(curator.user, topic) result.append({ 'type': 'curator', 'post': _get_post_context(post['post'], user_votes, curator_votes), 'curator': { 'position_image': _get_position_image( position, 'img/actor-positive.png', 'img/actor-negative.png', 'img/actor-neutral.png', ), 'name': str(curator.user), 'title': curator.title, 'photo': curator.photo, }, }) else: # post['type'] == 'quote' source = post['source'] actor = source.actor result.append({ 'type': 'quotes', 'source': { 'link': source.source_link, 'name': source.source_title, 'actor': { 'name': str(actor), 'title': source.actor_title or actor.title, 'photo': actor.photo, 'position_image': _get_position_image( source.position, 'img/actor-positive.png', 'img/actor-negative.png', 'img/actor-neutral.png', ), }, }, 'quotes': [{ 'text': quote.text, 'post': _get_post_context(post, user_votes, curator_votes), 'vote': { 'img': { 'top': 'img/thumb-up.png', 'bottom': 'img/thumb-down.png', }, }, 'arguments': [{ 'name': argument.title, 'classes': 'text-%s' % ('danger' if argument.position < 0 else 'success'), 'counterargument': { 'classes': 'glyphicon glyphicon-%s' % ('remove' if argument.counterargument else 'tag'), } } for argument in quote.postargument_set.order_by('pk')], } for post, quote in post['quotes']], }) return result