Пример #1
0
    def test_unread_counter_new_thread2(self):
        thread = self.create_thread_for_user(self.sender, self.recipient)
        thread.mark_as_seen(self.recipient)
        counter = get_unread_inbox_counter(self.recipient)
        self.assertEqual(counter.count, 0)

        counter = get_unread_inbox_counter(self.sender)
        self.assertEqual(counter.count, 0)
Пример #2
0
    def test_unread_counter_new_thread2(self):
        thread = self.create_thread_for_user(self.sender, self.recipient)
        thread.mark_as_seen(self.recipient)
        counter = get_unread_inbox_counter(self.recipient)
        self.assertEqual(counter.count, 0)

        counter = get_unread_inbox_counter(self.sender)
        self.assertEqual(counter.count, 0)
Пример #3
0
    def test_unread_counter_new_thread1(self):
        counter = get_unread_inbox_counter(self.recipient)
        self.assertEqual(counter.count, 0)

        thread = self.create_thread_for_user(self.sender, self.recipient)
        counter = get_unread_inbox_counter(self.recipient)
        self.assertEqual(counter.count, 1)

        counter = get_unread_inbox_counter(self.sender)
        self.assertEqual(counter.count, 0)
Пример #4
0
    def test_unread_counter_new_thread1(self):
        counter = get_unread_inbox_counter(self.recipient)
        self.assertEqual(counter.count, 0)

        thread = self.create_thread_for_user(self.sender, self.recipient)
        counter = get_unread_inbox_counter(self.recipient)
        self.assertEqual(counter.count, 1)

        counter = get_unread_inbox_counter(self.sender)
        self.assertEqual(counter.count, 0)
Пример #5
0
    def prepare(self):

        #copy group memberships
        memberships = GroupMembership.objects.filter(user=self.from_user)
        for from_gm in memberships:
            to_gm = self.to_user.get_group_membership(from_gm.group)
            if to_gm:
                to_gm.level = max(to_gm.level, from_gm.level)
                to_gm.save()
                from_gm.delete()
            else:
                from_gm.user = self.to_user
                from_gm.save()

        #add inbox counters and delete dupes
        from_ctr = get_unread_inbox_counter(self.from_user)
        to_ctr = get_unread_inbox_counter(self.to_user)
        to_ctr.count += from_ctr.count
        to_ctr.save()
        from_ctr.delete()

        #delete subscriptions (todo: merge properly)
        self.from_user.notification_subscriptions.all().delete()

        #merge reputations
        localized_profiles = LocalizedUserProfile.objects.filter(
            accounts_user=self.from_user)
        for profile in localized_profiles:
            self.to_user.receive_reputation(profile.reputation,
                                            profile.language_code)
        #delete dupes of localized profiles
        localized_profiles.delete()

        #merge badges
        from_profile = self.from_user.askbot_profile
        self.to_user.gold += from_profile.gold
        self.to_user.silver += from_profile.silver
        self.to_user.bronze += from_profile.bronze

        #merge last seen dates
        if from_profile.last_seen > self.to_user.last_seen:
            self.to_user.last_seen = from_profile.last_seen

        #merge date joined dates
        if self.from_user.date_joined < self.to_user.date_joined:
            self.to_user.date_joined = self.from_user.date_joined

        self.to_user.askbot_profile.save()
        self.to_user.save()
        from_profile.delete()
Пример #6
0
    def prepare(self):

        #copy group memberships
        memberships = GroupMembership.objects.filter(user=self.from_user)
        for from_gm in memberships:
            to_gm = self.to_user.get_group_membership(from_gm.group)
            if to_gm:
                to_gm.level = max(to_gm.level, from_gm.level)
                to_gm.save()
                from_gm.delete()
            else:
                from_gm.user = self.to_user
                from_gm.save()

        #add inbox counters and delete dupes
        from_ctr = get_unread_inbox_counter(self.from_user)
        to_ctr = get_unread_inbox_counter(self.to_user)
        to_ctr.count += from_ctr.count
        to_ctr.save()
        from_ctr.delete()

        #delete subscriptions (todo: merge properly)
        self.from_user.notification_subscriptions.all().delete()

        #merge reputations
        localized_profiles = LocalizedUserProfile.objects.filter(auth_user=self.from_user)
        for profile in localized_profiles:
            self.to_user.receive_reputation(profile.reputation, profile.language_code)
        #delete dupes of localized profiles
        localized_profiles.delete()

        #merge badges
        from_profile = self.from_user.askbot_profile
        self.to_user.gold += from_profile.gold
        self.to_user.silver += from_profile.silver
        self.to_user.bronze += from_profile.bronze

        #merge last seen dates
        if from_profile.last_seen > self.to_user.last_seen:
            self.to_user.last_seen = from_profile.last_seen

        #merge date joined dates
        if self.from_user.date_joined < self.to_user.date_joined:
            self.to_user.date_joined = self.from_user.date_joined

        self.to_user.askbot_profile.save()
        self.to_user.save()
        from_profile.delete()
Пример #7
0
 def test_recalculate_unread_counter(self):
     thread = self.create_thread_for_user(self.sender, self.recipient)
     counter = get_unread_inbox_counter(self.recipient)
     counter.reset()
     self.assertEqual(counter.count, 0)
     counter.recalculate()
     self.assertEqual(counter.count, 1)
Пример #8
0
 def test_recalculate_unread_counter(self):
     thread = self.create_thread_for_user(self.sender, self.recipient)
     counter = get_unread_inbox_counter(self.recipient)
     counter.reset()
     self.assertEqual(counter.count, 0)
     counter.recalculate()
     self.assertEqual(counter.count, 1)
