From 7b360886823dd0665cf73e5f22ffc1c0a9b4bdd6 Mon Sep 17 00:00:00 2001 From: Adolfo Fitoria Date: Tue, 8 Jan 2013 12:29:53 -0600 Subject: added signal to add missing tag subscriptions to newly created users --- askbot/models/__init__.py | 13 +++++++++++++ askbot/views/commands.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index f8a25721..2915c0f3 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -3546,6 +3546,18 @@ def add_missing_subscriptions(sender, instance, created, **kwargs): if created: instance.add_missing_askbot_subscriptions() +def add_missing_tag_subscriptions(sender, instance, created, **kwargs): + '''``sender` is instance of `User``. When the user is created + it add the tag subscriptions to the user via BulkTagSubscription + and MarkedTags. + ''' + if created: + user_groups = instance.get_groups() + for subscription in BulkTagSubscription.objects.filter(groups__in = user_groups): + tag_list = subscription.tag_list() + instance.mark_tags(tagnames = tag_list, + reason='subscribed', action='add') + def post_anonymous_askbot_content( sender, request, @@ -3598,6 +3610,7 @@ django_signals.pre_save.connect(calculate_gravatar_hash, sender=User) django_signals.post_save.connect(add_missing_subscriptions, sender=User) django_signals.post_save.connect(add_user_to_global_group, sender=User) django_signals.post_save.connect(add_user_to_personal_group, sender=User) +django_signals.post_save.connect(add_missing_tag_subscriptions, sender=User) django_signals.post_save.connect(record_award_event, sender=Award) django_signals.post_save.connect(notify_award_message, sender=Award) django_signals.post_save.connect(record_answer_accepted, sender=Post) diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 34c7345d..0cf4cad2 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -748,7 +748,7 @@ def edit_bulk_tag_subscription(request, pk): if 'groups' in form.cleaned_data: group_ids = [user.id for user in form.cleaned_data['groups']] - bulk_subscription.groups.add(group_ids) + bulk_subscription.groups.add(*group_ids) tags, new_tag_names = get_tags_by_names(form.cleaned_data['tags'].split(' ')) tag_id_list = [tag.id for tag in tags] -- cgit v1.2.3-1-g7c22