summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrei <andrei@u15356270.onlinehome-server.com>2011-02-28 06:41:05 -0500
committerandrei <andrei@u15356270.onlinehome-server.com>2011-02-28 06:41:05 -0500
commit6cd71c8523ea8a24c4e05e079987c4e6883c82a1 (patch)
treed20b6ea030e9b041c7e18529ebea9ad45fd30c0f
parent71b69217cd03e0cb4a971bf28216982761308357 (diff)
downloadaskbot-6cd71c8523ea8a24c4e05e079987c4e6883c82a1.tar.gz
askbot-6cd71c8523ea8a24c4e05e079987c4e6883c82a1.tar.bz2
askbot-6cd71c8523ea8a24c4e05e079987c4e6883c82a1.zip
finished tag subscription feature
-rw-r--r--askbot/deps/django_authopenid/views.py7
-rw-r--r--askbot/models/__init__.py66
-rwxr-xr-xaskbot/skins/default/media/style/style.css2
-rw-r--r--askbot/skins/default/templates/subscribe_for_tags.html19
-rw-r--r--askbot/urls.py5
-rw-r--r--askbot/views/commands.py78
6 files changed, 128 insertions, 49 deletions
diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py
index b4bd14fc..f29c5b75 100644
--- a/askbot/deps/django_authopenid/views.py
+++ b/askbot/deps/django_authopenid/views.py
@@ -89,7 +89,12 @@ def login(request,user):
#5) send signal with old session key as argument
logging.debug('logged in user %s with session key %s' % (user.username, session_key))
#todo: move to auth app
- signals.user_logged_in.send(user=user,session_key=session_key,sender=None)
+ signals.user_logged_in.send(
+ request = request,
+ user = user,
+ session_key=session_key,
+ sender=None
+ )
#todo: uncouple this from askbot
def logout(request):
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 701626f9..60d0e380 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -835,17 +835,46 @@ def user_post_comment(
)
return comment
+def user_mark_tags(self, tagnames, wildcards, reason = None, action = None):
+ """subscribe for or ignore a list of tags"""
+ cleaned_wildcards = list()
+ if wildcards:
+ cleaned_wildcards = self.update_wildcard_tag_selections(
+ action = action,
+ reason = reason,
+ wildcards = wildcards
+ )
-def user_mark_tag(self, tag_name = None, reason = None):
- """reason is either "bad" or "good"
- marks the tag
- """
- tag = models.Tag.objects.get(name = tag_name)
- models.MarkedTag(
- tag = tag,
- user = self,
- reason = reason
- ).save()
+ #below we update normal tag selections
+ marked_ts = MarkedTag.objects.filter(
+ user = self,
+ tag__name__in = tagnames
+ )
+ #todo: use the user api methods here instead of the straight ORM
+ cleaned_tagnames = list() #those that were actually updated
+ if action == 'remove':
+ logging.debug('deleting tag marks: %s' % ','.join(tagnames))
+ marked_ts.delete()
+ else:
+ marked_names = marked_ts.values_list('tag__name', flat = True)
+ if len(marked_names) < len(tagnames):
+ unmarked_names = set(tagnames).difference(set(marked_names))
+ ts = Tag.objects.filter(name__in = unmarked_names)
+ new_marks = list()
+ for tag in ts:
+ MarkedTag(
+ user = self,
+ reason = reason,
+ tag = tag
+ ).save()
+ new_marks.append(tag.name)
+ cleaned_tagnames.extend(marked_names)
+ cleaned_tagnames.extend(new_marks)
+ else:
+ marked_ts.update(reason=reason)
+ cleaned_tagnames = tagnames
+
+ return cleaned_tagnames, cleaned_wildcards
@auto_now_timestamp
def user_retag_question(
@@ -1769,6 +1798,7 @@ User.add_to_class('delete_messages', delete_messages)
User.add_to_class('toggle_favorite_question', toggle_favorite_question)
User.add_to_class('follow_question', user_follow_question)
User.add_to_class('unfollow_question', user_unfollow_question)
+User.add_to_class('mark_tags', user_mark_tags)
User.add_to_class('is_following', user_is_following)
User.add_to_class('decrement_response_count', user_decrement_response_count)
User.add_to_class('increment_response_count', user_increment_response_count)
@@ -2258,8 +2288,23 @@ def record_user_full_updated(instance, **kwargs):
)
activity.save()
+def complete_pending_tag_subscriptions(sender, request, *args, **kwargs):
+ """save pending tag subscriptions saved in the session"""
+ if 'subscribe_for_tags' in request.session:
+ (pure_tag_names, wildcards) = request.session.pop('subscribe_for_tags')
+ request.user.mark_tags(
+ pure_tag_names,
+ wildcards,
+ reason = 'good',
+ action = 'add'
+ )
+ request.user.message_set.create(
+ message = _('Your tag subscription was saved, thanks!')
+ )
+
def post_stored_anonymous_content(
sender,
+ request,
user,
session_key,
signal,
@@ -2327,6 +2372,7 @@ signals.flag_offensive.connect(record_flag_offensive, sender=Answer)
signals.tags_updated.connect(record_update_tags)
signals.user_updated.connect(record_user_full_updated, sender=User)
signals.user_logged_in.connect(post_stored_anonymous_content)
+signals.user_logged_in.connect(complete_pending_tag_subscriptions)
signals.post_updated.connect(
record_post_update_activity,
sender=Comment
diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css
index bcaad532..6f745357 100755
--- a/askbot/skins/default/media/style/style.css
+++ b/askbot/skins/default/media/style/style.css
@@ -36,9 +36,9 @@ input, select {
}
p {
- margin-bottom: 13px;
font-size: 14px;
line-height: 140%;
+ margin-bottom: 6px;
padding-left: 5px;
}
diff --git a/askbot/skins/default/templates/subscribe_for_tags.html b/askbot/skins/default/templates/subscribe_for_tags.html
new file mode 100644
index 00000000..9a58ccbf
--- /dev/null
+++ b/askbot/skins/default/templates/subscribe_for_tags.html
@@ -0,0 +1,19 @@
+{% extends "two_column_body.html" %}
+{% import "macros.html" as macros %}
+{% block title %}{% trans %}Subscribe for tags{% endtrans %}{% endblock %}
+{% block content %}
+<h1>{% trans %}Subscribe for tags{% endtrans %}</h1>
+<p>{% trans %}Please, subscribe for the following tags:{% endtrans %}</p>
+<ul class="tags" style="margin-left: 4px">
+ {% for tag in tags %}
+ {{ macros.tag_widget(tag, html_tag = 'li', is_link = False) }}
+ {% endfor %}
+</ul>
+<div style="clear:both;padding-top: 5px">
+ <form method="post" action="{% url subscribe_for_tags %}">
+ <input type="hidden" name="tags" value="{{tags|join(' ')|escape}}" />
+ <input type="submit" name="ok" value="{% trans %}Subscribe{% endtrans %}" />
+ <input type="submit" name="nope" value="{% trans %}Cancel{% endtrans %}" />
+ </form>
+</div>
+{% endblock %}
diff --git a/askbot/urls.py b/askbot/urls.py
index 56841cdc..4ebec8c7 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -162,6 +162,11 @@ urlpatterns = patterns('',
name = 'get_tags_by_wildcard'
),
url(
+ r'^%s$' % _('subscribe-for-tags/'),
+ views.commands.subscribe_for_tags,
+ name = 'subscribe_for_tags'
+ ),
+ url(
r'^%s$' % _('users/'),
views.users.users,
name='users'
diff --git a/askbot/views/commands.py b/askbot/views/commands.py
index c0637a71..571f97d1 100644
--- a/askbot/views/commands.py
+++ b/askbot/views/commands.py
@@ -334,44 +334,14 @@ def mark_tag(request, **kwargs):#tagging system
raw_tagnames = post_data['tagnames']
reason = kwargs.get('reason', None)
#separate plain tag names and wildcard tags
- tagnames, wildcards = forms.clean_marked_tagnames(raw_tagnames)
- cleaned_wildcards = list()
- if wildcards:
- cleaned_wildcards = request.user.update_wildcard_tag_selections(
- action = action,
- reason = reason,
- wildcards = wildcards
- )
-
- #below we update normal tag selections
- marked_ts = models.MarkedTag.objects.filter(
- user=request.user,
- tag__name__in=tagnames
- )
- #todo: use the user api methods here instead of the straight ORM
- cleaned_tagnames = list() #those that were actually updated
- if action == 'remove':
- logging.debug('deleting tag marks: %s' % ','.join(tagnames))
- marked_ts.delete()
- else:
- marked_names = marked_ts.values_list('tag__name', flat = True)
- if len(marked_names) < len(tagnames):
- unmarked_names = set(tagnames).difference(set(marked_names))
- ts = models.Tag.objects.filter(name__in = unmarked_names)
- new_marks = list()
- for tag in ts:
- models.MarkedTag(
- user=request.user,
- reason=reason,
- tag=tag
- ).save()
- new_marks.append(tag.name)
- cleaned_tagnames.extend(marked_names)
- cleaned_tagnames.extend(new_marks)
- else:
- marked_ts.update(reason=reason)
- cleaned_tagnames = tagnames
+ tagnames, wildcards = forms.clean_marked_tagnames(raw_tagnames)
+ cleaned_tagnames, cleaned_wildcards = request.user.mark_tags(
+ tagnames,
+ wildcards,
+ reason = reason,
+ action = action
+ )
#lastly - calculate tag usage counts
tag_usage_counts = dict()
@@ -406,6 +376,40 @@ def get_tags_by_wildcard(request):
return HttpResponse(re_data, mimetype = 'application/json')
+def subscribe_for_tags(request):
+ """process subscription of users by tags"""
+ tag_names = request.REQUEST['tags'].strip().split()
+ pure_tag_names, wildcards = forms.clean_marked_tagnames(tag_names)
+ if request.user.is_authenticated():
+ if request.method == 'POST':
+ if 'ok' in request.POST:
+ request.user.mark_tags(
+ pure_tag_names,
+ wildcards,
+ reason = 'good',
+ action = 'add'
+ )
+ request.user.message_set.create(
+ message = _('Your tag subscription was saved, thanks!')
+ )
+ else:
+ message = _(
+ 'Tag subscription was canceled (<a href="%(url)s">undo</a>).'
+ ) % {'url': request.path + '?tags=' + request.REQUEST['tags']}
+ request.user.message_set.create(message = message)
+ return HttpResponseRedirect(reverse('index'))
+ else:
+ data = {'tags': tag_names}
+ return render_into_skin('subscribe_for_tags.html', data, request)
+ else:
+ all_tag_names = pure_tag_names + wildcards
+ message = _('Please sign in to subscribe for: %(tags)s') \
+ % {'tags': ', '.join(all_tag_names)}
+ request.user.message_set.create(message = message)
+ request.session['subscribe_for_tags'] = (pure_tag_names, wildcards)
+ return HttpResponseRedirect(reverse('user_signin'))
+
+
@decorators.ajax_login_required
def ajax_toggle_ignored_questions(request):#ajax tagging and tag-filtering system
if request.user.hide_ignored_questions: