summaryrefslogtreecommitdiffstats
path: root/askbot
diff options
context:
space:
mode:
Diffstat (limited to 'askbot')
-rw-r--r--askbot/models/question.py28
-rw-r--r--askbot/skins/default/templates/question/sidebar.html39
-rw-r--r--askbot/urls.py13
-rw-r--r--askbot/views/commands.py10
-rw-r--r--askbot/views/readers.py14
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() %}
<h2>{% trans %}Share{% endtrans %}</h2>
<label for="share_user_name">{% trans %}Share with users{% endtrans %}</label>
- <p>{% trans %}Yourself{% endtrans %}</p>
- {% for group in thread.groups.all() %}
- {% if group.name.startswith('_internal_') %}
- <p>{{ group.created_by.get_profile_link() }}<p>
- {% endif %}
+ <p>
+ <a href="{{ request.user.get_profile_url() }}">
+ {% trans %}You{% endtrans %}
+ </a>
+ </p>
+ {% for user in sharing_info['users'] %}
+ <p>{{ user.get_profile_link() }}<p>
{% endfor %}
+ {% if sharing_info['more_users_count'] > 0 %}
+ <p><a
+ class="see-related-users"
+ data-url="{% url get_thread_shared_users %}"
+ data-thread-id="{{ thread.id }}"
+ >{% trans more_count=sharing_info['more_users_count'] %}... and {{ more_count }} more{% endtrans %}
+ </a></p>
+ {% endif %}
<form action="{% url share_question_with_user %}" method="post">{% csrf_token %}
<input id="share_user_name" type="text" class="groups-input" name="recipient_name" />
<input type="hidden" name="thread_id" value="{{ thread.id }}"/>
<input type="submit" class="add-groups" value="{% trans %}add{% endtrans %}"/>
</form>
- {#% if thread.groups.count() %}
+ {% if sharing_info['groups'].count() > 0 %}
<label for="group_name">{% trans %}Shared with groups:{% endtrans %}</label>
{% else %}
<label for="group_name">{% trans %}Share with a group{% endtrans %}</label>
- {% endif %#}
- <label for="share_group_name">{% trans %}Share with groups{% endtrans %}</label>
- {% for group in thread.groups.all() %}
- {% if not group.name.startswith('_internal_') %}{# todo: fix this hack #}
- <p>{{ macros.user_group(group) }}</p>
- {% endif %}
+ {% endif %}
+ {% for group in sharing_info['groups'] %}
+ <p>{{ macros.user_group(group) }}</p>
{% endfor %}
+ {% if sharing_info['more_groups_count'] > 0 %}
+ <p><a
+ class="see-related-groups"
+ data-url="{% url get_thread_shared_groups %}"
+ data-thread-id="{{ thread.id }}"
+ >{% trans more_count=sharing_info['more_groups_count'] %}... and {{ more_count }} more{% endtrans %}
+ </a></p>
+ {% endif %}
<form action="{% url share_question_with_group %}" method="post">{% csrf_token %}
<input id="share_group_name" type="text" class="groups-input" name="recipient_name" />
<input type="hidden" name="thread_id" value="{{ thread.id }}"/>
diff --git a/askbot/urls.py b/askbot/urls.py
index f6499845..4fe999da 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
@@ -476,6 +476,16 @@ def get_tags_by_wildcard(request):
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"""
template_name = request.REQUEST.get('template_name', None)
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,