Пример #9
0
 def handle_noargs(self, *args, **kwargs):
     users = User.objects.all()
     count = users.count()
     message = 'Fixing inbox counts for the users'
     for user in ProgressBar(users.iterator(), count, message):
         counter = get_unread_inbox_counter(user)
         counter.recalculate()
         counter.save()
Пример #10
0
 def handle_noargs(self, *args, **kwargs):
     users = User.objects.all()
     count = users.count()
     message = 'Fixing inbox counts for the users'
     for user in ProgressBar(users.iterator(), count, message):
         counter = get_unread_inbox_counter(user)
         counter.recalculate()
         counter.save()
Пример #11
0
    def post(self, request, thread_id=None):
        """process the post request:
        * delete or restore thread
        * recalculate the threads list and return it for display
          by reusing the threads list "get" function
        """
        #part of the threads list context
        sender_id = IntegerField().clean(request.POST['sender_id'])

        #sender_id==-2 means deleted post
        if self.thread_action == 'delete':
            if sender_id == -2:
                action = 'delete'
            else:
                action = 'archive'
        else:
            action = 'restore'

        thread = Message.objects.get(id=thread_id)
        memo, created = MessageMemo.objects.get_or_create(
                                    user=request.user,
                                    message=thread
                                )

        if created and action == 'archive':
            #unfortunately we lose "unseen" status when archiving
            counter = get_unread_inbox_counter(request.user)
            counter.decrement()
            counter.save()

        if action == 'archive':
            memo.status = MessageMemo.ARCHIVED
        elif action == 'restore':
            memo.status = MessageMemo.SEEN
        else:
            memo.status = MessageMemo.DELETED
        memo.save()

        context = self.get_context(request)
        return self.render_to_response(Context(context))
Пример #12
0
    def post(self, request, thread_id=None):
        """process the post request:
        * delete or restore thread
        * recalculate the threads list and return it for display
          by reusing the threads list "get" function
        """
        #part of the threads list context
        sender_id = IntegerField().clean(request.POST['sender_id'])

        #sender_id==-2 means deleted post
        if self.thread_action == 'delete':
            if sender_id == -2:
                action = 'delete'
            else:
                action = 'archive'
        else:
            action = 'restore'

        thread = Message.objects.get(id=thread_id)
        memo, created = MessageMemo.objects.get_or_create(user=request.user,
                                                          message=thread)

        if created and action == 'archive':
            #unfortunately we lose "unseen" status when archiving
            counter = get_unread_inbox_counter(request.user)
            counter.decrement()
            counter.save()

        if action == 'archive':
            memo.status = MessageMemo.ARCHIVED
        elif action == 'restore':
            memo.status = MessageMemo.SEEN
        else:
            memo.status = MessageMemo.DELETED
        memo.save()

        context = self.get_context(request)
        return self.render_to_response(Context(context))
Пример #13
0
def group_messaging_context(request):
    if request.user.is_authenticated():
        count_record = get_unread_inbox_counter(request.user)
        return {'group_messaging_unread_inbox_count': count_record.count}
    return {}
Пример #14
0
def group_messaging_context(request):
    if request.user.is_authenticated():
        count_record = get_unread_inbox_counter(request.user)
        return {'group_messaging_unread_inbox_count': count_record.count}
    return {}
Пример #15
0
    def prepare(self):
        """Takes care of things that cannot be done automatically"""
        #copy group memberships
        memberships = GroupMembership.objects.filter(user=self.from_user)
        for from_gm in memberships:
            to_gm = self.to_user.get_group_membership(from_gm.group)
            if to_gm:
                to_gm.level = max(to_gm.level, from_gm.level)
                to_gm.save()
                from_gm.delete()
            else:
                from_gm.user = self.to_user
                from_gm.save()

        #move followers
        for follower in self.from_user.get_followers():
            follower.unfollow_user(self.from_user)
            if follower.pk != self.to_user.pk:
                if not follower.is_following(self.to_user):
                    follower.follow_user(self.to_user)

        #move followed users
        for followed in self.from_user.get_followed_users():
            self.from_user.unfollow_user(followed)
            if followed.pk != self.to_user.pk:
                if not self.to_user.is_following(followed):
                    self.to_user.follow_user(followed)

        #add inbox counters and delete dupes
        from_ctr = get_unread_inbox_counter(self.from_user)
        to_ctr = get_unread_inbox_counter(self.to_user)
        to_ctr.count += from_ctr.count
        to_ctr.save()
        from_ctr.delete()

        #delete subscriptions (todo: merge properly)
        self.from_user.notification_subscriptions.all().delete()

        #merge reputations
        localized_profiles = LocalizedUserProfile.objects.filter(
            auth_user=self.from_user)
        for profile in localized_profiles:
            self.to_user.receive_reputation(profile.reputation,
                                            profile.language_code)
        #delete dupes of localized profiles
        localized_profiles.delete()

        #merge items stored in the user.askbot_profile
        try:
            from_profile = self.from_user.askbot_profile
        except UserProfile.DoesNotExist:
            pass
        else:
            self.to_user.gold += from_profile.gold
            self.to_user.silver += from_profile.silver
            self.to_user.bronze += from_profile.bronze

            #merge last seen dates
            if from_profile.last_seen > self.to_user.last_seen:
                self.to_user.last_seen = from_profile.last_seen

            #merge date joined dates
            if self.from_user.date_joined < self.to_user.date_joined:
                self.to_user.date_joined = self.from_user.date_joined

            self.to_user.askbot_profile.save()
            self.to_user.save()
            from_profile.delete()