summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-08-08 14:20:25 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-08-08 14:20:25 -0400
commita5c8f27dee35d92b5f29cf3fe40286499a111c44 (patch)
treedc0d271629ecc365f5a3081bb36f20cbb2da716f
parente25543bb9e3342f157a32c781b6c0efeb8f182e3 (diff)
downloadaskbot-a5c8f27dee35d92b5f29cf3fe40286499a111c44.tar.gz
askbot-a5c8f27dee35d92b5f29cf3fe40286499a111c44.tar.bz2
askbot-a5c8f27dee35d92b5f29cf3fe40286499a111c44.zip
added share with people function
-rw-r--r--askbot/forms.py2
-rw-r--r--askbot/skins/common/media/js/post.js17
-rw-r--r--askbot/skins/default/media/style/style.less6
-rw-r--r--askbot/skins/default/templates/question/sidebar.html27
-rw-r--r--askbot/urls.py7
-rw-r--r--askbot/views/commands.py38
6 files changed, 78 insertions, 19 deletions
diff --git a/askbot/forms.py b/askbot/forms.py
index 7906a5e0..4a36b8ac 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -1536,4 +1536,4 @@ class ModerateTagForm(forms.Form):
class ShareQuestionForm(forms.Form):
thread_id = forms.IntegerField()
- group_name = forms.CharField()
+ recipient_name = forms.CharField()
diff --git a/askbot/skins/common/media/js/post.js b/askbot/skins/common/media/js/post.js
index c427334c..5f2484ee 100644
--- a/askbot/skins/common/media/js/post.js
+++ b/askbot/skins/common/media/js/post.js
@@ -3841,7 +3841,7 @@ $(document).ready(function() {
tip.decorate(proxyUserEmailInput);
}
//if groups are enabled - activate share functions
- var groupsInput = $('.share-with-group');
+ var groupsInput = $('#share_group_name');
if (groupsInput.length === 1) {
var groupsAc = new AutoCompleter({
url: askbot['urls']['getGroupsList'],
@@ -3852,7 +3852,20 @@ $(document).ready(function() {
maxCacheLength: 100,
delay: 10
});
- fakeUserAc.decorate(proxyUserNameInput);
+ groupsAc.decorate(groupsInput);
+ }
+ var usersInput = $('#share_user_name');
+ if (usersInput.length === 1) {
+ var usersAc = new AutoCompleter({
+ url: '/get-users-info/',
+ preloadData: true,
+ minChars: 1,
+ useCache: false,
+ matchInside: true,
+ maxCacheLength: 100,
+ delay: 10
+ });
+ usersAc.decorate(usersInput);
}
});
diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less
index 56461c1f..069c36e4 100644
--- a/askbot/skins/default/media/style/style.less
+++ b/askbot/skins/default/media/style/style.less
@@ -1437,7 +1437,8 @@ ul#related-tags li {
}
}
-.groups-input {
+.groups-input,
+.users-input {
width:152px;
padding-left:5px;
border:#c9c9b5 1px solid;
@@ -1445,7 +1446,8 @@ ul#related-tags li {
font-size: 14px;
}
-.add-groups {
+.add-groups,
+.add-users {
border:0;
font-weight:bold;
margin-top:-2px;
diff --git a/askbot/skins/default/templates/question/sidebar.html b/askbot/skins/default/templates/question/sidebar.html
index 7c7f7860..6c4643e9 100644
--- a/askbot/skins/default/templates/question/sidebar.html
+++ b/askbot/skins/default/templates/question/sidebar.html
@@ -52,16 +52,31 @@
<div class="box sharing-widget">
{% if thread.is_private() %}
<h2>{% trans %}Share{% endtrans %}</h2>
- {% if thread.groups.count() %}
- <label for="group_name">{% trans %}Shared with groups{% endtrans %}</label>
+ <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 %}
+ {% endfor %}
+ <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() %}
+ <label for="group_name">{% trans %}Shared with groups:{% endtrans %}</label>
{% else %}
- <label for="group_name">{% trans %}Share with group{% endtrans %}</label>
- {% endif %}
+ <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() %}
- <p>{{ macros.user_group(group) }}</p>
+ {% if not group.name.startswith('_internal_') %}{# todo: fix this hack #}
+ <p>{{ macros.user_group(group) }}</p>
+ {% endif %}
{% endfor %}
<form action="{% url share_question_with_group %}" method="post">{% csrf_token %}
- <input type="text" class="groups-input" name="group_name" />
+ <input id="share_group_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>
diff --git a/askbot/urls.py b/askbot/urls.py
index 703cdcbd..cee5752a 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -91,7 +91,12 @@ urlpatterns = patterns('',
url(
r'^share-question-with-group/',
views.commands.share_question_with_group,
- name = 'share_question_with_group'
+ name='share_question_with_group'
+ ),
+ url(
+ r'^share-question-with-user/',
+ views.commands.share_question_with_user,
+ name='share_question_with_user'
),
url(
r'^get-users-info/',
diff --git a/askbot/views/commands.py b/askbot/views/commands.py
index 4a5c2682..316895f7 100644
--- a/askbot/views/commands.py
+++ b/askbot/views/commands.py
@@ -1126,12 +1126,16 @@ def get_users_info(request):
"""retuns list of user names and email addresses
of "fake" users - so that admins can post on their
behalf"""
- user_info_list = models.User.objects.filter(
- is_fake=True
- ).values_list(
- 'username',
- 'email'
- )
+ #user_info_list = models.User.objects.filter(
+ # is_fake=True
+ # ).values_list(
+ # 'username',
+ # 'email'
+ # )
+ user_info_list = models.User.objects.values_list(
+ 'username',
+ 'email'
+ )
result_list = list()
for user_info in user_info_list:
@@ -1149,7 +1153,7 @@ def share_question_with_group(request):
if form.is_valid():
thread_id = form.cleaned_data['thread_id']
- group_name = form.cleaned_data['group_name']
+ group_name = form.cleaned_data['recipient_name']
thread = models.Thread.objects.get(id=thread_id)
if group_name == askbot_settings.GLOBAL_GROUP_NAME:
@@ -1163,3 +1167,23 @@ def share_question_with_group(request):
error_message = _('Sorry, looks like sharing request was invalid')
request.user.message_set.create(message=error_message)
return HttpResponseRedirect(thread.get_absolute_url())
+
+@csrf.csrf_protect
+def share_question_with_user(request):
+ form = forms.ShareQuestionForm(request.POST)
+ try:
+ if form.is_valid():
+
+ thread_id = form.cleaned_data['thread_id']
+ username = form.cleaned_data['recipient_name']
+
+ thread = models.Thread.objects.get(id=thread_id)
+ user = models.User.objects.get(username=username)
+ group = user.get_personal_group()
+ thread.add_to_groups([group], recursive=True)
+
+ return HttpResponseRedirect(thread.get_absolute_url())
+ except Exception:
+ error_message = _('Sorry, looks like sharing request was invalid')
+ request.user.message_set.create(message=error_message)
+ return HttpResponseRedirect(thread.get_absolute_url())