How to use the spirit.user.models.UserProfile.objects.filter function in spirit

To help you get started, we’ve selected a few spirit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nitely / Spirit / spirit / user / tests.py View on Github external
form_data = {
            'username': 'UnIqUeFoO',
            'email': 'some@some.com',
            'email2': 'some@some.com',
            'password': 'pass'}
        response = self.client.post(
            reverse('spirit:user:auth:register'), form_data)
        expected_url = reverse('spirit:user:auth:login')
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertTrue(
            UserProfile.objects.filter(
                nickname='UnIqUeFoO',
                user__username='uniquefoo'
            ).exists())
        self.assertFalse(
            UserProfile.objects.filter(nickname='uniquefoo').exists())
github nitely / Spirit / spirit / user / tests.py View on Github external
def test_last_seen(self):
        """
        Should update user last_seen when threshold is reached
        """
        req = RequestFactory().get('/')
        req.user = self.user
        self.assertTrue(req.user.is_authenticated)
        delta = datetime.timedelta(
            seconds=settings.ST_USER_LAST_SEEN_THRESHOLD_MINUTES * 60 + 1)
        self.assertEqual(
            UserProfile.objects
                .filter(pk=req.user.st.pk)
                .update(last_seen=timezone.now() - delta), 1)
        # Some DBs don't save microseconds, so get the real value
        last_seen = UserProfile.objects.get(pk=req.user.st.pk).last_seen
        req.user.st.last_seen = last_seen
        self.assertIsNone(
            middleware.LastSeenMiddleware().process_request(req))
        self.assertGreater(
            UserProfile.objects.get(pk=req.user.st.pk).last_seen,
            last_seen)
github nitely / Spirit / spirit / user / tests.py View on Github external
def test_migration_profiles(self):
        """Should create profile for existing users"""
        foo = utils.create_user(username='foo')
        bar = utils.create_user(username='bar')
        UserProfile.objects.filter(user=foo).delete()
        UserProfile.objects.filter(user=bar).delete()
        foo = User.objects.get(pk=foo.pk)
        bar = User.objects.get(pk=bar.pk)
        with self.assertRaises(ObjectDoesNotExist):
            self.assertIsNone(foo.st)
        with self.assertRaises(ObjectDoesNotExist):
            self.assertIsNone(bar.st)
        data_migration_profiles.migrate_profiles(apps, None)
        self.assertTrue(User.objects.get(pk=foo.pk).st.is_verified)
        self.assertTrue(User.objects.get(pk=bar.pk).st.is_verified)
github nitely / Spirit / spirit / user / tests.py View on Github external
def test_profile_creation_on_register_case_insensitive_user(self):
        form_data = {
            'username': 'UnIqUeFoO',
            'email': 'some@some.com',
            'email2': 'some@some.com',
            'password': 'pass'}
        response = self.client.post(
            reverse('spirit:user:auth:register'), form_data)
        expected_url = reverse('spirit:user:auth:login')
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertTrue(
            UserProfile.objects.filter(
                nickname='UnIqUeFoO',
                user__username='uniquefoo'
            ).exists())
        self.assertFalse(
            UserProfile.objects.filter(nickname='uniquefoo').exists())
github nitely / Spirit / spirit / user / models.py View on Github external
def increase_received_likes_count(self):
        UserProfile.objects.filter(pk=self.pk).update(received_likes_count=F('received_likes_count') + 1)
github nitely / Spirit / spirit / user / models.py View on Github external
def increase_given_likes_count(self):
        UserProfile.objects.filter(pk=self.pk).update(given_likes_count=F('given_likes_count') + 1)
github nitely / Spirit / spirit / user / models.py View on Github external
def update_post_hash(self, post_hash):
        # Let the DB do the hash
        # comparison for atomicity
        return bool(
            UserProfile.objects
            .filter(pk=self.pk)
            .exclude(
                last_post_hash=post_hash,
                last_post_on__gte=timezone.now() - timedelta(
                    minutes=settings.ST_DOUBLE_POST_THRESHOLD_MINUTES))
            .update(
                last_post_hash=post_hash,
                last_post_on=timezone.now()))
github nitely / Spirit / spirit / user / models.py View on Github external
def increase_topic_count(self):
        UserProfile.objects.filter(pk=self.pk).update(topic_count=F('topic_count') + 1)
github nitely / Spirit / spirit / user / middleware.py View on Github external
def process_request(self, request):
        if not request.user.is_authenticated:
            return

        threshold = settings.ST_USER_LAST_SEEN_THRESHOLD_MINUTES * 60
        delta = timezone.now() - request.user.st.last_seen

        if delta.total_seconds() < threshold:
            return

        (UserProfile.objects
            .filter(pk=request.user.st.pk)
            .update(last_seen=timezone.now()))