From 5f486bd28b049f173ecd3b13185012fb351ef59b Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 17 Aug 2012 10:56:17 -0400 Subject: limited shared with list on thread page --- askbot/models/question.py | 28 ++++++++++++++++ .../skins/default/templates/question/sidebar.html | 39 +++++++++++++++------- askbot/urls.py | 13 ++++++-- askbot/views/commands.py | 10 ++++++ askbot/views/readers.py | 14 ++++++++ 5 files changed, 90 insertions(+), 14 deletions(-) diff --git a/askbot/models/question.py b/askbot/models/question.py index ab3e6959..bff4bc11 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -497,6 +497,34 @@ class Thread(models.Model): else: return self.get_answers(user).count() + def get_sharing_info(self): + """returns shared with user and group count""" + groups = self.groups + ugroups = groups.filter(name__startswith='_internal_') + ggroups = groups.exclude(name__startswith='_internal_') + return ugroups.count(), ggroups.count() + + def get_users_shared_with(self, max_count=None, exclude_user=None): + """returns query set of users with whom + this thread is shared + """ + groups = self.groups.filter(name__startswith='_internal_') + + if exclude_user: + groups = groups.exclude(created_by__id=exclude_user.id) + + user_ids = groups.values_list('created_by__id', flat=True) + if max_count: + user_ids = user_ids[:max_count] + return User.objects.filter(id__in=user_ids) + + def get_groups_shared_with(self, max_count=None): + """returns query set of groups with whom thread is shared""" + groups = self.groups.exclude(name__startswith='_internal_') + if max_count: + groups = groups[:max_count] + return groups + def update_favorite_count(self): self.favourite_count = FavoriteQuestion.objects.filter(thread=self).count() self.save() diff --git a/askbot/skins/default/templates/question/sidebar.html b/askbot/skins/default/templates/question/sidebar.html index ef99e988..837dfbe2 100644 --- a/askbot/skins/default/templates/question/sidebar.html +++ b/askbot/skins/default/templates/question/sidebar.html @@ -53,28 +53,43 @@ {% if thread.is_private() %}

{% trans %}Share{% endtrans %}

-

{% trans %}Yourself{% endtrans %}

- {% for group in thread.groups.all() %} - {% if group.name.startswith('_internal_') %} -

{{ group.created_by.get_profile_link() }}

- {% endif %} +

+ + {% trans %}You{% endtrans %} + +

+ {% for user in sharing_info['users'] %} +

{{ user.get_profile_link() }}

{% endfor %} + {% if sharing_info['more_users_count'] > 0 %} +

{% trans more_count=sharing_info['more_users_count'] %}... and {{ more_count }} more{% endtrans %} +

+ {% endif %}
{% csrf_token %}
- {#% if thread.groups.count() %} + {% if sharing_info['groups'].count() > 0 %} {% else %} - {% endif %#} - - {% for group in thread.groups.all() %} - {% if not group.name.startswith('_internal_') %}{# todo: fix this hack #} -

{{ macros.user_group(group) }}

- {% endif %} + {% endif %} + {% for group in sharing_info['groups'] %} +

{{ macros.user_group(group) }}

{% endfor %} + {% if sharing_info['more_groups_count'] > 0 %} +

{% trans more_count=sharing_info['more_groups_count'] %}... and {{ more_count }} more{% endtrans %} +

+ {% endif %}
{% csrf_token %} diff --git a/askbot/urls.py b/askbot/urls.py index f4576465..abadcfe9 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -72,11 +72,20 @@ urlpatterns = patterns('', ), # END main page urls - url( r'^api/get_questions/', views.commands.api_get_questions, - name = 'api_get_questions' + name='api_get_questions' + ), + url( + r'^get-thread-shared-users/', + views.commands.get_thread_shared_users, + name='get_thread_shared_users' + ), + url( + r'^get-thread-shared-groups/', + views.commands.get_thread_shared_groups, + name='get_thread_shared_groups' ), url( r'^save-draft-question/', diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 1b6b21e8..123fc112 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -475,6 +475,16 @@ def get_tags_by_wildcard(request): re_data = simplejson.dumps({'tag_count': count, 'tag_names': list(names)}) return HttpResponse(re_data, mimetype = 'application/json') +@decorators.ajax_only +@decorators.get_only +def get_thread_shared_users(request): + pass + +@decorators.ajax_only +@decorators.get_only +def get_thread_shared_groups(request): + pass + @decorators.ajax_only def get_html_template(request): """returns rendered template""" diff --git a/askbot/views/readers.py b/askbot/views/readers.py index 578e4ad8..a94ccc2d 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -565,6 +565,19 @@ def question(request, id):#refactor - long subroutine. display question body, an previous_answer = answer break + #shared with ... + users_count, groups_count = thread.get_sharing_info() + shared_users = thread.get_users_shared_with( + max_count=3, + exclude_user=request.user + ) + sharing_info = { + 'users': shared_users, + 'groups': thread.get_groups_shared_with(max_count=3), + 'more_users_count': max(0, users_count - 3), + 'more_groups_count': max(0, groups_count - 3) + } + data = { 'is_cacheable': False,#is_cacheable, #temporary, until invalidation fix 'long_time': const.LONG_TIME,#"forever" caching @@ -586,6 +599,7 @@ def question(request, id):#refactor - long subroutine. display question body, an 'similar_threads' : thread.get_similar_threads(), 'language_code': translation.get_language(), 'paginator_context' : paginator_context, + 'sharing_info': sharing_info, 'show_post': show_post, 'show_comment': show_comment, 'show_comment_position': show_comment_position, -- cgit v1.2.3-1-g7c22 From c10a87ecabd0a8e36b7eb2801ec0d23051c5e9d1 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 17 Aug 2012 11:10:53 -0400 Subject: fixed migration 135 --- askbot/migrations/0135_auto__add_askwidget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/askbot/migrations/0135_auto__add_askwidget.py b/askbot/migrations/0135_auto__add_askwidget.py index ebf6f717..0764e11d 100644 --- a/askbot/migrations/0135_auto__add_askwidget.py +++ b/askbot/migrations/0135_auto__add_askwidget.py @@ -77,7 +77,7 @@ class Migration(SchemaMigration): }, 'askbot.askwidget': { 'Meta': {'object_name': 'AskWidget'}, - 'default_group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Tag']", 'null': 'True', 'blank': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Tag']", 'null': 'True', 'blank': 'True'}), 'group': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'groups'", 'null': 'True', 'to': "orm['askbot.Tag']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'inner_style': ('django.db.models.fields.TextField', [], {'default': "''"}), -- cgit v1.2.3-1-g7c22 From 8b41842bfc6461a8b2f9b6bc9d80a3a82d54e81d Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 17 Aug 2012 11:18:20 -0400 Subject: fixed shared with user count --- askbot/views/readers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/askbot/views/readers.py b/askbot/views/readers.py index a94ccc2d..268227eb 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -568,12 +568,12 @@ def question(request, id):#refactor - long subroutine. display question body, an #shared with ... users_count, groups_count = thread.get_sharing_info() shared_users = thread.get_users_shared_with( - max_count=3, + max_count=2, exclude_user=request.user ) sharing_info = { 'users': shared_users, - 'groups': thread.get_groups_shared_with(max_count=3), + 'groups': thread.get_groups_shared_with(max_count=2), 'more_users_count': max(0, users_count - 3), 'more_groups_count': max(0, groups_count - 3) } -- cgit v1.2.3-1-g7c22